Imaging Prep: Difference between revisions

From CASA Guides
Jump to navigationJump to search
No edit summary
No edit summary
Line 11: Line 11:
== Review the Calibration ==
== 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.  
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
If the dataset is pipeline calibrated,  download and untar the pipeline file in the qa directory by using


Line 24: Line 24:
</source>
</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.   
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">
<source lang="bash">
Line 79: Line 79:
== Flux Equalization (optional) ==
== Flux Equalization (optional) ==


Flux equalization can be used if you have multiple executions using the same phase calibrator.  
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.
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.  
[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 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.
If you have performed flux equalization, you can skip to the “Splitting off science target data” section below.
 
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 ==
== 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.
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.
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.


Line 135: Line 140:
== Regridding spectral window (optional) ==
== 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.
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">
<source lang="python">
Line 175: Line 180:


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.
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.
If you haven’t regridded, your current ms should be named calibrated_source.ms.



Revision as of 16:16, 28 March 2017

Get a list of ms files to image

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.

# in CASA
import glob
vislist=glob.glob('*.ms.split.cal')

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

# in bash
for i in $(ls *.tar); do tar -xvf $i; done
# or in CASA
For i in glob.glob(*.tar):
	os.system(tar -xvf %s % (i))

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.

firefox index.html

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.

# 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")

Save the original flags of each ms prior to flagging any additional data.

# in CASA
for vis in vislist:
    flagmanager(vis=vis,
                mode='save',
                versionname='original_flags')

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.

# in CASA
flagdata(vis='',mode='manual',action='apply',flagbackup=False)

If you need to restore original flags, use the following command. You will need to update the ms name in the vis parameter.

# in CASA
flagmanager(vis='',mode='restore',versionname='original_flags')

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. ALMA Memo 434 outlines various uncertainties relevant to amplitude calibraion . You can refer to the respective cycle’s Proposer’s Guide (Cycle 4) for expected uncertainties. In addition, the 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.

# in CASA
concatvis='calibrated.ms'

rmtables(concatvis)
os.system('rm -rf ' + concatvis + '.flagversions')
concat(vis=vislist,
   concatvis=concatvis)

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.

# in CASA
# Uncomment following line for single executions
# concatvis = vislist[0]

# Uncomment following line for multiple executions
# concatvis='calibrated.ms'

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 this link for more information regarding the structure of measurement sets.

# 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')

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.

# in CASA
listobs(vis=sourcevis,listfile=sourcevis+'.listobs.txt')

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.

# 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.

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.

# 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)

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.

# in CASA
# uncomment if you haven’t regridded
# os.system('mv -i ' + sourcevis + ' ' + 'calibrated_final.ms')

If you have regridded, your current ms should be named calibrated_source_regrid.ms.

# in CASA
# uncomment if you have regridded
# os.system('mv -i ' + regridvis + ' ' + 'calibrated_final.ms')

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.

# in CASA
os.system('cp -ir calibrated_final.ms calibrated_final.ms.backup')