Imaging Prep: Difference between revisions

From CASA Guides
Jump to navigationJump to search
Ekeller (talk | contribs)
No edit summary
Masanche (talk | contribs)
m Changed redirect target from Imaging Prep CASA 6.5.4 to Imaging Prep CASA 6.6.1
Tag: Redirect target changed
 
(84 intermediate revisions by 5 users not shown)
Line 1: Line 1:
== Get a list of ms files to image ==
#REDIRECT [[Imaging Prep CASA 6.6.1]]
 
Once the calibration has run, it will produce ‘*.ms.split.cal’ files for each execution. These files contain the calibrated data. 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 called vislist.
 
<source lang="python">
# in CASA
import glob
vislist=glob.glob('*.ms.split.cal')
</source>
 
== Review the Calibration ==
 
Once the list of measurement set (ms) files have been collected, review the calibration to make sure it appears reasonable. The results of the calibration are in the qa directory of your delivered package.
If the dataset is pipeline calibrated,  download and untar the pipeline file in the qa directory by using
 
<source lang="bash">
# in bash
for i in $(ls *.tar); do tar -xvf $i; done
</source>
<source lang="python">
# or in CASA
For i in glob.glob(‘*.tar’):
os.system(‘tar -xvf %s’ % (i))
</source>
 
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. 
 
<source lang="bash">
firefox index.html
</source>
 
The standard opening page has three main sections: observation overview, pipeline summary, and observation summary.
If the data is 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.
 
== Flag bad data (optional) ==
 
Plotms() should be used to find worrisome data points by iterating through fields and spws. This should be done on the *.ms.split.cal files in the calibrated directory. The remainder of this guide should be run in CASA.
 
<source lang="python">
# in CASA
fieldlist = ['3'] # change to list of science data fields to inspect
spwlist = ['1'] # change to list of science spws to inspect
 
for vis in vislist:
    for field in fieldlist:
        for spw in spwlist:
            plotms(vis=vis,xaxis='uvwave',yaxis='amp',avgtime='3e8',
                  field=field,spw=spw)
            raw_input("push enter to continue")
            plotms(vis=vis,xaxis='chan',yaxis='amp',avgtime='3e8',
                  field=field,spw=spw)
            raw_input("push enter to continue")
</source>
 
Save the original flags of each ms prior to flagging any additional data.
 
<source lang="python">
# in CASA
for vis in vislist:
    flagmanager(vis=vis,
                mode='save',
                versionname='original_flags')
</source>
 
Use flagdata() if you find any additional antennas, data, SPW, etc which need to be flagged. Update the following command with the specific ms name with the vis parameter and any antenna, SPW, etc. Once the data is flagged, the flagging can be checked by using plotms.
 
<source lang="python">
# in CASA
flagdata(vis='',mode='manual',action='apply',flagbackup=False)
</source>
 
If you need to restore original flags, use the following command. You will need to update the ms name in the vis parameter.
 
<source lang="python">
# in CASA
flagmanager(vis='',mode='restore',versionname='original_flags')
</source>
 
== Flux Equalization (optional) ==
 
Flux equalization can be used if you have multiple executions using the same phase calibrator.
 
If you have determined flux equalization is required for your data, please file a Helpdesk ticket (help.almascience.org) and a NAASC staff member can assist you by generating a script for your measurement sets. Flux equalization is not generally recommended unless deemed absolutely necessary.
[http://legacy.nrao.edu/alma/memos/html-memos/alma434/memo434vb.pdf ALMA Memo 434] outlines various uncertainties relevant to amplitude calibraion . 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.
 
If your dataset was pipeline calibrated, the derived flux densities of your calibrators can be found in the ‘’’hifa_gfluxscale’’’ step of the weblog. If your dataset was manually calibrated, the *.fluxscale file of each execution contains derived flux densities.
 
The first step in flux equalization is individually setting the flux density of the phase calibrator in each spectral window 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’’’.
 
If you have performed flux equalization, you can skip to the “Splitting off science target data” section below.
 
== Combining measurement sets from multiple executions ==
 
This section will either need to be commented out or deleted if you have only one execution. However, if there are multiple *.ms.split.cal files within the calibrated directory, you will want to combine them all into one single ms file in order to make imaging more manageable later on.
 
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.
 
<source lang="python">
# in CASA
concatvis='calibrated.ms'
 
rmtables(concatvis)
os.system('rm -rf ' + concatvis + '.flagversions')
concat(vis=vislist,
  concatvis=concatvis)
</source>
 
== Splitting off science target data ==
 
The calibrated.ms produced in section IV, or your original ms file if you only have one execution, will not only contain the science target(s), but also all calibrator sources observed. At this point, you are only concerned with imaging our science targets so you can split off all non science fields from the ms. 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.
 
<source lang="python">
# in CASA
# Uncomment following line for single executions
# concatvis = vislist[0]
 
# Uncomment following line for multiple executions
# concatvis='calibrated.ms'
</source>
 
You will 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.
<source lang="python">
# in CASA
sourcevis='calibrated_source.ms'
rmtables(sourcevis)
os.system('rm -rf ' + sourcevis + '.flagversions')
split(vis=concatvis,
  intent='*TARGET*', # split off the target sources
  outputvis=sourcevis,
  datacolumn='data')
</source>
 
At this point, it is convenient to create a listobs file to reference during imaging. Inspect the listobs to make sure the split and concat worked as desired.
 
<source lang="python">
# in CASA
listobs(vis=sourcevis,listfile=sourcevis+'.listobs.txt')
</source>
 
== Regridding spectral window (optional) ==
 
The NA imaging team strongly recommends using the clean command to regrid spectral windows on the fly. An exception to this recommendation are cases where lines shift too much between executions to identify a common channel range for continuum subtraction. Regridding can be used when there are multiple executions done at different times for the same target, an extremely high redshifted project, ephemeris projects, or when spws or images have different coordinate systems. In general, if the rest frame between different spws/images needs to be used, regridding using the cvel command as opposed to just using the clean command could be optimal for the dataset. We will start by setting the parameters specific to your observations.
 
<source lang="python">
# in CASA
sourcevis='calibrated_source.ms'
regridvis='calibrated_source_regrid.ms'
veltype = 'radio' # Keep set to radio. See notes in imaging section.
width = '0.23km/s' # see science goals in the OT
nchan = -1 # leave this as the default
mode='velocity' # see science goals in the OT
start='' # leave this as the default
outframe = 'bary' # velocity reference frame. see science goals in the OT.
restfreq='115.27120GHz' # rest frequency of primary line of interest.
field = '4' # select science fields.
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.
</source>
 
Regridding here uses the cvel command to regrid multiple spws associated with a single rest frequency into a single spw. To avoid clean regridding the image a second time you will need to use the same parameters used for cvel for clean.
 
<source lang="python">
# in CASA
rmtables(regridvis)
os.system('rm -rf ' + regridvis + '.flagversions')
   
cvel(vis=sourcevis,
    field=field,
    outputvis=regridvis,
    spw=spw,
    mode=mode,
    nchan=nchan,
    width=width,
    start=start,
    restfreq=restfreq,
    outframe=outframe,
    veltype=veltype)
</source>
 
== Rename and backup data set ==
 
Depending on the different tasks that were performed above, the current measurement set will have a variety of names. For ease of beginning imaging with a common measurement set, rename the file to calibrated_final.ms.
 
If you haven’t regridded, your current ms should be named calibrated_source.ms.
 
<source lang="python">
# in CASA
# uncomment if you haven’t regridded
# os.system('mv -i ' + sourcevis + ' ' + 'calibrated_final.ms')
</source>
 
If you have regridded, your current ms should be named calibrated_source_regrid.ms.
 
<source lang="python">
# in CASA
# uncomment if you have regridded
# os.system('mv -i ' + regridvis + ' ' + 'calibrated_final.ms')
</source>
 
Now that you have one fully calibrated measurement set to image, we recommend creating a backup of the dataset. It is easy to corrupt a measurement set during ‘’’clean’’’, ‘’’tclean’’’, and ‘’’uvcontsub’’’ so it is a good idea to have a backup dataset.
 
<source lang="python">
# in CASA
os.system('cp -ir calibrated_final.ms calibrated_final.ms.backup')
</source>

Latest revision as of 18:46, 27 September 2024