Simulating ngVLA Data-CASA5.4.1

From CASA Guides
Revision as of 12:31, 23 February 2019 by Vrosero (talk | contribs)

Jump to: navigation, search


The following tutorial shows how to create simulated data for the next generation Very Large Array (ngVLA). The ngVLA is composed of different subarrays that make up the current reference design. The configuration files for the different subarrays are found in the "ngVLA Configuration Tools" and can be used for simulations and calculations that investigate the scientific capabilities of the ngVLA. Each configuration (.cfg) file contains the name of the observatory, the antenna positions, the coordinate system of the antenna positions, and the diameter and pad name of each antenna.

CASA provides two ways to create a simulation: the simobserve task and the sm toolkit. With these methods we can generate measurement sets, add thermal noise and predict model visibilities, from which we can explore the ngVLA’s imaging capabilities. The simobserve task is very user friendly but it is important to be aware that at the moment it has several limitations when making simulations for observatories other than ALMA and EVLA. For this reason, our suggested method for making simulations, specifically for advanced capabilities, is the sm toolkit. The sm toolkit provides much more flexibility in the observational parameters and is more compatible with observatories that are not recognized by CASA.

In this tutorial we present three example simulations: (i) simobserve using a model image, (ii) simobserve using a component list, and (iii) a sm toolkit simulation. For more information about component lists, see the CASA guides "here" and "here". The model image used in portions of this guide, a 93 GHz model of a protoplanetary disk, can be downloaded "here". We will also show how to create and use a component list instead of a model image for the simulations. We will create example continuum simulations at 93 GHz, consisting of a single channel observed for a total of 4 hours with a 60 second integration time . We will then add to these simulations an amount of thermal noise that is representative of the ngVLA's continuum sensitivity. The array configuration used in this guide is the Main ngVLA subarray, which is composed of 214 18 m antennas and extends over a maximum baseline of 1005.4 km. The configuration file that we will use throughout this tutorial is called ngvla-main-revC.cfg and it can be found "here".

We choose this integration time in order to keep the measurement set files small. Time smearing is not usually a concern for simulated observations, but this value would need to be reconsidered before scheduling actual observations.

Estimating the scaling parameter for adding thermal noise

Simobserve's parameter to corrupt the simulated data is called thermalnoise and for interferometric data the allowed values are 'tsys-atm', 'tsys-manual' or " " (see this "CASA guide" for more details). The option " " will not add any noise to the data, and the option 'tsys-atm' is only applicable to ALMA since it uses site parameters which are specific to that observatory. For the option 'tsys-manual', it is necessary to supply several additional parameters which are required to construct an atmospheric model. In order to achieve the desired sensitivity without atmospheric modeling, we have chosen to corrupt the simulated data using the "sm.setnoise" function of the sm toolkit. In addition to the modes 'tsys-atm' and 'tsys-manual', this function also allows the option of 'simplenoise'. As the name indicates, 'simplenoise' adds random Gaussian noise to the visibilities based on a simple scaling factor. We will use this same technique for all three example simulations, i.e., those made with the simobserve task and those made with the sm toolkit.


The RMS noise (\sigma_{NA}) in an untapered, naturally-weighted Stokes I image will be approximately (see "setnoise function")

     \sigma_{NA} \sim \frac{\sigma_{simple}}{ \sqrt{n_{ch}\,n_{pol}\,n_{baselines}\,n_{integrations} }}   (1)

where \sigma_{simple} is the simplenoise parameter in sm.setnoise and corresponds to the noise per visibility, n_{ch} is the total number of channels across all spectral windows, n_{pol} is the number of polarizations used for Stokes I (typically 2) and n_{integrations} is the number of correlator integration times in the measurement set (i.e., total on-source time / integration time). For the example simulations in this gude, the track time is 4 h and the integration time is 60 s, thus n_{integrations}=240. Additionally, for these examples the total number of channels is 1 and the number of polarizations is 2. The number of baselines n_{baselines} is N(N-1)/2 where N is the number of antennas in the array. For the array configuration used in this guide (ngvla-main-revC.cfg), N=214 and therefore n_{baselines}= 22791.

If you already know the expected image noise (\sigma_{NA}) for your untapered, naturally-weighted image, you can solve for the scaling parameter \sigma in the above equation (1) and pass \sigma_{simple} to the simplenoise parameter in sm.setnoise.

If instead you want to calculate the expected sensitivity for an ngVLA image we suggest the below procedure:.

(i) Calculate the expected untapered, naturally weighted point source sensitivity (\sigma_{NA}) using one of the ngVLA performance tables. In Appendix D of "ngVLA memo #55 " there are key performance metrics for 6 subarrays which are tabulated as a function of frequency and resolution. For our example, we find in Table 10 of ngVLA memo #55 that the untapered, naturally weighted point source sensitivity of the Main interferometric array at 93 GHz is 0.83 uJy/beam for a 1 hour observation.

(ii) Scale that number to the desired observation length, in this case t_{track}=4\,h. Therefore, \sigma_{NA} = 0.83/\sqrt{(t_{track}/1\,hour)} = 0.415\,\text{uJy/beam}.

(iii) Use the expected image noise (\sigma_{NA}) in the above equation (1) to solve for the scaling factor \sigma_{simple}. In this case, \sigma_{simple}=0.415*\sqrt{1*2*22791*240} = 1.4\,\text{mJy}.

Once you have derived the scaling factor \sigma_{simple}, run sm.setnoise and corrupt the visibilities of the noise-free measurement set. Your resulting untapered, naturally-weighted image will then have an RMS approximately equal to your desired image noise. Since it is not easy to undo this step, it is a good idea to make a copy of the noise-free measurement set before adding noise. The following mock example outlines this procedure:


os.system('cp -r')
sm.setnoise(mode = 'simplenoise', simplenoise = sigma_simple)

Note that this example will not execute without a measurement set named '' and a defined variable sigma_simple. See below for working examples of this procedure used in conjunction with the creation of simulated measurement sets and the prediction of model visibilities.

Example simulation using Simobserve with a model image

We will use the simobserve task to create our first noise-free measurement set (MS), using the configuration file and model image described in the Introduction.


simobserve(project = 'ngVLA_214_ant_60s_noise_free', 
                    skymodel = 'ppmodel_image_93GHz.fits', 
                    setpointings = True, 
                    integration = '60s',  
                    obsmode = 'int', 
                    antennalist = 'ngvla-main-revC.cfg', 
                    hourangle = 'transit', 
                    totaltime = '14400s',  
                    thermalnoise = '', 
                    graphics = 'none')

project: Simobserve will create a folder with the project name in your current working directory, and this folder will contain all the resulting files including the noise-free MS.

skymodel: The input model image in Jy/pixel units, which can be a single image or a spectral cube. The simulated MS will inherit the number of channels, central frequency, source direction and peak flux of this input model. These can be adjusted using the optional parameters inbright, indirection, incell, incenter and inwidth. In this example we do not modify these optional parameters.

setpointings: We choose the value of True, which allows simobserve to derive the pointing positions using its own algorithm and properties of the input model image. Since the size of the model is much smaller than the primary beam, a single pointing will be generated (instead of a mosaic). We also set the expanded parameter integration to '60s' (our chosen correlator integration time) and leave other expanded parameters set to their default values.

obsmode: We set this parameter to 'int' to simulate interferometric data. We also set values for several expandable parameters. For antennalist we provide the configuration file for the ngVLA Main interferometric array. We set totaltime to the total on-source observation time, use the hourangle parameter to center our observation time on transit, and leave other expanded parameters as default.

thermalnoise: We leave this parameter empty to create a noise-free simulation. We will add the noise later in a separate step (see below).

graphics: This will show graphics on the screen and/or save them as png files in the project directory. However, at the moment this is not working properly for baselines larger than a few hundred km. For this reason, we use 'none' in this example.

Now, to add thermal noise we do the following:


## create a copy of the noise-free MS
os.system('cp -r ngVLA_214_ant_60s_noise_free/')

## open the MS we want to add noise to with the sm tool

## set the noise level using the simplenoise parameter estimated in Section 2
sigma_simple = '1.4mJy'
sm.setnoise(mode = 'simplenoise', simplenoise = sigma_simple)

## add noise to the 'DATA' column (and the 'CORRECTED_DATA' column if present)

## close the sm tool

Example simulation using Simobserve with a component list

Instead of using a model image we can use a component list for the simulation. Warning: At the moment this method may take several times longer than using a model image due to internal issues with simobserve. Below is a simple example of how to a component list which contains a point source.


## Position of the source that we want to observe. 

## Use the component list (cl) tool to make a model centered at the direction given above, and with a source flux of 10 uJy
cl.addcomponent(dir = direction, flux = 10e-6, freq = '93GHz')

## name of the component list model 
cl.rename(filename = '')

## close the component list 

Now, we can run simobserve using the generated component list:


simobserve(project = 'ngVLA_214_ant_60s_noise_free', 
                    complist = '' , 
                    compwidth = '10GHz',
                    setpointings = True, 
                    integration = '60s',  
                    obsmode = 'int', 
                    antennalist = 'ngvla-main-revC.cfg', 
                    hourangle = 'transit', 
                    totaltime = '14400s',  
                    thermalnoise = '', 
                    graphics = 'none')

Most of the parameters are the same as the previous example. The parameters which are specific to using a component list are:

complist: Here we provide the component list created above. The expandable parameter compwidth indicates the bandwidth of the component, which will be used to set the bandwidth of the MS and resulting images.

Then we can add the thermal noise in the same way as in Section 3.

Example simulation using sm toolkit with either a model image or a component list


## Using the configuration file obtained from the ngVLA's website
conf_file = 'ngvla-main-revC.cfg'

## If the configuration file is already included with the CASA distribution, use:

## Use simutil to read the .cfg file
from simutil import simutil
u = simutil()
xx,yy,zz,diam,padnames,telescope,posobs = u.readantenna(conf_file)
## or use this if the .cfg file is already part of the CASA distribution:
## xx,yy,zz,diam,padnames,telescope,posobs = u.readantenna(configdir+conf_file)

## Setting the observation framework, i.e., defining the sources,
## resources, and scans similar to what we would do in the OPT  
## when setting up an observation.

## Simulate measurement set using the simulation utilities sm tool
ms_name = ''     ## Name of your measurement set ms_name )

pos_ngVLA = me.observatory('ngvla')

sm.setconfig(telescopename = telescope, x = xx, y = yy, z = zz,
                    dishdiameter = diam.tolist(), mount = 'alt-az',
                    antname = padnames,
                    coordsystem = 'global', referencelocation = pos_ngVLA)

## simulation with a channel resolution of 10 GHz 
sm.setspwindow(spwname = 'Band6', freq = '93GHz', deltafreq = '10GHz',
freqresolution = '10GHz', nchannels = 1, stokes = 'RR RL LR LL')

## set feed parameters for the antennas
sm.setfeed('perfect R L')

## a Dec of +24deg
sm.setfield(sourcename = 'My source',
                  sourcedirection = ['J2000','00h0m0.0','+'])

## set the limit of the observation for the antennas
sm.setlimits(shadowlimit = 0.001, elevationlimit = '8.0deg')

## weight to assign autocorrelation
sm.setauto(autocorrwt = 0.0)

## integration time or how often the array writes one visibility
integrationtime = '60s'
sm.settimes(integrationtime = integrationtime, usehourangle = True,
            referencetime = me.epoch('utc', 'today'))

starttime = '-2h'
stoptime = '2h'
sm.observe('My source', 'Band6', starttime = starttime, stoptime = stoptime)

## < steps for predicting model visibilities and adding noise can optionally appear here in this order >
## sm.predict...
## sm.setnoise...
## sm.corrupt...

## close the simulator tool

At this point we have made a noise-free and source-less MS, thus if the purpose of your study is only to investigate the PSF and do analysis of the image noise you can simply follow the steps to add thermal noise using 'simplenoise'.

However, if you want sources in the field we can write a scan of a source using the resource made above. Set the model either using a .fits model or a component list. After that we can predict the visibilities using sm.predict tool function. If using a component list follow the steps below:

## Using the same component list that we generated in Section 2
## predicts the visibility of the source
sm.predict( complist = '')



## To import the fits file as a CASA image 
model_file = 'ppmodel_image_93GHz'
importfits( fitsimage = model_file+'.fits', imagename = model_file+'.image')    

## Note: a warning is produced in CASA when running importfits about the image not having a beam or angular resolution. This is expected since the model is in units of Jy/pixel. Please ignore it.

## To predict the model visibilities
sm.predict( imagename = model_file+'.image') 





## Adding noise using the 'simplenoise' parameter estimated in Section 2
sigma_simple = '1.4mJy'
os.system('cp -r')
sm.setnoise(mode = 'simplenoise', simplenoise = sigma_simple)

Comparison of the results with the expected image noise

Here we show an example of the resulting images using the method presented in Section 3. Fig. 1 shows the model that we use for this simulation tutorial.

Fig 1.: Model image

Now we will make a dirty image. In order to calculate the size of the image we use blah and for the cell size we use the following:

# In CASA'')
x = im.advise()
## print the advise cell size in units of arcsec 
print x[2]


tclean(vis = '', datacolumn = 'data', imagename = 'sm_dirty_noisy', imsize = [3000, 3000], cell = ['0.3e-3arcsec'],   specmode = 'mfs',  gridder = 'standard', deconvolver = 'hogbom', weighting = 'natural', niter = 0)

We can open the image using the viewer:



Fig. 2 shows the dirty image.

Fig 2.: Dirty image


tclean(vis = '', datacolumn = 'data', imagename = 'sm_clean_noisy', imsize = [3000, 3000], cell = ['0.3e-3arcsec'],  startmodel = 'ppmodel_image_93GHz.image/', specmode = 'mfs',  gridder = 'standard', deconvolver = 'hogbom', weighting = 'natural', niter = 0)

Fig. 3 shows the perfectly deconvolved image.

Fig 3.: Perfectly deconvolved image

Fig. 4 shows the residual image. Using the statistics tab we can see that the rms and standard deviation of the image is in pretty good agreement with the expected image rms of 0.415 uJy/beam estimated in Section 2.

Fig 4.: Residual image

Last checked on CASA Version 5.4.1.