https://casaguides.nrao.edu/api.php?action=feedcontributions&user=Tashton&feedformat=atomCASA Guides - User contributions [en]2024-03-29T06:19:09ZUser contributionsMediaWiki 1.38.6https://casaguides.nrao.edu/index.php?title=Guide_to_the_NA_Imaging_Template&diff=36659Guide to the NA Imaging Template2024-02-28T20:55:50Z<p>Tashton: /* Guide Contents */</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 />
The older CASA 6.1 versions of these guides are available at the following links:<br />
#'''[[Imaging Prep CASA 6.1.1]]'''<br />
#'''[[Image Continuum CASA 6.1.1]]'''<br />
#'''[[Self-Calibration Template CASA 6.1.1]]'''<br />
#'''[[Image Line CASA 6.1.1]]'''<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>Tashtonhttps://casaguides.nrao.edu/index.php?title=Self-Calibration_Template_6.1.1&diff=36658Self-Calibration Template 6.1.12024-02-28T20:54:29Z<p>Tashton: Tashton moved page Self-Calibration Template 6.1.1 to Self-Calibration Template CASA 6.1.1</p>
<hr />
<div>#REDIRECT [[Self-Calibration Template CASA 6.1.1]]</div>Tashtonhttps://casaguides.nrao.edu/index.php?title=Self-Calibration_Template_CASA_6.1.1&diff=36657Self-Calibration Template CASA 6.1.12024-02-28T20:54:24Z<p>Tashton: Tashton moved page Self-Calibration Template 6.1.1 to Self-Calibration Template CASA 6.1.1</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,otf=True,scr=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 />
usepointing=False)<br />
<br />
# Note number of iterations performed.<br />
<br />
</source><br />
<br />
Before proceeding, make sure that {{tclean}} has saved the model column. You should see a message like the following <br />
<pre style="background-color: #E0FFFF;"><br />
>>> INFO .... ------ Predict Model ------<br />
>>> INFO ... Saving model column<br />
</pre><br />
If you don't see this message, you should repeat the above {{tclean}} command with the following modifications. This will populate the model column.<br />
<pre style="background-color: #E0FFFF;"><br />
niter=0<br />
calcpsf=False<br />
calcres=False<br />
</pre><br />
As you continue with the self-cal, always make sure the model column is saved after running {{tclean}}.<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 />
<br />
[[File:Plotcal_image.png|thumb|Figure 1: Solutions from the first round of self-cal.]]<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 />
plotms(caltable='pcal1',<br />
xaxis='time',<br />
yaxis='phase',<br />
iteration='antenna',<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 />
<br />
[[File:Pcal1.png|thumb|Figure 2: Continuum image after the first round of self-cal.]]<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 />
usepointing=False)<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 />
plotms(caltable='pcal2',<br />
xaxis='time',<br />
yaxis='phase',<br />
iteration='antenna',<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 />
usepointing=False)<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 />
plotms(caltable='pcal3',<br />
xaxis='time',<br />
yaxis='phase',<br />
iteration='antenna',<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 />
usepointing=False)<br />
<br />
# Note number of iterations performed.<br />
</source><br />
[[File:Imaging-tutorial-selfcal-3.png|thumb|Figure 3: Amplitude based residuals after phase self-cal.]]<br />
[[File:Apcal.png|thumb|Figure 4: Image after amplitude self-cal.]]<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 />
plotms(caltable='apcal',<br />
xaxis='time',<br />
yaxis='amp',<br />
iteration='antenna',<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 />
usepointing=False)<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>Tashtonhttps://casaguides.nrao.edu/index.php?title=Imaging_Prep&diff=36656Imaging Prep2024-02-28T20:48:49Z<p>Tashton: Changing main page to a redirect to the guide for the current version of CASA</p>
<hr />
<div>#REDIRECT [[Imaging Prep CASA 6.5.4]]</div>Tashtonhttps://casaguides.nrao.edu/index.php?title=Guide_to_the_NA_Imaging_Template&diff=36655Guide to the NA Imaging Template2024-02-28T20:38:26Z<p>Tashton: /* Guide Contents */</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>Tashtonhttps://casaguides.nrao.edu/index.php?title=Guide_to_the_NA_Imaging_Template&diff=36654Guide to the NA Imaging Template2024-02-28T20:37:47Z<p>Tashton: /* Guide Contents */</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_CASA_6.5.4 | 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_CASA_6.5.4 | 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_CASA_6.5.4 | 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>Tashtonhttps://casaguides.nrao.edu/index.php?title=Image_Line&diff=36652Image Line2024-02-28T20:37:03Z<p>Tashton: Changed redirect target from Image Line CASA 6.1.1 to Image Line CASA 6.5.4</p>
<hr />
<div>#REDIRECT [[Image Line CASA 6.5.4]]</div>Tashtonhttps://casaguides.nrao.edu/index.php?title=Image_Line&diff=36651Image Line2024-02-28T20:36:50Z<p>Tashton: Tashton moved page Image Line to Image Line CASA 6.1.1</p>
<hr />
<div>#REDIRECT [[Image Line CASA 6.1.1]]</div>Tashtonhttps://casaguides.nrao.edu/index.php?title=Image_Line_CASA_6.1.1&diff=36650Image Line CASA 6.1.12024-02-28T20:36:46Z<p>Tashton: Tashton moved page Image Line to Image Line CASA 6.1.1</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:0~1200;1500~3839,3:0~1200;1500~3839' # 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 />
[[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 />
<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/kb/articles/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='lsrk' # 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 />
[[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 />
<source lang="python"><br />
# in CASA<br />
plotms(vis=linevis,xaxis='velocity',yaxis='amp',avgtime='1e8',avgscan=True,avgantenna=True,<br />
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 />
# perchanweightdensity=False # uncomment if you are running in CASA >=5.5.0<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 />
usepointing=False)<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 />
[[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 />
[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>Tashtonhttps://casaguides.nrao.edu/index.php?title=Self-Calibration_Template&diff=36649Self-Calibration Template2024-02-28T20:35:57Z<p>Tashton: Changed redirect target from Self-Calibration Template 6.5.4 to Self-Calibration Template CASA 6.5.4</p>
<hr />
<div>#REDIRECT [[Self-Calibration Template CASA 6.5.4]]</div>Tashtonhttps://casaguides.nrao.edu/index.php?title=Self-Calibration_Template&diff=36648Self-Calibration Template2024-02-28T20:35:30Z<p>Tashton: Changed redirect target from Self-Calibration Template 6.1.1 to Self-Calibration Template 6.5.4</p>
<hr />
<div>#REDIRECT [[Self-Calibration Template 6.5.4]]</div>Tashtonhttps://casaguides.nrao.edu/index.php?title=Self-Calibration_Template&diff=36647Self-Calibration Template2024-02-28T20:35:18Z<p>Tashton: Tashton moved page Self-Calibration Template to Self-Calibration Template 6.1.1</p>
<hr />
<div>#REDIRECT [[Self-Calibration Template 6.1.1]]</div>Tashtonhttps://casaguides.nrao.edu/index.php?title=Self-Calibration_Template_CASA_6.1.1&diff=36646Self-Calibration Template CASA 6.1.12024-02-28T20:35:14Z<p>Tashton: Tashton moved page Self-Calibration Template to Self-Calibration Template 6.1.1</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,otf=True,scr=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 />
usepointing=False)<br />
<br />
# Note number of iterations performed.<br />
<br />
</source><br />
<br />
Before proceeding, make sure that {{tclean}} has saved the model column. You should see a message like the following <br />
<pre style="background-color: #E0FFFF;"><br />
>>> INFO .... ------ Predict Model ------<br />
>>> INFO ... Saving model column<br />
</pre><br />
If you don't see this message, you should repeat the above {{tclean}} command with the following modifications. This will populate the model column.<br />
<pre style="background-color: #E0FFFF;"><br />
niter=0<br />
calcpsf=False<br />
calcres=False<br />
</pre><br />
As you continue with the self-cal, always make sure the model column is saved after running {{tclean}}.<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 />
<br />
[[File:Plotcal_image.png|thumb|Figure 1: Solutions from the first round of self-cal.]]<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 />
plotms(caltable='pcal1',<br />
xaxis='time',<br />
yaxis='phase',<br />
iteration='antenna',<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 />
<br />
[[File:Pcal1.png|thumb|Figure 2: Continuum image after the first round of self-cal.]]<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 />
usepointing=False)<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 />
plotms(caltable='pcal2',<br />
xaxis='time',<br />
yaxis='phase',<br />
iteration='antenna',<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 />
usepointing=False)<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 />
plotms(caltable='pcal3',<br />
xaxis='time',<br />
yaxis='phase',<br />
iteration='antenna',<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 />
usepointing=False)<br />
<br />
# Note number of iterations performed.<br />
</source><br />
[[File:Imaging-tutorial-selfcal-3.png|thumb|Figure 3: Amplitude based residuals after phase self-cal.]]<br />
[[File:Apcal.png|thumb|Figure 4: Image after amplitude self-cal.]]<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 />
plotms(caltable='apcal',<br />
xaxis='time',<br />
yaxis='amp',<br />
iteration='antenna',<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 />
usepointing=False)<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>Tashtonhttps://casaguides.nrao.edu/index.php?title=Image_Continuum&diff=36645Image Continuum2024-02-28T20:34:18Z<p>Tashton: Changed redirect target from Image Continuum CASA 6.1.1 to Image Continuum CASA 6.5.4</p>
<hr />
<div>#REDIRECT [[Image Continuum CASA 6.5.4]]</div>Tashtonhttps://casaguides.nrao.edu/index.php?title=Image_Continuum&diff=36644Image Continuum2024-02-28T20:34:02Z<p>Tashton: Tashton moved page Image Continuum to Image Continuum CASA 6.1.1</p>
<hr />
<div>#REDIRECT [[Image Continuum CASA 6.1.1]]</div>Tashtonhttps://casaguides.nrao.edu/index.php?title=Image_Continuum_CASA_6.1.1&diff=36643Image Continuum CASA 6.1.12024-02-28T20:33:56Z<p>Tashton: Tashton moved page Image Continuum to Image Continuum CASA 6.1.1</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 6.1.1.15 and greater. The following code checks the version of CASA and exits if it is less than 6.1.1.15. 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 />
try:<br />
import casalith<br />
except:<br />
print("Script requires CASA 6.0 or greater")<br />
<br />
if casalith.compare_version("<",[6,1,1,15]):<br />
print("Please use CASA version greater than or equal to 6.1.1-15 with this script")<br />
</source><br />
<br />
== Create an Averaged Continuum MS ==<br />
[[File:Calibrated_final_Field0_Spw0.png|thumb|Figure 1: spw 0]]<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 />
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 />
finalvis='calibrated_final.ms' # This is your output ms from the data<br />
# preparation script.<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', # velocity reference frame. See science goals<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 />
[[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 />
<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 />
[[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 />
<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 />
[[File:Amp_vs_uvdist.png|thumb|Figure 5: Amplitude vs UVDistance plot of the continuum, colored by spw.]]<br />
<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 />
<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 />
<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 />
<br />
[[File:Antennae_Antennae_North.Cont.Dirty.image.png|thumb|Figure 7]]<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 />
<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/kb/articles/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='lsrk' # 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 [https://casadocs.readthedocs.io/en/stable/notebooks/memo-series.html?highlight=briggs#Dan-Briggs'-Dissertation---Robust-Weighting 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 />
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 />
[[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 />
[[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 />
[[File:Final_Cont_residual.png|thumb|Figure 11: The final residual image.]]<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 automatically.<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 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. Use if fractional bandwidth is >10%.<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 />
usepointing=False)<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>Tashtonhttps://casaguides.nrao.edu/index.php?title=Imaging_Prep_CASA_6.1.1&diff=36642Imaging Prep CASA 6.1.12024-02-28T20:28:42Z<p>Tashton: Created page with "== Imaging Prep Workflow == Commands for this page can be found in scriptForImagingPrep_template.py available on [https://github.com/aakepley/ALMAImagingScript github]. 1200px ''Use the Imaging Prep workflow to determine which sections of this guide are applicable to your dataset.'' == Splitting off the calibrated data (Pipeline Calibration) == If your measurement set (ms) is pipeline calibrated, use this step to split off th..."</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 />
<br />
[[File:Weblog_Home.png|thumb|Figure 1: The Observation Overview page is opened with index.html.]]<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 />
<br />
[[File:Weblog_MS_Overview.png|thumb|Figure 2: The MS Overview gives information specific to each execution.]]<br />
<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 />
<br />
[[File:Weblog_By_Task.png|thumb|Figure 3: The weblog By Task view shows an overview of QA scores.]]<br />
<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 />
input("push enter to continue")<br />
plotms(vis=vis,xaxis='chan',yaxis='amp',avgtime='3e8',<br />
field=field,spw=spw)<br />
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 />
<br />
[[File:TWHydra_corrected_Spw2.png|thumb|Figure 4: Inspect the data.]]<br />
<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 />
[[File:Gfluxscale_table.png|thumb|Figure 5: An example of the table created by hifa_gfluxscale.]]<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 {{cvel2}} 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 {{cvel2}} prior to imaging, you should make sure to use the same input parameters to the {{tclean}} task that you used for {{cvel2}}. In other words, you shouldn't regrid the data using both {{cvel2}} 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 {{cvel2}} 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 cvel2/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 {{cvel2}} 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 {{cvel2}} for {{tclean}}.<br />
<br />
<source lang="python"><br />
# in CASA<br />
rmtables(regridvis)<br />
os.system('rm -rf ' + regridvis + '.flagversions')<br />
<br />
cvel2(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>Tashtonhttps://casaguides.nrao.edu/index.php?title=ADMIT_Products_and_Usage_CASA_6.5.4&diff=36641ADMIT Products and Usage CASA 6.5.42024-02-28T20:18:38Z<p>Tashton: Adding link to old instructions for CASA 5.4</p>
<hr />
<div>== Intro/What is ADMIT? ==<br />
<br />
The ALMA Data-Mining Toolkit (ADMIT) is an execution environment and set of tools for analyzing image data cubes. ADMIT is based on python and designed to be fully compliant with CASA and to utilize CASA routines where possible. ADMIT has a flow-oriented approach, executing a series of ADMIT Tasks (AT) in a sequence to produce a sequence of outputs. For the beginner, ADMIT can be driven by simple scripts that can be run at the Unix level or from inside of CASA. ADMIT provides a simple browser interface for looking at the data products, and all major data products are on disk as CASA images and graphics files. For the advanced user, ADMIT is a python environment for data analysis and for creating new tools for analyzing data.<br />
<br />
For a detailed quick-look at ALMA images, standardized ADMIT “recipes” can be run which produce various products depending on the image type. For continuum images, ADMIT simply finds some of the basic image properties (RMS, peak flux, etc) and produces a moment map. For cube images, ADMIT will analyze the cube, attempt to identify spectral features, and create moment maps of each identified spectral line. <br />
<br />
ADMIT does not interact with u,v data or create images from u,v data; CASA should be used to create images. ADMIT provides a number of ways to inspect your image cubes. The astronomer can then decide whether the ALMA image cubes need to be improved, which requires running standard CASA routines to re-image the u,v data. If new images are made, the ADMIT flow can be run on these new image cubes to produce new set of ADMIT products.<br />
<br />
<br />
<br />
== Obtaining ADMIT and data for this guide ==<br />
<br />
For this CASA Guide, we will go through creating an ADMIT product of some science verification data and then inspect the output. You’ll of course need CASA installed (http://casa.nrao.edu/casa_obtaining.shtml) as well as ADMIT. To install ADMIT from scratch for use in CASA 6, you’ll need to clone the source code using git and then edit the setup script to create the necessary environment:<br />
<br />
<source lang="bash"><br />
# In bash<br />
# cd to the directory you want to host ADMIT in<br />
git clone https://github.com/astroumd/admit<br />
cd admit<br />
git checkout python3<br />
pip install -e .<br />
</source><br />
<br />
If the pip command does not work, try using pip3 or python3 -m pip install -e .<br />
<br />
This will set up your ADMIT installation to run with Python 3 and be compatible with CASA 6. After running the above commands, you'll need to edit the admit_start.sh.in startup file. The default file with comments about what parameters to edit appear below. The PATH, TCL_LIBRARY, and TK_LIBRARY variables have already been edited from the default values to the required values.<br />
<br />
<source lang="bash"><br />
# @EDIT_MSG@<br />
# for (ba)sh : source this file<br />
<br />
export ADMIT=@ADMIT@ # This needs to match the path of your ADMIT installation, i.e. the current directory<br />
export CASA_ROOT=@CASA_ROOT@ # This should be the path to your CASA installation<br />
if test "x$CASA_ROOT" = "x"; then<br />
unset CASA_ROOT<br />
export PATH=${ADMIT}/bin:${PATH}<br />
else<br />
# CASA_ROOT has been deprecated as a bin by CASA<br />
export PATH=${ADMIT}/bin:${CASA_ROOT}/bin:${CASA_ROOT}/lib/casa/bin:${CASA_ROOT}/:${PATH}<br />
export TCL_LIBRARY=${CASA_ROOT}/share/tcl<br />
export TK_LIBRARY=${CASA_ROOT}/share/tk<br />
export LD_LIBRARY_PATH=${CASA_ROOT}/lib:${LD_LIBRARY_PATH}<br />
fi<br />
<br />
export CASA_PATH="$CASA_ROOT linux admit `hostname`"<br />
<br />
export PYTHONPATH=${ADMIT}:${PYTHONPATH}<br />
</source><br />
<br />
Once you have edited the configuration script, simply source the admit_start.sh.in script before executing any ADMIT commands.<br />
<br />
<source lang="bash"><br />
# In bash<br />
source admit_start.sh.in<br />
</source><br />
<br />
If you want to check that ADMIT is set up, you can type <br />
<br />
<source lang="bash"><br />
# In bash<br />
admit<br />
</source><br />
<pre style="background-color: #fffacd;"><br />
ADMIT = <your/ADMIT/instalation/path><br />
version = 1.0.8.5<br />
CASA_PATH = <your/CASA/installation/path> linux admit cpu-name<br />
CASA_ROOT = <your/CASA/installation/path><br />
prefix = <your/CASA/installation/path><br />
version = 6.5.4<br />
revision = 1<br />
Trying CASA6, no worries if this fails<br />
</pre><br />
<br />
If the admit command returns some kind of error below the "Trying CASA6" output, it's okay to skip past it. The error is usually just from a mixup in the metadata bookkeeping.<br />
<br />
In your terminal after sourcing the start script and you should see the directory paths and versions of ADMIT. For more details, please see:<br />
<br />
http://admit.astro.umd.edu/installguide.html<br />
<br />
Now switch directories out of the ADMIT installation you just set up and to where you will be working on the data. For this guide, we’ll be using the images generated from the Antennae Band 7 CASA Guide. We’ll just need the reference images which we can grab with a wget command and then untar:<br />
<br />
<source lang="bash"><br />
# In bash<br />
wget https://bulk.cv.nrao.edu/almadata/sciver/AntennaeBand7/Antennae_Band7_ReferenceImages.tgz<br />
tar xzf Antennae_Band7_ReferenceImages.tgz<br />
cd Antennae_Band7_ReferenceImages<br />
</source><br />
<br />
== Creating an ADMIT product ==<br />
<br />
Now that we have some ALMA images and ADMIT installed, let’s run one of the standard ADMIT recipes on our image. There are two standard recipes that handle most ALMA images, admit1.py (http://admit.astro.umd.edu/tricks.html#runa1-and-admit1-py - Caveat: runa1 and runa2 might not work in CASA 6) which works on data cubes and admit2.py (http://admit.astro.umd.edu/tricks.html#runa2-and-admit2-py) which works on continuum images. These images are data cubes so we’ll use the first recipe. Specify the admit1.py recipe which allows you to use flags for customization. To do this, type:<br />
<br />
<source lang="bash"><br />
# In bash<br />
/path/to/your/admit/installation/admit/admit/test/admit1.py Antennae_North.CO3_2Line.Clean.pcal1.image.fits<br />
</source><br />
<br />
This will produce a long sequence of outputs in the terminal; however, there are over 30 tunable parameters that allow you to set the VLSR, rest frequency, regions of interest, etc. as well as many line identification parameters to tune such as using the online version of Splatalogue rather than the internal one for line identification. These can be tuned via creating a file with your parameter choices and specifying it via the --apar flag. Later in this guide we will go through a little bit more on how to customize ADMIT to better suit your data but for now, more information can be found here: <br />
<br />
http://admit.astro.umd.edu/tricks.html#admit1-apar-parameters <br />
<br />
In the end, if everything worked correctly, admit1.py will result in the creation of a file named Antennae_North.CO3_2Line.Clean.pcal1.image.admit which contains the output from the ADMIT recipe.<br />
<br />
== The ADMIT weblog, viewing the ADMIT product ==<br />
To view the ADMIT output, start by descending into the Antennae_North.CO3_2Line.Clean.pcal1.image.admit directory and open up the index.html file in your favorite browser (currently Firefox is the best option). This will open up the ADMIT browser interface (weblog) which is the most convenient way to view the ADMIT results on the image. It should look something like Figure 1.<br />
<br />
<br />
[[Image:ADMIT_weblog_homepage.png|600px|thumb|<caption>The homepage for an ADMIT weblog. Each green horizontal bar represents an individual ADMIT task that was run and clicking on it will expand that section to show more details and the output for that section.</caption>]]<br />
<br />
<br />
<br />
The text within each bar gives the ADMIT Task name, the task ID number, the parameters that were used within that task, and any output image names (Figure 1). Note that ADMIT uses the basename "x" if one isn't supplied so all the output file names will be "x.*". Clicking on one of the green horizontal bars will reveal all the output for that ADMIT task. Just under the expanded bar will be the task name (which hyperlinks to the ADMIT wiki page for that task) and a one-line explanation of what that task does (Figure 2).<br />
<br />
<br />
[[Image:ADMIT_task_link.png|600px|thumb|<caption>Below each green horizontal bar is a one-line description of that ADMIT task, clicking on the task name hyperlinks to the ADMIT wiki page for that task.</caption>]]<br />
<br />
<br />
Now, we will go through all of the output in the ADMIT weblog and describe what each task does and what output to expect.<br />
<br />
<br />
=== The ADMIT data Flow ===<br />
Clicking on the top-most bar of the weblog, “Flow Diagram for Antennae_North.CO3_2Line.Clean.pcal1.image.admit” (see Figure 1), reveals the “ADMIT Flow Diagram” (Figure 3). This is an illustration of how the products created in each task flow through the entire process. For a detailed discussion of how ADMIT flows work (and how to create your own) please see <br />
<br />
http://admit.astro.umd.edu/design.html#workflow-management<br />
<br />
For continuum images, these diagrams are extremely simple but for line-dense image cubes these can be incredibly complicated. Figure 3 shows what the ADMIT Flow looks like for our dataset. This diagram is a directed acyclic graph representing the ADMIT Task connections. Each arrow represents the connection from an ADMIT task output to the input of another ADMIT Task. The integer next to each arrow is the zero-based index of the ADMIT Task's output basic data product. Note that any output basic data product may be used as the input for more than one ADMIT Task.<br />
<br />
<br />
[[Image:ADMIT_Flow_diagram_example.png|300px|thumb|<caption>The ADMIT Flow diagram for processing the Antennae_North.CO3_2Line.Clean.pcal1.image.fits file.</caption>]]<br />
<br />
<br />
<br />
=== Ingest_AT ===<br />
This is the most basic task that is performed at the beginning of any ADMIT workflow. This task reads in a FITS image, creates a CASA image and extracts basic information such as rest frequency, beam size, image size, minimum/maximum values, etc.<br />
<br />
<br />
=== CubeStats_AT ===<br />
This task computes statistics on the image cube in the image-plane (meaning that the uv data is not examined). Here, ADMIT computes per-channel statistics in order to find the maximum and minimum values and pixel locations throughout the cube. This information is then used to generate global statistics such as mean intensity, a signal-free estimate of the noise, and the dynamic range. The maximum value pixel locations throughout the cube will also be used in later steps to help identify lines in the spectrum. Additionally, two plots are created:<br />
<br />
# Emission Characteristics Plot: The spectrum of various statistical measures (SNR, peak signal, RMS, and minimum signal) are plotted.<br />
# The Peak Point Plot: the image is searched and the peak emission locations are found for every channel in the cube and plotted. The size of the point in the image indicates the magnitude of the emission in that channel.<br />
<br />
=== CubeSum_AT ===<br />
This task creates a moment 0 map of all the emission in the image cube, regardless of whether or not it comes from different spectral lines (Figure 4). The RMS, and therefore cutoff emission level, is determined by the previous step, CubeStats_AT.<br />
<br />
<br />
[[Image:ADMIT_mom0.png|400px|thumb|<caption>A Moment 0 map of Antenna North created by ADMIT during CubeSum_AT.</caption>]]<br />
<br />
<br />
<br />
=== SFind2D_AT ===<br />
This task creates a list of sources found in the 2D image created by CubeSum_AT. The output is a table which lists peak source positions and fluxes. An image is also displayed which shows where the sources are located. <br />
<br />
<br />
=== CubeSpectrum_AT ===<br />
Given the input from SFind2D_AT of source positions, the statistics of the image from CubeStats_AT, the moment map created by CubeSum_AT, and the initial input image, this task computes the spectra of the cube at a specific point (or points). The output are averaged spectra taken at the locations of the three maximum flux values in the cube.<br />
<br />
=== LineSegment_AT ===<br />
This task detects segments of emission (i.e. spectral lines) based on RMS cutoffs and the input spectra provided from the previous CubeSpectrum_AT task but does not yet identify the lines (this will be done in a later stage). The output is then a list of potential spectral lines as well as spectra showing where the potential lines have been identified. Six plots are created (see Figure 5): peak intensity, minimum intensity, the three spectra provided as inputs from CubeSpectrum_AT, and a Signal/Noise summary plot. For each spectrum, the potentially identified lines are overlaid and the amplitude is given as a multiple of the noise (either Peak/Noise or Minimum/Noise)<br />
<br />
<br />
[[Image:ADMIT_LineSegment_AT.png|500px|thumb|<caption>ADMIT output from the LineSegment_AT task which identifies parts of the spectrum that contain line emission.</caption>]]<br />
<br />
<br />
=== PVSlice_AT ===<br />
This task creates a position-velocity (PV) diagram through the input image cube. Given the original image cube and the output moment map from CubeSum_AT, the moment of inertia is computed and used to derive "the best slice" through the image cube. The output is then two figures; the location of the PV slice drawn through the moment map, and the PV diagram.<br />
<br />
=== PVCorr_AT ===<br />
Using an input PV slice from PVSlice_AT and the cube statistics from CubeStats_AT (from which the RMS is taken), this task computes a cross-correlation of the PV slice. It does this by attempting to correlate sections of the spectrum with the whole PVSlice. If the section is not random noise, then the output will show a high correlation for that section. This can be most useful for detecting weak spectral lines.<br />
<br />
<br />
=== LineID_AT ===<br />
In this task, ADMIT identifies spectral lines in the input datacube using the output from CubeSpectrum_AT and CubeStats_AT. The output here is very similar to the above LineSegment_AT task except that the line segments have now been identified. For our example here of the Antenna North we see that the large spectral line has been correctly identified as CO (3-2). <br />
<br />
<br />
=== LineCube_AT ===<br />
Given the output list of lines from LineID_AT, this task generates smaller line cubes from the input image cube, each centered around an identified line. A table is presented showing the identified line molecule and rest frequency, the starting and ending channel for the smaller cube, and the name given to the output cube.<br />
<br />
=== Moment_AT ===<br />
For each line cube that is made during the above task, LineCube_AT, a moment map is produced via Moment_AT. This task uses the input line cube as well as information from CubeStats_AT to create a Moment 0, Moment 1, and Moment 2 map. <br />
<br />
[[Image:ADMIT_mom0-2.png|500px|thumb|<caption>ADMIT output from the Moment_AT task which creates the first three moment maps from the input cube.</caption>]]<br />
<br />
<br />
=== CubeSpectrum_AT ===<br />
Likewise, for each line cube that is made during LineCube_AT, this task computes the spectrum for the pixel with the maximum flux value in the moment 0 map created by the Moment_AT task.<br />
<br />
=== Moment_AT ===<br />
Finally, ADMIT creates another moment 0 map using the full, original input cube and information from CubeStats_AT.<br />
<br />
== Customizing ADMIT for your dataset == <br />
As outlined near the beginning of this guide, you can customize an ADMIT run by supplying additional parameters to admit1.py via a parameter file and pointing to it with the --apar flag in your admit1.py call.<br />
<br />
Each time ADMIT runs, it creates an admit0.py script (found in the same directory as the index.html file) which is an auto-generated script of the ADMIT flow that was performed. Therefore, another option for customizing your ADMIT output is to edit this script (admit0.py) to include extra parameters for your data, and run again. For example, you may add the VLSR to Ingest_AT or LineID_AT for more accurate line identification, or you may change the “online” boolean flag in LineID_AT to “True” so that ADMIT searches the online version of Splatalogue to identify lesser known chemical species. To find out what parameters are available for customization, please see the online documentation for each task by clicking on the task name under its header in the weblog (index.html). <br />
<br />
It is best practice to first make a copy of the admit0.py script in your working directory (one directory above the [image_file].admit directory). Then, edit the admit0.py script that was just copied to the working directory and run the script to create the new ADMIT products by simply typing: <br />
<br />
<source lang="bash"><br />
# In bash<br />
admit0.py<br />
</source><br />
<br />
Once you are comfortable with editing the admit0.py script, this can help you start to create your own ADMIT flows which you can use to help you quickly sift through large datasets.<br />
<br />
<br />
<br />
== Using an Older Version of ADMIT ==<br />
<br />
If you would like to use the older, Python2 version of ADMIT that was written for CASA 5.4.0, please instead follow the installation instructions found here: [[ADMIT Products and Usage CASA 5.4.0]]. However, this is not recommended on modern systems due to the ongoing deprecation of both Python2 and CASA 5.4.0; the old instructions are made available for surviving older systems.</div>Tashtonhttps://casaguides.nrao.edu/index.php?title=ADMIT_Products_and_Usage&diff=36640ADMIT Products and Usage2024-02-28T20:11:09Z<p>Tashton: Setting up redirect</p>
<hr />
<div>#REDIRECT [[ADMIT Products and Usage CASA 6.5.4]]</div>Tashtonhttps://casaguides.nrao.edu/index.php?title=ADMIT_Products_and_Usage_CASA_5.4.0&diff=36639ADMIT Products and Usage CASA 5.4.02024-02-28T20:10:04Z<p>Tashton: Making new version of CASA 5.4 version of ADMIT installation/usage instructions</p>
<hr />
<div>== Intro/What is ADMIT? ==<br />
<br />
The ALMA Data-Mining Toolkit (ADMIT) is an execution environment and set of tools for analyzing image data cubes. ADMIT is based on python and designed to be fully compliant with CASA and to utilize CASA routines where possible. ADMIT has a flow-oriented approach, executing a series of ADMIT Tasks (AT) in a sequence to produce a sequence of outputs. For the beginner, ADMIT can be driven by simple scripts that can be run at the Unix level or from inside of CASA. ADMIT provides a simple browser interface for looking at the data products, and all major data products are on disk as CASA images and graphics files. For the advanced user, ADMIT is a python environment for data analysis and for creating new tools for analyzing data.<br />
<br />
For a detailed quick-look at ALMA images, standardized ADMIT “recipes” can be run which produce various products depending on the image type. For continuum images, ADMIT simply finds some of the basic image properties (RMS, peak flux, etc) and produces a moment map. For cube images, ADMIT will analyze the cube, attempt to identify spectral features, and create moment maps of each identified spectral line. <br />
<br />
ADMIT does not interact with u,v data or create images from u,v data; CASA should be used to create images. ADMIT provides a number of ways to inspect your image cubes. The astronomer can then decide whether the ALMA image cubes need to be improved, which requires running standard CASA routines to re-image the u,v data. If new images are made, the ADMIT flow can be run on these new image cubes to produce new set of ADMIT products.<br />
<br />
<br />
<br />
== Obtaining ADMIT and data for this guide ==<br />
<br />
For this CASA Guide, we will go through creating an ADMIT product of some science verification data and then inspect the output. You’ll of course need CASA installed (http://casa.nrao.edu/casa_obtaining.shtml) as well as ADMIT. To install ADMIT from scratch, you’ll need to clone the source code using git and then run the setup script to create the necessary environment replacing "X" with the relevant software version:<br />
<br />
<source lang="bash"><br />
# In bash<br />
git clone https://github.com/astroumd/admit<br />
cd admit<br />
autoconf #creates the executable configure script<br />
./configure --with-casa-root=/path/to/your/local/casa-release-X.X.X-X<br />
</source><br />
<br />
If the above method doesn't work for whatever reason, you can also use wget, untar the file, and then run the setup script, again, replacing "X" with the relevant software versions:<br />
<br />
<source lang="bash"><br />
# In bash<br />
wget http://admit.astro.umd.edu/admit.tar.gz<br />
tar zxf admit.tar.gz<br />
ls<br />
cd admit_1.X.X<br />
./configure --with-casa-root=/path/to/your/local/casa-release-X.X.X-X<br />
</source><br />
<br />
Once you have run the configure script using either method, simply source the newly created admit_start.sh script before executing any ADMIT commands.<br />
<br />
<source lang="bash"><br />
# In bash<br />
source admit_start.sh<br />
</source><br />
<br />
If you want to check that ADMIT is set up, you can type <br />
<br />
<source lang="bash"><br />
# In bash<br />
admit<br />
</source><br />
<pre style="background-color: #fffacd;"><br />
ADMIT = /users/test/admit<br />
version = 1.0.8<br />
CASA_PATH = /home/casa/release/casa-release-5.4.0-70 linux admit cpu-name<br />
CASA_ROOT = /home/casa/release/casa-release-5.4.0-70<br />
prefix = /home/casa/release/casa-release-5.4.0-70<br />
version = 5.4.0-rel-70<br />
revision = 1<br />
</pre><br />
<br />
In your terminal after sourcing the start script and you should see the directory paths and versions of ADMIT. For more details, please see:<br />
<br />
http://admit.astro.umd.edu/installguide.html<br />
<br />
Now switch directories out of the ADMIT installation you just set up and to where you will be working on the data. For this guide, we’ll be using the images generated from the Antennae Band 7 CASA Guide. We’ll just need the reference images which we can grab with a wget command and then untar:<br />
<br />
<source lang="bash"><br />
# In bash<br />
wget https://bulk.cv.nrao.edu/almadata/sciver/AntennaeBand7/Antennae_Band7_ReferenceImages.tgz<br />
tar xzf Antennae_Band7_ReferenceImages.tgz<br />
cd Antennae_Band7_ReferenceImages<br />
</source><br />
<br />
== Creating an ADMIT product ==<br />
<br />
Now that we have some ALMA images and ADMIT installed, let’s run one of the standard ADMIT recipes on our image. There are two standard recipes that handle most ALMA images, admit1.py (or runa1, http://admit.astro.umd.edu/tricks.html#runa1-and-admit1-py) which works on data cubes and admit2.py (or runa2, http://admit.astro.umd.edu/tricks.html#runa2-and-admit2-py) which works on continuum images. These images are data cubes so we’ll use the first recipe. There are two ways to do this, if you just want the results of the ADMIT recipe just type<br />
<br />
<source lang="bash"><br />
# In bash<br />
runa1 Antennae_North.CO3_2Line.Clean.pcal1.image.fits<br />
</source><br />
<br />
within the directory where the image is located. runa1 is the default implementation and gives a streamlined result. Another option is to specify the admit1.py recipe which allows you to use flags for customization. To do this, type:<br />
<br />
<source lang="bash"><br />
# In bash<br />
/path/to/your/admit/installation/admit/admit/test/admit1.py Antennae_North.CO3_2Line.Clean.pcal1.image.fits<br />
</source><br />
<br />
This will produce identical output as runa1; however, there are over 30 tunable parameters that allow you to set the VLSR, rest frequency, regions of interest, etc. as well as many line identification parameters to tune such as using the online version of Splatalogue rather than the internal one for line identification. These can be tuned via creating a file with your parameter choices and specifying it via the --apar flag. Later in this guide we will go through a little bit more on how to customize ADMIT to better suit your data but for now, more information can be found here: <br />
<br />
http://admit.astro.umd.edu/tricks.html#admit1-apar-parameters <br />
<br />
In the end, if everything worked correctly, either method (runa1 or admit1.py) will result in the creation of a file named Antennae_North.CO3_2Line.Clean.pcal1.image.admit which contains the output from the ADMIT recipe.<br />
<br />
== The ADMIT weblog, viewing the ADMIT product ==<br />
To view the ADMIT output, start by descending into the Antennae_North.CO3_2Line.Clean.pcal1.image.admit directory and open up the index.html file in your favorite browser (currently Firefox is the best option). This will open up the ADMIT browser interface (weblog) which is the most convenient way to view the ADMIT results on the image. It should look something like Figure 1.<br />
<br />
<br />
[[Image:ADMIT_weblog_homepage.png|600px|thumb|<caption>The homepage for an ADMIT weblog. Each green horizontal bar represents an individual ADMIT task that was run and clicking on it will expand that section to show more details and the output for that section.</caption>]]<br />
<br />
<br />
<br />
The text within each bar gives the ADMIT Task name, the task ID number, the parameters that were used within that task, and any output image names (Figure 1). Note that ADMIT uses the basename "x" if one isn't supplied so all the output file names will be "x.*". Clicking on one of the green horizontal bars will reveal all the output for that ADMIT task. Just under the expanded bar will be the task name (which hyperlinks to the ADMIT wiki page for that task) and a one-line explanation of what that task does (Figure 2).<br />
<br />
<br />
[[Image:ADMIT_task_link.png|600px|thumb|<caption>Below each green horizontal bar is a one-line description of that ADMIT task, clicking on the task name hyperlinks to the ADMIT wiki page for that task.</caption>]]<br />
<br />
<br />
Now, we will go through all of the output in the ADMIT weblog and describe what each task does and what output to expect.<br />
<br />
<br />
=== The ADMIT data Flow ===<br />
Clicking on the top-most bar of the weblog, “Flow Diagram for Antennae_North.CO3_2Line.Clean.pcal1.image.admit” (see Figure 1), reveals the “ADMIT Flow Diagram” (Figure 3). This is an illustration of how the products created in each task flow through the entire process. For a detailed discussion of how ADMIT flows work (and how to create your own) please see <br />
<br />
http://admit.astro.umd.edu/design.html#workflow-management<br />
<br />
For continuum images, these diagrams are extremely simple but for line-dense image cubes these can be incredibly complicated. Figure 3 shows what the ADMIT Flow looks like for our dataset. This diagram is a directed acyclic graph representing the ADMIT Task connections. Each arrow represents the connection from an ADMIT task output to the input of another ADMIT Task. The integer next to each arrow is the zero-based index of the ADMIT Task's output basic data product. Note that any output basic data product may be used as the input for more than one ADMIT Task.<br />
<br />
<br />
[[Image:ADMIT_Flow_diagram_example.png|300px|thumb|<caption>The ADMIT Flow diagram for processing the Antennae_North.CO3_2Line.Clean.pcal1.image.fits file.</caption>]]<br />
<br />
<br />
<br />
=== Ingest_AT ===<br />
This is the most basic task that is performed at the beginning of any ADMIT workflow. This task reads in a FITS image, creates a CASA image and extracts basic information such as rest frequency, beam size, image size, minimum/maximum values, etc.<br />
<br />
<br />
=== CubeStats_AT ===<br />
This task computes statistics on the image cube in the image-plane (meaning that the uv data is not examined). Here, ADMIT computes per-channel statistics in order to find the maximum and minimum values and pixel locations throughout the cube. This information is then used to generate global statistics such as mean intensity, a signal-free estimate of the noise, and the dynamic range. The maximum value pixel locations throughout the cube will also be used in later steps to help identify lines in the spectrum. Additionally, two plots are created:<br />
<br />
# Emission Characteristics Plot: The spectrum of various statistical measures (SNR, peak signal, RMS, and minimum signal) are plotted.<br />
# The Peak Point Plot: the image is searched and the peak emission locations are found for every channel in the cube and plotted. The size of the point in the image indicates the magnitude of the emission in that channel.<br />
<br />
=== CubeSum_AT ===<br />
This task creates a moment 0 map of all the emission in the image cube, regardless of whether or not it comes from different spectral lines (Figure 4). The RMS, and therefore cutoff emission level, is determined by the previous step, CubeStats_AT.<br />
<br />
<br />
[[Image:ADMIT_mom0.png|400px|thumb|<caption>A Moment 0 map of Antenna North created by ADMIT during CubeSum_AT.</caption>]]<br />
<br />
<br />
<br />
=== SFind2D_AT ===<br />
This task creates a list of sources found in the 2D image created by CubeSum_AT. The output is a table which lists peak source positions and fluxes. An image is also displayed which shows where the sources are located. <br />
<br />
<br />
=== CubeSpectrum_AT ===<br />
Given the input from SFind2D_AT of source positions, the statistics of the image from CubeStats_AT, the moment map created by CubeSum_AT, and the initial input image, this task computes the spectra of the cube at a specific point (or points). The output are averaged spectra taken at the locations of the three maximum flux values in the cube.<br />
<br />
=== LineSegment_AT ===<br />
This task detects segments of emission (i.e. spectral lines) based on RMS cutoffs and the input spectra provided from the previous CubeSpectrum_AT task but does not yet identify the lines (this will be done in a later stage). The output is then a list of potential spectral lines as well as spectra showing where the potential lines have been identified. Six plots are created (see Figure 5): peak intensity, minimum intensity, the three spectra provided as inputs from CubeSpectrum_AT, and a Signal/Noise summary plot. For each spectrum, the potentially identified lines are overlaid and the amplitude is given as a multiple of the noise (either Peak/Noise or Minimum/Noise)<br />
<br />
<br />
[[Image:ADMIT_LineSegment_AT.png|500px|thumb|<caption>ADMIT output from the LineSegment_AT task which identifies parts of the spectrum that contain line emission.</caption>]]<br />
<br />
<br />
=== PVSlice_AT ===<br />
This task creates a position-velocity (PV) diagram through the input image cube. Given the original image cube and the output moment map from CubeSum_AT, the moment of inertia is computed and used to derive "the best slice" through the image cube. The output is then two figures; the location of the PV slice drawn through the moment map, and the PV diagram.<br />
<br />
=== PVCorr_AT ===<br />
Using an input PV slice from PVSlice_AT and the cube statistics from CubeStats_AT (from which the RMS is taken), this task computes a cross-correlation of the PV slice. It does this by attempting to correlate sections of the spectrum with the whole PVSlice. If the section is not random noise, then the output will show a high correlation for that section. This can be most useful for detecting weak spectral lines.<br />
<br />
<br />
=== LineID_AT ===<br />
In this task, ADMIT identifies spectral lines in the input datacube using the output from CubeSpectrum_AT and CubeStats_AT. The output here is very similar to the above LineSegment_AT task except that the line segments have now been identified. For our example here of the Antenna North we see that the large spectral line has been correctly identified as CO (3-2). <br />
<br />
<br />
=== LineCube_AT ===<br />
Given the output list of lines from LineID_AT, this task generates smaller line cubes from the input image cube, each centered around an identified line. A table is presented showing the identified line molecule and rest frequency, the starting and ending channel for the smaller cube, and the name given to the output cube.<br />
<br />
=== Moment_AT ===<br />
For each line cube that is made during the above task, LineCube_AT, a moment map is produced via Moment_AT. This task uses the input line cube as well as information from CubeStats_AT to create a Moment 0, Moment 1, and Moment 2 map. <br />
<br />
[[Image:ADMIT_mom0-2.png|500px|thumb|<caption>ADMIT output from the Moment_AT task which creates the first three moment maps from the input cube.</caption>]]<br />
<br />
<br />
=== CubeSpectrum_AT ===<br />
Likewise, for each line cube that is made during LineCube_AT, this task computes the spectrum for the pixel with the maximum flux value in the moment 0 map created by the Moment_AT task.<br />
<br />
=== Moment_AT ===<br />
Finally, ADMIT creates another moment 0 map using the full, original input cube and information from CubeStats_AT.<br />
<br />
== Customizing ADMIT for your dataset == <br />
As outlined near the beginning of this guide, you can customize an ADMIT run by supplying additional parameters to admit1.py via a parameter file and pointing to it with the --apar flag in your admit1.py call.<br />
<br />
Each time ADMIT runs, it creates an admit0.py script (found in the same directory as the index.html file) which is an auto-generated script of the ADMIT flow that was performed. Therefore, another option for customizing your ADMIT output is to edit this script (admit0.py) to include extra parameters for your data, and run again. For example, you may add the VLSR to Ingest_AT or LineID_AT for more accurate line identification, or you may change the “online” boolean flag in LineID_AT to “True” so that ADMIT searches the online version of Splatalogue to identify lesser known chemical species. To find out what parameters are available for customization, please see the online documentation for each task by clicking on the task name under its header in the weblog (index.html). <br />
<br />
It is best practice to first make a copy of the admit0.py script in your working directory (one directory above the [image_file].admit directory). Then, edit the admit0.py script that was just copied to the working directory and run the script to create the new ADMIT products by simply typing: <br />
<br />
<source lang="bash"><br />
# In bash<br />
admit0.py<br />
</source><br />
<br />
Once you are comfortable with editing the admit0.py script, this can help you start to create your own ADMIT flows which you can use to help you quickly sift through large datasets.</div>Tashtonhttps://casaguides.nrao.edu/index.php?title=ADMIT_Products_and_Usage&diff=36496ADMIT Products and Usage2024-02-07T19:55:14Z<p>Tashton: Adding page redirect to CASA 6.5.4 version</p>
<hr />
<div>#REDIRECT [[ADMIT Products and Usage CASA 6.5.4]]<br />
<br />
== Intro/What is ADMIT? ==<br />
<br />
The ALMA Data-Mining Toolkit (ADMIT) is an execution environment and set of tools for analyzing image data cubes. ADMIT is based on python and designed to be fully compliant with CASA and to utilize CASA routines where possible. ADMIT has a flow-oriented approach, executing a series of ADMIT Tasks (AT) in a sequence to produce a sequence of outputs. For the beginner, ADMIT can be driven by simple scripts that can be run at the Unix level or from inside of CASA. ADMIT provides a simple browser interface for looking at the data products, and all major data products are on disk as CASA images and graphics files. For the advanced user, ADMIT is a python environment for data analysis and for creating new tools for analyzing data.<br />
<br />
For a detailed quick-look at ALMA images, standardized ADMIT “recipes” can be run which produce various products depending on the image type. For continuum images, ADMIT simply finds some of the basic image properties (RMS, peak flux, etc) and produces a moment map. For cube images, ADMIT will analyze the cube, attempt to identify spectral features, and create moment maps of each identified spectral line. <br />
<br />
ADMIT does not interact with u,v data or create images from u,v data; CASA should be used to create images. ADMIT provides a number of ways to inspect your image cubes. The astronomer can then decide whether the ALMA image cubes need to be improved, which requires running standard CASA routines to re-image the u,v data. If new images are made, the ADMIT flow can be run on these new image cubes to produce new set of ADMIT products.<br />
<br />
<br />
<br />
== Obtaining ADMIT and data for this guide ==<br />
<br />
For this CASA Guide, we will go through creating an ADMIT product of some science verification data and then inspect the output. You’ll of course need CASA installed (http://casa.nrao.edu/casa_obtaining.shtml) as well as ADMIT. To install ADMIT from scratch, you’ll need to clone the source code using git and then run the setup script to create the necessary environment replacing "X" with the relevant software version:<br />
<br />
<source lang="bash"><br />
# In bash<br />
git clone https://github.com/astroumd/admit<br />
cd admit<br />
autoconf #creates the executable configure script<br />
./configure --with-casa-root=/path/to/your/local/casa-release-X.X.X-X<br />
</source><br />
<br />
If the above method doesn't work for whatever reason, you can also use wget, untar the file, and then run the setup script, again, replacing "X" with the relevant software versions:<br />
<br />
<source lang="bash"><br />
# In bash<br />
wget http://admit.astro.umd.edu/admit.tar.gz<br />
tar zxf admit.tar.gz<br />
ls<br />
cd admit_1.X.X<br />
./configure --with-casa-root=/path/to/your/local/casa-release-X.X.X-X<br />
</source><br />
<br />
Once you have run the configure script using either method, simply source the newly created admit_start.sh script before executing any ADMIT commands.<br />
<br />
<source lang="bash"><br />
# In bash<br />
source admit_start.sh<br />
</source><br />
<br />
If you want to check that ADMIT is set up, you can type <br />
<br />
<source lang="bash"><br />
# In bash<br />
admit<br />
</source><br />
<pre style="background-color: #fffacd;"><br />
ADMIT = /users/test/admit<br />
version = 1.0.8<br />
CASA_PATH = /home/casa/release/casa-release-5.4.0-70 linux admit cpu-name<br />
CASA_ROOT = /home/casa/release/casa-release-5.4.0-70<br />
prefix = /home/casa/release/casa-release-5.4.0-70<br />
version = 5.4.0-rel-70<br />
revision = 1<br />
</pre><br />
<br />
In your terminal after sourcing the start script and you should see the directory paths and versions of ADMIT. For more details, please see:<br />
<br />
http://admit.astro.umd.edu/installguide.html<br />
<br />
Now switch directories out of the ADMIT installation you just set up and to where you will be working on the data. For this guide, we’ll be using the images generated from the Antennae Band 7 CASA Guide. We’ll just need the reference images which we can grab with a wget command and then untar:<br />
<br />
<source lang="bash"><br />
# In bash<br />
wget https://bulk.cv.nrao.edu/almadata/sciver/AntennaeBand7/Antennae_Band7_ReferenceImages.tgz<br />
tar xzf Antennae_Band7_ReferenceImages.tgz<br />
cd Antennae_Band7_ReferenceImages<br />
</source><br />
<br />
== Creating an ADMIT product ==<br />
<br />
Now that we have some ALMA images and ADMIT installed, let’s run one of the standard ADMIT recipes on our image. There are two standard recipes that handle most ALMA images, admit1.py (or runa1, http://admit.astro.umd.edu/tricks.html#runa1-and-admit1-py) which works on data cubes and admit2.py (or runa2, http://admit.astro.umd.edu/tricks.html#runa2-and-admit2-py) which works on continuum images. These images are data cubes so we’ll use the first recipe. There are two ways to do this, if you just want the results of the ADMIT recipe just type<br />
<br />
<source lang="bash"><br />
# In bash<br />
runa1 Antennae_North.CO3_2Line.Clean.pcal1.image.fits<br />
</source><br />
<br />
within the directory where the image is located. runa1 is the default implementation and gives a streamlined result. Another option is to specify the admit1.py recipe which allows you to use flags for customization. To do this, type:<br />
<br />
<source lang="bash"><br />
# In bash<br />
/path/to/your/admit/installation/admit/admit/test/admit1.py Antennae_North.CO3_2Line.Clean.pcal1.image.fits<br />
</source><br />
<br />
This will produce identical output as runa1; however, there are over 30 tunable parameters that allow you to set the VLSR, rest frequency, regions of interest, etc. as well as many line identification parameters to tune such as using the online version of Splatalogue rather than the internal one for line identification. These can be tuned via creating a file with your parameter choices and specifying it via the --apar flag. Later in this guide we will go through a little bit more on how to customize ADMIT to better suit your data but for now, more information can be found here: <br />
<br />
http://admit.astro.umd.edu/tricks.html#admit1-apar-parameters <br />
<br />
In the end, if everything worked correctly, either method (runa1 or admit1.py) will result in the creation of a file named Antennae_North.CO3_2Line.Clean.pcal1.image.admit which contains the output from the ADMIT recipe.<br />
<br />
== The ADMIT weblog, viewing the ADMIT product ==<br />
To view the ADMIT output, start by descending into the Antennae_North.CO3_2Line.Clean.pcal1.image.admit directory and open up the index.html file in your favorite browser (currently Firefox is the best option). This will open up the ADMIT browser interface (weblog) which is the most convenient way to view the ADMIT results on the image. It should look something like Figure 1.<br />
<br />
<br />
[[Image:ADMIT_weblog_homepage.png|600px|thumb|<caption>The homepage for an ADMIT weblog. Each green horizontal bar represents an individual ADMIT task that was run and clicking on it will expand that section to show more details and the output for that section.</caption>]]<br />
<br />
<br />
<br />
The text within each bar gives the ADMIT Task name, the task ID number, the parameters that were used within that task, and any output image names (Figure 1). Note that ADMIT uses the basename "x" if one isn't supplied so all the output file names will be "x.*". Clicking on one of the green horizontal bars will reveal all the output for that ADMIT task. Just under the expanded bar will be the task name (which hyperlinks to the ADMIT wiki page for that task) and a one-line explanation of what that task does (Figure 2).<br />
<br />
<br />
[[Image:ADMIT_task_link.png|600px|thumb|<caption>Below each green horizontal bar is a one-line description of that ADMIT task, clicking on the task name hyperlinks to the ADMIT wiki page for that task.</caption>]]<br />
<br />
<br />
Now, we will go through all of the output in the ADMIT weblog and describe what each task does and what output to expect.<br />
<br />
<br />
=== The ADMIT data Flow ===<br />
Clicking on the top-most bar of the weblog, “Flow Diagram for Antennae_North.CO3_2Line.Clean.pcal1.image.admit” (see Figure 1), reveals the “ADMIT Flow Diagram” (Figure 3). This is an illustration of how the products created in each task flow through the entire process. For a detailed discussion of how ADMIT flows work (and how to create your own) please see <br />
<br />
http://admit.astro.umd.edu/design.html#workflow-management<br />
<br />
For continuum images, these diagrams are extremely simple but for line-dense image cubes these can be incredibly complicated. Figure 3 shows what the ADMIT Flow looks like for our dataset. This diagram is a directed acyclic graph representing the ADMIT Task connections. Each arrow represents the connection from an ADMIT task output to the input of another ADMIT Task. The integer next to each arrow is the zero-based index of the ADMIT Task's output basic data product. Note that any output basic data product may be used as the input for more than one ADMIT Task.<br />
<br />
<br />
[[Image:ADMIT_Flow_diagram_example.png|300px|thumb|<caption>The ADMIT Flow diagram for processing the Antennae_North.CO3_2Line.Clean.pcal1.image.fits file.</caption>]]<br />
<br />
<br />
<br />
=== Ingest_AT ===<br />
This is the most basic task that is performed at the beginning of any ADMIT workflow. This task reads in a FITS image, creates a CASA image and extracts basic information such as rest frequency, beam size, image size, minimum/maximum values, etc.<br />
<br />
<br />
=== CubeStats_AT ===<br />
This task computes statistics on the image cube in the image-plane (meaning that the uv data is not examined). Here, ADMIT computes per-channel statistics in order to find the maximum and minimum values and pixel locations throughout the cube. This information is then used to generate global statistics such as mean intensity, a signal-free estimate of the noise, and the dynamic range. The maximum value pixel locations throughout the cube will also be used in later steps to help identify lines in the spectrum. Additionally, two plots are created:<br />
<br />
# Emission Characteristics Plot: The spectrum of various statistical measures (SNR, peak signal, RMS, and minimum signal) are plotted.<br />
# The Peak Point Plot: the image is searched and the peak emission locations are found for every channel in the cube and plotted. The size of the point in the image indicates the magnitude of the emission in that channel.<br />
<br />
=== CubeSum_AT ===<br />
This task creates a moment 0 map of all the emission in the image cube, regardless of whether or not it comes from different spectral lines (Figure 4). The RMS, and therefore cutoff emission level, is determined by the previous step, CubeStats_AT.<br />
<br />
<br />
[[Image:ADMIT_mom0.png|400px|thumb|<caption>A Moment 0 map of Antenna North created by ADMIT during CubeSum_AT.</caption>]]<br />
<br />
<br />
<br />
=== SFind2D_AT ===<br />
This task creates a list of sources found in the 2D image created by CubeSum_AT. The output is a table which lists peak source positions and fluxes. An image is also displayed which shows where the sources are located. <br />
<br />
<br />
=== CubeSpectrum_AT ===<br />
Given the input from SFind2D_AT of source positions, the statistics of the image from CubeStats_AT, the moment map created by CubeSum_AT, and the initial input image, this task computes the spectra of the cube at a specific point (or points). The output are averaged spectra taken at the locations of the three maximum flux values in the cube.<br />
<br />
=== LineSegment_AT ===<br />
This task detects segments of emission (i.e. spectral lines) based on RMS cutoffs and the input spectra provided from the previous CubeSpectrum_AT task but does not yet identify the lines (this will be done in a later stage). The output is then a list of potential spectral lines as well as spectra showing where the potential lines have been identified. Six plots are created (see Figure 5): peak intensity, minimum intensity, the three spectra provided as inputs from CubeSpectrum_AT, and a Signal/Noise summary plot. For each spectrum, the potentially identified lines are overlaid and the amplitude is given as a multiple of the noise (either Peak/Noise or Minimum/Noise)<br />
<br />
<br />
[[Image:ADMIT_LineSegment_AT.png|500px|thumb|<caption>ADMIT output from the LineSegment_AT task which identifies parts of the spectrum that contain line emission.</caption>]]<br />
<br />
<br />
=== PVSlice_AT ===<br />
This task creates a position-velocity (PV) diagram through the input image cube. Given the original image cube and the output moment map from CubeSum_AT, the moment of inertia is computed and used to derive "the best slice" through the image cube. The output is then two figures; the location of the PV slice drawn through the moment map, and the PV diagram.<br />
<br />
=== PVCorr_AT ===<br />
Using an input PV slice from PVSlice_AT and the cube statistics from CubeStats_AT (from which the RMS is taken), this task computes a cross-correlation of the PV slice. It does this by attempting to correlate sections of the spectrum with the whole PVSlice. If the section is not random noise, then the output will show a high correlation for that section. This can be most useful for detecting weak spectral lines.<br />
<br />
<br />
=== LineID_AT ===<br />
In this task, ADMIT identifies spectral lines in the input datacube using the output from CubeSpectrum_AT and CubeStats_AT. The output here is very similar to the above LineSegment_AT task except that the line segments have now been identified. For our example here of the Antenna North we see that the large spectral line has been correctly identified as CO (3-2). <br />
<br />
<br />
=== LineCube_AT ===<br />
Given the output list of lines from LineID_AT, this task generates smaller line cubes from the input image cube, each centered around an identified line. A table is presented showing the identified line molecule and rest frequency, the starting and ending channel for the smaller cube, and the name given to the output cube.<br />
<br />
=== Moment_AT ===<br />
For each line cube that is made during the above task, LineCube_AT, a moment map is produced via Moment_AT. This task uses the input line cube as well as information from CubeStats_AT to create a Moment 0, Moment 1, and Moment 2 map. <br />
<br />
[[Image:ADMIT_mom0-2.png|500px|thumb|<caption>ADMIT output from the Moment_AT task which creates the first three moment maps from the input cube.</caption>]]<br />
<br />
<br />
=== CubeSpectrum_AT ===<br />
Likewise, for each line cube that is made during LineCube_AT, this task computes the spectrum for the pixel with the maximum flux value in the moment 0 map created by the Moment_AT task.<br />
<br />
=== Moment_AT ===<br />
Finally, ADMIT creates another moment 0 map using the full, original input cube and information from CubeStats_AT.<br />
<br />
== Customizing ADMIT for your dataset == <br />
As outlined near the beginning of this guide, you can customize an ADMIT run by supplying additional parameters to admit1.py via a parameter file and pointing to it with the --apar flag in your admit1.py call.<br />
<br />
Each time ADMIT runs, it creates an admit0.py script (found in the same directory as the index.html file) which is an auto-generated script of the ADMIT flow that was performed. Therefore, another option for customizing your ADMIT output is to edit this script (admit0.py) to include extra parameters for your data, and run again. For example, you may add the VLSR to Ingest_AT or LineID_AT for more accurate line identification, or you may change the “online” boolean flag in LineID_AT to “True” so that ADMIT searches the online version of Splatalogue to identify lesser known chemical species. To find out what parameters are available for customization, please see the online documentation for each task by clicking on the task name under its header in the weblog (index.html). <br />
<br />
It is best practice to first make a copy of the admit0.py script in your working directory (one directory above the [image_file].admit directory). Then, edit the admit0.py script that was just copied to the working directory and run the script to create the new ADMIT products by simply typing: <br />
<br />
<source lang="bash"><br />
# In bash<br />
admit0.py<br />
</source><br />
<br />
Once you are comfortable with editing the admit0.py script, this can help you start to create your own ADMIT flows which you can use to help you quickly sift through large datasets.</div>Tashtonhttps://casaguides.nrao.edu/index.php?title=Guide_to_the_NA_Imaging_Template&diff=35932Guide to the NA Imaging Template2023-10-19T18:27:29Z<p>Tashton: /* Guide Contents */</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_CASA_6.5.4 | 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_CASA_6.5.4 | 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_CASA_6.5.4 | 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_CASA_6.5.4 | Self-Calibration]]''' This page provides a basic template for phase and amplitude self calibration of the continuum using the MS created in [[Image_Continuum_CASA_6.5.4 | Image the Continuum]] section. Commands can be found in scriptForImaging_template.py available on [https://github.com/aakepley/ALMAImagingScript github].<br />
#'''[[Image_Line_CASA_6.5.4 | Spectral Line Imaging]]''' This page performs continuum subtraction and creates spectral line cubes using the MS created in [[Imaging_Prep_CASA_6.5.4 | 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>Tashtonhttps://casaguides.nrao.edu/index.php?title=Guide_to_the_NA_Imaging_Template&diff=35931Guide to the NA Imaging Template2023-10-19T18:27:10Z<p>Tashton: /* Guide Contents */</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_CASA_6.5.4 | 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_CASA_6.5.4 | 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_CASA_6.5.4 | 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_CASA_6.5.4 | Self-Calibration]]''' This page provides a basic template for phase and amplitude self calibration of the continuum using the MS created in [[Image_Continuum_CASA_6.5.4 | Image the Continuum]] section. Commands can be found in scriptForImaging_template.py available on [https://github.com/aakepley/ALMAImagingScript github].<br />
#'''[[Image_Line_CASA_6.5.4 | Spectral Line Imaging]]''' This page performs continuum subtraction and creates spectral line cubes using the MS created in [[Imaging_Prep_CASA_6.5.4 | 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>Tashtonhttps://casaguides.nrao.edu/index.php?title=Guide_to_the_NA_Imaging_Template&diff=35930Guide to the NA Imaging Template2023-10-19T18:25:36Z<p>Tashton: /* Guide Contents */</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_CASA_6.5.4 | 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>Tashtonhttps://casaguides.nrao.edu/index.php?title=Guide_to_the_NA_Imaging_Template&diff=35929Guide to the NA Imaging Template2023-10-19T18:25:08Z<p>Tashton: /* Guide Contents */</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>Tashtonhttps://casaguides.nrao.edu/index.php?title=Guide_to_the_NA_Imaging_Template&diff=35928Guide to the NA Imaging Template2023-10-19T18:24:33Z<p>Tashton: /* Guide Contents */</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_6.5.4 | 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>Tashtonhttps://casaguides.nrao.edu/index.php?title=Image_Line_CASA_6.5.4&diff=35921Image Line CASA 6.5.42023-10-18T19:03:22Z<p>Tashton: </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 />
This guide features CARTA, the “Cube Analysis and Rendering Tool for Astronomy,” which is the new NRAO visualization tool for images and cubes. The CASA viewer (imview) has not been maintained for a few years and will be removed from future versions of CASA. We strongly recommend using CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASA viewer and CARTA, as well as instructions on how to use CARTA at NRAO, is provided in the CARTA section of the CASA docs. <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_6.5.4}} 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_6.5.4}} once. However, if different fields have different line-free channels, then you will need to run {{uvcontsub_6.5.4}} multiple times. (And probably get a cup of coffee or two.)<br />
<br />
The output file for {{uvcontsub_6.5.4}} 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 />
<source lang="python"><br />
# in CASA<br />
fitspw = '2:0~1200;1500~3839,3:0~1200;1500~3839' # line free channels. Use au.invertChannelRanges<br />
finalvis='calibrated_final.ms'<br />
<br />
uvcontsub(vis=finalvis,<br />
outputvis=finalvis+'.contsub',<br />
fitspec=fitspw, # spw(s) (and channels) to do continuum subtraction on<br />
fitorder=1,<br />
intent='OBSERVE_TARGET*')<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_6.5.4}} 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_6.5.4}} 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_6.5.4}} or {{listobs_6.5.4}} 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_6.5.4}}. 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_6.5.4}} or {{mstransform_6.5.4}} 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_6.5.4}} and once in {{tclean_6.5.4}}.<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 />
<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. This can be done in either velocity space or channel space.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# velocity space<br />
start='-100km/s' <br />
width='2km/s'<br />
nchan = 100<br />
<br />
# alternate option<br />
# channel space<br />
start = 1600<br />
width = 1<br />
nchan = 150<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/kb/articles/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_6.5.4}} 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_6.5.4}} 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='lsrk' # velocity reference frame. See science goals.<br />
veltype='radio' # velocity type.<br />
</source><br />
<br />
You can use {{plotms_6.5.4}} 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 />
[[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 />
<source lang="python"><br />
# in CASA<br />
plotms(vis=linevis,xaxis='velocity',yaxis='amp',avgtime='1e8',avgscan=True,avgantenna=True,<br />
spw=spw,coloraxis='spw',transform=True,freqframe=outframe.upper(),restfreq=restfreq)<br />
</source><br />
<br />
The {{tclean_6.5.4}} 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_6.5.4}} 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_6.5.4}} 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 />
# perchanweightdensity=False # uncomment if you are running in CASA >=5.5.0<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 />
usepointing=False)<br />
</source><br />
<br />
As you may recall from the continuum imaging section, {{tclean_6.5.4}} generates several images with the name imagename+extension every time it cleans an image. If you re-run tclean with the same imagename, {{tclean_6.5.4}} 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_6.5.4}} 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_6.5.4}} 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_6.5.4}} 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 />
[[File:TWHydra_CO_3_2.image.mom8_6.5.4.png|thumb|<caption>The moment 8 map is shown for the CO (3-2) line cube created above.</caption>]]<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_6.5.4}} to create moment maps.<br />
The commands create png files of the continuum image and moment 8 maps, which you can open and examine in CARTA. <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>Tashtonhttps://casaguides.nrao.edu/index.php?title=Image_Continuum_CASA_6.5.4&diff=35920Image Continuum CASA 6.5.42023-10-18T18:42:19Z<p>Tashton: </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 />
<br />
This guide features CARTA, the “Cube Analysis and Rendering Tool for Astronomy,” which is the new NRAO visualization tool for images and cubes. The CASA viewer (imview) has not been maintained for a few years and will be removed from future versions of CASA. We strongly recommend using CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASA viewer and CARTA, as well as instructions on how to use CARTA at NRAO, is provided in the CARTA section of the CASA docs. <br />
<br />
== Check CASA version ==<br />
<br />
This template is for use in CASA versions 6.5.4 and greater. The following code checks the version of CASA and exits if it is less than 6.5.4. 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 />
try:<br />
import casalith<br />
except:<br />
print("Script requires CASA 6.0 or greater")<br />
<br />
if casalith.compare_version("<",[6,5,4]):<br />
print("Please use CASA version greater than or equal to 6.5.4 with this script")<br />
</source><br />
<br />
== Create an Averaged Continuum MS ==<br />
[[File:Calibrated_final_Field0_Spw0_6.5.4.png|thumb|Figure 1: spw 0]]<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 />
Appropriate averaging of a measurement set can reduce overall data volume, making imaging faster with {{tclean_6.5.4}}. 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 />
finalvis='calibrated_final.ms' # This is your output ms from the data<br />
# preparation script.<br />
# Set spws to be used to form continuum<br />
contspws = '0,1,2,3'<br />
<br />
# Set the weighting parameters for the upcoming tclean commands. These are discussed in detail in the Image Parameters section below<br />
weighting = 'briggs'<br />
robust = 0.5<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_6.5.4}} 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_6.5.4}} command. For now, we will set the parameters specifically, but the link (which takes you to another section of this guide) will explain how we arrive at their values. This command should be repeated for each spw and science field. <br />
<br />
<source lang="python"><br />
#In CASA <br />
testimagename='testImage'<br />
<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(testimagename+ext)<br />
<br />
field=['2'] #list all target fields<br />
spw=['0','1','2','3'] #list all target spw’s<br />
veltype='radio'<br />
cell='0.25arcsec'<br />
imsize=[128,128]<br />
gridder='standard'<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='lsrk', # velocity reference frame. See science goals<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 />
[[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 />
<br />
The first step to flagging the spectral line channels in your data is to use the {{flagmanager_6.5.4}} 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_6.5.4}}.<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 {{initweights_6.5.4}}. 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='0:1660~1760,2:2100~2200' # modify the channel range for your dataset<br />
</source><br />
<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 />
<br />
Next, use the task {{flagdata_6.5.4}} 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_6.5.4}} 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='2') <br />
</source><br />
<br />
Finally, we need to use the {{flagmanager_6.5.4}} tasks to restore the ms file to its original unflagged state, so that later we can do continuum subtraction and line imaging.<br />
[[File:Amp_vs_uvdist.png|thumb|Figure 5: Amplitude vs UVDistance plot of the continuum, colored by spw.]]<br />
<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_6.5.4}} 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='2'<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 />
<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 />
<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 />
<br />
[[File:Antennae_Antennae_North.Cont.Dirty.image.png|thumb|Figure 7]]<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 />
<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='0.25arcsec' # 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/kb/articles/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_6.5.4}} 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='lsrk' # 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_6.5.4}} 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_6.5.4}} 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_6.5.4}}. 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 [https://casadocs.readthedocs.io/en/stable/notebooks/memo-series.html?highlight=briggs#Dan-Briggs'-Dissertation---Robust-Weighting 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 />
The parameters niter and threshold provide two ways to stop the {{tclean_6.5.4}} process. The niter parameter is the maximum number of iterations allowed. After this limit has been reached, {{tclean_6.5.4}} will terminate. The threshold parameter sets a flux density threshold for the {{tclean_6.5.4}}. When the peak residual is below this value, {{tclean_6.5.4}} 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_6.5.4}} 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 CARTA. 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_6.5.4}}, 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 />
[[File:Cont_before_clean.png|thumb|Figure 9: During interactive {{tclean_6.5.4}}, the GUI will show an initial dirty image. From this GUI, create the {{tclean_6.5.4}} mask.]]<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 />
[[File:Final_Cont_residual.png|thumb|Figure 11: The final residual image.]]<br />
Now that you have set all of the imaging parameters you will need in {{tclean_6.5.4}}, 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_6.5.4}} to generate the mask used for cleaning automatically.<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_6.5.4}}. 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_6.5.4}} 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_6.5.4}} 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 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. Use if fractional bandwidth is >10%.<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 />
usepointing=False)<br />
</source><br />
<br />
Figure 9 shows the {{tclean_6.5.4}} 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_6.5.4}}. 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_6.5.4}} where you are, the blue arrow will stop the interactive part of {{tclean_6.5.4}}, 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_6.5.4}}. 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_6.5.4.png|center|frame|300px|Figure 12: The final continuum image.]]<br />
<br />
After creating the continuum image, you should now open the image in CARTA. If using NRAO machines, you can open a new terminal tab, cd to the working directory, then type:<br />
<br />
<source lang="bash"><br />
# in bash<br />
carta --no_browser<br />
</source><br />
<br />
Copy the output URL into a browser to view your CARTA session. Select and load <name.image>, and 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_6.5.4}} generates several images with the name imagename+extension. If you re-run tclean with the same imagename, {{tclean_6.5.4}} 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_6.5.4}} run. Note that CASA retains some image information in memory, so to truly delete the images, you need to run the {{rmtables_6.5.4}} command. You will also want to remove datacolumns that were added by tclean with {{clearcal_6.5.4}} and {{delmod_6.5.4}}. 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_6.5.4}} 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_6.5.4}} 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>Tashtonhttps://casaguides.nrao.edu/index.php?title=Image_Line_CASA_6.5.4&diff=35919Image Line CASA 6.5.42023-10-18T18:40:19Z<p>Tashton: </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 />
This guide features CARTA, the “Cube Analysis and Rendering Tool for Astronomy,” which is the new NRAO visualization tool for images and cubes. The CASA viewer (imview) has not been maintained for a few years and will be removed from future versions of CASA. We strongly recommend using CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASA viewer and CARTA, as well as instructions on how to use CARTA at NRAO, is provided in the CARTA section of the CASA docs. <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_6.5.4}} 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_6.5.4}} once. However, if different fields have different line-free channels, then you will need to run {{uvcontsub_6.5.4}} multiple times. (And probably get a cup of coffee or two.)<br />
<br />
The output file for {{uvcontsub_6.5.4}} 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 />
<source lang="python"><br />
# in CASA<br />
fitspw = '2:0~1200;1500~3839,3:0~1200;1500~3839' # line free channels. Use au.invertChannelRanges<br />
finalvis='calibrated_final.ms'<br />
<br />
uvcontsub(vis=finalvis,<br />
outputvis=finalvis+'.contsub',<br />
fitspec=fitspw, # spw(s) (and channels) to do continuum subtraction on<br />
fitorder=1,<br />
intent='OBSERVE_TARGET*')<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_6.5.4}} 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_6.5.4}} 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_6.5.4}} or {{listobs_6.5.4}} 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_6.5.4}}. 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_6.5.4}} or {{mstransform_6.5.4}} 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_6.5.4}} and once in {{tclean_6.5.4}}.<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 />
<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. This can be done in either velocity space or channel space.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# velocity space<br />
start='-100km/s' <br />
width='2km/s'<br />
nchan = 100<br />
<br />
# alternate option<br />
# channel space<br />
start = 1600<br />
width = 1<br />
nchan = 150<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/kb/articles/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_6.5.4}} 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_6.5.4}} 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='lsrk' # velocity reference frame. See science goals.<br />
veltype='radio' # velocity type.<br />
</source><br />
<br />
You can use {{plotms_6.5.4}} 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 />
[[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 />
<source lang="python"><br />
# in CASA<br />
plotms(vis=linevis,xaxis='velocity',yaxis='amp',avgtime='1e8',avgscan=True,avgantenna=True,<br />
spw=spw,coloraxis='spw',transform=True,freqframe=outframe.upper(),restfreq=restfreq)<br />
</source><br />
<br />
The {{tclean_6.5.4}} 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_6.5.4}} 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_6.5.4}} 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 />
# perchanweightdensity=False # uncomment if you are running in CASA >=5.5.0<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 />
usepointing=False)<br />
</source><br />
<br />
As you may recall from the continuum imaging section, {{tclean_6.5.4}} generates several images with the name imagename+extension every time it cleans an image. If you re-run tclean with the same imagename, {{tclean_6.5.4}} 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_6.5.4}} 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_6.5.4}} 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_6.5.4}} 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 />
[[File:TWHydra_CO_3_2.image.mom8_6.5.4.png|thumb|<caption>The moment 8 map is shown for the CO (3-2) line cube created above.</caption>]]<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_6.5.4}} to create moment maps.<br />
The commands create png files of the continuum image and moment 8 maps, which you can open and examine in CARTA. <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>Tashtonhttps://casaguides.nrao.edu/index.php?title=Image_Continuum_CASA_6.5.4&diff=35914Image Continuum CASA 6.5.42023-10-18T16:40:36Z<p>Tashton: </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 />
<br />
This guide features CARTA, the “Cube Analysis and Rendering Tool for Astronomy,” which is the new NRAO visualization tool for images and cubes. The CASA viewer (imview) has not been maintained for a few years and will be removed from future versions of CASA. We strongly recommend using CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASA viewer and CARTA, as well as instructions on how to use CARTA at NRAO, is provided in the CARTA section of the CASA docs. <br />
<br />
== Check CASA version ==<br />
<br />
This template is for use in CASA versions 6.5.4 and greater. The following code checks the version of CASA and exits if it is less than 6.5.4. 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 />
try:<br />
import casalith<br />
except:<br />
print("Script requires CASA 6.0 or greater")<br />
<br />
if casalith.compare_version("<",[6,5,4]):<br />
print("Please use CASA version greater than or equal to 6.5.4 with this script")<br />
</source><br />
<br />
== Create an Averaged Continuum MS ==<br />
[[File:Calibrated_final_Field0_Spw0_6.5.4.png|thumb|Figure 1: spw 0]]<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 />
Appropriate averaging of a measurement set can reduce overall data volume, making imaging faster with {{tclean_6.5.4}}. 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 />
finalvis='calibrated_final.ms' # This is your output ms from the data<br />
# preparation script.<br />
# Set spws to be used to form continuum<br />
contspws = '0,1,2,3'<br />
<br />
# Set the weighting parameters for the upcoming tclean commands. These are discussed in detail in the Image Parameters section below<br />
weighting = 'briggs'<br />
robust = 0.5<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_6.5.4}} 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_6.5.4}} command. For now, we will set the parameters specifically, but the link (which takes you to another section of this guide) will explain how we arrive at their values. This command should be repeated for each spw and science field. <br />
<br />
<source lang="python"><br />
#In CASA <br />
testimagename='testImage'<br />
<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(testimagename+ext)<br />
<br />
field=['2'] #list all target fields<br />
spw=['0','1','2','3'] #list all target spw’s<br />
veltype='radio'<br />
cell='0.25arcsec'<br />
imsize=[128,128]<br />
gridder='standard'<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='lsrk', # velocity reference frame. See science goals<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 />
[[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 />
<br />
The first step to flagging the spectral line channels in your data is to use the {{flagmanager_6.5.4}} 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_6.5.4}}.<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 {{initweights_6.5.4}}. 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='0:1660~1760,2:2100~2200' # modify the channel range for your dataset<br />
</source><br />
<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 />
<br />
Next, use the task {{flagdata_6.5.4}} 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_6.5.4}} 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_6.5.4}} tasks to restore the ms file to its original unflagged state, so that later we can do continuum subtraction and line imaging.<br />
[[File:Amp_vs_uvdist.png|thumb|Figure 5: Amplitude vs UVDistance plot of the continuum, colored by spw.]]<br />
<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_6.5.4}} 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 />
<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 />
<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 />
<br />
[[File:Antennae_Antennae_North.Cont.Dirty.image.png|thumb|Figure 7]]<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 />
<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='0.25arcsec' # 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/kb/articles/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_6.5.4}} 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='lsrk' # 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_6.5.4}} 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_6.5.4}} 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_6.5.4}}. 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 [https://casadocs.readthedocs.io/en/stable/notebooks/memo-series.html?highlight=briggs#Dan-Briggs'-Dissertation---Robust-Weighting 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 />
The parameters niter and threshold provide two ways to stop the {{tclean_6.5.4}} process. The niter parameter is the maximum number of iterations allowed. After this limit has been reached, {{tclean_6.5.4}} will terminate. The threshold parameter sets a flux density threshold for the {{tclean_6.5.4}}. When the peak residual is below this value, {{tclean_6.5.4}} 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_6.5.4}} 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 CARTA. 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_6.5.4}}, 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 />
[[File:Cont_before_clean.png|thumb|Figure 9: During interactive {{tclean_6.5.4}}, the GUI will show an initial dirty image. From this GUI, create the {{tclean_6.5.4}} mask.]]<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 />
[[File:Final_Cont_residual.png|thumb|Figure 11: The final residual image.]]<br />
Now that you have set all of the imaging parameters you will need in {{tclean_6.5.4}}, 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_6.5.4}} to generate the mask used for cleaning automatically.<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_6.5.4}}. 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_6.5.4}} 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_6.5.4}} 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 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. Use if fractional bandwidth is >10%.<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 />
usepointing=False)<br />
</source><br />
<br />
Figure 9 shows the {{tclean_6.5.4}} 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_6.5.4}}. 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_6.5.4}} where you are, the blue arrow will stop the interactive part of {{tclean_6.5.4}}, 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_6.5.4}}. 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_6.5.4.png|center|frame|300px|Figure 12: The final continuum image.]]<br />
<br />
After creating the continuum image, you should now open the image in CARTA. If using NRAO machines, you can open a new terminal tab, cd to the working directory, then type:<br />
<br />
<source lang="bash"><br />
# in bash<br />
carta --no_browser<br />
</source><br />
<br />
Copy the output URL into a browser to view your CARTA session. Select and load <name.image>, and 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_6.5.4}} generates several images with the name imagename+extension. If you re-run tclean with the same imagename, {{tclean_6.5.4}} 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_6.5.4}} run. Note that CASA retains some image information in memory, so to truly delete the images, you need to run the {{rmtables_6.5.4}} command. You will also want to remove datacolumns that were added by tclean with {{clearcal_6.5.4}} and {{delmod_6.5.4}}. 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_6.5.4}} 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_6.5.4}} 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>Tashtonhttps://casaguides.nrao.edu/index.php?title=Image_Continuum_CASA_6.5.4&diff=35910Image Continuum CASA 6.5.42023-10-17T17:47:18Z<p>Tashton: </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 />
<br />
This guide features CARTA, the “Cube Analysis and Rendering Tool for Astronomy,” which is the new NRAO visualization tool for images and cubes. The CASA viewer (imview) has not been maintained for a few years and will be removed from future versions of CASA. We strongly recommend using CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASA viewer and CARTA, as well as instructions on how to use CARTA at NRAO, is provided in the CARTA section of the CASA docs. <br />
<br />
== Check CASA version ==<br />
<br />
This template is for use in CASA versions 6.5.4 and greater. The following code checks the version of CASA and exits if it is less than 6.5.4. 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 />
try:<br />
import casalith<br />
except:<br />
print("Script requires CASA 6.0 or greater")<br />
<br />
if casalith.compare_version("<",[6,5,4]):<br />
print("Please use CASA version greater than or equal to 6.5.4 with this script")<br />
</source><br />
<br />
== Create an Averaged Continuum MS ==<br />
[[File:Calibrated_final_Field0_Spw0_6.5.4.png|thumb|Figure 1: spw 0]]<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 />
Appropriate averaging of a measurement set can reduce overall data volume, making imaging faster with {{tclean_6.5.4}}. 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 />
finalvis='calibrated_final.ms' # This is your output ms from the data<br />
# preparation script.<br />
# Set spws to be used to form continuum<br />
contspws = '0,1,2,3'<br />
<br />
# Set the weighting parameters for the upcoming tclean commands. These are discussed in detail in the Image Parameters section below<br />
weighting = 'briggs'<br />
robust = 0.5<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_6.5.4}} 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_6.5.4}} command. For now, we will set the parameters specifically, but the link (which takes you to another section of this guide) will explain how we arrive at their values. This command should be repeated for each spw and science field. <br />
<br />
<source lang="python"><br />
#In CASA <br />
testimagename='testImage'<br />
<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(testimagename+ext)<br />
<br />
field=['0'] #list all target fields<br />
spw=['0','1','2','3'] #list all target spw’s<br />
veltype='radio'<br />
cell='0.25arcsec'<br />
imsize=[128,128]<br />
gridder='standard'<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='lsrk', # velocity reference frame. See science goals<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 />
[[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 />
<br />
The first step to flagging the spectral line channels in your data is to use the {{flagmanager_6.5.4}} 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_6.5.4}}.<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 {{initweights_6.5.4}}. 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='0:1660~1760,2:2100~2200' # modify the channel range for your dataset<br />
</source><br />
<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 />
<br />
Next, use the task {{flagdata_6.5.4}} 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_6.5.4}} 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_6.5.4}} tasks to restore the ms file to its original unflagged state, so that later we can do continuum subtraction and line imaging.<br />
[[File:Amp_vs_uvdist.png|thumb|Figure 5: Amplitude vs UVDistance plot of the continuum, colored by spw.]]<br />
<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_6.5.4}} 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 />
<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 />
<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 />
<br />
[[File:Antennae_Antennae_North.Cont.Dirty.image.png|thumb|Figure 7]]<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 />
<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='0.25arcsec' # 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/kb/articles/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_6.5.4}} 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='lsrk' # 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_6.5.4}} 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_6.5.4}} 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_6.5.4}}. 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 [https://casadocs.readthedocs.io/en/stable/notebooks/memo-series.html?highlight=briggs#Dan-Briggs'-Dissertation---Robust-Weighting 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 />
The parameters niter and threshold provide two ways to stop the {{tclean_6.5.4}} process. The niter parameter is the maximum number of iterations allowed. After this limit has been reached, {{tclean_6.5.4}} will terminate. The threshold parameter sets a flux density threshold for the {{tclean_6.5.4}}. When the peak residual is below this value, {{tclean_6.5.4}} 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_6.5.4}} 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 CARTA. 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_6.5.4}}, 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 />
[[File:Cont_before_clean.png|thumb|Figure 9: During interactive {{tclean_6.5.4}}, the GUI will show an initial dirty image. From this GUI, create the {{tclean_6.5.4}} mask.]]<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 />
[[File:Final_Cont_residual.png|thumb|Figure 11: The final residual image.]]<br />
Now that you have set all of the imaging parameters you will need in {{tclean_6.5.4}}, 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_6.5.4}} to generate the mask used for cleaning automatically.<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_6.5.4}}. 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_6.5.4}} 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_6.5.4}} 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 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. Use if fractional bandwidth is >10%.<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 />
usepointing=False)<br />
</source><br />
<br />
Figure 9 shows the {{tclean_6.5.4}} 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_6.5.4}}. 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_6.5.4}} where you are, the blue arrow will stop the interactive part of {{tclean_6.5.4}}, 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_6.5.4}}. 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_6.5.4.png|center|frame|300px|Figure 12: The final continuum image.]]<br />
<br />
After creating the continuum image, you should now open the image in CARTA. If using NRAO machines, you can open a new terminal tab, cd to the working directory, then type:<br />
<br />
<source lang="bash"><br />
# in bash<br />
carta --no_browser<br />
</source><br />
<br />
Copy the output URL into a browser to view your CARTA session. Select and load <name.image>, and 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_6.5.4}} generates several images with the name imagename+extension. If you re-run tclean with the same imagename, {{tclean_6.5.4}} 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_6.5.4}} run. Note that CASA retains some image information in memory, so to truly delete the images, you need to run the {{rmtables_6.5.4}} command. You will also want to remove datacolumns that were added by tclean with {{clearcal_6.5.4}} and {{delmod_6.5.4}}. 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_6.5.4}} 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_6.5.4}} 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>Tashtonhttps://casaguides.nrao.edu/index.php?title=Self-Calibration_Template_CASA_6.5.4&diff=35797Self-Calibration Template CASA 6.5.42023-10-11T20:35:16Z<p>Tashton: </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 />
This guide features CARTA, the “Cube Analysis and Rendering Tool for Astronomy,” which is the new NRAO visualization tool for images and cubes. The CASA viewer (imview) has not been maintained for a few years and will be removed from future versions of CASA. We strongly recommend using CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASA viewer and CARTA, as well as instructions on how to use CARTA at NRAO, is provided in the CARTA section of the CASA docs. <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_6.5.4}}. Then you use this model to determine the gains as a function of time using the {{gaincal_6.5.4}} 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_6.5.4}} 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_6.5.4}} task as well as the {{clearcal_6.5.4}} task (which will need to be uncommented in the code below).<br />
<br />
<source lang="python"><br />
# in CASA<br />
# delmod(vis=contvis,otf=True,scr=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_6.5.4}} or {{listobs_6.5.4}}/{{vishead_6.5.4}} 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 />
usepointing=False)<br />
<br />
# Note number of iterations performed.<br />
<br />
</source><br />
<br />
Before proceeding, make sure that {{tclean_6.5.4}} has saved the model column. You should see a message like the following <br />
<pre style="background-color: #E0FFFF;"><br />
>>> INFO .... ------ Predict Model ------<br />
>>> INFO ... Saving model column<br />
</pre><br />
If you don't see this message, you should repeat the above {{tclean_6.5.4}} command with the following modifications. This will populate the model column.<br />
<pre style="background-color: #E0FFFF;"><br />
niter=0<br />
calcpsf=False<br />
calcres=False<br />
</pre><br />
As you continue with the self-cal, always make sure the model column is saved after running {{tclean_6.5.4}}.<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_6.5.4}}. We use the {{rmtables_6.5.4}} 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_6.5.4}} 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_6.5.4}} 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 />
<br />
[[File:Plotcal_image.png|thumb|Figure 1: Solutions from the first round of self-cal.]]<br />
<br />
You should also check the solutions (above) that were obtained using {{plotms_6.5.4}}. 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 />
plotms(vis='pcal1',<br />
xaxis='time',<br />
yaxis='phase',<br />
iteraxis='antenna',<br />
plotrange=[0,0,-180,180],<br />
gridrows=3,<br />
gridcols=3)<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 />
<br />
[[File:Pcal1_6.5.4.png|thumb|Figure 2: Continuum image after the first round of self-cal.]]<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_6.5.4}}. 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 />
usepointing=False)<br />
# Note number of iterations performed.<br />
</source><br />
<br />
You should inspect the new image in CARTA to assess how well self-calibration worked. If using NRAO machines, you can open a new terminal tab, cd to the working directory, then type: <br />
<br />
<source lang="bash><br />
# in bash<br />
carta --no_browser<br />
</source><br />
<br />
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_6.5.4}} 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 />
plotms(vis='pcal2',<br />
xaxis='time',<br />
yaxis='phase',<br />
iteraxis='antenna',<br />
plotrange=[0,0,-180,180],<br />
gridrows=3,<br />
gridcols=3)<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_6.5.4}}/{{gaincal_6.5.4}}/{{applycal_6.5.4}} 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 />
usepointing=False)<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 />
plotms(vis='pcal3',<br />
xaxis='time',<br />
yaxis='phase',<br />
iteraxis='antenna',<br />
plotrange=[0,0,-180,180],<br />
gridrows=3,<br />
gridcols=3)<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 />
usepointing=False)<br />
<br />
# Note number of iterations performed.<br />
</source><br />
[[File:Imaging-tutorial-selfcal-3.png|thumb|Figure 3: Amplitude based residuals after phase self-cal.]]<br />
[[File:Apcal_6.5.4.png|thumb|Figure 4: Image after amplitude self-cal.]]<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 />
plotms(vis='apcal',<br />
xaxis='time',<br />
yaxis='phase',<br />
iteraxis='antenna',<br />
plotrange=[0,0,-180,180],<br />
gridrows=3,<br />
gridcols=3)<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 />
usepointing=False)<br />
</source><br />
<br />
Using CARTA, compare the final image to the initial image and see if the image dynamic range (ratio between 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_6.5.4}} 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_6.5.4}} and {{delmod_6.5.4}} 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>Tashtonhttps://casaguides.nrao.edu/index.php?title=Template:Vishead_6.5.4&diff=35796Template:Vishead 6.5.42023-10-11T20:32:48Z<p>Tashton: Created page with "[https://casadocs.readthedocs.io/en/stable/api/tt/casatasks.information.vishead.html vishead]"</p>
<hr />
<div>[https://casadocs.readthedocs.io/en/stable/api/tt/casatasks.information.vishead.html vishead]</div>Tashtonhttps://casaguides.nrao.edu/index.php?title=Image_Continuum_CASA_6.5.4&diff=35795Image Continuum CASA 6.5.42023-10-11T20:32:15Z<p>Tashton: </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 />
<br />
This guide features CARTA, the “Cube Analysis and Rendering Tool for Astronomy,” which is the new NRAO visualization tool for images and cubes. The CASA viewer (imview) has not been maintained for a few years and will be removed from future versions of CASA. We strongly recommend using CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASA viewer and CARTA, as well as instructions on how to use CARTA at NRAO, is provided in the CARTA section of the CASA docs. <br />
<br />
== Check CASA version ==<br />
<br />
This template is for use in CASA versions 6.5.4 and greater. The following code checks the version of CASA and exits if it is less than 6.5.4. 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 />
try:<br />
import casalith<br />
except:<br />
print("Script requires CASA 6.0 or greater")<br />
<br />
if casalith.compare_version("<",[6,5,4]):<br />
print("Please use CASA version greater than or equal to 6.5.4 with this script")<br />
</source><br />
<br />
== Create an Averaged Continuum MS ==<br />
[[File:Calibrated_final_Field0_Spw0_6.5.4.png|thumb|Figure 1: spw 0]]<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 />
Appropriate averaging of a measurement set can reduce overall data volume, making imaging faster with {{tclean_6.5.4}}. 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 />
finalvis='calibrated_final.ms' # This is your output ms from the data<br />
# preparation script.<br />
# Set spws to be used to form continuum<br />
contspws = '0,1,2,3'<br />
<br />
# Set the weighting parameters for the upcoming tclean commands. These are discussed in detail in the Image Parameters section below<br />
weighting = 'briggs'<br />
robust = 0.5<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_6.5.4}} 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_6.5.4}} command. For now, we will set the parameters specifically, but the link (which takes you to another section of this guide) will explain how we arrive at their values. This command should be repeated for each spw and science field. <br />
<br />
<source lang="python"><br />
#In CASA <br />
testimagename='testImage'<br />
<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(testimagename+ext)<br />
<br />
field=['0'] #list all target fields<br />
spw=['0','1','2','3'] #list all target spw’s<br />
veltype='radio'<br />
cell='0.25arcsec'<br />
imsize=[128,128]<br />
gridder='standard'<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='lsrk', # velocity reference frame. See science goals<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 />
[[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 />
<br />
The first step to flagging the spectral line channels in your data is to use the {{flagmanager_6.5.4}} 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_6.5.4}}.<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 {{initweights_6.5.4}}. 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='0:1660~1760,2:2100~2200' # modify the channel range for your dataset<br />
</source><br />
<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 />
<br />
Next, use the task {{flagdata_6.5.4}} 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_6.5.4}} 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_6.5.4}} tasks to restore the ms file to its original unflagged state, so that later we can do continuum subtraction and line imaging.<br />
[[File:Amp_vs_uvdist.png|thumb|Figure 5: Amplitude vs UVDistance plot of the continuum, colored by spw.]]<br />
<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_6.5.4}} 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 />
<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 />
<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 />
<br />
[[File:Antennae_Antennae_North.Cont.Dirty.image.png|thumb|Figure 7]]<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 />
<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='0.25arcsec' # 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/kb/articles/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_6.5.4}} 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='lsrk' # 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_6.5.4}} 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_6.5.4}} 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_6.5.4}}. 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 [https://casadocs.readthedocs.io/en/stable/notebooks/memo-series.html?highlight=briggs#Dan-Briggs'-Dissertation---Robust-Weighting 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 />
The parameters niter and threshold provide two ways to stop the {{tclean_6.5.4}} process. The niter parameter is the maximum number of iterations allowed. After this limit has been reached, {{tclean_6.5.4}} will terminate. The threshold parameter sets a flux density threshold for the {{tclean_6.5.4}}. When the peak residual is below this value, {{tclean_6.5.4}} 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_6.5.4}} 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 CARTA. 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_6.5.4}}, 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 />
[[File:Cont_before_clean.png|thumb|Figure 9: During interactive {{tclean_6.5.4}}, the GUI will show an initial dirty image. From this GUI, create the {{tclean_6.5.4}} mask.]]<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 />
[[File:Final_Cont_residual.png|thumb|Figure 11: The final residual image.]]<br />
Now that you have set all of the imaging parameters you will need in {{tclean_6.5.4}}, 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_6.5.4}} to generate the mask used for cleaning automatically.<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_6.5.4}}. 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_6.5.4}} 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_6.5.4}} 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 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. Use if fractional bandwidth is >10%.<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 />
usepointing=False)<br />
</source><br />
<br />
Figure 9 shows the {{tclean_6.5.4}} 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_6.5.4}}. 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_6.5.4}} where you are, the blue arrow will stop the interactive part of {{tclean_6.5.4}}, 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_6.5.4}}. 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_6.5.4.png|center|frame|300px|Figure 12: The final continuum image.]]<br />
<br />
After creating the continuum image, you should now open the image in CARTA. If using NRAO machines, you can open a new terminal tab, cd to the working directory, then type:<br />
<br />
<source lang="bash"><br />
# in bash<br />
carta --no_browser<br />
</source><br />
<br />
Copy the output URL into a browser to view your CARTA session. Select and load <name.image>, and 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_6.5.4}} generates several images with the name imagename+extension. If you re-run tclean with the same imagename, {{tclean_6.5.4}} 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_6.5.4}} run. Note that CASA retains some image information in memory, so to truly delete the images, you need to run the {{rmtables_6.5.4}} command. You will also want to remove datacolumns that were added by tclean with {{clearcal_6.5.4}} and {{delmod_6.5.4}}. 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_6.5.4}} 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_6.5.4}} 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>Tashtonhttps://casaguides.nrao.edu/index.php?title=Template:Initweights_6.5.4&diff=35794Template:Initweights 6.5.42023-10-11T20:31:25Z<p>Tashton: Created page with "[https://casadocs.readthedocs.io/en/stable/api/tt/casatasks.calibration.initweights.html initweights]"</p>
<hr />
<div>[https://casadocs.readthedocs.io/en/stable/api/tt/casatasks.calibration.initweights.html initweights]</div>Tashtonhttps://casaguides.nrao.edu/index.php?title=Template:Delmod_6.5.4&diff=35793Template:Delmod 6.5.42023-10-11T20:30:14Z<p>Tashton: Created page with "[https://casadocs.readthedocs.io/en/stable/api/tt/casatasks.imaging.delmod.html delmod]"</p>
<hr />
<div>[https://casadocs.readthedocs.io/en/stable/api/tt/casatasks.imaging.delmod.html delmod]</div>Tashtonhttps://casaguides.nrao.edu/index.php?title=Template:Clearcal_6.5.4&diff=35792Template:Clearcal 6.5.42023-10-11T20:29:20Z<p>Tashton: Created page with "[https://casadocs.readthedocs.io/en/stable/api/tt/casatasks.calibration.clearcal.html clearcal]"</p>
<hr />
<div>[https://casadocs.readthedocs.io/en/stable/api/tt/casatasks.calibration.clearcal.html clearcal]</div>Tashtonhttps://casaguides.nrao.edu/index.php?title=Template:Rmtables_6.5.4&diff=35791Template:Rmtables 6.5.42023-10-11T20:28:39Z<p>Tashton: Created page with "[https://casadocs.readthedocs.io/en/stable/api/tt/casatasks.manipulation.rmtables.html rmtables]"</p>
<hr />
<div>[https://casadocs.readthedocs.io/en/stable/api/tt/casatasks.manipulation.rmtables.html rmtables]</div>Tashtonhttps://casaguides.nrao.edu/index.php?title=Imaging_Prep_CASA_6.5.4&diff=35790Imaging Prep CASA 6.5.42023-10-11T20:28:14Z<p>Tashton: </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 />
# If your MS is from Cycle 9 or later, when ALMA began delivering _targets.ms instead of _target.ms, comment out the previous line and uncomment the following line<br />
# vislist = glob.glob('*[!_ts].ms')<br />
<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 />
<br />
[[File:Weblog_Home.png|thumb|Figure 1: The Observation Overview page is opened with index.html.]]<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 />
<br />
[[File:Weblog_MS_Overview.png|thumb|Figure 2: The MS Overview gives information specific to each execution.]]<br />
<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 />
<br />
[[File:Weblog_By_Task.png|thumb|Figure 3: The weblog By Task view shows an overview of QA scores.]]<br />
<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 task {{plotms_6.5.4}} is 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_6.5.4}} 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 = ['0'] # change to list of science data fields to inspect<br />
spwlist = ['0','1','2','3'] # 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 />
input("push enter to continue")<br />
plotms(vis=vis,xaxis='chan',yaxis='amp',avgtime='3e8',<br />
field=field,spw=spw)<br />
input("push enter to continue")<br />
</source><br />
<br />
<br />
Use {{flagdata_6.5.4}} to flag bad antennas, spws, timeranges, etc. You can use the locate buttons in {{plotms_6.5.4}} 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_6.5.4}} 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_6.5.4}} GUI.<br />
<br />
[[File:TWHydra_corrected_Spw2.png|thumb|Figure 4: Inspect the data.]]<br />
<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 calibrators. [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 />
[[File:Gfluxscale_table.png|thumb|Figure 5: An example of the table created by hifa_gfluxscale.]]<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_6.5.4}}. Then amplitude calibration tables are generated and applied using {{gaincal_6.5.4}} and {{applycal_6.5.4}} respectively. Finally, all calibrated measurement sets will be concatenated using {{concat_6.5.4}}. <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_6.5.4}} 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_6.5.4}} file with information about the sources and spectral windows to reference during imaging. Inspect the {{listobs_6.5.4}} to make sure the {{split_6.5.4}} and {{concat_6.5.4}} 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_6.5.4}} 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_6.5.4}} 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 {{cvel2_6.5.4}} 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 {{cvel2_6.5.4}} prior to imaging, you should make sure to use the same input parameters to the {{tclean_6.5.4}} task that you used for {{cvel2_6.5.4}}. In other words, you shouldn't regrid the data using both {{cvel2_6.5.4}} and {{tclean_6.5.4}}.<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_6.5.4}} and {{cvel2_6.5.4}} should not be used to average greater than 2 channels together. This averaging should be done using {{tclean_6.5.4}} 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 cvel2/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 {{cvel2_6.5.4}} command to regrid multiple spws associated with a single rest frequency into a single spw. To avoid {{tclean_6.5.4}} regridding the image a second time you will need to use the same parameters used for {{cvel2_6.5.4}} for {{tclean_6.5.4}}.<br />
<br />
<source lang="python"><br />
# in CASA<br />
rmtables(regridvis)<br />
os.system('rm -rf ' + regridvis + '.flagversions')<br />
<br />
cvel2(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 {{tclean_6.5.4}} or {{uvcontsub_6.5.4}} 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>Tashtonhttps://casaguides.nrao.edu/index.php?title=Template:Cvel2_6.5.4&diff=35789Template:Cvel2 6.5.42023-10-11T20:27:05Z<p>Tashton: Created page with "[https://casadocs.readthedocs.io/en/stable/api/tt/casatasks.manipulation.cvel2.html cvel2]"</p>
<hr />
<div>[https://casadocs.readthedocs.io/en/stable/api/tt/casatasks.manipulation.cvel2.html cvel2]</div>Tashtonhttps://casaguides.nrao.edu/index.php?title=Template:Mstransform_6.5.4&diff=35788Template:Mstransform 6.5.42023-10-11T20:26:10Z<p>Tashton: Created page with "[https://casadocs.readthedocs.io/en/stable/api/tt/casatasks.manipulation.mstransform.html mstransform]"</p>
<hr />
<div>[https://casadocs.readthedocs.io/en/stable/api/tt/casatasks.manipulation.mstransform.html mstransform]</div>Tashtonhttps://casaguides.nrao.edu/index.php?title=Self-Calibration_Template_CASA_6.5.4&diff=35716Self-Calibration Template CASA 6.5.42023-10-06T19:43:42Z<p>Tashton: </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 />
This guide features CARTA, the “Cube Analysis and Rendering Tool for Astronomy,” which is the new NRAO visualization tool for images and cubes. The CASA viewer (imview) has not been maintained for a few years and will be removed from future versions of CASA. We strongly recommend using CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASA viewer and CARTA, as well as instructions on how to use CARTA at NRAO, is provided in the CARTA section of the CASA docs. <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_6.5.4}}. Then you use this model to determine the gains as a function of time using the {{gaincal_6.5.4}} 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_6.5.4}} 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_6.5.4}} task as well as the {{clearcal_6.5.4}} task (which will need to be uncommented in the code below).<br />
<br />
<source lang="python"><br />
# in CASA<br />
# delmod(vis=contvis,otf=True,scr=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_6.5.4}} or {{listobs_6.5.4}}/{{vishead_6.5.4}} 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 />
usepointing=False)<br />
<br />
# Note number of iterations performed.<br />
<br />
</source><br />
<br />
Before proceeding, make sure that {{tclean_6.5.4}} has saved the model column. You should see a message like the following <br />
<pre style="background-color: #E0FFFF;"><br />
>>> INFO .... ------ Predict Model ------<br />
>>> INFO ... Saving model column<br />
</pre><br />
If you don't see this message, you should repeat the above {{tclean_6.5.4}} command with the following modifications. This will populate the model column.<br />
<pre style="background-color: #E0FFFF;"><br />
niter=0<br />
calcpsf=False<br />
calcres=False<br />
</pre><br />
As you continue with the self-cal, always make sure the model column is saved after running {{tclean_6.5.4}}.<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_6.5.4}}. We use the {{rmtables_6.5.4}} 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_6.5.4}} 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_6.5.4}} 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 />
<br />
[[File:Plotcal_image.png|thumb|Figure 1: Solutions from the first round of self-cal.]]<br />
<br />
You should also check the solutions (above) that were obtained using {{plotcal_6.5.4}}. 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 />
plotms(vis='pcal1',<br />
xaxis='time',<br />
yaxis='phase',<br />
iteraxis='antenna',<br />
plotrange=[0,0,-180,180],<br />
gridrows=3,<br />
gridcols=3)<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 />
<br />
[[File:Pcal1_6.5.4.png|thumb|Figure 2: Continuum image after the first round of self-cal.]]<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_6.5.4}}. 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 />
usepointing=False)<br />
# Note number of iterations performed.<br />
</source><br />
<br />
You should inspect the new image in CARTA to assess how well self-calibration worked. If using NRAO machines, you can open a new terminal tab, cd to the working directory, then type: <br />
<br />
<source lang="bash><br />
# in bash<br />
carta --no_browser<br />
</source><br />
<br />
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_6.5.4}} 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 />
plotms(vis='pcal2',<br />
xaxis='time',<br />
yaxis='phase',<br />
iteraxis='antenna',<br />
plotrange=[0,0,-180,180],<br />
gridrows=3,<br />
gridcols=3)<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_6.5.4}}/{{gaincal_6.5.4}}/{{applycal_6.5.4}} 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 />
usepointing=False)<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 />
plotms(vis='pcal3',<br />
xaxis='time',<br />
yaxis='phase',<br />
iteraxis='antenna',<br />
plotrange=[0,0,-180,180],<br />
gridrows=3,<br />
gridcols=3)<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 />
usepointing=False)<br />
<br />
# Note number of iterations performed.<br />
</source><br />
[[File:Imaging-tutorial-selfcal-3.png|thumb|Figure 3: Amplitude based residuals after phase self-cal.]]<br />
[[File:Apcal_6.5.4.png|thumb|Figure 4: Image after amplitude self-cal.]]<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 />
plotms(vis='apcal',<br />
xaxis='time',<br />
yaxis='phase',<br />
iteraxis='antenna',<br />
plotrange=[0,0,-180,180],<br />
gridrows=3,<br />
gridcols=3)<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 />
usepointing=False)<br />
</source><br />
<br />
Using CARTA, compare the final image to the initial image and see if the image dynamic range (ratio between 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_6.5.4}} 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_6.5.4}} and {{delmod_6.5.4}} 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>Tashtonhttps://casaguides.nrao.edu/index.php?title=File:Apcal_6.5.4.png&diff=35715File:Apcal 6.5.4.png2023-10-06T19:42:53Z<p>Tashton: </p>
<hr />
<div></div>Tashtonhttps://casaguides.nrao.edu/index.php?title=Self-Calibration_Template_CASA_6.5.4&diff=35714Self-Calibration Template CASA 6.5.42023-10-06T19:42:19Z<p>Tashton: </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 />
This guide features CARTA, the “Cube Analysis and Rendering Tool for Astronomy,” which is the new NRAO visualization tool for images and cubes. The CASA viewer (imview) has not been maintained for a few years and will be removed from future versions of CASA. We strongly recommend using CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASA viewer and CARTA, as well as instructions on how to use CARTA at NRAO, is provided in the CARTA section of the CASA docs. <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_6.5.4}}. Then you use this model to determine the gains as a function of time using the {{gaincal_6.5.4}} 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_6.5.4}} 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_6.5.4}} task as well as the {{clearcal_6.5.4}} task (which will need to be uncommented in the code below).<br />
<br />
<source lang="python"><br />
# in CASA<br />
# delmod(vis=contvis,otf=True,scr=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_6.5.4}} or {{listobs_6.5.4}}/{{vishead_6.5.4}} 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 />
usepointing=False)<br />
<br />
# Note number of iterations performed.<br />
<br />
</source><br />
<br />
Before proceeding, make sure that {{tclean_6.5.4}} has saved the model column. You should see a message like the following <br />
<pre style="background-color: #E0FFFF;"><br />
>>> INFO .... ------ Predict Model ------<br />
>>> INFO ... Saving model column<br />
</pre><br />
If you don't see this message, you should repeat the above {{tclean_6.5.4}} command with the following modifications. This will populate the model column.<br />
<pre style="background-color: #E0FFFF;"><br />
niter=0<br />
calcpsf=False<br />
calcres=False<br />
</pre><br />
As you continue with the self-cal, always make sure the model column is saved after running {{tclean_6.5.4}}.<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_6.5.4}}. We use the {{rmtables_6.5.4}} 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_6.5.4}} 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_6.5.4}} 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 />
<br />
[[File:Plotcal_image.png|thumb|Figure 1: Solutions from the first round of self-cal.]]<br />
<br />
You should also check the solutions (above) that were obtained using {{plotcal_6.5.4}}. 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 />
plotms(vis='pcal1',<br />
xaxis='time',<br />
yaxis='phase',<br />
iteraxis='antenna',<br />
plotrange=[0,0,-180,180],<br />
gridrows=3,<br />
gridcols=3)<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 />
<br />
[[File:Pcal1_6.5.4.png|thumb|Figure 2: Continuum image after the first round of self-cal.]]<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_6.5.4}}. 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 />
usepointing=False)<br />
# Note number of iterations performed.<br />
</source><br />
<br />
You should inspect the new image in CARTA to assess how well self-calibration worked. If using NRAO machines, you can open a new terminal tab, cd to the working directory, then type: <br />
<br />
<source lang="bash><br />
# in bash<br />
carta --no_browser<br />
</source><br />
<br />
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_6.5.4}} 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 />
plotms(vis='pcal2',<br />
xaxis='time',<br />
yaxis='phase',<br />
iteraxis='antenna',<br />
plotrange=[0,0,-180,180],<br />
gridrows=3,<br />
gridcols=3)<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_6.5.4}}/{{gaincal_6.5.4}}/{{applycal_6.5.4}} 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 />
usepointing=False)<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 />
plotms(vis='pcal3',<br />
xaxis='time',<br />
yaxis='phase',<br />
iteraxis='antenna',<br />
plotrange=[0,0,-180,180],<br />
gridrows=3,<br />
gridcols=3)<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 />
usepointing=False)<br />
<br />
# Note number of iterations performed.<br />
</source><br />
[[File:Imaging-tutorial-selfcal-3.png|thumb|Figure 3: Amplitude based residuals after phase self-cal.]]<br />
[[File:Apcal.png|thumb|Figure 4: Image after amplitude self-cal.]]<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 />
plotms(vis='apcal',<br />
xaxis='time',<br />
yaxis='phase',<br />
iteraxis='antenna',<br />
plotrange=[0,0,-180,180],<br />
gridrows=3,<br />
gridcols=3)<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 />
usepointing=False)<br />
</source><br />
<br />
Using CARTA, compare the final image to the initial image and see if the image dynamic range (ratio between 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_6.5.4}} 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_6.5.4}} and {{delmod_6.5.4}} 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>Tashtonhttps://casaguides.nrao.edu/index.php?title=File:Pcal1_6.5.4.png&diff=35713File:Pcal1 6.5.4.png2023-10-06T19:41:46Z<p>Tashton: </p>
<hr />
<div></div>Tashtonhttps://casaguides.nrao.edu/index.php?title=Image_Line_CASA_6.5.4&diff=35712Image Line CASA 6.5.42023-10-06T19:40:29Z<p>Tashton: </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 />
This guide features CARTA, the “Cube Analysis and Rendering Tool for Astronomy,” which is the new NRAO visualization tool for images and cubes. The CASA viewer (imview) has not been maintained for a few years and will be removed from future versions of CASA. We strongly recommend using CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASA viewer and CARTA, as well as instructions on how to use CARTA at NRAO, is provided in the CARTA section of the CASA docs. <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_6.5.4}} 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_6.5.4}} once. However, if different fields have different line-free channels, then you will need to run {{uvcontsub_6.5.4}} multiple times. (And probably get a cup of coffee or two.)<br />
<br />
The output file for {{uvcontsub_6.5.4}} 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 />
<source lang="python"><br />
# in CASA<br />
fitspw = '2:0~1200;1500~3839,3:0~1200;1500~3839' # line free channels. Use au.invertChannelRanges<br />
finalvis='calibrated_final.ms'<br />
<br />
uvcontsub(vis=finalvis,<br />
outputvis=finalvis+'.contsub',<br />
fitspec=fitspw, # spw(s) (and channels) to do continuum subtraction on<br />
fitorder=1,<br />
intent='OBSERVE_TARGET*')<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_6.5.4}} 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_6.5.4}} 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_6.5.4}} or {{listobs_6.5.4}} 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_6.5.4}}. 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_6.5.4}} or {{mstransform_6.5.4}} 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_6.5.4}} and once in {{tclean_6.5.4}}.<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 />
<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. This can be done in either velocity space or channel space.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# velocity space<br />
start='-100km/s' <br />
width='2km/s'<br />
nchan = 100<br />
<br />
# alternate option<br />
# channel space<br />
start = 1600<br />
width = 1<br />
nchan = 150<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/kb/articles/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_6.5.4}} 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_6.5.4}} 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='lsrk' # velocity reference frame. See science goals.<br />
veltype='radio' # velocity type.<br />
</source><br />
<br />
You can use {{plotms_6.5.4}} 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 />
[[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 />
<source lang="python"><br />
# in CASA<br />
plotms(vis=linevis,xaxis='velocity',yaxis='amp',avgtime='1e8',avgscan=True,avgantenna=True,<br />
spw=spw,coloraxis='spw',transform=True,freqframe=outframe.upper(),restfreq=restfreq)<br />
</source><br />
<br />
The {{tclean_6.5.4}} 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_6.5.4}} 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_6.5.4}} 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 />
# perchanweightdensity=False # uncomment if you are running in CASA >=5.5.0<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 />
usepointing=False)<br />
</source><br />
<br />
As you may recall from the continuum imaging section, {{tclean_6.5.4}} generates several images with the name imagename+extension every time it cleans an image. If you re-run tclean with the same imagename, {{tclean_6.5.4}} 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_6.5.4}} 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_6.5.4}} 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_6.5.4}} 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 />
[[File:TWHydra_CO_3_2.image.mom8_6.5.4.png|thumb|<caption>The moment 8 map is shown for the CO (3-2) line cube created above.</caption>]]<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_6.5.4}} to create moment maps.<br />
The commands create png files of the continuum image and moment 8 maps, which you can open and examine in CARTA. <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>Tashtonhttps://casaguides.nrao.edu/index.php?title=File:TWHydra_CO_3_2.image.mom8_6.5.4.png&diff=35711File:TWHydra CO 3 2.image.mom8 6.5.4.png2023-10-06T19:39:59Z<p>Tashton: </p>
<hr />
<div></div>Tashtonhttps://casaguides.nrao.edu/index.php?title=Image_Continuum_CASA_6.5.4&diff=35710Image Continuum CASA 6.5.42023-10-06T19:38:42Z<p>Tashton: </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 />
<br />
This guide features CARTA, the “Cube Analysis and Rendering Tool for Astronomy,” which is the new NRAO visualization tool for images and cubes. The CASA viewer (imview) has not been maintained for a few years and will be removed from future versions of CASA. We strongly recommend using CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASA viewer and CARTA, as well as instructions on how to use CARTA at NRAO, is provided in the CARTA section of the CASA docs. <br />
<br />
== Check CASA version ==<br />
<br />
This template is for use in CASA versions 6.5.4 and greater. The following code checks the version of CASA and exits if it is less than 6.5.4. 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 />
try:<br />
import casalith<br />
except:<br />
print("Script requires CASA 6.0 or greater")<br />
<br />
if casalith.compare_version("<",[6,5,4]):<br />
print("Please use CASA version greater than or equal to 6.5.4 with this script")<br />
</source><br />
<br />
== Create an Averaged Continuum MS ==<br />
[[File:Calibrated_final_Field0_Spw0_6.5.4.png|thumb|Figure 1: spw 0]]<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 />
Appropriate averaging of a measurement set can reduce overall data volume, making imaging faster with {{tclean_6.5.4}}. 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 />
finalvis='calibrated_final.ms' # This is your output ms from the data<br />
# preparation script.<br />
# Set spws to be used to form continuum<br />
contspws = '0,1,2,3'<br />
<br />
# Set the weighting parameters for the upcoming tclean commands. These are discussed in detail in the Image Parameters section below<br />
weighting = 'briggs'<br />
robust = 0.5<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_6.5.4}} 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_6.5.4}} command. For now, we will set the parameters specifically, but the link (which takes you to another section of this guide) will explain how we arrive at their values. This command should be repeated for each spw and science field. <br />
<br />
<source lang="python"><br />
#In CASA <br />
testimagename='testImage'<br />
<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(testimagename+ext)<br />
<br />
field=['0'] #list all target fields<br />
spw=['0','1','2','3'] #list all target spw’s<br />
veltype='radio'<br />
cell='0.25arcsec'<br />
imsize=[128,128]<br />
gridder='standard'<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='lsrk', # velocity reference frame. See science goals<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 />
[[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 />
<br />
The first step to flagging the spectral line channels in your data is to use the {{flagmanager_6.5.4}} 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_6.5.4}}.<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 {{initweights_6.5.4}}. 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='0:1660~1760,2:2100~2200' # modify the channel range for your dataset<br />
</source><br />
<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 />
<br />
Next, use the task {{flagdata_6.5.4}} 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_6.5.4}} 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_6.5.4}} tasks to restore the ms file to its original unflagged state, so that later we can do continuum subtraction and line imaging.<br />
[[File:Amp_vs_uvdist.png|thumb|Figure 5: Amplitude vs UVDistance plot of the continuum, colored by spw.]]<br />
<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_6.5.4}} 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 />
<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 />
<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 />
<br />
[[File:Antennae_Antennae_North.Cont.Dirty.image.png|thumb|Figure 7]]<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 />
<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='0.25arcsec' # 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/kb/articles/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_6.5.4}} 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='lsrk' # 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_6.5.4}} 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_6.5.4}} 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_6.5.4}}. 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 [https://casadocs.readthedocs.io/en/stable/notebooks/memo-series.html?highlight=briggs#Dan-Briggs'-Dissertation---Robust-Weighting 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 />
The parameters niter and threshold provide two ways to stop the {{tclean_6.5.4}} process. The niter parameter is the maximum number of iterations allowed. After this limit has been reached, {{tclean_6.5.4}} will terminate. The threshold parameter sets a flux density threshold for the {{tclean_6.5.4}}. When the peak residual is below this value, {{tclean_6.5.4}} 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_6.5.4}} 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_6.5.4}}. 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_6.5.4}}, 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 />
[[File:Cont_before_clean.png|thumb|Figure 9: During interactive {{tclean_6.5.4}}, the GUI will show an initial dirty image. From this GUI, create the {{tclean_6.5.4}} mask.]]<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 />
[[File:Final_Cont_residual.png|thumb|Figure 11: The final residual image.]]<br />
Now that you have set all of the imaging parameters you will need in {{tclean_6.5.4}}, 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_6.5.4}} to generate the mask used for cleaning automatically.<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_6.5.4}}. 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_6.5.4}} 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_6.5.4}} 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 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. Use if fractional bandwidth is >10%.<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 />
usepointing=False)<br />
</source><br />
<br />
Figure 9 shows the {{tclean_6.5.4}} 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_6.5.4}}. 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_6.5.4}} where you are, the blue arrow will stop the interactive part of {{tclean_6.5.4}}, 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_6.5.4}}. 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_6.5.4.png|center|frame|300px|Figure 12: The final continuum image.]]<br />
<br />
After creating the continuum image, you should now open the image in CARTA. If using NRAO machines, you can open a new terminal tab, cd to the working directory, then type:<br />
<br />
<source lang="bash"><br />
# in bash<br />
carta --no_browser<br />
</source><br />
<br />
Copy the output URL into a browser to view your CARTA session. Select and load <name.image>, and 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_6.5.4}} generates several images with the name imagename+extension. If you re-run tclean with the same imagename, {{tclean_6.5.4}} 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_6.5.4}} run. Note that CASA retains some image information in memory, so to truly delete the images, you need to run the {{rmtables_6.5.4}} command. You will also want to remove datacolumns that were added by tclean with {{clearcal_6.5.4}} and {{delmod_6.5.4}}. 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_6.5.4}} 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_6.5.4}} 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>Tashtonhttps://casaguides.nrao.edu/index.php?title=Image_Continuum_CASA_6.5.4&diff=35709Image Continuum CASA 6.5.42023-10-06T19:38:07Z<p>Tashton: </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 />
<br />
This guide features CARTA, the “Cube Analysis and Rendering Tool for Astronomy,” which is the new NRAO visualization tool for images and cubes. The CASA viewer (imview) has not been maintained for a few years and will be removed from future versions of CASA. We strongly recommend using CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASA viewer and CARTA, as well as instructions on how to use CARTA at NRAO, is provided in the CARTA section of the CASA docs. <br />
<br />
== Check CASA version ==<br />
<br />
This template is for use in CASA versions 6.5.4 and greater. The following code checks the version of CASA and exits if it is less than 6.5.4. 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 />
try:<br />
import casalith<br />
except:<br />
print("Script requires CASA 6.0 or greater")<br />
<br />
if casalith.compare_version("<",[6,5,4]):<br />
print("Please use CASA version greater than or equal to 6.5.4 with this script")<br />
</source><br />
<br />
== Create an Averaged Continuum MS ==<br />
[[File:Calibrated_final_Field0_Spw0_6.5.4.png|thumb|Figure 1: spw 0]]<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 />
Appropriate averaging of a measurement set can reduce overall data volume, making imaging faster with {{tclean_6.5.4}}. 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 />
finalvis='calibrated_final.ms' # This is your output ms from the data<br />
# preparation script.<br />
# Set spws to be used to form continuum<br />
contspws = '0,1,2,3'<br />
<br />
# Set the weighting parameters for the upcoming tclean commands. These are discussed in detail in the Image Parameters section below<br />
weighting = 'briggs'<br />
robust = 0.5<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_6.5.4}} 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_6.5.4}} command. For now, we will set the parameters specifically, but the link (which takes you to another section of this guide) will explain how we arrive at their values. This command should be repeated for each spw and science field. <br />
<br />
<source lang="python"><br />
#In CASA <br />
testimagename='testImage'<br />
<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(testimagename+ext)<br />
<br />
field=['0'] #list all target fields<br />
spw=['0','1','2','3'] #list all target spw’s<br />
veltype='radio'<br />
cell='0.25arcsec'<br />
imsize=[128,128]<br />
gridder='standard'<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='lsrk', # velocity reference frame. See science goals<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 />
[[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 />
<br />
The first step to flagging the spectral line channels in your data is to use the {{flagmanager_6.5.4}} 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_6.5.4}}.<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 {{initweights_6.5.4}}. 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='0:1660~1760,2:2100~2200' # modify the channel range for your dataset<br />
</source><br />
<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 />
<br />
Next, use the task {{flagdata_6.5.4}} 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_6.5.4}} 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_6.5.4}} tasks to restore the ms file to its original unflagged state, so that later we can do continuum subtraction and line imaging.<br />
[[File:Amp_vs_uvdist.png|thumb|Figure 5: Amplitude vs UVDistance plot of the continuum, colored by spw.]]<br />
<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_6.5.4}} 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 />
<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 />
<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 />
<br />
[[File:Antennae_Antennae_North.Cont.Dirty.image.png|thumb|Figure 7]]<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 />
<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='0.25arcsec' # 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/kb/articles/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_6.5.4}} 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='lsrk' # 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_6.5.4}} 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_6.5.4}} 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_6.5.4}}. 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 [https://casadocs.readthedocs.io/en/stable/notebooks/memo-series.html?highlight=briggs#Dan-Briggs'-Dissertation---Robust-Weighting 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 />
The parameters niter and threshold provide two ways to stop the {{tclean_6.5.4}} process. The niter parameter is the maximum number of iterations allowed. After this limit has been reached, {{tclean_6.5.4}} will terminate. The threshold parameter sets a flux density threshold for the {{tclean_6.5.4}}. When the peak residual is below this value, {{tclean_6.5.4}} 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_6.5.4}} 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_6.5.4}}. 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_6.5.4}}, 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 />
[[File:Cont_before_clean.png|thumb|Figure 9: During interactive {{tclean_6.5.4}}, the GUI will show an initial dirty image. From this GUI, create the {{tclean_6.5.4}} mask.]]<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 />
[[File:Final_Cont_residual.png|thumb|Figure 11: The final residual image.]]<br />
Now that you have set all of the imaging parameters you will need in {{tclean_6.5.4}}, 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_6.5.4}} to generate the mask used for cleaning automatically.<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_6.5.4}}. 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_6.5.4}} 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_6.5.4}} 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 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. Use if fractional bandwidth is >10%.<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 />
usepointing=False)<br />
</source><br />
<br />
Figure 9 shows the {{tclean_6.5.4}} 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_6.5.4}}. 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_6.5.4}} where you are, the blue arrow will stop the interactive part of {{tclean_6.5.4}}, 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_6.5.4}}. 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_6.5.4.png|center|frame|600px|Figure 12: The final continuum image.]]<br />
<br />
After creating the continuum image, you should now open the image in CARTA. If using NRAO machines, you can open a new terminal tab, cd to the working directory, then type:<br />
<br />
<source lang="bash"><br />
# in bash<br />
carta --no_browser<br />
</source><br />
<br />
Copy the output URL into a browser to view your CARTA session. Select and load <name.image>, and 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_6.5.4}} generates several images with the name imagename+extension. If you re-run tclean with the same imagename, {{tclean_6.5.4}} 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_6.5.4}} run. Note that CASA retains some image information in memory, so to truly delete the images, you need to run the {{rmtables_6.5.4}} command. You will also want to remove datacolumns that were added by tclean with {{clearcal_6.5.4}} and {{delmod_6.5.4}}. 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_6.5.4}} 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_6.5.4}} 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>Tashtonhttps://casaguides.nrao.edu/index.php?title=Image_Continuum_CASA_6.5.4&diff=35708Image Continuum CASA 6.5.42023-10-06T19:36:41Z<p>Tashton: </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 />
<br />
This guide features CARTA, the “Cube Analysis and Rendering Tool for Astronomy,” which is the new NRAO visualization tool for images and cubes. The CASA viewer (imview) has not been maintained for a few years and will be removed from future versions of CASA. We strongly recommend using CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASA viewer and CARTA, as well as instructions on how to use CARTA at NRAO, is provided in the CARTA section of the CASA docs. <br />
<br />
== Check CASA version ==<br />
<br />
This template is for use in CASA versions 6.5.4 and greater. The following code checks the version of CASA and exits if it is less than 6.5.4. 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 />
try:<br />
import casalith<br />
except:<br />
print("Script requires CASA 6.0 or greater")<br />
<br />
if casalith.compare_version("<",[6,5,4]):<br />
print("Please use CASA version greater than or equal to 6.5.4 with this script")<br />
</source><br />
<br />
== Create an Averaged Continuum MS ==<br />
[[File:Calibrated_final_Field0_Spw0_6.5.4.png|thumb|Figure 1: spw 0]]<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 />
Appropriate averaging of a measurement set can reduce overall data volume, making imaging faster with {{tclean_6.5.4}}. 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 />
finalvis='calibrated_final.ms' # This is your output ms from the data<br />
# preparation script.<br />
# Set spws to be used to form continuum<br />
contspws = '0,1,2,3'<br />
<br />
# Set the weighting parameters for the upcoming tclean commands. These are discussed in detail in the Image Parameters section below<br />
weighting = 'briggs'<br />
robust = 0.5<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_6.5.4}} 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_6.5.4}} command. For now, we will set the parameters specifically, but the link (which takes you to another section of this guide) will explain how we arrive at their values. This command should be repeated for each spw and science field. <br />
<br />
<source lang="python"><br />
#In CASA <br />
testimagename='testImage'<br />
<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(testimagename+ext)<br />
<br />
field=['0'] #list all target fields<br />
spw=['0','1','2','3'] #list all target spw’s<br />
veltype='radio'<br />
cell='0.25arcsec'<br />
imsize=[128,128]<br />
gridder='standard'<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='lsrk', # velocity reference frame. See science goals<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 />
[[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 />
<br />
The first step to flagging the spectral line channels in your data is to use the {{flagmanager_6.5.4}} 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_6.5.4}}.<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 {{initweights_6.5.4}}. 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='0:1660~1760,2:2100~2200' # modify the channel range for your dataset<br />
</source><br />
<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 />
<br />
Next, use the task {{flagdata_6.5.4}} 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_6.5.4}} 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_6.5.4}} tasks to restore the ms file to its original unflagged state, so that later we can do continuum subtraction and line imaging.<br />
[[File:Amp_vs_uvdist.png|thumb|Figure 5: Amplitude vs UVDistance plot of the continuum, colored by spw.]]<br />
<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_6.5.4}} 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 />
<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 />
<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 />
<br />
[[File:Antennae_Antennae_North.Cont.Dirty.image.png|thumb|Figure 7]]<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 />
<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='0.25arcsec' # 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/kb/articles/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_6.5.4}} 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='lsrk' # 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_6.5.4}} 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_6.5.4}} 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_6.5.4}}. 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 [https://casadocs.readthedocs.io/en/stable/notebooks/memo-series.html?highlight=briggs#Dan-Briggs'-Dissertation---Robust-Weighting 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 />
The parameters niter and threshold provide two ways to stop the {{tclean_6.5.4}} process. The niter parameter is the maximum number of iterations allowed. After this limit has been reached, {{tclean_6.5.4}} will terminate. The threshold parameter sets a flux density threshold for the {{tclean_6.5.4}}. When the peak residual is below this value, {{tclean_6.5.4}} 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_6.5.4}} 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_6.5.4}}. 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_6.5.4}}, 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 />
[[File:Cont_before_clean.png|thumb|Figure 9: During interactive {{tclean_6.5.4}}, the GUI will show an initial dirty image. From this GUI, create the {{tclean_6.5.4}} mask.]]<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 />
[[File:Final_Cont_residual.png|thumb|Figure 11: The final residual image.]]<br />
Now that you have set all of the imaging parameters you will need in {{tclean_6.5.4}}, 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_6.5.4}} to generate the mask used for cleaning automatically.<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_6.5.4}}. 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_6.5.4}} 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_6.5.4}} 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 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. Use if fractional bandwidth is >10%.<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 />
usepointing=False)<br />
</source><br />
<br />
Figure 9 shows the {{tclean_6.5.4}} 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_6.5.4}}. 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_6.5.4}} where you are, the blue arrow will stop the interactive part of {{tclean_6.5.4}}, 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_6.5.4}}. 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_6.5.4.png|center|frame|800px: The final continuum image.]] ''The final continuum image.''<br />
<br />
After creating the continuum image, you should now open the image in CARTA. If using NRAO machines, you can open a new terminal tab, cd to the working directory, then type:<br />
<br />
<source lang="bash"><br />
# in bash<br />
carta --no_browser<br />
</source><br />
<br />
Copy the output URL into a browser to view your CARTA session. Select and load <name.image>, and 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_6.5.4}} generates several images with the name imagename+extension. If you re-run tclean with the same imagename, {{tclean_6.5.4}} 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_6.5.4}} run. Note that CASA retains some image information in memory, so to truly delete the images, you need to run the {{rmtables_6.5.4}} command. You will also want to remove datacolumns that were added by tclean with {{clearcal_6.5.4}} and {{delmod_6.5.4}}. 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_6.5.4}} 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_6.5.4}} 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>Tashton