CARMA spectral line mosaic M99 3.1

From CASA Guides
Revision as of 19:50, 3 June 2010 by Jgallimo (talk | contribs)
Jump to: navigation, search

CARMA Tutorials


This tutorial describes the data reduction for CO (1-0) data observed toward the galaxy M99 (NGC 4254) using CARMA. These data were kindly provided by the CARMA STING team and should not be used for scientific purposes. More information about STING and these data in particular can be found in Rahman et al. (2010) and CARMA STING webpage.

In this tutorial we follow common CARMA practice to utilize a wide band (500 MHz) spectral window to calibrate narrow band (6 MHz) spectral windows in order to achieve better signal-to-noise.

The tutorial below assumes that you have followed the initial MIRIAD data reduction and export to fits steps described at Extracting data from MIRIAD.

A tar file of the resulting fits files can be downloaded from

After downloading, unpack the data in the directory you will be working in with

tar -xvf M99_CARMA.fits.tar

this will create a directory called fits.

Import fits files

Below we show an example of creating a python dictionary and using "for" loops in python to run importuvfits multiple times, and then use the output as the input to the concat task.

myfiles = []
for i in range(4,7):
        msfile = "c0104I"+str(i)+".ms"

Look at the logger output. Notice that the CARMA data comes into CASA with antenna names that are numbers and that CASA also creates an antenna ID number for each antenna (it also creates ID numbers for fields and spw). Both the antenna name and ID can be used to identify an antenna, which is very confusing if both are numbers -- but not the same number. The python commands below will append the antenna names with CA to more easily distinguish them from their IDs. ALMA will already have antenna names that are strings, as does the EVLA. This step is only needed for data that comes into CASA via importuvfits."c0104I/ANTENNA",nomodify=False)
for i in range(len(namelist)):
	name = 'CA'+namelist[i]
	print ' Changing '+namelist[i]+' to '+name

 Fields: 22
   ID   Code Name         RA            Decl           Epoch   nVis   
   0         MARS         09:15:50.0585 + J2000   9450   
   1         3C273        12:29:06.7000 + J2000   60480  
   2         NGC4254      12:18:47.8090 + J2000   24570  
   3         NGC4254      12:18:49.6000 + J2000   24570  
   4         NGC4254      12:18:51.3910 + J2000   24570  
   5         NGC4254      12:18:52.2865 + J2000   24570  
   6         NGC4254      12:18:50.4955 + J2000   24570  
   7         NGC4254      12:18:48.7045 + J2000   24570  
   8         NGC4254      12:18:46.9135 + J2000   24570  
   9         NGC4254      12:18:46.0179 + J2000   24570  
   10        NGC4254      12:18:47.8090 + J2000   24570  
   11        NGC4254      12:18:49.6000 + J2000   24570  
   12        NGC4254      12:18:51.3910 + J2000   24570  
   13        NGC4254      12:18:53.1821 + J2000   24570  
   14        NGC4254      12:18:52.2865 + J2000   24570  
   15        NGC4254      12:18:50.4955 + J2000   24570  
   16        NGC4254      12:18:48.7045 + J2000   24570  
   17        NGC4254      12:18:46.9135 + J2000   22680  
   18        NGC4254      12:18:47.8090 + J2000   22680  
   19        NGC4254      12:18:49.6000 + J2000   22680  
   20        NGC4254      12:18:51.3910 + J2000   22680  
   21        3C274        12:30:49.4230 + J2000   45360  
    (nVis = Total number of time/baseline visibilities per field) 
 Spectral Windows:  (3 unique spectral windows and 1 unique polarization setups)
   SpwID  Chans Frame Ch1(MHz)    ChanWid(kHz)TotBW(kHz)  Ref(MHz)    Corrs
   0          15 LSRK  113978.067  31250       468750      113978.067  RR  
   1          63 LSRK  114289.671  976.5625    61523.4375  114289.671  RR  
   2          63 LSRK  114341.036  976.5625    61523.4375  114341.036  RR  
 The SOURCE table is empty: see the FIELD table
 Antennas: 15:
   ID   Name  Station   Diam.    Long.         Lat.         
   0    CA1     ANT1      10.4 m   -  +  
   1    CA2     ANT2      10.4 m   -  +  
   2    CA3     ANT3      10.4 m   -  +  
   3    CA4     ANT4      10.4 m   -  +  
   4    CA5     ANT5      10.4 m   -  +  
   5    CA6     ANT6      10.4 m   -  +  
   6    CA7     ANT7      6.1  m   -  +  
   7    CA8     ANT8      6.1  m   -  +  
   8    CA9     ANT9      6.1  m   -  +  
   9    CA10    ANT10     6.1  m   -  +  
   10   CA11    ANT11     6.1  m   -  +  
   11   CA12    ANT12     6.1  m   -  +  
   12   CA13    ANT13     6.1  m   -  +  
   13   CA14    ANT14     6.1  m   -  +  
   14   CA15    ANT15     6.1  m   -  +  

Since you were (likely) not the original observer for these data, here is a basic overview of how we will use them:

Observing Strategy:

Bandpass, Gain, and Flux calibrator: 3c273 field ID=1
Secondary Gain Calibrator 3C274 field ID=21
Extra flux calibrator Mars field ID=0

The target mosaic (M99) is in field IDs 2~20

There is one wideband channel (spw=0) and two narrow band channels

Initial Inspection and Flagging

Amplitude as a function of time for all sources, with each field shown in a different color.
Zoom on bad target data, with small marked region.
Zoom on last few scans of 3c273 (field=1) and 3c274 (field=21).

First, flag edge channels:


Let's look at the wide band channel on all sources:

plotms(vis='c0104I',xaxis='time',yaxis='amp',field='1~21', spw='0',

Click "Display" tab in the plotms GUI and select "Colorize by: Field", then click the plot button.

There are a few things to notice:

First there is some very noticeably bad target data near the end of the observation. Use the zoom button to zoom in on the bad timerange, click the Mark Region icon and put a box over a modest number of the offending high points, and then press the Locate button.

Information about the located points will display to the terminal (not the Log Messages window). This will tell you that the offending telescope is antenna name=CA13 (id=12) and that the field-ids are 2~11. Looking at the plot the bad time range is 05:43:00~05:54:00.

Click the "Clear Regions" button, and then the "house" button to unzoom.

Next note that the first two scans on 3c273 and the last scan on 3c273 show some low points. Also the last scan on 3c274 shows low points. Again use zoom, mark, and locate to see if you can see a pattern.

The first two scans on 3c273 don't show a particular pattern -- no particular antenna or individual time range appears to be responsible. This is usually a good indication that it cannot be calibrated out. Also note that it is unlikely that the target data in between is good, though this is not obvious because the target is weak. However, 3c274 does look ok, before the second 3c273 scan. Unfortunately, there is no way to calibrate the first target scans even if they are good, with no calibrator scan to precede them. For now we will flag 3c273 scans and the target in that timerange.

As for the last scans, there is a pattern: problems with the last scan on 3c273 appears to be caused by antenna CA7 (in scan 272) and problems with the last scan on 3c274 appears to be related to antenna CA8 (scan 255).

Looking at the lowest points on all the 3c273 scans, baseline CA2-CA8 appears low, we will also wait to see if this calibrates out.

We will flag the narrow band channels wherever we see problems in wideband. You can either make separate plotting commands, or combine as below. To demonstrate different possibilities we use timerange to identify some data, and scan number to identify others.


Note that each of these flagging commands could have been written out separately, but combining them into one command will run much faster than the combined time of multiple calls as the data only have to be searched once.

Set the Absolute Flux Scale

Often for millimeter observations, the absolute flux scale is determined by observing a planet and using a model of its flux as a function of baseline length (most planets are not point sources at mm frequencies using typical arrays). This is because the flux of planets change in a mostly predictable way (depending primarily on distance at any given time) than quasars. CASA does not yet have this functionality (we expect it for the next release). The flux of 3c273 is inserted from CARMA flux monitoring (which used the Mars observation to derive the 3c273 flux).

setjy(vis='c0104I', field='3C273',fluxdensity=[17.8,0.,0.,0.], spw='0~2')

Transferring Gains from One Spectral Window to Another

Below we lay out in detail the steps for using the wideband gain calibration for the narrowband CARMA data. There are a few important things to note about this procedure:

(1) There are two essential calibrations that must be done: Bandpass as a function of frequency (amplitude and phase) and Gain as a function of time (amplitude and phase).

(2) Each spectral window (spw) will have independent bandpass shapes in both amplitude and phase.

(3) As long as the system is relatively stable with time, the gain calibrations are typically the same for each spectral window after the full bandpass dependence is removed.

In a dataset where each spw calibrates only itself, one typically normalizes the bandpass solutions, so that they take out the shape of the bandpass (in amplitude and phase), but not the absolute amplitude or phase offsets (which vary from spw to spw). In that case the gain solutions contain both the phase and amplitude solutions as a function of time, but also the absolute bandpass amplitude and phase offsets. The CASAguide EVLA spectral line IRC10216 provides an example of this procedure.

By contrast, in a case where you want to apply the gain calibrations from one spw to another, you definitely do not want those gains to apply the absolute bandpass amplitude and phase offsets derived from one spw to another. This is why in the steps below, we use solnorm=F in the bandpass task. This forces the absolute bandpass amplitude and phase offsets to be contained in the bandpass solutions (which are derived independently for each spw).

Calibrate the Wideband Bandpass

Bandpass calibrator's (raw) wideband phase as a function of channel.
Bandpass calibrator's wideband phase as a function of time.
Initial wideband gaincal solutions on 3C273, prior to bandpass calibration.
Bandpass wideband amplitude solution with applied initial gaincal.
Bandpass wideband phase solution with applied initial gaincal.

Lets start by looking at the bandpass calibrator's phase as a function of channel for the wideband data.


Select colorize by antenna2, and select "custom" for unflagged points, and then raise the style to 3 to make the plotted points easier to see. You will see that the phase does not change a great deal on individual baselines over the wide band channel (spw=0). This means that averaging over some channels will not introduce significant closure errors. Check other antennas if you like.

Now look at the phase as a function of time. With avgtime a large number, but no avgscan=T, this command will show the average phase per scan. Since the cache changes, the colorize option changes too. You will have to select these again as above.


Here you see significant variation with time. This is not surprising as the bandpass calibrator was observed over a fairly long period of time (~6 hours). In this case, it is important to calibrate the phase before solving for the bandpass. We choose a fairly narrow channel range since the bandpass phase as a function of frequency has not been taken out yet (though for these data it is quite well behaved).


The use of solint='inf' here without setting combine will get one solution per scan.

Look at the solutions:


Note the phase drift is > 100 degrees on some antennas -- this is why it would not have been appropriate to vector average these data into one bp solution before taking out the phase. Use the "Next" button to page through all antennas.

Having done a preliminary phase solution we can now combine all the 3C273 scans into one bandpass solution. Note the default combine parameter is different for bandpass : combine='scan'.


Next plot the amplitude and phase of the wideband bandpass solutions.


Calibrate the Wideband Gains

Wideband phase solution over individual integrations.
Wideband gains for 3C274 (top points) and 3C273 (bottom points).
Residual phase from wideband amplitude solutions.

Now resolve for phase and also amplitude while applying the bandpass solutions, for both calibrators 3c273 and 3c274. We will not use the first gain solution again.

First, do a phase solution on the timescale of an individual integration. (Consulting the listobs will reveal that each scan is about 5 minutes long, built up of 10-second integrations.)



Note the significant phase variation within a single scan. If we used an average phase over each whole scan to derive the amplitude solutions, it would decorrelate the subsequent amplitude corrections.

So use the phase calibration just derived to get an amplitude solution over each scan:



Note the different gains for 3c273 scans and 3c274 scans, this just reflects that the two calibrators have different strengths.

Next plot the phase from the amplitude solutions -- this will be the residual phase after taking out the integration-time based solutions. This gives a good idea of the residual phase noise. If this is more than a few degrees, the cause should be investigated. Note that the scatter for 3c274 is larger than 3c273 -- this reflects that 3c274 is significantly weaker and thus has lower S/N.

Wideband gain phase solutions on scan timescales.

Here we re-run the phase only calibration but now getting one solution per scan to apply later to the target. An alternative would be to smooth the integration time phase calibration table, but this is a bit simpler.



This is a very important plot to look at carefully as these are the phase solutions that will be applied to the target. Note that the phases for 3c273 and 3c274 are very similar, but not exactly the same. Unfortunately we can not color by field here to make it easier to see.

Calibrate the Narrow Band Bandpasses

Narrowband bandpass amplitude solutions.
Narrowband bandpass phase solutions.

Solve for narrow band bandpasses, applying wideband phase and amplitude corrections. Because there are 3 spw in the data, you must set a placeholder for all three in spwmap, even though we are only solving for 2 of them.




Calibrate Absolute Flux

Plotcal for the fluxscale solution.
Flux density for 3C274 in SpW=0 is: 3.11626 +/- 0.0146614 
     (SNR = 212.549, nAnt= 15)

Check that the flux table looks reasonable; as the raw fluxes of the calibrators were close to their measured values in Jy, it is not surprising that the points for each antenna are clustered around 1.0.


Applycal and Inspect

We run applycal separately for the wide and narrow band data so we can apply the appropriate bandpass tables.

Applying solutions to 3C273:


Applying solutions to 3C274:

Phases after calibration.
Amplitudes after calibration.

For the target we will use both gain calibrators, so whichever is closest in time will be applied to the target.


You should now see, for example, that the phases are flat across all spw for 3C273, and amplitudes match the monitored calibrator fluxes for this date (with the source data at the bottom).



Deconvolution and Imaging

Narrowband spw as a function of velocity, colorized by spw.

in plotms in the Trans tab set the CO rest frequency (115271.2 MHz) in order to see the velocity range of the narrow band channels (don't forget to click Plot again). Unfortunately the individual pointings are a bit too weak to see the UV vector averaged CO signal but you can at least see the observed velocity range.

Go to Display tab and choose colorize by spw. Notice that the edge channels are a bit noisy -- especially a concern in the overlap region. We will exclude these below.

The interactive viewer with the .flux contours in magenta and the clean mask in white contours.

The clean call below, uses the interactive clean mode. This is important for complex extended emission as is seen in the CO(1-0) for M99. Below we provide a brief description of one easy way you might make a clean mask for this image. Of course making a clean mask for each channel individually would be better if you have the time and patience.


When the interactive viewer pops up (this may take a few minutes), click the "folder" icon in top left. From file GUI select "M99_cube_nearest.flux" and then click "Contour Map" under "Display As". This will show the convolution of the primary beam coverage. Next click the "wrench" next to the file folder icon. This will open the "Data Display Options" GUI. At the top, tab over until you see the "M99_cube_nearest.flux-contour" tab.

Now change the line color to magenta (from foreground). Now click the zoom button in the Display panel and zoom in on the mosaic region. Chose "all channels" toggle in the green box and then chose the "Polygon drawing" tool from the top, and make a clean mask around the outermost contour (this happens to be the 0.2 contour level). Double click inside the polygon area (with the same button you used to define the polygon), and you should see it turn white. If you now use the tape deck commands below the image to move back and forth through the cube, you can check that all the emission falls within the masked region.

Once you are satisfied with the mask, go to the data drop down menu and close the "M99_cube_nearest.flux-contour" file. If you don't do this you will get a table lock and the final image will not be constructed. Then hit the blue arrow to continue cleaning with this mask until the threshold is reached. More clean masking tips and techniques are described in the EVLA spectral line IRC10216 casaguide.

Image Analysis

First lets see what the rms noise level in a single channel is using the viewer.


Then use the tape deck to go to a line free channel, select the box region tool and make a box. When you double click in the box, the image statistics for the whole cube will print to the terminal and for the channel you are on it will print to a pop up window. Move the box around a bit to see what the variation is. You should get something like 22 - 25 mJy. If you want the box tool to go away, hit the escape key.

Next make integrated intensity maps (moment 0) and integrated velocity maps (moment 1). to do this, we'll want to know what channels the line emission starts on. The first channel with significant emission is channel 1, while the last channel with significant emission is channel 23.

Example of moment 0 and moment 1 images side by side.

For moment zero, its best to limit the calculation to image channels with significant signal in them, but not to apply a flux cutoff, as this will bias the derived integrated intensities upward.


For moment 1, it is essential to apply a conservative flux cutoff to limit the calculation to high signal-to-noise areas. Here we use about 5sigma.

Example of moment 1 raster superposed with white moment 0 contours.

Next you can open the viewer by typing


You can open both moment maps as rasters and then blink between them by first clicking the "blink" toggle and then using the tape deck to cycle through. You might also try opening the "p wrench tool" (Viewer Canvas Manager) at the top of the Viewer display panel, then go to "Number of panels" and up the number in x to 2. Then if its not already selected, click blink in the Viewer display to see both images side by side. It will help to make your viewer window fairly wide.

Also try opening the moment1 as a raster and moment0 as a contour map (In the example at right, I've played with the default contour levels in the "Data display options").

Last checked on CASA Version 3.0.2 (r11631).

--Crystal Brogan