https://casaguides.nrao.edu/api.php?action=feedcontributions&user=Sstierwa&feedformat=atomCASA Guides - User contributions [en]2024-03-29T07:58:09ZUser contributionsMediaWiki 1.38.6https://casaguides.nrao.edu/index.php?title=ALMA2014_LBC_SVDATA&diff=19970ALMA2014 LBC SVDATA2016-06-07T04:03:05Z<p>Sstierwa: /* HL Tau - Protoplanetary Disk */</p>
<hr />
<div><br />
= '''Overview''' =<br />
<br />
This casaguide describes the imaging used for the ALMA 2014 Long Baseline Campaign (LBC) Science Verification (SV) data. The purpose of this campaign was to verify and demonstrate ALMA's performance on baseline lengths of ~10 km in preparation for this very high angular resolution capability to be offered for Cycle 3. As part of the overall LBC testing plan, five science targets were chosen to span the range of properties that would be needed to offer the capability and to demonstrate to the community both the power and caveats associated with long baseline observing. The SV portion of the campaign was carried out from October 12 to November 14, 2014. As described below, the data products for four of the five targets can now be dowloaded from the regional ALMA Science Portals, while the imaging scripts and salient details are provided on this page (the final target 3C138, will be released separately with other SV polarization data in the near future).<br />
<br />
==Obtaining the Data==<br />
<br />
To download the data, go to the ALMA Science Portal (SP) [https://almascience.nrao.edu/alma-data/science-verification Science Verification data page]:<br />
<br />
Choose a LBC SV science target:<br />
'''13. Juno''', '''14. Mira''', '''15. HL Tau''', or '''16. SDP.81'''<br />
<br />
There you will find gzipped tar files of the form (these files can be unpacked with the ''tar -xvzf'' command):<br />
<br />
*'''Target_Band_Freq_UnCalibratedData''': Raw, uncalibrated data in ALMA Science Data Model (asdm) format<br />
<br />
*'''Target_Band_Freq_CalibrationScripts''': Calibration scripts that go along with the UnCalibratedData. These scripts can be executed once placed in the same directory as the UnCalibratedData<br />
<br />
*'''Target_Band_Freq_CalibratedData''': Calibrated and combined uv-data. In the case of continuum datasets, an appropropriate amount of channel averaging has been applied to reduce the data size. Line data sets are provided at their full resolution. If self-calibration was possible, you will also find the final phase-only and amplitude tables in a subdirectory called "calibration". This gives the choice of either performing your own self-calibration or applying the supplied tables. If you are going to apply these tables, be sure to also run any {{flagdata}} commands in the imaging scripts. If the self-calibration tables are not present, we deemed self-calibration unfeasible. '''Note that the imaging scripts are provided on this page, not at the science portal'''.<br />
<br />
*'''Target_Band_Freq_ReferenceImages''': Final reference images with self-calibration applied where possible. For the few cases where primary beam correction is warranted these files are also provided. Continuum images with .pbcor in the name have already been corrected. The line files with .flux in the name are the primary beam images themselves and can be applied to the corresponding line data if desired using the CASA task {{impbcor}}.<br />
<br />
*'''README''': Summarizes the data available for that science target.<br />
<br />
<br />
''The data have been packaged in this manner to allow a wide range of interaction with the data, ranging from complete re-reduction, to simply having a look at the final reference images. Please only download the data products you expect to use -- we expect the initial load on the servers could be high and for the UnCalibratedData, and in the case of targets/bands with spectral line data the CalibratedData, files are quite large.''<br />
<br />
'''Using the data for publication''': Please use the acknowledgement given at the bottom of the [https://almascience.nrao.edu/alma-data/science-verification Science Verification Data page].<br />
<br />
<br />
==CASA Version==<br />
<br />
The data were calibrated and imaged using CASA 4.2.2. At this time, we have no reason to believe that they would not work in CASA 4.3 with a few caveats: (1) The calibration scripts check that the version they were made in matches the version being used. If you want to try them in CASA 4.3 you will need to change this section of each calibration script. (2) Be aware that data imported in CASA 4.3 cannot then be imaged in CASA 4.2.2 due to the necessary addition of a new keyword in the MS format. Please note, however, that only CASA 4.2.2 has been tested.<br />
<br />
CASA can be downloaded from: http://casa.nrao.edu/casa_obtaining.shtml<br />
The CASA 4.2.2 version is called '''ALMA pipeline CASA 4.2.2'''<br />
<br />
In addition to CASA 4.2.2 you will also need the Analysis Utilities available from https://casaguides.nrao.edu/index.php/Analysis_Utilities <br />
<br />
='''LBC SV Imaging'''=<br />
<br />
For each LBC SV target there is a brief description of the data and imaging, along with links to the imaging scripts. For spectral line targets, a table of the lines observed is also given. The "detection" columns are merely descriptive to give a sense of what the data show, they are not meant to be taken as scientific assessments. The continuum was detected for all four of the science targets at each observed band. For all of the targets the number of antennas employed was of order 30. For cases in which there was enough signal for self-calibration this is also demonstrated in the imaging scripts (i.e. all sources except SDP.81). <br />
<br />
====The most important imaging take home messages====<br />
*'''UV-Coverage is critically important''': For each target/band a scheduling block was designed to run for 60-70 minutes, with about 30 minutes on source per execution. The number of executions carried out depended on the complexity of the imaging required, from short snapshots of the bright compact emission from Juno to to the many executions required for the complex morphologies of HL Tau and SDP.81. Additionally, we found that due to the non-optimal configuration available for the LBC, which had a deficit in uv-coverage for baselines between 200 to 500 m the choice of the robust parameter in clean is a crucial one. Although more naturally-weighted choices (i.e. larger ''robust'' parameter) in principle give better sensitivity, they also show poor dirty beam (i.e. psf) characteristics, with a large extended plateau in addition to the more point-like morphology that corresponds to the fitted clean beam. Thus, for full resolution images, we typically employed ''robust=0.0'', though occasionally up to 1.0 was used. <br />
<br />
*'''Observing narrow ''thermal'' line emission at high resolution is challenging''': Except for Mira, which has the advantage of having compact line emission, as well as emission from highly-excited or even masing lines, the imaging of line emission at the very high resolution afforded by the longest baselines is challenging. For example, at 89 GHz with 0.25 km/s channels, 30 antennas, 3.5 hours on-source, and an angular resolution of 70 mas, the expected spectral rms noise per channel is 2.6 mJy/beam but only 83 K in surface brightness sensitivity. As a result, it was necessary to apply a uv taper when making the spectral line images for HL Tau and SDP.81 in order to achieve good detections. <br />
<br />
*'''Extended emission at high angular resolution can best be imaged with multiscale''': Cleaning diffuse emission on size scales significantly larger than the beam with the standard delta-function deconvolution method results in the "clean instability": giving the diffuse emission a "pointilated" or "cotton-candy" like morphology. This can be ameliorated by using a range of scales to do the cleaning. In CASA, this technique is accessed through the {{clean}} ''multiscale'' parameter. The scales are given as multipliers of the cell (pixel) size. It is essential to always use 0 for the first scale as this corresponds to the normal clean beam, ''multiscale=[0,5,15]'' is usually a good starting point for experimentation. For more details see: Cornwell 2008 (IEEE Journal of Sig Proc., 2, 793).<br />
<br />
*'''Combining bands can produce amazing results''': For sources that have significant spatial changes in continuum spectral index, and wide observed fractional bandwidth (>15%) for which the signal-to-noise is high throughout the frequency range, it is possible to use a technique in {{clean}} to simultaneously account for the changing spectral index (<math>S_{\nu}\propto \nu^{\alpha}</math>) to produce a high fidelity image, and a map of the spectral index along with its estimated error (see Rau, U., & Cornwell, T.J. 2011, A&A, 532, AA71). However, the caveat that the signal to noise must be very good, especially at the frequency extrema, is a strong one. So far we have restricted our tests to ''nterms=2'', though even higher orders are possible. The results of this technique on HL Tau Band 6+7 are dramatic, and it also provides some improvement for Mira at Band 3. However, our test show that for the weaker emission at Band 3 for HL Tau and all bands for SDP.81 at native resolution, this technique does not work well. Bottom line: use with caution, but it can produce amazing results. Since this method automatically masks the resulting spectral index (<math>\alpha</math>) map where it estimates <math>\alpha/\alpha_{error}< 4</math> a good rule of thumb is that if the spectral index map is mostly masked in the image signal regions, there is inadequate S/N for this technique to be successful.<br />
<br />
==Juno - Asteroid==<br />
<br />
[[File:Juno_b6.png|150px|thumb|right|Juno (0): The beam size (lower left corner) is 33x25 mas (~41 km).]]<br />
<br />
Asteroid (3) Juno was observed in continuum in Band 6 to demonstrate the ephemeris capability. The observations were taken over 60% of Juno's rotation period of 7.2 hours. The data are split into approximately 18min intervals (10min on source) spread across 10 individual datasets and imaged and self-calibrated separately in order to prevent smearing due to the rapid rotation. The angular resolution achieved ranges from 32 x 24 mas to 42 x 36 mas, differing primarily due to the level of phase stability as the observations span the transition from night through dawn and into daytime, but changing uv-coverage also plays a role.<br />
<br />
'''Juno Band 6 Continuum''' (5 executions): [[media:Juno_Band6_Imaging.py|Juno_Band6_Imaging.py]]<br />
<br />
Mean Continuum Frequency: 233 GHz<br />
<br />
==Mira - AGB Star==<br />
<br />
Mira (omicron Cet) was observed in continuum and spectral lines in Bands 3 and 6. Angular resolutions achieved for the continuum data are 70 x 60 mas and 34 x 24 mas in Bands 3 and 6, respectively. In order to achieve the best possible dynamic range, the continuum and SiO v=1 line data were self-calibrated independently. The maser emission from the SiO v=1 line was used to derive self-calibration for the line data. In order to obtain high dynamic range on the band 3 continuum, which has a wide fractional bandwidth, it was also necessary to take into account the spectral index with ''nterms=2''.<br />
<br />
[[File:Mira_B6sv_multi3panel_fig.png|500px||right|]]<br />
<br />
'''Mira Band 3 Continuum and Lines''' (3 executions): [[media:Mira_Band3_Imaging.py|Mira_Band3_Imaging.py]]<br />
<br />
Mean Continuum Frequency: 94 GHz<br />
<br />
{| class="wikitable" <br />
! align="Center"| Line <br />
!align="Center"|Transition<br />
!El (K)<br />
!Rest Freq (GHz)<br />
!detection<br />
|-<br />
| SiO v=0 || 2-1 || 2.1 || 86.8470 || weak maser? + thermal <br />
|-<br />
| SiO v=1 || 2-1 || 1771 || 86.2434 || strong maser + thermal <br />
|-<br />
| SiO v=2 || 2-1 || 3523 || 85.6405 || thermal + absorption <br />
|-<br />
| 29SiO v=0 || 2-1 || 2.1 || 85.7590 || weak maser? + thermal <br />
|-<br />
|}<br />
<br />
'''Mira Band 6 Continuum and Lines''' (2 executions): [[media:Mira_Band6_Imaging.py|Mira_Band6_Imaging.py]]<br />
<br />
Mean Continuum Frequency: 231 GHz<br />
<br />
{| class="wikitable" <br />
! align="Center"| Line <br />
!align="Center"|Transition<br />
!El (K)<br />
!Rest Freq (GHz)<br />
!detection<br />
|-<br />
| H30alpha || - || - || 231.90093 || none <br />
|-<br />
| H2O v2=1 || 5(5,0)-6(4,3) || 3450.7 || 232.68670 || thermal <br />
|-<br />
| SiO v=0 || 5-4 || 20.84 || 217.10498 || weak maser? + thermal <br />
|-<br />
| SiO v=1 || 5-4 || 1789.8 || 215.59595 || strong maser + thermal <br />
|-<br />
| SiO v=2 || 5-4 || 3541.7 || 214.08854 || thermal + absorption<br />
|-<br />
| 29SiO v=0 || 5-4 || 20.58 || 214.38576 || weak maser? + thermal <br />
|-<br />
|}<br />
<br />
==HL Tau - Protoplanetary Disk==<br />
<br />
HL Tau was observed in continuum and spectral lines in Band 3, and (only) continuum in Bands 6 & 7. Angular resolutions achieved for the continuum data are 85 x 61 mas, 35 x 22 mas, and 30 x 19 mas in Bands 3, 6, and 7, respectively. It was necessary to uv-taper the spectral line data so the resulting angular resolution is coarser (ranging from 0.25arcsec to 1.1 arcsec). In addition to the more standard image products we also provide an example of combining the Band 6 and Band 7 continuum data using ''nterms=2'' to derive the spectral index and create a high fidelity image.<br />
<br />
[[File:HLTAU_newb6_fig.png|300px||right|]]<br />
<br />
'''HL Tau Band 3 Lines''' (7 executions for each of two tunings: 89 and 115 GHz): [[media:HLTau_Band3_89GHz_Imaging.py|HLTau_Band3_89GHz_Imaging.py]] , [[media:HLTau_Band3_115GHz_Imaging.py|HLTau_Band3_115GHz_Imaging.py]]<br />
{| class="wikitable" <br />
! align="Center"| Line <br />
!align="Center"|Transition<br />
!El (K)<br />
!Rest Freq (GHz)<br />
!detection<br />
|-<br />
| HCN || 1-0 || 0.0 || 88.63185 || absorption<br />
|-<br />
| HCO+ || 1-0 || 0.0 || 89.18853 || outflow, disk, absorption<br />
|-<br />
| CN || 1-0 || 0.0 || 113.49097 || absorption<br />
|-<br />
| 12CO || 1-0 || 0.0 || 115.2712 || outflow, confused<br />
|-<br />
|}<br />
Note only the frequency of the strongest hyperfine (HF) transition is listed for HCN (3 HFs) and CN (4 HFs).<br />
<br />
'''HL Tau Band 3 Continuum''' (combined continuum from both line tunings): [[media:HLTau_Band3_Cont_Imaging.py|HLTau_Band3_Cont_Imaging.py]]<br />
<br />
Mean Continuum Frequency: 101.9 GHz<br />
<br />
'''HL Tau Band 6 Continuum''' (9 executions): [[media:HLTau_Band6_Cont_Imaging.py|HLTau_Band6_Cont_Imaging.py]]<br />
<br />
Mean Continuum Frequency: 233.0 GHz <br />
<br />
'''HL Tau Band 7 Continuum''' (10 executions): [[media:HLTau_Band7_Cont_Imaging.py|HLTau_Band7_Cont_Imaging.py]]<br />
<br />
Mean Continuum Frequency: 343.5 GHz<br />
<br />
'''HL Tau Combined Band 6+7 Continuum (nterms=2)''': [[media:HLTau_Band67_Cont_Imaging.py|HLTau_Band67_Cont_Imaging.py]]<br />
<br />
Mean Continuum Frequency: 287 GHz<br />
<br />
==SDP.81 - Lensed Galaxy==<br />
<br />
The lensed galaxy SDP.81 was observed in continuum and spectral lines in Bands 4, 6 & 7. Angular resolutions achieved for the continuum data are 60 x 54 mas, 39 x 30 mas and 31 x 23 mas in Bands 4, 6, and 7, respectively. It was necessary to uv-taper the spectral line data so the resulting angular resolution is coarser (up to 169 mas). This source lies at a redshift of z~3, accounting for the large offset in rest frequency compared to the observing band. In addition to the more standard image products we also provide an example of combining the Band 6 and Band 7 continuum data using ''nterms=2'' to derive the spectral index and create a high fidelity image. However it is important to note that this procedure did not work well at full resolution, as evidenced by the almost complete masking of the resulting spectral index map -- this is an indication that the spectral index and hence resulting flux-densities are not well constrained. However, using a bit of taper (larger beam) improved the signal enough for the technique to work. <br />
<br />
[[File:SDP81_b6_fig.png|300px||right|]]<br />
<br />
'''SDP.81 Band 4 Continuum and Lines''' (12 executions): [[media:SDP.81_Band4_Imaging.py|SDP.81_Band4_Imaging.py]]<br />
<br />
Mean Continuum Frequency: 151 GHz<br />
<br />
{| class="wikitable" <br />
! align="Center"| Line <br />
!align="Center"|Transition<br />
!El (K)<br />
!Rest Freq (GHz)<br />
!detection<br />
|-<br />
| CO || 5-4 || 55.3 || 576.26793 || detection <br />
|-<br />
|}<br />
<br />
'''SDP.81 Band 6 Continuum and Lines''' (9 executions): [[media:SDP.81_Band6_Imaging.py|SDP.81_Band6_Imaging.py]]<br />
<br />
Mean Continuum Frequency: 236 GHz<br />
<br />
{| class="wikitable" <br />
! align="Center"| Line <br />
!align="Center"|Transition<br />
!El (K)<br />
!Rest Freq (GHz)<br />
!detection<br />
|-<br />
| CO || 8-7 || 154.9 || 921.79970 || detection <br />
|-<br />
| H2O v=0|| 2(0,2)-1(1,1) || 53.4 || 987.92676 || weak detection <br />
|-<br />
|}<br />
<br />
'''SDP.81 Band 7 Continuum and Lines''' (11 executions): [[media:SDP.81_Band7_Imaging.py|SDP.81_Band7_Imaging.py]]<br />
<br />
Mean Continuum Frequency: 290 GHz<br />
<br />
{| class="wikitable" <br />
! align="Center"| Line <br />
!align="Center"|Transition<br />
!El (K)<br />
!Rest Freq (GHz)<br />
!detection<br />
|-<br />
| CO || 10-9 || 248.9 || 1151.98544 || detection <br />
|-<br />
|}<br />
<br />
'''SDP.81 Combined Band 6+7 Continuum (tapered, nterms=2)''': [[media:SDP.81_Band67_Cont_Imaging.py|SDP.81_Band67_Cont_Imaging.py]]<br />
<br />
Mean Continuum Frequency: 268 GHz</div>Sstierwahttps://casaguides.nrao.edu/index.php?title=ALMA2014_LBC_SVDATA&diff=19969ALMA2014 LBC SVDATA2016-06-07T03:58:25Z<p>Sstierwa: /* HL Tau - Protoplanetary Disk */</p>
<hr />
<div><br />
= '''Overview''' =<br />
<br />
This casaguide describes the imaging used for the ALMA 2014 Long Baseline Campaign (LBC) Science Verification (SV) data. The purpose of this campaign was to verify and demonstrate ALMA's performance on baseline lengths of ~10 km in preparation for this very high angular resolution capability to be offered for Cycle 3. As part of the overall LBC testing plan, five science targets were chosen to span the range of properties that would be needed to offer the capability and to demonstrate to the community both the power and caveats associated with long baseline observing. The SV portion of the campaign was carried out from October 12 to November 14, 2014. As described below, the data products for four of the five targets can now be dowloaded from the regional ALMA Science Portals, while the imaging scripts and salient details are provided on this page (the final target 3C138, will be released separately with other SV polarization data in the near future).<br />
<br />
==Obtaining the Data==<br />
<br />
To download the data, go to the ALMA Science Portal (SP) [https://almascience.nrao.edu/alma-data/science-verification Science Verification data page]:<br />
<br />
Choose a LBC SV science target:<br />
'''13. Juno''', '''14. Mira''', '''15. HL Tau''', or '''16. SDP.81'''<br />
<br />
There you will find gzipped tar files of the form (these files can be unpacked with the ''tar -xvzf'' command):<br />
<br />
*'''Target_Band_Freq_UnCalibratedData''': Raw, uncalibrated data in ALMA Science Data Model (asdm) format<br />
<br />
*'''Target_Band_Freq_CalibrationScripts''': Calibration scripts that go along with the UnCalibratedData. These scripts can be executed once placed in the same directory as the UnCalibratedData<br />
<br />
*'''Target_Band_Freq_CalibratedData''': Calibrated and combined uv-data. In the case of continuum datasets, an appropropriate amount of channel averaging has been applied to reduce the data size. Line data sets are provided at their full resolution. If self-calibration was possible, you will also find the final phase-only and amplitude tables in a subdirectory called "calibration". This gives the choice of either performing your own self-calibration or applying the supplied tables. If you are going to apply these tables, be sure to also run any {{flagdata}} commands in the imaging scripts. If the self-calibration tables are not present, we deemed self-calibration unfeasible. '''Note that the imaging scripts are provided on this page, not at the science portal'''.<br />
<br />
*'''Target_Band_Freq_ReferenceImages''': Final reference images with self-calibration applied where possible. For the few cases where primary beam correction is warranted these files are also provided. Continuum images with .pbcor in the name have already been corrected. The line files with .flux in the name are the primary beam images themselves and can be applied to the corresponding line data if desired using the CASA task {{impbcor}}.<br />
<br />
*'''README''': Summarizes the data available for that science target.<br />
<br />
<br />
''The data have been packaged in this manner to allow a wide range of interaction with the data, ranging from complete re-reduction, to simply having a look at the final reference images. Please only download the data products you expect to use -- we expect the initial load on the servers could be high and for the UnCalibratedData, and in the case of targets/bands with spectral line data the CalibratedData, files are quite large.''<br />
<br />
'''Using the data for publication''': Please use the acknowledgement given at the bottom of the [https://almascience.nrao.edu/alma-data/science-verification Science Verification Data page].<br />
<br />
<br />
==CASA Version==<br />
<br />
The data were calibrated and imaged using CASA 4.2.2. At this time, we have no reason to believe that they would not work in CASA 4.3 with a few caveats: (1) The calibration scripts check that the version they were made in matches the version being used. If you want to try them in CASA 4.3 you will need to change this section of each calibration script. (2) Be aware that data imported in CASA 4.3 cannot then be imaged in CASA 4.2.2 due to the necessary addition of a new keyword in the MS format. Please note, however, that only CASA 4.2.2 has been tested.<br />
<br />
CASA can be downloaded from: http://casa.nrao.edu/casa_obtaining.shtml<br />
The CASA 4.2.2 version is called '''ALMA pipeline CASA 4.2.2'''<br />
<br />
In addition to CASA 4.2.2 you will also need the Analysis Utilities available from https://casaguides.nrao.edu/index.php/Analysis_Utilities <br />
<br />
='''LBC SV Imaging'''=<br />
<br />
For each LBC SV target there is a brief description of the data and imaging, along with links to the imaging scripts. For spectral line targets, a table of the lines observed is also given. The "detection" columns are merely descriptive to give a sense of what the data show, they are not meant to be taken as scientific assessments. The continuum was detected for all four of the science targets at each observed band. For all of the targets the number of antennas employed was of order 30. For cases in which there was enough signal for self-calibration this is also demonstrated in the imaging scripts (i.e. all sources except SDP.81). <br />
<br />
====The most important imaging take home messages====<br />
*'''UV-Coverage is critically important''': For each target/band a scheduling block was designed to run for 60-70 minutes, with about 30 minutes on source per execution. The number of executions carried out depended on the complexity of the imaging required, from short snapshots of the bright compact emission from Juno to to the many executions required for the complex morphologies of HL Tau and SDP.81. Additionally, we found that due to the non-optimal configuration available for the LBC, which had a deficit in uv-coverage for baselines between 200 to 500 m the choice of the robust parameter in clean is a crucial one. Although more naturally-weighted choices (i.e. larger ''robust'' parameter) in principle give better sensitivity, they also show poor dirty beam (i.e. psf) characteristics, with a large extended plateau in addition to the more point-like morphology that corresponds to the fitted clean beam. Thus, for full resolution images, we typically employed ''robust=0.0'', though occasionally up to 1.0 was used. <br />
<br />
*'''Observing narrow ''thermal'' line emission at high resolution is challenging''': Except for Mira, which has the advantage of having compact line emission, as well as emission from highly-excited or even masing lines, the imaging of line emission at the very high resolution afforded by the longest baselines is challenging. For example, at 89 GHz with 0.25 km/s channels, 30 antennas, 3.5 hours on-source, and an angular resolution of 70 mas, the expected spectral rms noise per channel is 2.6 mJy/beam but only 83 K in surface brightness sensitivity. As a result, it was necessary to apply a uv taper when making the spectral line images for HL Tau and SDP.81 in order to achieve good detections. <br />
<br />
*'''Extended emission at high angular resolution can best be imaged with multiscale''': Cleaning diffuse emission on size scales significantly larger than the beam with the standard delta-function deconvolution method results in the "clean instability": giving the diffuse emission a "pointilated" or "cotton-candy" like morphology. This can be ameliorated by using a range of scales to do the cleaning. In CASA, this technique is accessed through the {{clean}} ''multiscale'' parameter. The scales are given as multipliers of the cell (pixel) size. It is essential to always use 0 for the first scale as this corresponds to the normal clean beam, ''multiscale=[0,5,15]'' is usually a good starting point for experimentation. For more details see: Cornwell 2008 (IEEE Journal of Sig Proc., 2, 793).<br />
<br />
*'''Combining bands can produce amazing results''': For sources that have significant spatial changes in continuum spectral index, and wide observed fractional bandwidth (>15%) for which the signal-to-noise is high throughout the frequency range, it is possible to use a technique in {{clean}} to simultaneously account for the changing spectral index (<math>S_{\nu}\propto \nu^{\alpha}</math>) to produce a high fidelity image, and a map of the spectral index along with its estimated error (see Rau, U., & Cornwell, T.J. 2011, A&A, 532, AA71). However, the caveat that the signal to noise must be very good, especially at the frequency extrema, is a strong one. So far we have restricted our tests to ''nterms=2'', though even higher orders are possible. The results of this technique on HL Tau Band 6+7 are dramatic, and it also provides some improvement for Mira at Band 3. However, our test show that for the weaker emission at Band 3 for HL Tau and all bands for SDP.81 at native resolution, this technique does not work well. Bottom line: use with caution, but it can produce amazing results. Since this method automatically masks the resulting spectral index (<math>\alpha</math>) map where it estimates <math>\alpha/\alpha_{error}< 4</math> a good rule of thumb is that if the spectral index map is mostly masked in the image signal regions, there is inadequate S/N for this technique to be successful.<br />
<br />
==Juno - Asteroid==<br />
<br />
[[File:Juno_b6.png|150px|thumb|right|Juno (0): The beam size (lower left corner) is 33x25 mas (~41 km).]]<br />
<br />
Asteroid (3) Juno was observed in continuum in Band 6 to demonstrate the ephemeris capability. The observations were taken over 60% of Juno's rotation period of 7.2 hours. The data are split into approximately 18min intervals (10min on source) spread across 10 individual datasets and imaged and self-calibrated separately in order to prevent smearing due to the rapid rotation. The angular resolution achieved ranges from 32 x 24 mas to 42 x 36 mas, differing primarily due to the level of phase stability as the observations span the transition from night through dawn and into daytime, but changing uv-coverage also plays a role.<br />
<br />
'''Juno Band 6 Continuum''' (5 executions): [[media:Juno_Band6_Imaging.py|Juno_Band6_Imaging.py]]<br />
<br />
Mean Continuum Frequency: 233 GHz<br />
<br />
==Mira - AGB Star==<br />
<br />
Mira (omicron Cet) was observed in continuum and spectral lines in Bands 3 and 6. Angular resolutions achieved for the continuum data are 70 x 60 mas and 34 x 24 mas in Bands 3 and 6, respectively. In order to achieve the best possible dynamic range, the continuum and SiO v=1 line data were self-calibrated independently. The maser emission from the SiO v=1 line was used to derive self-calibration for the line data. In order to obtain high dynamic range on the band 3 continuum, which has a wide fractional bandwidth, it was also necessary to take into account the spectral index with ''nterms=2''.<br />
<br />
[[File:Mira_B6sv_multi3panel_fig.png|500px||right|]]<br />
<br />
'''Mira Band 3 Continuum and Lines''' (3 executions): [[media:Mira_Band3_Imaging.py|Mira_Band3_Imaging.py]]<br />
<br />
Mean Continuum Frequency: 94 GHz<br />
<br />
{| class="wikitable" <br />
! align="Center"| Line <br />
!align="Center"|Transition<br />
!El (K)<br />
!Rest Freq (GHz)<br />
!detection<br />
|-<br />
| SiO v=0 || 2-1 || 2.1 || 86.8470 || weak maser? + thermal <br />
|-<br />
| SiO v=1 || 2-1 || 1771 || 86.2434 || strong maser + thermal <br />
|-<br />
| SiO v=2 || 2-1 || 3523 || 85.6405 || thermal + absorption <br />
|-<br />
| 29SiO v=0 || 2-1 || 2.1 || 85.7590 || weak maser? + thermal <br />
|-<br />
|}<br />
<br />
'''Mira Band 6 Continuum and Lines''' (2 executions): [[media:Mira_Band6_Imaging.py|Mira_Band6_Imaging.py]]<br />
<br />
Mean Continuum Frequency: 231 GHz<br />
<br />
{| class="wikitable" <br />
! align="Center"| Line <br />
!align="Center"|Transition<br />
!El (K)<br />
!Rest Freq (GHz)<br />
!detection<br />
|-<br />
| H30alpha || - || - || 231.90093 || none <br />
|-<br />
| H2O v2=1 || 5(5,0)-6(4,3) || 3450.7 || 232.68670 || thermal <br />
|-<br />
| SiO v=0 || 5-4 || 20.84 || 217.10498 || weak maser? + thermal <br />
|-<br />
| SiO v=1 || 5-4 || 1789.8 || 215.59595 || strong maser + thermal <br />
|-<br />
| SiO v=2 || 5-4 || 3541.7 || 214.08854 || thermal + absorption<br />
|-<br />
| 29SiO v=0 || 5-4 || 20.58 || 214.38576 || weak maser? + thermal <br />
|-<br />
|}<br />
<br />
==HL Tau - Protoplanetary Disk==<br />
<br />
HL Tau was observed in continuum and spectral lines in Band 3, and (only) continuum in Bands 6 & 7. Angular resolutions achieved for the continuum data are 85 x 61 mas, 35 x 22 mas, and 30 x 19 mas in Bands 3, 6, and 7, respectively. It was necessary to uv-taper the spectral line data so the resulting angular resolution is coarser (ranging from 0.25arcsec to 1.1 arcsec). In addition to the more standard image products we also provide an example of combining the Band 6 and Band 7 continuum data using ''nterms=2'' to derive the spectral index and create a high fidelity image.<br />
<br />
[[File:HLTAU_newb6_fig.png|300px||right|]]<br />
<br />
'''HL Tau Band 3 Lines''' (7 executions for each of two tunings: 89 and 115 GHz): [[media:HLTau_Band3_89GHz_Imaging.py|HLTau_Band3_89GHz_Imaging.py]] , [[media:HLTau_Band3_115GHz_Imaging.py|HLTau_Band3_115GHz_Imaging.py]]<br />
{| class="wikitable" <br />
! align="Center"| Line <br />
!align="Center"|Transition<br />
!El (K)<br />
!Rest Freq (GHz)<br />
!detection<br />
|-<br />
| HCN || 1-0 || 0.0 || 88.63185 || absorption<br />
|-<br />
| HCO+ || 1-0 || 0.0 || 89.18853 || outflow, disk, absorption<br />
|-<br />
| CN || 1-0 || 0.0 || 113.49097 || absorption<br />
|-<br />
| 12CO || 1-0 || 0.0 || 115.2712 || outflow, confused<br />
|-<br />
|}<br />
Note only the frequency of the strongest hyperfine (HF) transition is listed for HCN (3 HFs) and CN (4 HFs).<br />
<br />
'''HL Tau Band 3 Continuum''' (combined continuum from both line tunings): [[media:HLTau_Band3_Cont_Imaging.py|HLTau_Band3_Cont_Imaging.py]]<br />
<br />
Mean Continuum Frequency: 101.9 GHz<br />
<br />
'''HL Tau Band 6 Continuum''' (9 executions): [[media:HLTau_Band6_Cont_Imaging.py|HLTau_Band6_Cont_Imaging.py]]<br />
<br />
Mean Continuum Frequency: 233.0 GHz <br />
<br />
'''HL Tau Band 7 Continuum''' (10 executions): [[media:HLTau_Band7_Continuum_Imaging.py|HLTau_Band7_Continuum_Imaging.py]]<br />
<br />
Mean Continuum Frequency: 343.5 GHz<br />
<br />
'''HL Tau Combined Band 6+7 Continuum (nterms=2)''': [[media:HLTau_Band67_Cont_Imaging.py|HLTau_Band67_Cont_Imaging.py]]<br />
<br />
Mean Continuum Frequency: 287 GHz<br />
<br />
==SDP.81 - Lensed Galaxy==<br />
<br />
The lensed galaxy SDP.81 was observed in continuum and spectral lines in Bands 4, 6 & 7. Angular resolutions achieved for the continuum data are 60 x 54 mas, 39 x 30 mas and 31 x 23 mas in Bands 4, 6, and 7, respectively. It was necessary to uv-taper the spectral line data so the resulting angular resolution is coarser (up to 169 mas). This source lies at a redshift of z~3, accounting for the large offset in rest frequency compared to the observing band. In addition to the more standard image products we also provide an example of combining the Band 6 and Band 7 continuum data using ''nterms=2'' to derive the spectral index and create a high fidelity image. However it is important to note that this procedure did not work well at full resolution, as evidenced by the almost complete masking of the resulting spectral index map -- this is an indication that the spectral index and hence resulting flux-densities are not well constrained. However, using a bit of taper (larger beam) improved the signal enough for the technique to work. <br />
<br />
[[File:SDP81_b6_fig.png|300px||right|]]<br />
<br />
'''SDP.81 Band 4 Continuum and Lines''' (12 executions): [[media:SDP.81_Band4_Imaging.py|SDP.81_Band4_Imaging.py]]<br />
<br />
Mean Continuum Frequency: 151 GHz<br />
<br />
{| class="wikitable" <br />
! align="Center"| Line <br />
!align="Center"|Transition<br />
!El (K)<br />
!Rest Freq (GHz)<br />
!detection<br />
|-<br />
| CO || 5-4 || 55.3 || 576.26793 || detection <br />
|-<br />
|}<br />
<br />
'''SDP.81 Band 6 Continuum and Lines''' (9 executions): [[media:SDP.81_Band6_Imaging.py|SDP.81_Band6_Imaging.py]]<br />
<br />
Mean Continuum Frequency: 236 GHz<br />
<br />
{| class="wikitable" <br />
! align="Center"| Line <br />
!align="Center"|Transition<br />
!El (K)<br />
!Rest Freq (GHz)<br />
!detection<br />
|-<br />
| CO || 8-7 || 154.9 || 921.79970 || detection <br />
|-<br />
| H2O v=0|| 2(0,2)-1(1,1) || 53.4 || 987.92676 || weak detection <br />
|-<br />
|}<br />
<br />
'''SDP.81 Band 7 Continuum and Lines''' (11 executions): [[media:SDP.81_Band7_Imaging.py|SDP.81_Band7_Imaging.py]]<br />
<br />
Mean Continuum Frequency: 290 GHz<br />
<br />
{| class="wikitable" <br />
! align="Center"| Line <br />
!align="Center"|Transition<br />
!El (K)<br />
!Rest Freq (GHz)<br />
!detection<br />
|-<br />
| CO || 10-9 || 248.9 || 1151.98544 || detection <br />
|-<br />
|}<br />
<br />
'''SDP.81 Combined Band 6+7 Continuum (tapered, nterms=2)''': [[media:SDP.81_Band67_Cont_Imaging.py|SDP.81_Band67_Cont_Imaging.py]]<br />
<br />
Mean Continuum Frequency: 268 GHz</div>Sstierwahttps://casaguides.nrao.edu/index.php?title=ALMA2014_LBC_SVDATA&diff=19968ALMA2014 LBC SVDATA2016-06-07T03:57:08Z<p>Sstierwa: /* HL Tau - Protoplanetary Disk */</p>
<hr />
<div><br />
= '''Overview''' =<br />
<br />
This casaguide describes the imaging used for the ALMA 2014 Long Baseline Campaign (LBC) Science Verification (SV) data. The purpose of this campaign was to verify and demonstrate ALMA's performance on baseline lengths of ~10 km in preparation for this very high angular resolution capability to be offered for Cycle 3. As part of the overall LBC testing plan, five science targets were chosen to span the range of properties that would be needed to offer the capability and to demonstrate to the community both the power and caveats associated with long baseline observing. The SV portion of the campaign was carried out from October 12 to November 14, 2014. As described below, the data products for four of the five targets can now be dowloaded from the regional ALMA Science Portals, while the imaging scripts and salient details are provided on this page (the final target 3C138, will be released separately with other SV polarization data in the near future).<br />
<br />
==Obtaining the Data==<br />
<br />
To download the data, go to the ALMA Science Portal (SP) [https://almascience.nrao.edu/alma-data/science-verification Science Verification data page]:<br />
<br />
Choose a LBC SV science target:<br />
'''13. Juno''', '''14. Mira''', '''15. HL Tau''', or '''16. SDP.81'''<br />
<br />
There you will find gzipped tar files of the form (these files can be unpacked with the ''tar -xvzf'' command):<br />
<br />
*'''Target_Band_Freq_UnCalibratedData''': Raw, uncalibrated data in ALMA Science Data Model (asdm) format<br />
<br />
*'''Target_Band_Freq_CalibrationScripts''': Calibration scripts that go along with the UnCalibratedData. These scripts can be executed once placed in the same directory as the UnCalibratedData<br />
<br />
*'''Target_Band_Freq_CalibratedData''': Calibrated and combined uv-data. In the case of continuum datasets, an appropropriate amount of channel averaging has been applied to reduce the data size. Line data sets are provided at their full resolution. If self-calibration was possible, you will also find the final phase-only and amplitude tables in a subdirectory called "calibration". This gives the choice of either performing your own self-calibration or applying the supplied tables. If you are going to apply these tables, be sure to also run any {{flagdata}} commands in the imaging scripts. If the self-calibration tables are not present, we deemed self-calibration unfeasible. '''Note that the imaging scripts are provided on this page, not at the science portal'''.<br />
<br />
*'''Target_Band_Freq_ReferenceImages''': Final reference images with self-calibration applied where possible. For the few cases where primary beam correction is warranted these files are also provided. Continuum images with .pbcor in the name have already been corrected. The line files with .flux in the name are the primary beam images themselves and can be applied to the corresponding line data if desired using the CASA task {{impbcor}}.<br />
<br />
*'''README''': Summarizes the data available for that science target.<br />
<br />
<br />
''The data have been packaged in this manner to allow a wide range of interaction with the data, ranging from complete re-reduction, to simply having a look at the final reference images. Please only download the data products you expect to use -- we expect the initial load on the servers could be high and for the UnCalibratedData, and in the case of targets/bands with spectral line data the CalibratedData, files are quite large.''<br />
<br />
'''Using the data for publication''': Please use the acknowledgement given at the bottom of the [https://almascience.nrao.edu/alma-data/science-verification Science Verification Data page].<br />
<br />
<br />
==CASA Version==<br />
<br />
The data were calibrated and imaged using CASA 4.2.2. At this time, we have no reason to believe that they would not work in CASA 4.3 with a few caveats: (1) The calibration scripts check that the version they were made in matches the version being used. If you want to try them in CASA 4.3 you will need to change this section of each calibration script. (2) Be aware that data imported in CASA 4.3 cannot then be imaged in CASA 4.2.2 due to the necessary addition of a new keyword in the MS format. Please note, however, that only CASA 4.2.2 has been tested.<br />
<br />
CASA can be downloaded from: http://casa.nrao.edu/casa_obtaining.shtml<br />
The CASA 4.2.2 version is called '''ALMA pipeline CASA 4.2.2'''<br />
<br />
In addition to CASA 4.2.2 you will also need the Analysis Utilities available from https://casaguides.nrao.edu/index.php/Analysis_Utilities <br />
<br />
='''LBC SV Imaging'''=<br />
<br />
For each LBC SV target there is a brief description of the data and imaging, along with links to the imaging scripts. For spectral line targets, a table of the lines observed is also given. The "detection" columns are merely descriptive to give a sense of what the data show, they are not meant to be taken as scientific assessments. The continuum was detected for all four of the science targets at each observed band. For all of the targets the number of antennas employed was of order 30. For cases in which there was enough signal for self-calibration this is also demonstrated in the imaging scripts (i.e. all sources except SDP.81). <br />
<br />
====The most important imaging take home messages====<br />
*'''UV-Coverage is critically important''': For each target/band a scheduling block was designed to run for 60-70 minutes, with about 30 minutes on source per execution. The number of executions carried out depended on the complexity of the imaging required, from short snapshots of the bright compact emission from Juno to to the many executions required for the complex morphologies of HL Tau and SDP.81. Additionally, we found that due to the non-optimal configuration available for the LBC, which had a deficit in uv-coverage for baselines between 200 to 500 m the choice of the robust parameter in clean is a crucial one. Although more naturally-weighted choices (i.e. larger ''robust'' parameter) in principle give better sensitivity, they also show poor dirty beam (i.e. psf) characteristics, with a large extended plateau in addition to the more point-like morphology that corresponds to the fitted clean beam. Thus, for full resolution images, we typically employed ''robust=0.0'', though occasionally up to 1.0 was used. <br />
<br />
*'''Observing narrow ''thermal'' line emission at high resolution is challenging''': Except for Mira, which has the advantage of having compact line emission, as well as emission from highly-excited or even masing lines, the imaging of line emission at the very high resolution afforded by the longest baselines is challenging. For example, at 89 GHz with 0.25 km/s channels, 30 antennas, 3.5 hours on-source, and an angular resolution of 70 mas, the expected spectral rms noise per channel is 2.6 mJy/beam but only 83 K in surface brightness sensitivity. As a result, it was necessary to apply a uv taper when making the spectral line images for HL Tau and SDP.81 in order to achieve good detections. <br />
<br />
*'''Extended emission at high angular resolution can best be imaged with multiscale''': Cleaning diffuse emission on size scales significantly larger than the beam with the standard delta-function deconvolution method results in the "clean instability": giving the diffuse emission a "pointilated" or "cotton-candy" like morphology. This can be ameliorated by using a range of scales to do the cleaning. In CASA, this technique is accessed through the {{clean}} ''multiscale'' parameter. The scales are given as multipliers of the cell (pixel) size. It is essential to always use 0 for the first scale as this corresponds to the normal clean beam, ''multiscale=[0,5,15]'' is usually a good starting point for experimentation. For more details see: Cornwell 2008 (IEEE Journal of Sig Proc., 2, 793).<br />
<br />
*'''Combining bands can produce amazing results''': For sources that have significant spatial changes in continuum spectral index, and wide observed fractional bandwidth (>15%) for which the signal-to-noise is high throughout the frequency range, it is possible to use a technique in {{clean}} to simultaneously account for the changing spectral index (<math>S_{\nu}\propto \nu^{\alpha}</math>) to produce a high fidelity image, and a map of the spectral index along with its estimated error (see Rau, U., & Cornwell, T.J. 2011, A&A, 532, AA71). However, the caveat that the signal to noise must be very good, especially at the frequency extrema, is a strong one. So far we have restricted our tests to ''nterms=2'', though even higher orders are possible. The results of this technique on HL Tau Band 6+7 are dramatic, and it also provides some improvement for Mira at Band 3. However, our test show that for the weaker emission at Band 3 for HL Tau and all bands for SDP.81 at native resolution, this technique does not work well. Bottom line: use with caution, but it can produce amazing results. Since this method automatically masks the resulting spectral index (<math>\alpha</math>) map where it estimates <math>\alpha/\alpha_{error}< 4</math> a good rule of thumb is that if the spectral index map is mostly masked in the image signal regions, there is inadequate S/N for this technique to be successful.<br />
<br />
==Juno - Asteroid==<br />
<br />
[[File:Juno_b6.png|150px|thumb|right|Juno (0): The beam size (lower left corner) is 33x25 mas (~41 km).]]<br />
<br />
Asteroid (3) Juno was observed in continuum in Band 6 to demonstrate the ephemeris capability. The observations were taken over 60% of Juno's rotation period of 7.2 hours. The data are split into approximately 18min intervals (10min on source) spread across 10 individual datasets and imaged and self-calibrated separately in order to prevent smearing due to the rapid rotation. The angular resolution achieved ranges from 32 x 24 mas to 42 x 36 mas, differing primarily due to the level of phase stability as the observations span the transition from night through dawn and into daytime, but changing uv-coverage also plays a role.<br />
<br />
'''Juno Band 6 Continuum''' (5 executions): [[media:Juno_Band6_Imaging.py|Juno_Band6_Imaging.py]]<br />
<br />
Mean Continuum Frequency: 233 GHz<br />
<br />
==Mira - AGB Star==<br />
<br />
Mira (omicron Cet) was observed in continuum and spectral lines in Bands 3 and 6. Angular resolutions achieved for the continuum data are 70 x 60 mas and 34 x 24 mas in Bands 3 and 6, respectively. In order to achieve the best possible dynamic range, the continuum and SiO v=1 line data were self-calibrated independently. The maser emission from the SiO v=1 line was used to derive self-calibration for the line data. In order to obtain high dynamic range on the band 3 continuum, which has a wide fractional bandwidth, it was also necessary to take into account the spectral index with ''nterms=2''.<br />
<br />
[[File:Mira_B6sv_multi3panel_fig.png|500px||right|]]<br />
<br />
'''Mira Band 3 Continuum and Lines''' (3 executions): [[media:Mira_Band3_Imaging.py|Mira_Band3_Imaging.py]]<br />
<br />
Mean Continuum Frequency: 94 GHz<br />
<br />
{| class="wikitable" <br />
! align="Center"| Line <br />
!align="Center"|Transition<br />
!El (K)<br />
!Rest Freq (GHz)<br />
!detection<br />
|-<br />
| SiO v=0 || 2-1 || 2.1 || 86.8470 || weak maser? + thermal <br />
|-<br />
| SiO v=1 || 2-1 || 1771 || 86.2434 || strong maser + thermal <br />
|-<br />
| SiO v=2 || 2-1 || 3523 || 85.6405 || thermal + absorption <br />
|-<br />
| 29SiO v=0 || 2-1 || 2.1 || 85.7590 || weak maser? + thermal <br />
|-<br />
|}<br />
<br />
'''Mira Band 6 Continuum and Lines''' (2 executions): [[media:Mira_Band6_Imaging.py|Mira_Band6_Imaging.py]]<br />
<br />
Mean Continuum Frequency: 231 GHz<br />
<br />
{| class="wikitable" <br />
! align="Center"| Line <br />
!align="Center"|Transition<br />
!El (K)<br />
!Rest Freq (GHz)<br />
!detection<br />
|-<br />
| H30alpha || - || - || 231.90093 || none <br />
|-<br />
| H2O v2=1 || 5(5,0)-6(4,3) || 3450.7 || 232.68670 || thermal <br />
|-<br />
| SiO v=0 || 5-4 || 20.84 || 217.10498 || weak maser? + thermal <br />
|-<br />
| SiO v=1 || 5-4 || 1789.8 || 215.59595 || strong maser + thermal <br />
|-<br />
| SiO v=2 || 5-4 || 3541.7 || 214.08854 || thermal + absorption<br />
|-<br />
| 29SiO v=0 || 5-4 || 20.58 || 214.38576 || weak maser? + thermal <br />
|-<br />
|}<br />
<br />
==HL Tau - Protoplanetary Disk==<br />
<br />
HL Tau was observed in continuum and spectral lines in Band 3, and (only) continuum in Bands 6 & 7. Angular resolutions achieved for the continuum data are 85 x 61 mas, 35 x 22 mas, and 30 x 19 mas in Bands 3, 6, and 7, respectively. It was necessary to uv-taper the spectral line data so the resulting angular resolution is coarser (ranging from 0.25arcsec to 1.1 arcsec). In addition to the more standard image products we also provide an example of combining the Band 6 and Band 7 continuum data using ''nterms=2'' to derive the spectral index and create a high fidelity image.<br />
<br />
[[File:HLTAU_newb6_fig.png|300px||right|]]<br />
<br />
'''HL Tau Band 3 Lines''' (7 executions for each of two tunings: 89 and 115 GHz): [[media:HLTau_Band3_89GHz_Imaging.py|HLTau_Band3_89GHz_Imaging.py]] , [[media:HLTau_Band3_115GHz_Imaging.py|HLTau_Band3_115GHz_Imaging.py]]<br />
{| class="wikitable" <br />
! align="Center"| Line <br />
!align="Center"|Transition<br />
!El (K)<br />
!Rest Freq (GHz)<br />
!detection<br />
|-<br />
| HCN || 1-0 || 0.0 || 88.63185 || absorption<br />
|-<br />
| HCO+ || 1-0 || 0.0 || 89.18853 || outflow, disk, absorption<br />
|-<br />
| CN || 1-0 || 0.0 || 113.49097 || absorption<br />
|-<br />
| 12CO || 1-0 || 0.0 || 115.2712 || outflow, confused<br />
|-<br />
|}<br />
Note only the frequency of the strongest hyperfine (HF) transition is listed for HCN (3 HFs) and CN (4 HFs).<br />
<br />
'''HL Tau Band 3 Continuum''' (combined continuum from both line tunings): [[media:HLTau_Band3_Cont_Imaging.py|HLTau_Band3_Cont_Imaging.py]]<br />
<br />
Mean Continuum Frequency: 101.9 GHz<br />
<br />
'''HL Tau Band 6 Continuum''' (9 executions): [[media:HLTau_Band6_Cont_Imaging.py|HLTau_Band6_Cont_Imaging.py]]<br />
<br />
Mean Continuum Frequency: 233.0 GHz <br />
<br />
'''HL Tau Band 7 Continuum''' (10 executions): [[media:HLTau_Band7_Cont_Imaging.py|HLTau_Band7_Continuum_Imaging.py]]<br />
<br />
Mean Continuum Frequency: 343.5 GHz<br />
<br />
'''HL Tau Combined Band 6+7 Continuum (nterms=2)''': [[media:HLTau_Band67_Cont_Imaging.py|HLTau_Band67_Cont_Imaging.py]]<br />
<br />
Mean Continuum Frequency: 287 GHz<br />
<br />
==SDP.81 - Lensed Galaxy==<br />
<br />
The lensed galaxy SDP.81 was observed in continuum and spectral lines in Bands 4, 6 & 7. Angular resolutions achieved for the continuum data are 60 x 54 mas, 39 x 30 mas and 31 x 23 mas in Bands 4, 6, and 7, respectively. It was necessary to uv-taper the spectral line data so the resulting angular resolution is coarser (up to 169 mas). This source lies at a redshift of z~3, accounting for the large offset in rest frequency compared to the observing band. In addition to the more standard image products we also provide an example of combining the Band 6 and Band 7 continuum data using ''nterms=2'' to derive the spectral index and create a high fidelity image. However it is important to note that this procedure did not work well at full resolution, as evidenced by the almost complete masking of the resulting spectral index map -- this is an indication that the spectral index and hence resulting flux-densities are not well constrained. However, using a bit of taper (larger beam) improved the signal enough for the technique to work. <br />
<br />
[[File:SDP81_b6_fig.png|300px||right|]]<br />
<br />
'''SDP.81 Band 4 Continuum and Lines''' (12 executions): [[media:SDP.81_Band4_Imaging.py|SDP.81_Band4_Imaging.py]]<br />
<br />
Mean Continuum Frequency: 151 GHz<br />
<br />
{| class="wikitable" <br />
! align="Center"| Line <br />
!align="Center"|Transition<br />
!El (K)<br />
!Rest Freq (GHz)<br />
!detection<br />
|-<br />
| CO || 5-4 || 55.3 || 576.26793 || detection <br />
|-<br />
|}<br />
<br />
'''SDP.81 Band 6 Continuum and Lines''' (9 executions): [[media:SDP.81_Band6_Imaging.py|SDP.81_Band6_Imaging.py]]<br />
<br />
Mean Continuum Frequency: 236 GHz<br />
<br />
{| class="wikitable" <br />
! align="Center"| Line <br />
!align="Center"|Transition<br />
!El (K)<br />
!Rest Freq (GHz)<br />
!detection<br />
|-<br />
| CO || 8-7 || 154.9 || 921.79970 || detection <br />
|-<br />
| H2O v=0|| 2(0,2)-1(1,1) || 53.4 || 987.92676 || weak detection <br />
|-<br />
|}<br />
<br />
'''SDP.81 Band 7 Continuum and Lines''' (11 executions): [[media:SDP.81_Band7_Imaging.py|SDP.81_Band7_Imaging.py]]<br />
<br />
Mean Continuum Frequency: 290 GHz<br />
<br />
{| class="wikitable" <br />
! align="Center"| Line <br />
!align="Center"|Transition<br />
!El (K)<br />
!Rest Freq (GHz)<br />
!detection<br />
|-<br />
| CO || 10-9 || 248.9 || 1151.98544 || detection <br />
|-<br />
|}<br />
<br />
'''SDP.81 Combined Band 6+7 Continuum (tapered, nterms=2)''': [[media:SDP.81_Band67_Cont_Imaging.py|SDP.81_Band67_Cont_Imaging.py]]<br />
<br />
Mean Continuum Frequency: 268 GHz</div>Sstierwahttps://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_4.5&diff=19493TWHydraBand7 Imaging 4.52016-05-18T06:00:31Z<p>Sstierwa: /* Make Moment 0 Maps */</p>
<hr />
<div>[[Category:ALMA]][[Category:Imaging]][[Category:Spectral Line]]<br />
<br />
* '''This tutorial picks up where '''[[TWHydraBand7_Calibration_4.5]]''' leaves off, with fully calibrated, split science target MS. If you wish to skip the Calibration guide: obtain the calibrated data from [[TWHydraBand7#Getting_the_Data]]; extract it using <tt>tar -xzvf FILENAME</tt>; and <tt>cd</tt> into the extracted directory.'''<br />
<br />
*'''This guide is designed for CASA 4.5.2. If you are using an older version of CASA please see [[TWHydraBand7_Imaging_4.3]].<br />
<br />
* '''Details of the ALMA data are provided at [[TWHydraBand7]]'''<br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.5.2. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.5.0'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
== Prepare Continuum Data for Further Processing==<br />
<br />
In order to speed up imaging/self-calibration for the continuum data we will average channels together, and then flag the few spectral features. This method works well in the case of only a few spectral lines, while retaining enough channelization to aid in multi-frequency synthesis and being able to remove spectral features in the averaged data. When generalizing this process to other datasets, the amount of channel averaging will vary. '''Note for wide bandwidth data it is never a good idea to use the continuum estimate generated by uv-continuum subtraction as your continuum data'''. This worked OK in the past with the narrow band systems like the VLA and low dynamic range instruments like the SMA, but is not advised for ALMA wide bandwidth, high dynamic range data. <br />
<br />
<figure id="Cont_spw2.png"><br />
[[Image:Cont_spw2.png|thumb|<caption>CO(3-2) in spw=2 from the "continuum" channel averaged data.</caption>]]<br />
</figure><br />
<figure id="Cont_spw3.png"><br />
[[Image:Cont_spw3.png|thumb|<caption>Notice upswing at high channel numbers in spw=3.</caption>]]<br />
</figure><br />
<br />
One can also flag the spectral features first but in that case make a backup of the file that is analogous to TWHydra_corrected.ms as you will need it later (unflagged) for spectral line imaging. We begin by excluding ~20 channels on each edge, and averaging over 100 channel intervals:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_cont.ms*')<br />
split(vis='TWHydra_corrected.ms',outputvis='TWHydra_cont.ms',<br />
spw='0~3:21~3820',width=100,datacolumn='data')<br />
</source><br />
<br />
Now make a plot of amplitude vs. channel to see what needs to be flagged<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',spw='0~3',xaxis='channel',yaxis='amp',<br />
avgtime='1e8',avgscan=T,coloraxis='spw',iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
The CO(3-2) and HCO+(4-3) lines are obvious. The 4th spw; spw=3 also shows an upswing on the highest channels that is problematic, it was seen on the calibrators too and is likely due to a weak atmospheric feature, we will flag the worst of it.<br />
<br />
<figure id="Cont_uvplot.png"><br />
[[Image:Cont_uvplot.png|thumb|<caption>UV-plot of the continuum emission, colors show spws.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='TWHydra_cont.ms', mode='manual', <br />
spw='0:16~16, 2:21~21, 3:33~37')<br />
</source><br />
<br />
Have a look at the continuum as a function of uv-distance (in the plot to the right, the 4 spw are shown in different colors on top of each other). If the data are flat as a function of uv-distance, the source is completely unresolved. If instead you see structure (in this case decreasing amplitude with uv-distance), the source is resolved. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',spw='',xaxis='uvdist',yaxis='amp',field='',avgchannel='38',<br />
coloraxis='spw',plotfile='cont_uvplot.png')<br />
</source><br />
<br />
Notice that the spw do not have the same amplitude. Unfortunately, the red spw (highest frequency) should be higher than the green one (lowest frequency) because optically thin dust goes as nu^4, and optically thick as nu^2. This inconsistency is due to imperfect amplitude/absolute flux calibration. The self-calibration below will bring them into agreement with each other, but this is the sort of thing that results in considerable absolute flux uncertainty at submillimeter wavelengths. We are working on how to do this better.<br />
<br />
==A priori Noise Estimates==<br />
<br />
<figure id="Corrected_time.png"><br />
[[File:Corrected_time.png|thumb|<caption>Plot for estimating time.</caption>]]<br />
</figure><br />
<figure id="sensitivity_cont.png"><br />
[[File:sensitivity_cont.png|thumb|<caption>Sensitivity calculator setup with observed continuum parameters for these observations.</caption>]]<br />
</figure><br />
<br />
To estimate what the expected noise levels are, we first need to know how much time we had on source. Looking at <br />
a plot of amplitude vs time for the concatenated but pre-split data (see below) there are 9x8min scans + 6x6min scans + 3x1min + 2x2min scans for about 1.9 hours on source. There are 2 polarizations and about 1.75 GHz of total continuum bandwidth taking into account flagging.<br />
<br />
Using this information and https://almascience.nrao.edu/proposing/sensitivity-calculator, we find that the '''expected rms noise for the continuum is about 0.3 mJy/beam'''.<br />
<br />
For the spectral line data, which we will image below, with 0.12 km/s channels (needs to be entered in the field ''bandwidth per polarization''), the '''expected rms noise for the spectral lines is about 32 mJy/beam'''.<br />
<br />
==Image and Self-Calibrate the Continuum==<br />
<br />
====Create Initial Clean Image====<br />
<br />
First we will make an initial image using {{clean}}, this task will both deconvolve and clean. <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
If you are unfamiliar with the basic concepts of deconvolution and clean,<br />
pause here and review for example<br />
http://www.aoc.nrao.edu/events/synthesis/2010/lectures/wilner_synthesis10.pdf<br />
</pre><br />
<br />
In {{clean}}, we use '''mode='mfs'''' to do multifrequency synthesis, in other words grid each uv-channel independently. Since the uv-spacing is a function of frequency, this will actually achieve greater uv-coverage than if all the channels and spws had been averaged in advance. The '''imsize=100''' and '''cellsize=['0.3arcsec']''' were chosen to be appropriate for the Band and antenna configuration. At ALMA Band 7, the Full Width Half Power primary beam is about 20", so we want to make our image at least this big. We've made it a bit larger out to about the 25% power point. For the configuration used to take these data, the resolution is expected to be about 1.5" and it is a good idea to oversample the beam by setting the cell size to be a factor of 4 or 5 smaller than the beam (we have used 5 here). <br />
<br />
For doing self-calibration it is essential that only "real" signal be included in the image model, thus it is important to make a clean mask, and clean the first iteration rather conservatively (shallowly) so that you are sure that you do not have clean components in your model that do not represent real source emission. In the example below we set '''interactive=T''' so you can interactively make the clean mask and stop clean when the signal from the source starts to approach the surrounding "noise" areas in the residual map.<br />
<br />
'''NOTE:''' Real emission will not go away if you do not put a clean box on it. Conversely if you put a clean box on something that is NOT real and clean deeply you can amplify that feature. Thus, its best to be conservative and build up your clean box as you go, you can generally see fainter "real" features in the residuals.<br />
<br />
'''NOTE:''' If you start an interactive clean, and then do not make a mask, clean will stop when you tell it to go on because it has nothing to clean. There is no default mask.<br />
<br />
<figure id="Viewer_clean1.png"><br />
[[Image:Viewer_clean1.png|thumb|<caption>Interactive viewer.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall',<br />
mode='mfs', imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5, <br />
mask='',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
'''NOTE:'''{{clean}} will generate several files automatically with the '''imagename''' prepended:<br />
* <imagename>.image # the final restored image<br />
* <imagename>.flux # the effective primary beam response (e.g. for pbcor)<br />
* <imagename>.flux.pbcoverage # the primary beam coverage (ftmachine=’mosaic’ only)<br />
* <imagename>.model # the model image<br />
* <imagename>.residual # the residual image<br />
* <imagename>.psf # the synthesized (dirty) beam<br />
<br />
Once the Clean Viewer opens, click on the polygon tool with your left mouse button, and draw a polygon around the continuum emission with the left mouse button. Double click inside the region with the left mouse button when you are happy with it. It will turn from green to white when the clean mask is accepted. To continue with clean use the "Next action" buttons in the green area on the Viewer Display GUI. <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
The red X will stop clean where you are, the blue arrow will stop <br />
the interactive part of clean, but continue to clean non-interactively <br />
until reaching the number of iterations requested (niter) or the flux <br />
density threshold (whichever comes first), and the green circle arrow <br />
will clean until it reaches the "iterations" parameter on the left side <br />
of the green area. <br />
</pre><br />
<br />
'''You should chose the green circle arrow'''. It will clean 100 iterations (number under iteration in the green area on the Viewer GUI) and then show the '''residual image''' again. The middle mouse button is automatically assigned to the "plus" icon, which adjusts the colorscale. '''If you cannot easily access multiple mouse buttons, you can always assign your one mouse button the icon you want by clicking on it'''. Adjust the color scale so you can see the structure in the noise better. Also, note that the logger is telling you the amount of clean flux recovered so far, the min/max residuals, and the synthesized beam:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Model 0: max, min residuals = 0.0203454, 0.00267232 clean flux 1.30124<br />
Threshhold not reached yet.<br />
Beam used in restoration: 1.6962 by 1.54549 (arcsec) at pa 28.9043 (deg) <br />
</pre> <br />
<br />
Already with only 100 iterations, the residuals outside the clean mask are larger than that inside. So we will stop here by hitting the Red X symbol.<br />
<br />
====1st Round of Continuum Data Phase Self-calibration====<br />
<br />
Next we can use the clean model to self-calibrate the uv-data. The process of self-calibration tries to adjust the data to better match the model you give it. That is why it is important to make the model as good as you can. {{clean}} places a uv-model of the resulting image in the file <tt>TWHydra_cont.model</tt>. This model can then be used to self-calibrate the data using {{gaincal}}. We use '''gaintype='T'''' to tell it to average the polarizations before deriving solutions (which gains us a sqrt(2) in sensitivity). A critical parameter to play with is '''solint'''; we use '''solint=30s'''. From {{listobs}} the integration time of these data is about 10 seconds, so using '''solint=30s''' then gains us a sqrt(3) in sensitivity. It is often best to start with a larger '''solint''' and then work your way down to the integration time if the S/N of the data permits. For the same reasons as described in the [[TWHydraBand7_Calibration_4.5]] tutorial we want to fix up the phases before tackling amplitude by setting '''calmode='p''''.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='TWHydra_cont.ms',caltable='self_1.pcal',<br />
solint='30s',combine='',gaintype='T',<br />
refant='DV06',spw='',minblperant=4,<br />
calmode='p',minsnr=2)<br />
</source><br />
<br />
<figure id="Self_1_phase.png"><br />
[[Image:Self_1_phase.png|thumb|<caption>Phase solutions from self_1.pcal with solint=30s.</caption>]]<br />
</figure><br />
<br />
Because '''combine=' '''', we are getting independent solutions for each spw. If you are desperate for S/N, you can try combining them with combine='spw'. We have plenty of S/N in these data so we keep them separate. Look at the solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_1.pcal',xaxis='time',yaxis='phase',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,-80,80],figfile='self_1_phase.png')<br />
</source><br />
<br />
The magnitude of corrections gives you a sense of how accurate the phase transfer from the calibrators was. You are checking to see that the phases are being well tracked by the solutions, i.e. smoothly varying functions of time within a given scan. Also the solutions for each spw are lying basically on top of each other which indicates that the spw to spw phase offsets are well calibrated already. Overall, these solutions look quite good. If they didn't you could try increasing the solint and/or combining the spw into a single solution. <br />
<br />
After checking that you are happy with the solutions, apply them with {{applycal}}<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_cont.ms',field='',gaintable=['self_1.pcal'],calwt=F)<br />
</source><br />
<br />
<figure id="Viewer_pcal1.png"><br />
[[Image:Viewer_pcal1.png|thumb|<caption>Clean residuals after 100 iterations and the 1st phase only self-cal. Residuals inside mask are higher than the "noise" outside.</caption>]]<br />
</figure><br />
<br />
Next clean the source again, to save time we can start with the clean mask from the last iteration. If you make interactive adjustments to the clean mask, they will be written to the '''new''' mask TWHydra_contall_1pcal.mask, and not the old one. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_1pcal.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall_1pcal',<br />
mode='mfs',imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5, <br />
mask='TWHydra_contall.mask',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
Now after the first 100 iterations you see that the residuals inside the clean mask are higher than those outside. This is because flux that had been spread out in the map due to poorly correlated phases has been placed where it belongs on the source, thereby increasing its flux. You may also notice that your original clean mask is a little too small. If so, you can make it a bit larger, just by drawing a new polygon around the area you want to include. When you double click, it will incorporate the new mask into the current mask (if your box goes awry you can use the erase toggle [radio button] to erase and redo the mask). The new mask area need not overlap the original mask (though for this source it probably will). You might also want to use the magnifying glass to zoom in. Again, you assign mouse buttons by clicking on the icon you want. Clean another 100 iterations (for a total of 200) and stop by clicking the red X.<br />
<br />
Now open initial and 1st self-cal images to compare them using {{imview}}. This is an alternative version of the {{viewer}} that is somewhat scriptable. <br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(raster=[{'file':'TWHydra_contall.image','range':[-0.01,0.05]},<br />
{'file':'TWHydra_contall_1pcal.image','range':[-0.01,0.05]}])<br />
</source><br />
<br />
Once the Viewer Display panel opens, click on the box next in the "Images" panel and then use the tapedeck buttons in the panel to alternate between the two images. Because the range was explicitly set, they are on the same color scale. It is obvious that the self-calibrated image is better. To quantify, 1st toggle back to "normal" and then draw a region that excludes the central source with the polygon tool and then double click inside (if you stay in the "Images" view, only the statistics for the last image opened will appear on the terminal instead of both). The basic statistics of the polygon region will print to the '''terminal''':<br />
<br />
<pre style="background-color: #fffacd;"><br />
TWHydra_contall.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2357 -9.434800e-01 -2.858690e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-4.002885e-04 7.906752e-03 7.898289e-03 -2.541723e-02 2.172779e-02 <br />
<br />
TWHydra_contall_1pcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2357 6.326584e-01 1.916918e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
2.684168e-04 3.655786e-03 3.646692e-03 -1.215155e-02 1.109403e-02 <br />
</pre><br />
<br />
The self-calibrated image has more than a factor of 2 lower rms noise!<br />
<br />
====2nd Round of Continuum Data Phase Self-calibration====<br />
<br />
Now that we have a better model, we solve for solutions again. This time we will try making the solint smaller -- the integration time is about 10 seconds, so we set '''solint='int'''' to have it use the integration time.<br />
<br />
<figure id="Self_2_phase.png"><br />
[[Image:Self_2_phase.png|thumb|<caption>Phase solutions from self_2.pcal with solint='int'.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='TWHydra_cont.ms',caltable='self_2.pcal',<br />
solint='int',combine='',gaintype='T',<br />
refant='DV06',spw='',minblperant=4,<br />
calmode='p',minsnr=2)<br />
</source><br />
<br />
Now plot the new solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_2.pcal',xaxis='time',yaxis='phase',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,-80,80],figfile='self_2_phase.png')<br />
</source><br />
<br />
The phases on this shorter '''solint''' still seem to be tracking well so we will apply it and make a new image and check to see if there is improvement. <br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_cont.ms',field='',gaintable=['self_2.pcal'],calwt=F)<br />
</source><br />
<br />
<figure id="Viewer_pcal2.png"><br />
[[Image:Viewer_pcal2.png|thumb|<caption>Clean residuals after 2nd phase only self-cal and 250 iterations. The residuals inside the clean mask are lower than those outside, so its time to stop.</caption>]]<br />
</figure><br />
<br />
Now clean again, updating '''mask''' with the most recent mask file.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_2pcal.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall_2pcal',<br />
mode='mfs',imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5,usescratch=False,<br />
mask='TWHydra_contall_1pcal.mask',<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
After 200 iterations<br />
<br />
<pre style="background-color: #fffacd;"><br />
Model 0: max, min residuals = 0.00489776, -0.00464541 clean flux 1.44461<br />
</pre><br />
<br />
It looks like it could use just a little more cleaning, so set '''iterations=50 in the GUI'''.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Clean used 50 iterations to approach a threshhold of 0.0015067<br />
0.0107122 Jy <- cleaned in this cycle for model 0 (Total flux : 1.45532Jy)<br />
Final maximum residual = 0.00326382<br />
Model 0: max, min residuals = 0.00326382, -0.00321361 clean flux 1.45532<br />
</pre><br />
<br />
The small amount of flux cleaned this cycle indicates that clean is converging and it's about time to stop. Also the residuals inside the clean mask are now smaller than the residuals outside (i.e. the noise) also indicating it's time to stop by hitting the red X on the GUI.<br />
<br />
Now repeat the display, blinking, and image statistics steps described above for the 1st and 2nd phase-only self-cal iterations.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(raster=[{'file':'TWHydra_contall_1pcal.image','range':[-0.01,0.05]},<br />
{'file':'TWHydra_contall_2pcal.image','range':[-0.01,0.05]}])<br />
</source><br />
<br />
The difference is small:<br />
<pre style="background-color: #fffacd;"><br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2466 4.611597e-02 1.397287e-03 <br />
Mean Rms Std dev Minimum Maximum <br />
1.870072e-05 3.831524e-03 3.832255e-03 -1.414417e-02 1.109403e-02 <br />
<br />
TWHydra_contall_2pcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2466 1.159416e-01 3.512963e-03 <br />
Mean Rms Std dev Minimum Maximum <br />
4.701606e-05 3.811716e-03 3.812199e-03 -1.383034e-02 1.078456e-02 <br />
</pre><br />
<br />
This small improvement suggests that we have gone as far as we can with phase self-cal.<br />
<br />
===Continuum Data Amplitude Self-Calibration===<br />
<br />
Now we will apply the best phase solution table on-the-fly while solving for the amplitude self-cal solutions. Since amplitude changes more slowly and is less constrained than phase, we use a longer '''solint='inf'''', as long as '''combine=' '''' this means to do one solution per scan. <br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='TWHydra_cont.ms',caltable='self_ap.cal',<br />
solint='inf',combine='',gaintype='T',<br />
refant='DV06',spw='',minblperant=4,<br />
gaintable=['self_2.pcal'],<br />
calmode='ap',minsnr=2)<br />
</source><br />
<br />
It's useful to look at the residual phase in the amplitude calibration table, i.e. since we applied our best phase-only solution while solving for this new amplitude and phase ('''calmode='ap'''') solution, the phase should already be corrected.<br />
<br />
<figure id="Self_ap_phase.png"><br />
[[Image:Self_ap_phase.png|thumb|<caption>Residual phase solutions from self_ap.cal.</caption>]]<br />
</figure><br />
<figure id="Self_ap_amp.png"><br />
[[Image:Self_ap_amp.png|thumb|<caption>Amplitude solutions from self_ap.cal.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_ap.cal',xaxis='time',yaxis='phase',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,-1,1],figfile='self_ap_phase.png')<br />
</source><br />
<br />
The residuals are very small as expected. (If you see large residuals here, it means that the phase-only solution is suspect, and you were mostly just moving noise around.) Now look at the amplitude solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_ap.cal',xaxis='time',yaxis='amp',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,0.6,1.4],figfile='self_ap_amp.png')<br />
</source><br />
<br />
For the most part these look very good except one rather large deviation on DV06. Apply both the final phase and the amplitude calibration tables.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_cont.ms',field='',gaintable=['self_2.pcal','self_ap.cal'],calwt=F)<br />
</source><br />
<br />
Plot the corrected data as a function of both time and uv-distance. It is always a good idea to check these after an amplitude self-calbration to be sure that it worked properly. Occasionally, a few spurious bits of data will get blown up by the amplitude self-cal if it is not well-constrained. <br />
<br />
<figure id="Selfcal_time.png"><br />
[[Image:Selfcal_time.png|thumb|<caption>Post self-calibration amplitude vs. time</caption>]]<br />
</figure><br />
<figure id="Selfcal_uvdist.png"><br />
[[Image:Selfcal_uvdist.png|thumb|<caption>Post self-calibration amplitude vs. uv-distance</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',xaxis='time',yaxis='amp',<br />
avgchannel='38',ydatacolumn='corrected',coloraxis='spw',<br />
plotfile='selfcal_time.png')<br />
</source><br />
<br />
The time where we saw a large amplitude correction on DV06 looks consistent here so the large correction we saw in the solutions corrected a real issue. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',xaxis='uvdist',yaxis='amp',<br />
avgchannel='38',ydatacolumn='corrected',coloraxis='spw',<br />
plotfile='selfcal_uvdist.png')<br />
</source><br />
<br />
You will see that this plot looks much better than before. <br />
<br />
<figure id="Viewer_apcal.png"><br />
[[Image:Viewer_apcal.png|thumb|<caption>Clean residuals after final amplitude and phase self-cal.</caption>]]<br />
</figure><br />
<br />
Now make the final continuum image.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_apcal.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall_apcal',<br />
mode='mfs',imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5,usescratch=False,<br />
mask='TWHydra_contall_2pcal.mask',<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
We know we need to clean with at least 250 iterations (i.e. 100+100+50=250), so set iterations to 300 in the gui and hit the round green arrow. After this notice how much better the residual looks. Clean another 100 iterations. The "circular pattern", and 4 bright spots at each corner you see now in the residual is likely due to non-closing amplitude errors that cannot be removed with an antenna based self-calibration, so this is as good as it gets with pure self-cal. Hit the Red X to stop clean.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Clean used 100 iterations to approach a threshhold of 0.00105507<br />
0.0061808 Jy <- cleaned in this cycle for model 0<br />
Final maximum residual = 0.00242926<br />
Model 0: max, min residuals = 0.00238278, -0.00242926 clean flux 1.48201<br />
</pre><br />
<br />
Now repeat the display, blinking, and image statistics described above for the 2nd phase only and the new amplitude & phase self-cal'ed images.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(raster=[{'file':'TWHydra_contall_2pcal.image','range':[-0.01,0.05]},<br />
{'file':'TWHydra_contall_apcal.image','range':[-0.01,0.05]}])<br />
</source><br />
<br />
The amplitude and phase self cal'ed image is notably better than phase-only. Quantitatively:<br />
<pre style="background-color: #fffacd;"><br />
<br />
TWHydra_contall_2pcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 3542 2.053068e-01 6.220676e-03 <br />
Mean Rms Std dev Minimum Maximum <br />
5.796351e-05 3.955967e-03 3.956101e-03 -1.383034e-02 1.078456e-02 <br />
<br />
TWHydra_contall_apcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 3542 6.044652e-04 1.831495e-05 <br />
Mean Rms Std dev Minimum Maximum <br />
1.706565e-07 1.270183e-03 1.270362e-03 -4.980673e-03 4.137159e-03 <br />
</pre> <br />
<br />
and indeed, we've gained another factor of 3 in sensitivity. <br />
<br />
'''Overall with this self-calibration we've improved the noise by a factor of 6.7! With a peak flux density of 0.98 Jy, the S/N increased from 115 initially to 770 after. So, well worth the trouble.'''<br />
<br />
<div class="noprint" style="float:none; border:0px solid blue;background-color:#F6CEF5;padding:2px;"><br />
If you have used the '''standard='Butler-JPL-Horizons 2012' ''' model during the calibration process, you should see an increase in peak flux density of about 3%.<br />
</div><br />
<br />
It is notable that we are still a factor of more than 4 from the apriori noise estimate of 0.3 mJy/beam. This is likely due to residual sources of non-closing (not antenna based) errors in the data like baseline errors and baseline-dependent bandpass errors. Additionally, polarization errors (which we did not calibrate at all) can contribute, as well as imperfect uv-coverage with only 8 antennas. A dynamic range of 770 is actually quite good in the submillimeter.<br />
<br />
==Apply self-calibration to Full Dataset and Split Line Data==<br />
<br />
Now apply the self-calibration derived from the continuum emission to the full unchannel-averaged data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_corrected.ms',gaintable=['self_2.pcal','self_ap.cal'],calwt=F)<br />
</source><br />
<br />
Split off the CO(3-2) spectral line data in spw=2 and the HCO+(4-3) data in spw=0 for further processing.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2.ms*')<br />
split(vis='TWHydra_corrected.ms',outputvis='TWHydra_CO3_2.ms',datacolumn='corrected',spw='2')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplus.ms*')<br />
split(vis='TWHydra_corrected.ms',outputvis='TWHydra_HCOplus.ms',datacolumn='corrected',spw='0')<br />
</source><br />
<br />
==Continuum Subtraction== <br />
<br />
Next we need to subtract the continuum emission from the spectral line data. It is best to do this in the uv-plane. The first step is to make a channel plot of the spectral data to get the line-free channel ranges for both spectral lines. Since the line emission is simple (one spectral line per spw) and there are more than enough line-free channels we do not need to be very precise just stay well away from the line and whenever possible it is best to chose line-free channel ranges on either side of the line for the best possible baseline subtraction. <br />
<br />
<figure id="CO3_2_channel.png"><br />
[[Image:CO3_2_channel.png|thumb|<caption>CO(3-2) line in channel space.</caption>]]<br />
</figure><br />
<figure id="HCOp4_3_channel.png"><br />
[[Image:HCOp4_3_channel.png|thumb|<caption>HCO+(4-3) in channel space.</caption>]]<br />
</figure><br />
<br />
'''Note''': after the split above, the original spw ids will be relabeled as 0 in each file because there is only one spectral window in each file.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_CO3_2.ms',spw='0',xaxis='channel',yaxis='amp',<br />
avgtime='1e8',avgscan=T,coloraxis='spw',plotfile='CO3_2_channel.png')<br />
</source><br />
<br />
It is a good idea to stay a little away from the very edges of the baseband which can be noisy. The channel ranges <br />
20~2000 and 2400~3800 look like good choices for CO(3-2).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_HCOplus.ms',spw='0',xaxis='channel',yaxis='amp',<br />
avgtime='1e8',avgscan=T,coloraxis='spw',plotfile='HCOp4_3_channel.png')<br />
</source><br />
<br />
The channel ranges 20~1500 and 1900~3800 look like good choices for HCO+(4-3).<br />
<br />
Next use the identified line-free channel ranges and {{uvcontsub}} to subtract the continuum model from the line emission.<br />
<br />
<source lang="python"><br />
# In CASA<br />
uvcontsub(vis='TWHydra_CO3_2.ms',fitorder=1,fitspw='0:20~2000,0:2400~3800')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
uvcontsub(vis='TWHydra_HCOplus.ms',fitorder=1,fitspw='0:20~1500,0:1900~3800')<br />
</source><br />
<br />
Note: If you do not have line-free channels on both sides of the line emission, it is safer to use '''fitorder=0''', or the fit may diverge.<br />
<br />
==Spectral Line Imaging==<br />
<br />
Now we are ready to make cubes of the line emission. The imaging parameters are similar to the continuum except for <br />
those dealing with the spectral setup: '''mode''', '''start''', '''width''', '''nchan''', '''restfreq''', and '''outframe''' parameters. When making spectral images you have three choices for the '''mode''' parameter: '''channel''', '''velocity''', and '''frequency'''. Data are taken using constant frequency channels. For spectral line analysis it's often more useful to have constant velocity channels, and this is also the best way to make images of multiple lines with the exact same channelization for later comparison. For '''mode='velocity'''', the desired '''start''' and '''width''' also need to be given in velocity units for the desired output frame. <br />
<br />
It is important to note that ALMA does not do on-line Doppler Tracking and the native frame of the data is TOPO. If you do not specify '''outframe''' the output cube will also be in TOPO, which is not very useful for spectral line work. The Doppler Shift is taken out during the regridding to the desired outframe in {{clean}} or alternatively it can be done separately by the {{cvel}} task which would need to be run before {{clean}}. <br />
<br />
<figure id="CO3_2_vel.png"><br />
[[Image:CO3_2_vel.png|thumb|<caption>CO(3-2) spectrum in LSRK velocity space.</caption>]]<br />
</figure><br />
<figure id="HCOp4_3_vel.png"><br />
[[Image:HCOp4_3_vel.png|thumb|<caption>HCO+(4-3) spectrum in LSRK velocity space.</caption>]]<br />
</figure><br />
<br />
To see what velocity parameters you want to set in clean it is useful to make a plot in {{plotms}} in the desired output frame. To make it easier to see, we set a '''plotrange''' since we know the LSRK velocity of TW Hya is about 2.88 km/s. Note these plots take a little longer because of the frame shift.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_CO3_2.ms.contsub',xaxis='velocity',yaxis='amp',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',<br />
restfreq='345.79599GHz',plotrange=[-20,23,0,0],plotfile='CO3_2_vel.png')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_HCOplus.ms.contsub',xaxis='velocity',yaxis='amp',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',<br />
restfreq='356.7342GHz',plotrange=[-20,23,0,0],plotfile='HCOp4_3_vel.png') <br />
</source><br />
<br />
From these plots it looks like imaging the cubes from about -5 to +8 km/s will encompass the line, but still provide several line-free channels on either side so the noise level can be estimated. The channel width is 122 kHz, which at <br />
345.79599 GHz is 0.106 km/s. Recall that the spectral ''resolution'' is a factor of two poorer. We will use a velocity channel width of 0.12 km/s for a little oversampling, but the spectral resolution remains 0.2 km/s.<br />
<br />
As before, it is very important that you make a clean mask. There are many ways to do this ranging from the complicated to simple. For this example we will make a single clean mask that encompasses the line emission in every channel and apply it to all channels. This is much better than no clean mask, though not quite as good as making an individual mask for each channel. For some sources, one can use the continuum mask to clean the line, however TW Hya is a bit curious in that the continuum emission is not as extended as the line emission (Hughes et al. 2008).<br />
<br />
=== CO(3-2) Imaging ===<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.*')<br />
clean(vis='TWHydra_CO3_2.ms.contsub',imagename='TWHydra_CO3_2line',<br />
imagermode='csclean',spw='',<br />
imsize=100,cell=['0.3arcsec'],<br />
mode='velocity',start='-4km/s',width='0.12km/s',nchan=118,<br />
restfreq='345.79599GHz',outframe='LSRK',<br />
weighting='briggs',robust=0.5,<br />
mask='',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=100000)<br />
</source><br />
<br />
<figure id="Viewer_55.png"><br />
[[Image:Viewer_55.png|thumb|<caption>Interactive Viewer window with CO(3-2) clean mask, before cleaning starts.</caption>]]<br />
</figure><br />
<figure id="Viewer_500.png"><br />
[[Image:Viewer_500.png|thumb|<caption>Interactive Viewer window for CO(3-2), after 500 iterations, more cleaning is needed.</caption>]]<br />
</figure><br />
<br />
It will take a little while to grid the cube, when the interactive viewer opens, use the tapedeck to cycle through the channels. You should see a progress of line emission in channels 40 to 70 or so.<br />
*Go to channel 57 (about line center)<br />
*Select the polygon tool with the left mouse button<br />
*Select the "All Channels" toggle in the green area<br />
*Draw a polygon around the channel 57 emission, double click inside to activate.<br />
*Now go to channel 60, this is the channel with the most extent to the SE, draw another polygon that encompasses this emission if necessary,double click inside to activate.<br />
*Now go to channel 55, this is the channel with the most extent to the NW, draw another polygon that encompasses this emission if necessary,double click inside to activate. <br />
*Now double check the mask by cycling through channels with real line emission to be sure that your clean box encompasses the emission, but does not extend far beyond it. Again the "erase" toggle can come in handy if things go awry or if you want to just delete a small portion of an existing mask (just draw a polygon around what you want to erase and double click inside), be sure to switch back to "add" before going on.<br />
<br />
The figure shows what the final clean box should look like. Now clean using the green circle arrow. You can watch the progress in the logger. When 100 iterations are done, the viewer will show the residual map for each channel. Cycle through the channels and see whether you are still happy with the clean box in each signal channel. The "erase button" can help you fix mistakes. If necessary adjust. It is often useful to adjust the colorscale with the "plus" symbol icon. Keep going until the residual emission looks like the surrounding noise. If it seems to be going slowly, increase the iterations to 300 for a round or two. I stopped cleaning (Red x) when the logger showed (about 900 iterations). <br />
<pre style="background-color: #fffacd;"><br />
12.9846 Jy <- cleaned in this cycle for model 0<br />
Final maximum residual = 0.157312<br />
Model 0: max, min residuals = 0.157312, -0.0871295 clean flux 279.304<br />
</pre><br />
<br />
NOTE: The residuals are still a bit high in the strongest emission channels after it is well cleaned in the weaker channels. This is an indication that the sensitivity is "dynamic range" limited. In other words even with more <br />
intrinsic sensitivity per integration (i.e. better system temperature), the dynamic range limit would remain the same unless you get more uv-coverage. The fundamental dynamic range limitations of ALMA will be considerably better with 16 antennas in Early Science and MUCH better with the full 50-antenna array.<br />
<br />
=== HCO+(4-3) Imaging ===<br />
<br />
Now image and clean the HCO+(4-3) line using what you learned above.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.*')<br />
clean(vis='TWHydra_HCOplus.ms.contsub',imagename='TWHydra_HCOplusline',<br />
imagermode='csclean',spw='',<br />
imsize=100,cell=['0.3arcsec'],<br />
mode='velocity',start='-4km/s',nchan=118,width='0.12km/s',<br />
restfreq='356.7342GHz',outframe='LSRK',<br />
weighting='briggs',robust=0.5,<br />
mask='',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=100000)<br />
</source><br />
<br />
I stopped cleaning when: <br />
<pre style="background-color: #fffacd;"><br />
4.79833 Jy <- cleaned in this cycle for model 0<br />
Final maximum residual = 0.0977348<br />
Model 0: max, min residuals = 0.0977348, -0.060484 clean flux 192.066<br />
</pre><br />
<br />
==Image Analysis==<br />
<br />
After all that hard work you now have deconvolved images of the 350 GHz continuum, the CO (3-2) line, and the HCO+ (4-3) line. CASA includes tools to help you understand the contents of these images and make basic scientific measurements. These tools are divided between graphical exploration tools, accessible via the CASA viewer, and command line analysis tasks. To access the viewer, simply type '''viewer()''' and to see the list of analysis tasks available in CASA type '''tasklist''' at the CASA prompt and look under the Analysis sub-heading.<br />
<br />
If you want to do this portion of the guide and have downloaded the (.FITS) reference images, you can import them to be CASA images using '''importfits'''. If you are re-importing the images, use the commented remove command, here, to delete the previous import first.<br />
<br />
<source lang="python"><br />
# In CASA<br />
# os.system("rm -rf TWHydra_CO3_2line.image")<br />
importfits(fitsimage="TWHydra_CO3_2line.image.fits", imagename="TWHydra_CO3_2line.image")<br />
</source><br />
<br />
where '''fitsimage''' refers to the file to imported and '''imagename''' gives the output filename. If you are proceeding directly from the imaging step, your data are already CASA images and you may proceed without any importing.<br />
<br />
You can get the basic properties of any CASA image using the '''imhead''' command. For example, type <br />
<br />
<source lang="python"><br />
# In CASA<br />
imhead("TWHydra_CO3_2line.image")<br />
</source><br />
<br />
and look at the CASA logger. You will see an image summary like the following<br />
<br />
<pre style="background-color: #fffacd;"><br />
INFO imhead ##########################################<br />
INFO imhead ##### Begin Task: imhead #####<br />
INFO imhead imhead(imagename="TWHydra_CO3_2line.image",mode="summary",hdkey="",hdvalue="",<br />
INFO imhead hdtype="",hdcomment="",verbose=False)<br />
INFO ImageAnalysis <br />
INFO ImageAnalysis Image name : TWHydra_CO3_2line.image<br />
INFO ImageAnalysis Object name : TW Hya<br />
INFO ImageAnalysis Image type : PagedImage<br />
INFO ImageAnalysis Image quantity : Intensity<br />
INFO ImageAnalysis Pixel mask(s) : None<br />
INFO ImageAnalysis Region(s) : None<br />
INFO ImageAnalysis Image units : Jy/beam<br />
INFO ImageAnalysis Restoring Beam : 1.68065 arcsec, 1.53193 arcsec, 22.3015 deg<br />
INFO ImageAnalysis <br />
INFO ImageAnalysis Direction reference : J2000<br />
INFO ImageAnalysis Spectral reference : LSRK<br />
INFO ImageAnalysis Velocity type : RADIO<br />
INFO ImageAnalysis Rest frequency : 3.45796e+11 Hz<br />
INFO ImageAnalysis Pointing center : 11:01:51.844983 -34.42.17.160885<br />
INFO ImageAnalysis Telescope : ALMA<br />
INFO ImageAnalysis Observer : Unknown<br />
INFO ImageAnalysis Date observation : 2011/04/22/00:15:42<br />
INFO ImageAnalysis Telescope position: [2.22514e+06m, -5.44031e+06m, -2.48103e+06m] (ITRF)<br />
INFO ImageAnalysis <br />
INFO ImageAnalysis Axis Coord Type Name Proj Shape Tile Coord value at pixel Coord incr Units<br />
INFO ImageAnalysis -------------------------------------------------------------------------------------------------- <br />
INFO ImageAnalysis 0 0 Direction Right Ascension SIN 100 25 11:01:51.845 50.00 -3.000000e-01 arcsec<br />
INFO ImageAnalysis 1 0 Direction Declination SIN 100 25 -34.42.17.161 50.00 3.000000e-01 arcsec<br />
INFO ImageAnalysis 2 2 Spectral Frequency 118 59 3.45801e+11 0.00 -1.38414152e+05 Hz<br />
INFO ImageAnalysis Velocity -4 0.00 1.200000e-01 km/s<br />
INFO ImageAnalysis 3 1 Stokes Stokes 1 1 I<br />
INFO imhead ##### End Task: imhead #####<br />
INFO imhead ##########################################<br />
<br />
</pre><br />
<br />
This report tells you about the target, shape, and coordinates of the image. It also notes the rest frequency and some details of the observation. '''imhead''' may be used more generally to retrieve header keywords as python variables or to manipulate the header of an image. Consult the help for details.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
You may want to pay particular attention to the third and fourth axis of the CASA image. These are <br />
usually frequency (velocity) and Stokes (polarization) in some order. An occasional source of confusion <br />
is that this order is not always the same. Often CLEAN will output images with the Stokes axis third, <br />
while IMPORTFITS usually yields images with the frequency axis third. If you encounter problems with<br />
image analysis tasks, you may want to check whether this results from conflicting axis definitions. You<br />
can adjust the order of the axes using the IMTRANS task.<br />
</pre><br />
<br />
Before proceeding, make sure that you have all three data sets as CASA images: '''TWHydra_CO3_2line.image''', '''TWHydra_HCOPlusline.image''', and '''TWHydra_contall_apcal.image'''. If you do not, then import them from the provided reference images. If you are re-importing the FITS images, run the commented remove commands before running importfits.<br />
<br />
<source lang="python"><br />
# In CASA<br />
# os.system("rm -rf TWHydra_CO3_2line.image")<br />
importfits(fitsimage="TWHydra_CO3_2line.image.fits", imagename="TWHydra_CO3_2line.image")<br />
# os.system("rm -rf TWHydra_HCOplusline.image")<br />
importfits(fitsimage="TWHydra_HCOplusline.image.fits", imagename="TWHydra_HCOplusline.image")<br />
# os.system("rm -rf TWHydra_contall_apcal.image")<br />
importfits(fitsimage="TWHydra_contall_apcal.image.fits", imagename="TWHydra_contall_apcal.image")<br />
</source><br />
<br />
In the rest of this guide we will construct ''moment maps'' showing the integrates, velocity field, and line width of the two lines. We will carry out Gaussian fits to the continuum and line maps. We will also illustrate some of the additional analysis capabilities available in CASA: subcube extraction, retrieval of data into python arrays, cube alignment, smoothing, and overlays of multiple spectral lines.<br />
<br />
===Moment Maps===<br />
<br />
The line "images" of CO(3-2) and HCO+(4-3) are, of course, cubes rather than images. Two dimensional ''moment maps'' are a standard way to present such data. These are maps showing the result of various moments (or similar calculations) carried out along the frequency axis of the cube. For example, the "moment 0" map is the sum of emission along the frequency axis at each pixel. The first moment is the intensity-weighted velocity (or frequency). The second moment is the intensity-weighted velocity (or frequency) dispersion about the mean. These and a number of other calculations (for example the maximum intensity) can be calculated via the '''immoments''' task. Consult the help or the CASA cookbook for more details.<br />
<br />
In this section, we will calculate moments for our two spectral line data cubes. To make the highest quality moment maps, we will first identify the planes of the data cube that contain emission, so that we can carry out the sum only over these channels. Doing otherwise adds noise to the moment map without adding signal and so lowers the signal-to-noise ratio of the final image. For the first and second moments we will identify an intensity threshold above which the data are statistically very likely to correspond to real astronomical emission. We will restrict the calculation to consider only data above this threshold, yielding a cleaner calculation (the second moment, in particular, is not at all robust against the inclusion of outlying noise). Finally, we will inspect the resulting moment maps with the viewer and output them to .FITS files.<br />
<br />
====Estimate the Spectral Extent====<br />
<br />
First, we want to figure out what planes appear to contain real emission. Open the CO data cube with the CASA viewer via:<br />
<br />
<source lang="python"><br />
# In CASA<br />
viewer("TWHydra_CO3_2line.image")<br />
</source><br />
<br />
This will open the CO(3-2) data cube as a raster image. Use the Animator pane to scroll through the cube, noting that the emission is mostly confined to ~40 channels near the center of the cube. There are several ways to make a more rigorous estimate. <br />
<br />
''By-Plane Inspection:'' First, you could increase the stretch of the image to identify by hand the first and last channels with visible emission. To do open the Data Display Options panel in the viewer (the wrench icon) and manually set the data range and/or scaling power cycles to highlight faint emission (note that you can also do this using the mouse and the color stretch - sun - icon). I left the scaling power cycles at 0 and set the data range to [-0.15, 0.15]. Then scroll through the cube and note the first and last channels with obvious emission. If I do this, I find emission from about plane 30 through plane 86.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:DataDisplayPanelStretch.png|The Data Display Panel used to set the color stretch, here from [-0.15, 0.15] with a linear (0) stretch. Setting the stretch to a negative value will highlight lower emission (a more logarithmic stretch). We got to this panel by clicking the wrench icon. You can also get from the dropdown menus (Data->Adjust).<br />
File:TWHydraCOChan33.png|Channel 33 of the CO(3-2) cube on this stretch. This is about the first channel to show clear emission.<br />
File:TWHydraCOChan80.png|Channel 80 of the CO(3-2) cube on this stretch. This is about the last channel to show clear emission.<br />
</gallery><br />
</center><br />
<br />
To make this more rigorous, you can work out a noise estimate before hand (we'll find it to be about 0.025 Jy/beam) and overplot a contour to indicate significant emission. You can do this by hand by using the Data Manager (folder icon) to open TWHydra_CO3_2line.image as a "contour map" and then using the Data Display Options to manipulate the contour levels. To show a 3-sigma contour with sigma=0.025 Jy/beam set the Relative Contour Levels to [3], the Base Contour Level to 0, and the Unit Contour Level to 0.025. You can display a 5-sigma contour or change the RMS analogously. Scrolling through the cube, I see 3-sigma emission from channels 33 through 80.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:DataDisplayPanelContour.png|The Data Display Panel now being used to set the contour levels. We set the contour unit to 0.025 and ask for a single contour at 3 times this value. Notice that we clicked the tab along the top of the window to select the contour map.<br />
File:TWHydraCOChan33Contour.png|Channel 33 of the CO(3-2) cube on this stretch with a 3-sigma contour overlaid.<br />
File:TWHydraCOChan80Contour.png|Channel 80 of the CO(3-2) cube on this stretch with a 3-sigma contour overlaid.<br />
</gallery><br />
</center><br />
<br />
''Look at a Spectrum:'' You can also look at a spectrum of the source. To do this, scroll to a channel with a lot of emission (I went to 57) and then use the mouse to drag out a rectangle. To do this, left click on the rectangle box in the mouse toolbar (this assigns the left mouse button to define rectangle regions). Then drag out a box around the emission using the same button. Now click the spectrum in the toolbar to open the spectral profile tool. You will see the average profile for the selected region. You can set the bottom axis to show channels. You can zoom in within the spectral profile by dragging out a rectangle. When I do this, I find significant emission from channels 40-80.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:TWHydraRectangle.png|Defining a rectangular region around the main emission from TW Hydra. First we clicked the rectangle button on the mouse toolbar, then we held that button and dragged out the purple rectangle. After defining the rectangle, you can drag it around or delete it with <ESC>.<br />
File:TWHydraSpectrum.png|The spectrum of this rectangular region viewed in the spectral profile browser. Note that the bottom axis has been set to show channels. To get this spectrum, we defined the rectangular region and then clicked the spectrum button on the toolbar.<br />
File:TWHydraSpectrumZoom.png|A zoom in on the spectrum. The line extends from channels ~40-80.<br />
</gallery><br />
</center><br />
<br />
''Look at a Declination-Frequency Projection (or an R.A.-Frequency Projection):'' This is probably the least reliable way to do this, but illustrates a neat capability of the viewer. Open the Data Display Options (click the wrench icon) and open the "display axes" and "hidden axes" tabs. Use the dropdown menus to change the display so that the x-axis shows Declination, the y-axis shows Frequency, and the z-axis shows "Right Ascension." Now you are scrolling through planes of intensity as a function of Declination and Frequency. Use the animator to move to R.A. plane ~ 50 (the center of the source) and pull the stretch up (in the wrench tool; I used [-0.15,0.15] again). Mouse over the image and look at the "Position Tracking" pane in the bottom of the image, noting the pixel extent of emission in the frequency axis of this plane. I see traces of emission from channel ~30-90.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:DataDisplayPanelAxes.png|The Data Display Panel, here used to set which axes are displayed. We have adjusted the y-axis to show frequency and the x-axis to show Declination. The z-axis is now Right Ascension, so that we will scroll through planes of Right Ascension.<br />
File:DataDisplayPanelPixels.png|The Data Display Panel, here we are setting coordinates to show "pixels" rather than world coordinates.<br />
File:TWHydraDecFreqPixels.png|A Frequency-Declination plane of the cube near the central R.A. pixel (50). The rough extent of emission may be simply read off the y-coordinate. As above, we could overplot a 3-sigma contour to add more rigor.<br />
</gallery><br />
</center><br />
<br />
<br />
You can repeat this exercise for the HCO+ (4-3) emission. Using the Spectral Profile Browser, I find that the line extends from about channel 40 through channel 75.<br />
<br />
====Make Moment 0 Maps====<br />
<br />
With an estimate of the spectral extent of emission, we are now ready to make moment 0 maps of the CO(3-2) and HCO+(4-3) lines. It is possible to do this using the 'Calculate Moments/Spectral Profile tool' in the viewer, but here we do this using the '''immmoments''' command,<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom0')<br />
immoments(imagename='TWHydra_CO3_2line.image',moments=[0],<br />
outfile='TWHydra_CO3_2line.image.mom0',<br />
chans='30~90')<br />
</source><br />
<br />
and<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom0')<br />
immoments(imagename='TWHydra_HCOplusline.image',moments=[0],<br />
outfile='TWHydra_HCOplusline.image.mom0',<br />
chans='40~75')<br />
</source><br />
<br />
immoments will sum across the channels specified by '''chans''' and produce new CASA images with the names specified by '''outfile'''. These can be inspected using the CASA viewer just like any other image. Note that unlike higher-order moments, the moment-0 map is robust to the inclusion of noisy signal-free channels (to within reason, you just decrease your signal-to-noise ratio) and indeed may be biased to miss faint emission by imposing a threshold. For that reason, we will eschew the '''includepix''' keyword as we make the moment 0 maps.<br />
<br />
Let's look at the output using the viewer. We can specify some of the display options in the call to start the viewer by using '''imview''' instead of '''viewer'''.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview( raster=[ {'file':'TWHydra_CO3_2line.image.mom0',<br />
'range':[0.0,10.],<br />
'scaling':-1},<br />
{'file':'TWHydra_HCOplusline.image.mom0',<br />
'range':[0.0,10.],<br />
'scaling':-1}], <br />
contour={'file':'TWHydra_contall_apcal.image', 'base':0, 'unit':0.0025, 'levels':[3,100]} )<br />
</source><br />
<br />
This does several things: It opens the viewer with raster images of the moment 0 maps of CO(3-2) and HCO+(4-3), sets the range of the color stretch from [0, 10] for each image and sets the scaling to be -1, which highlights faint emission compared to the normal (0) stretch. It also opens the continuum image as a contour and defines two contour levels. Once the viewer is open, you can blink between the images by going into the Animator pane, checking the white box next to "Images" to enable animation between images, and then sliding the bar back and forth. See the name of the image being shown change. You can also show two images side by side by going to the Viewer Canvas Manager (wrench+P icon) and opening the "Number of Panels" tab. Set the "Number of panels in x" to 2 and make sure that the Images box is checked in the Animator pane. You will see both images side by side.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:CanvasManagerPanels.png|The Viewer Canvas Manager, accessed via the Wrech+P icon (not to be confused with the plain old wrench). Here we have adjusted the number of x-panels from 1 to 2 so that we show the two moment maps side by side.<br />
File:TWHydraMoment0Maps.png|The moment-0 maps of CO(3-2) and HCO+(4-3) plotted side by side on the same color stretch, both with the continuum contours overlaid. To get the two images side by side, run the imview call above then set the number of panels to 2 and make sure that the Images box in the Animator Pane (here at the bottom of the window) is checked.<br />
File:DataDisplayImview.png|Data Display Panel after our imview call. Imview allowed us to set the stretch, range, and contour levels from the command line.<br />
</gallery><br />
</center><br />
<br />
====Estimate the Noise====<br />
<br />
We have already made a few offhand comparisons to the RMS noise. This quantity is often critical to know when exploring the data. Because the higher-order moments (especially the dispersion) are not at all robust to the inclusion of noise, we will calculate them only from regions of the cube that have intensity several times the RMS noise value or higher and are thus very likely to contain real astronomical emission. To proceed, we need to estimate the RMS noise for our data.<br />
<br />
The easiest way to do this is to calculate the RMS scatter of the data about zero from a part of the data that you suspect to be (mostly) free of astronomical signal. In a data cube the easiest way to do this will often be to identify signal-free planes (channels) of the cube and to simply calculate the RMS in these regions. We can do this straightforwardly using the '''imstat''' command in CASA.<br />
<br />
IMSTAT COMMAND<br />
<br />
IMSTAT OUTPUT<br />
<br />
Alternatively, you can get similar statistics on a region of an image or data cube selected manually inside the viewer. Drag out a region, for example a rectangle, using one of the mouse tools. Then <br />
<br />
IMAGES OF REGION SELECTION, OUTPUT, REGION MANAGER<br />
<br />
Suggested values for CO(3-2), HCO+(4-3), and continuum. Short discussion of dynamic range limited vs. line-free channels.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
A note on primary beam corrections and noise.<br />
</pre><br />
<br />
====Higher Order Moment Maps for CO(3-2)====<br />
<br />
For higher order moments it is very important to set a conservative flux <br />
threshold. Typically something like 6 sigma, using sigma from peak line channel, works well.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom')<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_coord')<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_dispersion_coord')<br />
immoments(imagename='TWHydra_CO3_2line.image',moments=[1,2],<br />
outfile='TWHydra_CO3_2line.image.mom',<br />
chans='40~76',includepix=[0.3,100])<br />
</source><br />
<br />
Display all three moment maps in the viewer, overlaid with continuum contours.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview( raster=[ {'file':'TWHydra_CO3_2line.image.mom0'},<br />
{'file':'TWHydra_CO3_2line.image.mom.weighted_coord'},<br />
{'file':'TWHydra_CO3_2line.image.mom.weighted_dispersion_coord'} ], <br />
contour={'file':'TWHydra_contall_apcal.image', 'base':0, 'unit':0.0025, 'levels':[3,100]} )<br />
</source><br />
<br />
To see all three raster images simultaneously, open the viewer's Panel Display Options (the "P-wrench" icon in the viewer tool bar), click "Number of panels", and change "Number of panels in x" to 3. Then select the "Blink" toggle (radio button) from the Animator panel.<br />
<br />
<figure id="TWHya_CO3_2_moments.png"><br />
[[Image:TWHya_CO3_2_moments.png|center|800px|frame|<caption>ALMA CO(3-2) moment maps, with white continuum contours at 3 and 100 sigma. From left to right: integrated intensity, intensity weighted velocity field, intensity weighted velocity dispersion are shown.</caption>]]<br />
</figure><br />
<br />
Repeat for HCO+(4-3) which has a bit narrower velocity extent than the CO(3-2), but similar rms noise.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom0')<br />
immoments(imagename='TWHydra_HCOplusline.image',moments=[0],<br />
outfile='TWHydra_HCOplusline.image.mom0',<br />
chans='43~74')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom')<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_coord')<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_dispersion_coord')<br />
immoments(imagename='TWHydra_HCOplusline.image',moments=[1,2],<br />
outfile='TWHydra_HCOplusline.image.mom',<br />
chans='43~74',includepix=[0.3,100])<br />
</source><br />
<br />
Display all three moment maps in the viewer using the same method described above for the CO(3-2) maps.<br />
<br />
<figure id="TWHya_HCOp4_3_moments.png"><br />
[[Image:TWHya_HCOp4_3_moments.png|center|800px|frame|<caption>ALMA HCO+(4-3) moment maps, with white continuum contours at 3 and 100 sigma. From left to right: integrated intensity, intensity weighted velocity field, intensity weighted velocity dispersion are shown.</caption>]]<br />
</figure><br />
<br />
=====Exporting Fits Images=====<br />
<br />
If you want to analyze the data using another software package it is easy to convert from CASA format to FITS. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image',fitsimage='TWHydra_CO3_2line.image.fits')<br />
</source><br />
<br />
Although "FITS format" is supposed to be a standard, in fact most packages expect slightly different things from a FITS image. If you are having difficulty, try setting '''velocity=T''' and/or '''dropstokes=T'''.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf TWHydra_HCOplusline.image.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image',fitsimage='TWHydra_HCOplusline.image.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom0.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image.mom0',<br />
fitsimage='TWHydra_CO3_2line.image.mom0.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_coord.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image.mom.weighted_coord',<br />
fitsimage='TWHydra_CO3_2line.image.mom.weighted_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_dispersion_coord.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image.mom.weighted_dispersion_coord',<br />
fitsimage='TWHydra_CO3_2line.image.mom.weighted_dispersion_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom0.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image.mom0',<br />
fitsimage='TWHydra_HCOplusline.image.mom0.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_coord.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image.mom.weighted_coord',<br />
fitsimage='TWHydra_HCOplusline.image.mom.weighted_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_dispersion_coord.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image.mom.weighted_dispersion_coord',<br />
fitsimage='TWHydra_HCOplusline.image.mom.weighted_dispersion_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_apcal.image.fits')<br />
exportfits(imagename='TWHydra_contall_apcal.image',fitsimage='TWHydra_contall_apcal.image.fits')<br />
</source><br />
<br />
===Display Channel Maps===<br />
<br />
Using the Viewer you can make channel map figures. Start the Viewer and then open the CO(3-2) cube as a raster image and then the continuum as a contour image. Then we use the "wrench" icon and "P wrench" icons to set up the channel images, contour levels etc. (If you need help setting up the viewer for this image, see a screen shot of the viewer setup windows, below.)<br />
<br />
<figure id="TWHya_channel_co3_2.png"><br />
[[Image:TWHya_channel_co3_2.png|center|frame|<caption>Channel maps of the CO(3-2) emission with white continuum contours at 3 and 100 sigma.</caption>]]<br />
</figure><br />
<br />
<figure id="Viewer_setup.png"><br />
[[Image:Viewer_setup.png|center|thumb|500px|<caption>The setup windows looked like this</caption>]]<br />
</figure><br />
<br />
Repeat for HCO+(4-3)<br />
<br />
<figure id="TWHya_channel_HCOp4_3.png"><br />
[[Image:TWHya_channel_HCOp4_3.png|center|thumb|800px|<caption>Channel maps of the HCO+(4-3) emission with white continuum contours at 3 and 100 sigma. The color intensity scale is the same as that used for CO(3-2).</caption>]]<br />
</figure><br />
<br />
<!--<br />
====Examine CO Contours on an HCO+ Raster====<br />
<br />
====Matched Movies====<br />
<br />
===Image Plane and Spectral Fits===<br />
<br />
====Fit a Gaussian to the Continuum====<br />
<br />
=====Fit In the Viewer=====<br />
<br />
=====Fit Using the Command Line=====<br />
<br />
====Fit a Gaussian to the CO Line====<br />
<br />
=====Fit In the Viewer=====<br />
<br />
=====Fit Using the Command Line=====<br />
<br />
===Extract a Sub-Image===<br />
<br />
===Align Image Cubes===<br />
--><br />
<br />
{{Checked 4.5.0}}</div>Sstierwahttps://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_4.5&diff=19492TWHydraBand7 Imaging 4.52016-05-18T05:59:27Z<p>Sstierwa: /* Continuum Data Amplitude Self-Calibration */</p>
<hr />
<div>[[Category:ALMA]][[Category:Imaging]][[Category:Spectral Line]]<br />
<br />
* '''This tutorial picks up where '''[[TWHydraBand7_Calibration_4.5]]''' leaves off, with fully calibrated, split science target MS. If you wish to skip the Calibration guide: obtain the calibrated data from [[TWHydraBand7#Getting_the_Data]]; extract it using <tt>tar -xzvf FILENAME</tt>; and <tt>cd</tt> into the extracted directory.'''<br />
<br />
*'''This guide is designed for CASA 4.5.2. If you are using an older version of CASA please see [[TWHydraBand7_Imaging_4.3]].<br />
<br />
* '''Details of the ALMA data are provided at [[TWHydraBand7]]'''<br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.5.2. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.5.0'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
== Prepare Continuum Data for Further Processing==<br />
<br />
In order to speed up imaging/self-calibration for the continuum data we will average channels together, and then flag the few spectral features. This method works well in the case of only a few spectral lines, while retaining enough channelization to aid in multi-frequency synthesis and being able to remove spectral features in the averaged data. When generalizing this process to other datasets, the amount of channel averaging will vary. '''Note for wide bandwidth data it is never a good idea to use the continuum estimate generated by uv-continuum subtraction as your continuum data'''. This worked OK in the past with the narrow band systems like the VLA and low dynamic range instruments like the SMA, but is not advised for ALMA wide bandwidth, high dynamic range data. <br />
<br />
<figure id="Cont_spw2.png"><br />
[[Image:Cont_spw2.png|thumb|<caption>CO(3-2) in spw=2 from the "continuum" channel averaged data.</caption>]]<br />
</figure><br />
<figure id="Cont_spw3.png"><br />
[[Image:Cont_spw3.png|thumb|<caption>Notice upswing at high channel numbers in spw=3.</caption>]]<br />
</figure><br />
<br />
One can also flag the spectral features first but in that case make a backup of the file that is analogous to TWHydra_corrected.ms as you will need it later (unflagged) for spectral line imaging. We begin by excluding ~20 channels on each edge, and averaging over 100 channel intervals:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_cont.ms*')<br />
split(vis='TWHydra_corrected.ms',outputvis='TWHydra_cont.ms',<br />
spw='0~3:21~3820',width=100,datacolumn='data')<br />
</source><br />
<br />
Now make a plot of amplitude vs. channel to see what needs to be flagged<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',spw='0~3',xaxis='channel',yaxis='amp',<br />
avgtime='1e8',avgscan=T,coloraxis='spw',iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
The CO(3-2) and HCO+(4-3) lines are obvious. The 4th spw; spw=3 also shows an upswing on the highest channels that is problematic, it was seen on the calibrators too and is likely due to a weak atmospheric feature, we will flag the worst of it.<br />
<br />
<figure id="Cont_uvplot.png"><br />
[[Image:Cont_uvplot.png|thumb|<caption>UV-plot of the continuum emission, colors show spws.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='TWHydra_cont.ms', mode='manual', <br />
spw='0:16~16, 2:21~21, 3:33~37')<br />
</source><br />
<br />
Have a look at the continuum as a function of uv-distance (in the plot to the right, the 4 spw are shown in different colors on top of each other). If the data are flat as a function of uv-distance, the source is completely unresolved. If instead you see structure (in this case decreasing amplitude with uv-distance), the source is resolved. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',spw='',xaxis='uvdist',yaxis='amp',field='',avgchannel='38',<br />
coloraxis='spw',plotfile='cont_uvplot.png')<br />
</source><br />
<br />
Notice that the spw do not have the same amplitude. Unfortunately, the red spw (highest frequency) should be higher than the green one (lowest frequency) because optically thin dust goes as nu^4, and optically thick as nu^2. This inconsistency is due to imperfect amplitude/absolute flux calibration. The self-calibration below will bring them into agreement with each other, but this is the sort of thing that results in considerable absolute flux uncertainty at submillimeter wavelengths. We are working on how to do this better.<br />
<br />
==A priori Noise Estimates==<br />
<br />
<figure id="Corrected_time.png"><br />
[[File:Corrected_time.png|thumb|<caption>Plot for estimating time.</caption>]]<br />
</figure><br />
<figure id="sensitivity_cont.png"><br />
[[File:sensitivity_cont.png|thumb|<caption>Sensitivity calculator setup with observed continuum parameters for these observations.</caption>]]<br />
</figure><br />
<br />
To estimate what the expected noise levels are, we first need to know how much time we had on source. Looking at <br />
a plot of amplitude vs time for the concatenated but pre-split data (see below) there are 9x8min scans + 6x6min scans + 3x1min + 2x2min scans for about 1.9 hours on source. There are 2 polarizations and about 1.75 GHz of total continuum bandwidth taking into account flagging.<br />
<br />
Using this information and https://almascience.nrao.edu/proposing/sensitivity-calculator, we find that the '''expected rms noise for the continuum is about 0.3 mJy/beam'''.<br />
<br />
For the spectral line data, which we will image below, with 0.12 km/s channels (needs to be entered in the field ''bandwidth per polarization''), the '''expected rms noise for the spectral lines is about 32 mJy/beam'''.<br />
<br />
==Image and Self-Calibrate the Continuum==<br />
<br />
====Create Initial Clean Image====<br />
<br />
First we will make an initial image using {{clean}}, this task will both deconvolve and clean. <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
If you are unfamiliar with the basic concepts of deconvolution and clean,<br />
pause here and review for example<br />
http://www.aoc.nrao.edu/events/synthesis/2010/lectures/wilner_synthesis10.pdf<br />
</pre><br />
<br />
In {{clean}}, we use '''mode='mfs'''' to do multifrequency synthesis, in other words grid each uv-channel independently. Since the uv-spacing is a function of frequency, this will actually achieve greater uv-coverage than if all the channels and spws had been averaged in advance. The '''imsize=100''' and '''cellsize=['0.3arcsec']''' were chosen to be appropriate for the Band and antenna configuration. At ALMA Band 7, the Full Width Half Power primary beam is about 20", so we want to make our image at least this big. We've made it a bit larger out to about the 25% power point. For the configuration used to take these data, the resolution is expected to be about 1.5" and it is a good idea to oversample the beam by setting the cell size to be a factor of 4 or 5 smaller than the beam (we have used 5 here). <br />
<br />
For doing self-calibration it is essential that only "real" signal be included in the image model, thus it is important to make a clean mask, and clean the first iteration rather conservatively (shallowly) so that you are sure that you do not have clean components in your model that do not represent real source emission. In the example below we set '''interactive=T''' so you can interactively make the clean mask and stop clean when the signal from the source starts to approach the surrounding "noise" areas in the residual map.<br />
<br />
'''NOTE:''' Real emission will not go away if you do not put a clean box on it. Conversely if you put a clean box on something that is NOT real and clean deeply you can amplify that feature. Thus, its best to be conservative and build up your clean box as you go, you can generally see fainter "real" features in the residuals.<br />
<br />
'''NOTE:''' If you start an interactive clean, and then do not make a mask, clean will stop when you tell it to go on because it has nothing to clean. There is no default mask.<br />
<br />
<figure id="Viewer_clean1.png"><br />
[[Image:Viewer_clean1.png|thumb|<caption>Interactive viewer.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall',<br />
mode='mfs', imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5, <br />
mask='',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
'''NOTE:'''{{clean}} will generate several files automatically with the '''imagename''' prepended:<br />
* <imagename>.image # the final restored image<br />
* <imagename>.flux # the effective primary beam response (e.g. for pbcor)<br />
* <imagename>.flux.pbcoverage # the primary beam coverage (ftmachine=’mosaic’ only)<br />
* <imagename>.model # the model image<br />
* <imagename>.residual # the residual image<br />
* <imagename>.psf # the synthesized (dirty) beam<br />
<br />
Once the Clean Viewer opens, click on the polygon tool with your left mouse button, and draw a polygon around the continuum emission with the left mouse button. Double click inside the region with the left mouse button when you are happy with it. It will turn from green to white when the clean mask is accepted. To continue with clean use the "Next action" buttons in the green area on the Viewer Display GUI. <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
The red X will stop clean where you are, the blue arrow will stop <br />
the interactive part of clean, but continue to clean non-interactively <br />
until reaching the number of iterations requested (niter) or the flux <br />
density threshold (whichever comes first), and the green circle arrow <br />
will clean until it reaches the "iterations" parameter on the left side <br />
of the green area. <br />
</pre><br />
<br />
'''You should chose the green circle arrow'''. It will clean 100 iterations (number under iteration in the green area on the Viewer GUI) and then show the '''residual image''' again. The middle mouse button is automatically assigned to the "plus" icon, which adjusts the colorscale. '''If you cannot easily access multiple mouse buttons, you can always assign your one mouse button the icon you want by clicking on it'''. Adjust the color scale so you can see the structure in the noise better. Also, note that the logger is telling you the amount of clean flux recovered so far, the min/max residuals, and the synthesized beam:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Model 0: max, min residuals = 0.0203454, 0.00267232 clean flux 1.30124<br />
Threshhold not reached yet.<br />
Beam used in restoration: 1.6962 by 1.54549 (arcsec) at pa 28.9043 (deg) <br />
</pre> <br />
<br />
Already with only 100 iterations, the residuals outside the clean mask are larger than that inside. So we will stop here by hitting the Red X symbol.<br />
<br />
====1st Round of Continuum Data Phase Self-calibration====<br />
<br />
Next we can use the clean model to self-calibrate the uv-data. The process of self-calibration tries to adjust the data to better match the model you give it. That is why it is important to make the model as good as you can. {{clean}} places a uv-model of the resulting image in the file <tt>TWHydra_cont.model</tt>. This model can then be used to self-calibrate the data using {{gaincal}}. We use '''gaintype='T'''' to tell it to average the polarizations before deriving solutions (which gains us a sqrt(2) in sensitivity). A critical parameter to play with is '''solint'''; we use '''solint=30s'''. From {{listobs}} the integration time of these data is about 10 seconds, so using '''solint=30s''' then gains us a sqrt(3) in sensitivity. It is often best to start with a larger '''solint''' and then work your way down to the integration time if the S/N of the data permits. For the same reasons as described in the [[TWHydraBand7_Calibration_4.5]] tutorial we want to fix up the phases before tackling amplitude by setting '''calmode='p''''.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='TWHydra_cont.ms',caltable='self_1.pcal',<br />
solint='30s',combine='',gaintype='T',<br />
refant='DV06',spw='',minblperant=4,<br />
calmode='p',minsnr=2)<br />
</source><br />
<br />
<figure id="Self_1_phase.png"><br />
[[Image:Self_1_phase.png|thumb|<caption>Phase solutions from self_1.pcal with solint=30s.</caption>]]<br />
</figure><br />
<br />
Because '''combine=' '''', we are getting independent solutions for each spw. If you are desperate for S/N, you can try combining them with combine='spw'. We have plenty of S/N in these data so we keep them separate. Look at the solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_1.pcal',xaxis='time',yaxis='phase',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,-80,80],figfile='self_1_phase.png')<br />
</source><br />
<br />
The magnitude of corrections gives you a sense of how accurate the phase transfer from the calibrators was. You are checking to see that the phases are being well tracked by the solutions, i.e. smoothly varying functions of time within a given scan. Also the solutions for each spw are lying basically on top of each other which indicates that the spw to spw phase offsets are well calibrated already. Overall, these solutions look quite good. If they didn't you could try increasing the solint and/or combining the spw into a single solution. <br />
<br />
After checking that you are happy with the solutions, apply them with {{applycal}}<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_cont.ms',field='',gaintable=['self_1.pcal'],calwt=F)<br />
</source><br />
<br />
<figure id="Viewer_pcal1.png"><br />
[[Image:Viewer_pcal1.png|thumb|<caption>Clean residuals after 100 iterations and the 1st phase only self-cal. Residuals inside mask are higher than the "noise" outside.</caption>]]<br />
</figure><br />
<br />
Next clean the source again, to save time we can start with the clean mask from the last iteration. If you make interactive adjustments to the clean mask, they will be written to the '''new''' mask TWHydra_contall_1pcal.mask, and not the old one. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_1pcal.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall_1pcal',<br />
mode='mfs',imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5, <br />
mask='TWHydra_contall.mask',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
Now after the first 100 iterations you see that the residuals inside the clean mask are higher than those outside. This is because flux that had been spread out in the map due to poorly correlated phases has been placed where it belongs on the source, thereby increasing its flux. You may also notice that your original clean mask is a little too small. If so, you can make it a bit larger, just by drawing a new polygon around the area you want to include. When you double click, it will incorporate the new mask into the current mask (if your box goes awry you can use the erase toggle [radio button] to erase and redo the mask). The new mask area need not overlap the original mask (though for this source it probably will). You might also want to use the magnifying glass to zoom in. Again, you assign mouse buttons by clicking on the icon you want. Clean another 100 iterations (for a total of 200) and stop by clicking the red X.<br />
<br />
Now open initial and 1st self-cal images to compare them using {{imview}}. This is an alternative version of the {{viewer}} that is somewhat scriptable. <br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(raster=[{'file':'TWHydra_contall.image','range':[-0.01,0.05]},<br />
{'file':'TWHydra_contall_1pcal.image','range':[-0.01,0.05]}])<br />
</source><br />
<br />
Once the Viewer Display panel opens, click on the box next in the "Images" panel and then use the tapedeck buttons in the panel to alternate between the two images. Because the range was explicitly set, they are on the same color scale. It is obvious that the self-calibrated image is better. To quantify, 1st toggle back to "normal" and then draw a region that excludes the central source with the polygon tool and then double click inside (if you stay in the "Images" view, only the statistics for the last image opened will appear on the terminal instead of both). The basic statistics of the polygon region will print to the '''terminal''':<br />
<br />
<pre style="background-color: #fffacd;"><br />
TWHydra_contall.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2357 -9.434800e-01 -2.858690e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-4.002885e-04 7.906752e-03 7.898289e-03 -2.541723e-02 2.172779e-02 <br />
<br />
TWHydra_contall_1pcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2357 6.326584e-01 1.916918e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
2.684168e-04 3.655786e-03 3.646692e-03 -1.215155e-02 1.109403e-02 <br />
</pre><br />
<br />
The self-calibrated image has more than a factor of 2 lower rms noise!<br />
<br />
====2nd Round of Continuum Data Phase Self-calibration====<br />
<br />
Now that we have a better model, we solve for solutions again. This time we will try making the solint smaller -- the integration time is about 10 seconds, so we set '''solint='int'''' to have it use the integration time.<br />
<br />
<figure id="Self_2_phase.png"><br />
[[Image:Self_2_phase.png|thumb|<caption>Phase solutions from self_2.pcal with solint='int'.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='TWHydra_cont.ms',caltable='self_2.pcal',<br />
solint='int',combine='',gaintype='T',<br />
refant='DV06',spw='',minblperant=4,<br />
calmode='p',minsnr=2)<br />
</source><br />
<br />
Now plot the new solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_2.pcal',xaxis='time',yaxis='phase',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,-80,80],figfile='self_2_phase.png')<br />
</source><br />
<br />
The phases on this shorter '''solint''' still seem to be tracking well so we will apply it and make a new image and check to see if there is improvement. <br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_cont.ms',field='',gaintable=['self_2.pcal'],calwt=F)<br />
</source><br />
<br />
<figure id="Viewer_pcal2.png"><br />
[[Image:Viewer_pcal2.png|thumb|<caption>Clean residuals after 2nd phase only self-cal and 250 iterations. The residuals inside the clean mask are lower than those outside, so its time to stop.</caption>]]<br />
</figure><br />
<br />
Now clean again, updating '''mask''' with the most recent mask file.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_2pcal.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall_2pcal',<br />
mode='mfs',imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5,usescratch=False,<br />
mask='TWHydra_contall_1pcal.mask',<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
After 200 iterations<br />
<br />
<pre style="background-color: #fffacd;"><br />
Model 0: max, min residuals = 0.00489776, -0.00464541 clean flux 1.44461<br />
</pre><br />
<br />
It looks like it could use just a little more cleaning, so set '''iterations=50 in the GUI'''.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Clean used 50 iterations to approach a threshhold of 0.0015067<br />
0.0107122 Jy <- cleaned in this cycle for model 0 (Total flux : 1.45532Jy)<br />
Final maximum residual = 0.00326382<br />
Model 0: max, min residuals = 0.00326382, -0.00321361 clean flux 1.45532<br />
</pre><br />
<br />
The small amount of flux cleaned this cycle indicates that clean is converging and it's about time to stop. Also the residuals inside the clean mask are now smaller than the residuals outside (i.e. the noise) also indicating it's time to stop by hitting the red X on the GUI.<br />
<br />
Now repeat the display, blinking, and image statistics steps described above for the 1st and 2nd phase-only self-cal iterations.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(raster=[{'file':'TWHydra_contall_1pcal.image','range':[-0.01,0.05]},<br />
{'file':'TWHydra_contall_2pcal.image','range':[-0.01,0.05]}])<br />
</source><br />
<br />
The difference is small:<br />
<pre style="background-color: #fffacd;"><br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2466 4.611597e-02 1.397287e-03 <br />
Mean Rms Std dev Minimum Maximum <br />
1.870072e-05 3.831524e-03 3.832255e-03 -1.414417e-02 1.109403e-02 <br />
<br />
TWHydra_contall_2pcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2466 1.159416e-01 3.512963e-03 <br />
Mean Rms Std dev Minimum Maximum <br />
4.701606e-05 3.811716e-03 3.812199e-03 -1.383034e-02 1.078456e-02 <br />
</pre><br />
<br />
This small improvement suggests that we have gone as far as we can with phase self-cal.<br />
<br />
===Continuum Data Amplitude Self-Calibration===<br />
<br />
Now we will apply the best phase solution table on-the-fly while solving for the amplitude self-cal solutions. Since amplitude changes more slowly and is less constrained than phase, we use a longer '''solint='inf'''', as long as '''combine=' '''' this means to do one solution per scan. <br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='TWHydra_cont.ms',caltable='self_ap.cal',<br />
solint='inf',combine='',gaintype='T',<br />
refant='DV06',spw='',minblperant=4,<br />
gaintable=['self_2.pcal'],<br />
calmode='ap',minsnr=2)<br />
</source><br />
<br />
It's useful to look at the residual phase in the amplitude calibration table, i.e. since we applied our best phase-only solution while solving for this new amplitude and phase ('''calmode='ap'''') solution, the phase should already be corrected.<br />
<br />
<figure id="Self_ap_phase.png"><br />
[[Image:Self_ap_phase.png|thumb|<caption>Residual phase solutions from self_ap.cal.</caption>]]<br />
</figure><br />
<figure id="Self_ap_amp.png"><br />
[[Image:Self_ap_amp.png|thumb|<caption>Amplitude solutions from self_ap.cal.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_ap.cal',xaxis='time',yaxis='phase',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,-1,1],figfile='self_ap_phase.png')<br />
</source><br />
<br />
The residuals are very small as expected. (If you see large residuals here, it means that the phase-only solution is suspect, and you were mostly just moving noise around.) Now look at the amplitude solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_ap.cal',xaxis='time',yaxis='amp',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,0.6,1.4],figfile='self_ap_amp.png')<br />
</source><br />
<br />
For the most part these look very good except one rather large deviation on DV06. Apply both the final phase and the amplitude calibration tables.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_cont.ms',field='',gaintable=['self_2.pcal','self_ap.cal'],calwt=F)<br />
</source><br />
<br />
Plot the corrected data as a function of both time and uv-distance. It is always a good idea to check these after an amplitude self-calbration to be sure that it worked properly. Occasionally, a few spurious bits of data will get blown up by the amplitude self-cal if it is not well-constrained. <br />
<br />
<figure id="Selfcal_time.png"><br />
[[Image:Selfcal_time.png|thumb|<caption>Post self-calibration amplitude vs. time</caption>]]<br />
</figure><br />
<figure id="Selfcal_uvdist.png"><br />
[[Image:Selfcal_uvdist.png|thumb|<caption>Post self-calibration amplitude vs. uv-distance</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',xaxis='time',yaxis='amp',<br />
avgchannel='38',ydatacolumn='corrected',coloraxis='spw',<br />
plotfile='selfcal_time.png')<br />
</source><br />
<br />
The time where we saw a large amplitude correction on DV06 looks consistent here so the large correction we saw in the solutions corrected a real issue. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',xaxis='uvdist',yaxis='amp',<br />
avgchannel='38',ydatacolumn='corrected',coloraxis='spw',<br />
plotfile='selfcal_uvdist.png')<br />
</source><br />
<br />
You will see that this plot looks much better than before. <br />
<br />
<figure id="Viewer_apcal.png"><br />
[[Image:Viewer_apcal.png|thumb|<caption>Clean residuals after final amplitude and phase self-cal.</caption>]]<br />
</figure><br />
<br />
Now make the final continuum image.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_apcal.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall_apcal',<br />
mode='mfs',imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5,usescratch=False,<br />
mask='TWHydra_contall_2pcal.mask',<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
We know we need to clean with at least 250 iterations (i.e. 100+100+50=250), so set iterations to 300 in the gui and hit the round green arrow. After this notice how much better the residual looks. Clean another 100 iterations. The "circular pattern", and 4 bright spots at each corner you see now in the residual is likely due to non-closing amplitude errors that cannot be removed with an antenna based self-calibration, so this is as good as it gets with pure self-cal. Hit the Red X to stop clean.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Clean used 100 iterations to approach a threshhold of 0.00105507<br />
0.0061808 Jy <- cleaned in this cycle for model 0<br />
Final maximum residual = 0.00242926<br />
Model 0: max, min residuals = 0.00238278, -0.00242926 clean flux 1.48201<br />
</pre><br />
<br />
Now repeat the display, blinking, and image statistics described above for the 2nd phase only and the new amplitude & phase self-cal'ed images.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(raster=[{'file':'TWHydra_contall_2pcal.image','range':[-0.01,0.05]},<br />
{'file':'TWHydra_contall_apcal.image','range':[-0.01,0.05]}])<br />
</source><br />
<br />
The amplitude and phase self cal'ed image is notably better than phase-only. Quantitatively:<br />
<pre style="background-color: #fffacd;"><br />
<br />
TWHydra_contall_2pcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 3542 2.053068e-01 6.220676e-03 <br />
Mean Rms Std dev Minimum Maximum <br />
5.796351e-05 3.955967e-03 3.956101e-03 -1.383034e-02 1.078456e-02 <br />
<br />
TWHydra_contall_apcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 3542 6.044652e-04 1.831495e-05 <br />
Mean Rms Std dev Minimum Maximum <br />
1.706565e-07 1.270183e-03 1.270362e-03 -4.980673e-03 4.137159e-03 <br />
</pre> <br />
<br />
and indeed, we've gained another factor of 3 in sensitivity. <br />
<br />
'''Overall with this self-calibration we've improved the noise by a factor of 6.7! With a peak flux density of 0.98 Jy, the S/N increased from 115 initially to 770 after. So, well worth the trouble.'''<br />
<br />
<div class="noprint" style="float:none; border:0px solid blue;background-color:#F6CEF5;padding:2px;"><br />
If you have used the '''standard='Butler-JPL-Horizons 2012' ''' model during the calibration process, you should see an increase in peak flux density of about 3%.<br />
</div><br />
<br />
It is notable that we are still a factor of more than 4 from the apriori noise estimate of 0.3 mJy/beam. This is likely due to residual sources of non-closing (not antenna based) errors in the data like baseline errors and baseline-dependent bandpass errors. Additionally, polarization errors (which we did not calibrate at all) can contribute, as well as imperfect uv-coverage with only 8 antennas. A dynamic range of 770 is actually quite good in the submillimeter.<br />
<br />
==Apply self-calibration to Full Dataset and Split Line Data==<br />
<br />
Now apply the self-calibration derived from the continuum emission to the full unchannel-averaged data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_corrected.ms',gaintable=['self_2.pcal','self_ap.cal'],calwt=F)<br />
</source><br />
<br />
Split off the CO(3-2) spectral line data in spw=2 and the HCO+(4-3) data in spw=0 for further processing.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2.ms*')<br />
split(vis='TWHydra_corrected.ms',outputvis='TWHydra_CO3_2.ms',datacolumn='corrected',spw='2')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplus.ms*')<br />
split(vis='TWHydra_corrected.ms',outputvis='TWHydra_HCOplus.ms',datacolumn='corrected',spw='0')<br />
</source><br />
<br />
==Continuum Subtraction== <br />
<br />
Next we need to subtract the continuum emission from the spectral line data. It is best to do this in the uv-plane. The first step is to make a channel plot of the spectral data to get the line-free channel ranges for both spectral lines. Since the line emission is simple (one spectral line per spw) and there are more than enough line-free channels we do not need to be very precise just stay well away from the line and whenever possible it is best to chose line-free channel ranges on either side of the line for the best possible baseline subtraction. <br />
<br />
<figure id="CO3_2_channel.png"><br />
[[Image:CO3_2_channel.png|thumb|<caption>CO(3-2) line in channel space.</caption>]]<br />
</figure><br />
<figure id="HCOp4_3_channel.png"><br />
[[Image:HCOp4_3_channel.png|thumb|<caption>HCO+(4-3) in channel space.</caption>]]<br />
</figure><br />
<br />
'''Note''': after the split above, the original spw ids will be relabeled as 0 in each file because there is only one spectral window in each file.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_CO3_2.ms',spw='0',xaxis='channel',yaxis='amp',<br />
avgtime='1e8',avgscan=T,coloraxis='spw',plotfile='CO3_2_channel.png')<br />
</source><br />
<br />
It is a good idea to stay a little away from the very edges of the baseband which can be noisy. The channel ranges <br />
20~2000 and 2400~3800 look like good choices for CO(3-2).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_HCOplus.ms',spw='0',xaxis='channel',yaxis='amp',<br />
avgtime='1e8',avgscan=T,coloraxis='spw',plotfile='HCOp4_3_channel.png')<br />
</source><br />
<br />
The channel ranges 20~1500 and 1900~3800 look like good choices for HCO+(4-3).<br />
<br />
Next use the identified line-free channel ranges and {{uvcontsub}} to subtract the continuum model from the line emission.<br />
<br />
<source lang="python"><br />
# In CASA<br />
uvcontsub(vis='TWHydra_CO3_2.ms',fitorder=1,fitspw='0:20~2000,0:2400~3800')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
uvcontsub(vis='TWHydra_HCOplus.ms',fitorder=1,fitspw='0:20~1500,0:1900~3800')<br />
</source><br />
<br />
Note: If you do not have line-free channels on both sides of the line emission, it is safer to use '''fitorder=0''', or the fit may diverge.<br />
<br />
==Spectral Line Imaging==<br />
<br />
Now we are ready to make cubes of the line emission. The imaging parameters are similar to the continuum except for <br />
those dealing with the spectral setup: '''mode''', '''start''', '''width''', '''nchan''', '''restfreq''', and '''outframe''' parameters. When making spectral images you have three choices for the '''mode''' parameter: '''channel''', '''velocity''', and '''frequency'''. Data are taken using constant frequency channels. For spectral line analysis it's often more useful to have constant velocity channels, and this is also the best way to make images of multiple lines with the exact same channelization for later comparison. For '''mode='velocity'''', the desired '''start''' and '''width''' also need to be given in velocity units for the desired output frame. <br />
<br />
It is important to note that ALMA does not do on-line Doppler Tracking and the native frame of the data is TOPO. If you do not specify '''outframe''' the output cube will also be in TOPO, which is not very useful for spectral line work. The Doppler Shift is taken out during the regridding to the desired outframe in {{clean}} or alternatively it can be done separately by the {{cvel}} task which would need to be run before {{clean}}. <br />
<br />
<figure id="CO3_2_vel.png"><br />
[[Image:CO3_2_vel.png|thumb|<caption>CO(3-2) spectrum in LSRK velocity space.</caption>]]<br />
</figure><br />
<figure id="HCOp4_3_vel.png"><br />
[[Image:HCOp4_3_vel.png|thumb|<caption>HCO+(4-3) spectrum in LSRK velocity space.</caption>]]<br />
</figure><br />
<br />
To see what velocity parameters you want to set in clean it is useful to make a plot in {{plotms}} in the desired output frame. To make it easier to see, we set a '''plotrange''' since we know the LSRK velocity of TW Hya is about 2.88 km/s. Note these plots take a little longer because of the frame shift.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_CO3_2.ms.contsub',xaxis='velocity',yaxis='amp',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',<br />
restfreq='345.79599GHz',plotrange=[-20,23,0,0],plotfile='CO3_2_vel.png')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_HCOplus.ms.contsub',xaxis='velocity',yaxis='amp',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',<br />
restfreq='356.7342GHz',plotrange=[-20,23,0,0],plotfile='HCOp4_3_vel.png') <br />
</source><br />
<br />
From these plots it looks like imaging the cubes from about -5 to +8 km/s will encompass the line, but still provide several line-free channels on either side so the noise level can be estimated. The channel width is 122 kHz, which at <br />
345.79599 GHz is 0.106 km/s. Recall that the spectral ''resolution'' is a factor of two poorer. We will use a velocity channel width of 0.12 km/s for a little oversampling, but the spectral resolution remains 0.2 km/s.<br />
<br />
As before, it is very important that you make a clean mask. There are many ways to do this ranging from the complicated to simple. For this example we will make a single clean mask that encompasses the line emission in every channel and apply it to all channels. This is much better than no clean mask, though not quite as good as making an individual mask for each channel. For some sources, one can use the continuum mask to clean the line, however TW Hya is a bit curious in that the continuum emission is not as extended as the line emission (Hughes et al. 2008).<br />
<br />
=== CO(3-2) Imaging ===<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.*')<br />
clean(vis='TWHydra_CO3_2.ms.contsub',imagename='TWHydra_CO3_2line',<br />
imagermode='csclean',spw='',<br />
imsize=100,cell=['0.3arcsec'],<br />
mode='velocity',start='-4km/s',width='0.12km/s',nchan=118,<br />
restfreq='345.79599GHz',outframe='LSRK',<br />
weighting='briggs',robust=0.5,<br />
mask='',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=100000)<br />
</source><br />
<br />
<figure id="Viewer_55.png"><br />
[[Image:Viewer_55.png|thumb|<caption>Interactive Viewer window with CO(3-2) clean mask, before cleaning starts.</caption>]]<br />
</figure><br />
<figure id="Viewer_500.png"><br />
[[Image:Viewer_500.png|thumb|<caption>Interactive Viewer window for CO(3-2), after 500 iterations, more cleaning is needed.</caption>]]<br />
</figure><br />
<br />
It will take a little while to grid the cube, when the interactive viewer opens, use the tapedeck to cycle through the channels. You should see a progress of line emission in channels 40 to 70 or so.<br />
*Go to channel 57 (about line center)<br />
*Select the polygon tool with the left mouse button<br />
*Select the "All Channels" toggle in the green area<br />
*Draw a polygon around the channel 57 emission, double click inside to activate.<br />
*Now go to channel 60, this is the channel with the most extent to the SE, draw another polygon that encompasses this emission if necessary,double click inside to activate.<br />
*Now go to channel 55, this is the channel with the most extent to the NW, draw another polygon that encompasses this emission if necessary,double click inside to activate. <br />
*Now double check the mask by cycling through channels with real line emission to be sure that your clean box encompasses the emission, but does not extend far beyond it. Again the "erase" toggle can come in handy if things go awry or if you want to just delete a small portion of an existing mask (just draw a polygon around what you want to erase and double click inside), be sure to switch back to "add" before going on.<br />
<br />
The figure shows what the final clean box should look like. Now clean using the green circle arrow. You can watch the progress in the logger. When 100 iterations are done, the viewer will show the residual map for each channel. Cycle through the channels and see whether you are still happy with the clean box in each signal channel. The "erase button" can help you fix mistakes. If necessary adjust. It is often useful to adjust the colorscale with the "plus" symbol icon. Keep going until the residual emission looks like the surrounding noise. If it seems to be going slowly, increase the iterations to 300 for a round or two. I stopped cleaning (Red x) when the logger showed (about 900 iterations). <br />
<pre style="background-color: #fffacd;"><br />
12.9846 Jy <- cleaned in this cycle for model 0<br />
Final maximum residual = 0.157312<br />
Model 0: max, min residuals = 0.157312, -0.0871295 clean flux 279.304<br />
</pre><br />
<br />
NOTE: The residuals are still a bit high in the strongest emission channels after it is well cleaned in the weaker channels. This is an indication that the sensitivity is "dynamic range" limited. In other words even with more <br />
intrinsic sensitivity per integration (i.e. better system temperature), the dynamic range limit would remain the same unless you get more uv-coverage. The fundamental dynamic range limitations of ALMA will be considerably better with 16 antennas in Early Science and MUCH better with the full 50-antenna array.<br />
<br />
=== HCO+(4-3) Imaging ===<br />
<br />
Now image and clean the HCO+(4-3) line using what you learned above.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.*')<br />
clean(vis='TWHydra_HCOplus.ms.contsub',imagename='TWHydra_HCOplusline',<br />
imagermode='csclean',spw='',<br />
imsize=100,cell=['0.3arcsec'],<br />
mode='velocity',start='-4km/s',nchan=118,width='0.12km/s',<br />
restfreq='356.7342GHz',outframe='LSRK',<br />
weighting='briggs',robust=0.5,<br />
mask='',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=100000)<br />
</source><br />
<br />
I stopped cleaning when: <br />
<pre style="background-color: #fffacd;"><br />
4.79833 Jy <- cleaned in this cycle for model 0<br />
Final maximum residual = 0.0977348<br />
Model 0: max, min residuals = 0.0977348, -0.060484 clean flux 192.066<br />
</pre><br />
<br />
==Image Analysis==<br />
<br />
After all that hard work you now have deconvolved images of the 350 GHz continuum, the CO (3-2) line, and the HCO+ (4-3) line. CASA includes tools to help you understand the contents of these images and make basic scientific measurements. These tools are divided between graphical exploration tools, accessible via the CASA viewer, and command line analysis tasks. To access the viewer, simply type '''viewer()''' and to see the list of analysis tasks available in CASA type '''tasklist''' at the CASA prompt and look under the Analysis sub-heading.<br />
<br />
If you want to do this portion of the guide and have downloaded the (.FITS) reference images, you can import them to be CASA images using '''importfits'''. If you are re-importing the images, use the commented remove command, here, to delete the previous import first.<br />
<br />
<source lang="python"><br />
# In CASA<br />
# os.system("rm -rf TWHydra_CO3_2line.image")<br />
importfits(fitsimage="TWHydra_CO3_2line.image.fits", imagename="TWHydra_CO3_2line.image")<br />
</source><br />
<br />
where '''fitsimage''' refers to the file to imported and '''imagename''' gives the output filename. If you are proceeding directly from the imaging step, your data are already CASA images and you may proceed without any importing.<br />
<br />
You can get the basic properties of any CASA image using the '''imhead''' command. For example, type <br />
<br />
<source lang="python"><br />
# In CASA<br />
imhead("TWHydra_CO3_2line.image")<br />
</source><br />
<br />
and look at the CASA logger. You will see an image summary like the following<br />
<br />
<pre style="background-color: #fffacd;"><br />
INFO imhead ##########################################<br />
INFO imhead ##### Begin Task: imhead #####<br />
INFO imhead imhead(imagename="TWHydra_CO3_2line.image",mode="summary",hdkey="",hdvalue="",<br />
INFO imhead hdtype="",hdcomment="",verbose=False)<br />
INFO ImageAnalysis <br />
INFO ImageAnalysis Image name : TWHydra_CO3_2line.image<br />
INFO ImageAnalysis Object name : TW Hya<br />
INFO ImageAnalysis Image type : PagedImage<br />
INFO ImageAnalysis Image quantity : Intensity<br />
INFO ImageAnalysis Pixel mask(s) : None<br />
INFO ImageAnalysis Region(s) : None<br />
INFO ImageAnalysis Image units : Jy/beam<br />
INFO ImageAnalysis Restoring Beam : 1.68065 arcsec, 1.53193 arcsec, 22.3015 deg<br />
INFO ImageAnalysis <br />
INFO ImageAnalysis Direction reference : J2000<br />
INFO ImageAnalysis Spectral reference : LSRK<br />
INFO ImageAnalysis Velocity type : RADIO<br />
INFO ImageAnalysis Rest frequency : 3.45796e+11 Hz<br />
INFO ImageAnalysis Pointing center : 11:01:51.844983 -34.42.17.160885<br />
INFO ImageAnalysis Telescope : ALMA<br />
INFO ImageAnalysis Observer : Unknown<br />
INFO ImageAnalysis Date observation : 2011/04/22/00:15:42<br />
INFO ImageAnalysis Telescope position: [2.22514e+06m, -5.44031e+06m, -2.48103e+06m] (ITRF)<br />
INFO ImageAnalysis <br />
INFO ImageAnalysis Axis Coord Type Name Proj Shape Tile Coord value at pixel Coord incr Units<br />
INFO ImageAnalysis -------------------------------------------------------------------------------------------------- <br />
INFO ImageAnalysis 0 0 Direction Right Ascension SIN 100 25 11:01:51.845 50.00 -3.000000e-01 arcsec<br />
INFO ImageAnalysis 1 0 Direction Declination SIN 100 25 -34.42.17.161 50.00 3.000000e-01 arcsec<br />
INFO ImageAnalysis 2 2 Spectral Frequency 118 59 3.45801e+11 0.00 -1.38414152e+05 Hz<br />
INFO ImageAnalysis Velocity -4 0.00 1.200000e-01 km/s<br />
INFO ImageAnalysis 3 1 Stokes Stokes 1 1 I<br />
INFO imhead ##### End Task: imhead #####<br />
INFO imhead ##########################################<br />
<br />
</pre><br />
<br />
This report tells you about the target, shape, and coordinates of the image. It also notes the rest frequency and some details of the observation. '''imhead''' may be used more generally to retrieve header keywords as python variables or to manipulate the header of an image. Consult the help for details.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
You may want to pay particular attention to the third and fourth axis of the CASA image. These are <br />
usually frequency (velocity) and Stokes (polarization) in some order. An occasional source of confusion <br />
is that this order is not always the same. Often CLEAN will output images with the Stokes axis third, <br />
while IMPORTFITS usually yields images with the frequency axis third. If you encounter problems with<br />
image analysis tasks, you may want to check whether this results from conflicting axis definitions. You<br />
can adjust the order of the axes using the IMTRANS task.<br />
</pre><br />
<br />
Before proceeding, make sure that you have all three data sets as CASA images: '''TWHydra_CO3_2line.image''', '''TWHydra_HCOPlusline.image''', and '''TWHydra_contall_apcal.image'''. If you do not, then import them from the provided reference images. If you are re-importing the FITS images, run the commented remove commands before running importfits.<br />
<br />
<source lang="python"><br />
# In CASA<br />
# os.system("rm -rf TWHydra_CO3_2line.image")<br />
importfits(fitsimage="TWHydra_CO3_2line.image.fits", imagename="TWHydra_CO3_2line.image")<br />
# os.system("rm -rf TWHydra_HCOplusline.image")<br />
importfits(fitsimage="TWHydra_HCOplusline.image.fits", imagename="TWHydra_HCOplusline.image")<br />
# os.system("rm -rf TWHydra_contall_apcal.image")<br />
importfits(fitsimage="TWHydra_contall_apcal.image.fits", imagename="TWHydra_contall_apcal.image")<br />
</source><br />
<br />
In the rest of this guide we will construct ''moment maps'' showing the integrates, velocity field, and line width of the two lines. We will carry out Gaussian fits to the continuum and line maps. We will also illustrate some of the additional analysis capabilities available in CASA: subcube extraction, retrieval of data into python arrays, cube alignment, smoothing, and overlays of multiple spectral lines.<br />
<br />
===Moment Maps===<br />
<br />
The line "images" of CO(3-2) and HCO+(4-3) are, of course, cubes rather than images. Two dimensional ''moment maps'' are a standard way to present such data. These are maps showing the result of various moments (or similar calculations) carried out along the frequency axis of the cube. For example, the "moment 0" map is the sum of emission along the frequency axis at each pixel. The first moment is the intensity-weighted velocity (or frequency). The second moment is the intensity-weighted velocity (or frequency) dispersion about the mean. These and a number of other calculations (for example the maximum intensity) can be calculated via the '''immoments''' task. Consult the help or the CASA cookbook for more details.<br />
<br />
In this section, we will calculate moments for our two spectral line data cubes. To make the highest quality moment maps, we will first identify the planes of the data cube that contain emission, so that we can carry out the sum only over these channels. Doing otherwise adds noise to the moment map without adding signal and so lowers the signal-to-noise ratio of the final image. For the first and second moments we will identify an intensity threshold above which the data are statistically very likely to correspond to real astronomical emission. We will restrict the calculation to consider only data above this threshold, yielding a cleaner calculation (the second moment, in particular, is not at all robust against the inclusion of outlying noise). Finally, we will inspect the resulting moment maps with the viewer and output them to .FITS files.<br />
<br />
====Estimate the Spectral Extent====<br />
<br />
First, we want to figure out what planes appear to contain real emission. Open the CO data cube with the CASA viewer via:<br />
<br />
<source lang="python"><br />
# In CASA<br />
viewer("TWHydra_CO3_2line.image")<br />
</source><br />
<br />
This will open the CO(3-2) data cube as a raster image. Use the Animator pane to scroll through the cube, noting that the emission is mostly confined to ~40 channels near the center of the cube. There are several ways to make a more rigorous estimate. <br />
<br />
''By-Plane Inspection:'' First, you could increase the stretch of the image to identify by hand the first and last channels with visible emission. To do open the Data Display Options panel in the viewer (the wrench icon) and manually set the data range and/or scaling power cycles to highlight faint emission (note that you can also do this using the mouse and the color stretch - sun - icon). I left the scaling power cycles at 0 and set the data range to [-0.15, 0.15]. Then scroll through the cube and note the first and last channels with obvious emission. If I do this, I find emission from about plane 30 through plane 86.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:DataDisplayPanelStretch.png|The Data Display Panel used to set the color stretch, here from [-0.15, 0.15] with a linear (0) stretch. Setting the stretch to a negative value will highlight lower emission (a more logarithmic stretch). We got to this panel by clicking the wrench icon. You can also get from the dropdown menus (Data->Adjust).<br />
File:TWHydraCOChan33.png|Channel 33 of the CO(3-2) cube on this stretch. This is about the first channel to show clear emission.<br />
File:TWHydraCOChan80.png|Channel 80 of the CO(3-2) cube on this stretch. This is about the last channel to show clear emission.<br />
</gallery><br />
</center><br />
<br />
To make this more rigorous, you can work out a noise estimate before hand (we'll find it to be about 0.025 Jy/beam) and overplot a contour to indicate significant emission. You can do this by hand by using the Data Manager (folder icon) to open TWHydra_CO3_2line.image as a "contour map" and then using the Data Display Options to manipulate the contour levels. To show a 3-sigma contour with sigma=0.025 Jy/beam set the Relative Contour Levels to [3], the Base Contour Level to 0, and the Unit Contour Level to 0.025. You can display a 5-sigma contour or change the RMS analogously. Scrolling through the cube, I see 3-sigma emission from channels 33 through 80.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:DataDisplayPanelContour.png|The Data Display Panel now being used to set the contour levels. We set the contour unit to 0.025 and ask for a single contour at 3 times this value. Notice that we clicked the tab along the top of the window to select the contour map.<br />
File:TWHydraCOChan33Contour.png|Channel 33 of the CO(3-2) cube on this stretch with a 3-sigma contour overlaid.<br />
File:TWHydraCOChan80Contour.png|Channel 80 of the CO(3-2) cube on this stretch with a 3-sigma contour overlaid.<br />
</gallery><br />
</center><br />
<br />
''Look at a Spectrum:'' You can also look at a spectrum of the source. To do this, scroll to a channel with a lot of emission (I went to 57) and then use the mouse to drag out a rectangle. To do this, left click on the rectangle box in the mouse toolbar (this assigns the left mouse button to define rectangle regions). Then drag out a box around the emission using the same button. Now click the spectrum in the toolbar to open the spectral profile tool. You will see the average profile for the selected region. You can set the bottom axis to show channels. You can zoom in within the spectral profile by dragging out a rectangle. When I do this, I find significant emission from channels 40-80.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:TWHydraRectangle.png|Defining a rectangular region around the main emission from TW Hydra. First we clicked the rectangle button on the mouse toolbar, then we held that button and dragged out the purple rectangle. After defining the rectangle, you can drag it around or delete it with <ESC>.<br />
File:TWHydraSpectrum.png|The spectrum of this rectangular region viewed in the spectral profile browser. Note that the bottom axis has been set to show channels. To get this spectrum, we defined the rectangular region and then clicked the spectrum button on the toolbar.<br />
File:TWHydraSpectrumZoom.png|A zoom in on the spectrum. The line extends from channels ~40-80.<br />
</gallery><br />
</center><br />
<br />
''Look at a Declination-Frequency Projection (or an R.A.-Frequency Projection):'' This is probably the least reliable way to do this, but illustrates a neat capability of the viewer. Open the Data Display Options (click the wrench icon) and open the "display axes" and "hidden axes" tabs. Use the dropdown menus to change the display so that the x-axis shows Declination, the y-axis shows Frequency, and the z-axis shows "Right Ascension." Now you are scrolling through planes of intensity as a function of Declination and Frequency. Use the animator to move to R.A. plane ~ 50 (the center of the source) and pull the stretch up (in the wrench tool; I used [-0.15,0.15] again). Mouse over the image and look at the "Position Tracking" pane in the bottom of the image, noting the pixel extent of emission in the frequency axis of this plane. I see traces of emission from channel ~30-90.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:DataDisplayPanelAxes.png|The Data Display Panel, here used to set which axes are displayed. We have adjusted the y-axis to show frequency and the x-axis to show Declination. The z-axis is now Right Ascension, so that we will scroll through planes of Right Ascension.<br />
File:DataDisplayPanelPixels.png|The Data Display Panel, here we are setting coordinates to show "pixels" rather than world coordinates.<br />
File:TWHydraDecFreqPixels.png|A Frequency-Declination plane of the cube near the central R.A. pixel (50). The rough extent of emission may be simply read off the y-coordinate. As above, we could overplot a 3-sigma contour to add more rigor.<br />
</gallery><br />
</center><br />
<br />
<br />
You can repeat this exercise for the HCO+ (4-3) emission. Using the Spectral Profile Browser, I find that the line extends from about channel 40 through channel 75.<br />
<br />
====Make Moment 0 Maps====<br />
<br />
With an estimate of the spectral extent of emission, we are now ready to make moment 0 maps of the CO(3-2) and HCO+(4-3) lines. We do this using the '''immmoments''' command,<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom0')<br />
immoments(imagename='TWHydra_CO3_2line.image',moments=[0],<br />
outfile='TWHydra_CO3_2line.image.mom0',<br />
chans='30~90')<br />
</source><br />
<br />
and<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom0')<br />
immoments(imagename='TWHydra_HCOplusline.image',moments=[0],<br />
outfile='TWHydra_HCOplusline.image.mom0',<br />
chans='40~75')<br />
</source><br />
<br />
immoments will sum across the channels specified by '''chans''' and produce new CASA images with the names specified by '''outfile'''. These can be inspected using the CASA viewer just like any other image. Note that unlike higher-order moments, the moment-0 map is robust to the inclusion of noisy signal-free channels (to within reason, you just decrease your signal-to-noise ratio) and indeed may be biased to miss faint emission by imposing a threshold. For that reason, we will eschew the '''includepix''' keyword as we make the moment 0 maps.<br />
<br />
Let's look at the output using the viewer. We can specify some of the display options in the call to start the viewer by using '''imview''' instead of '''viewer'''.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview( raster=[ {'file':'TWHydra_CO3_2line.image.mom0',<br />
'range':[0.0,10.],<br />
'scaling':-1},<br />
{'file':'TWHydra_HCOplusline.image.mom0',<br />
'range':[0.0,10.],<br />
'scaling':-1}], <br />
contour={'file':'TWHydra_contall_apcal.image', 'base':0, 'unit':0.0025, 'levels':[3,100]} )<br />
</source><br />
<br />
This does several things: It opens the viewer with raster images of the moment 0 maps of CO(3-2) and HCO+(4-3), sets the range of the color stretch from [0, 10] for each image and sets the scaling to be -1, which highlights faint emission compared to the normal (0) stretch. It also opens the continuum image as a contour and defines two contour levels. Once the viewer is open, you can blink between the images by going into the Animator pane, checking the white box next to "Images" to enable animation between images, and then sliding the bar back and forth. See the name of the image being shown change. You can also show two images side by side by going to the Viewer Canvas Manager (wrench+P icon) and opening the "Number of Panels" tab. Set the "Number of panels in x" to 2 and make sure that the Images box is checked in the Animator pane. You will see both images side by side.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:CanvasManagerPanels.png|The Viewer Canvas Manager, accessed via the Wrech+P icon (not to be confused with the plain old wrench). Here we have adjusted the number of x-panels from 1 to 2 so that we show the two moment maps side by side.<br />
File:TWHydraMoment0Maps.png|The moment-0 maps of CO(3-2) and HCO+(4-3) plotted side by side on the same color stretch, both with the continuum contours overlaid. To get the two images side by side, run the imview call above then set the number of panels to 2 and make sure that the Images box in the Animator Pane (here at the bottom of the window) is checked.<br />
File:DataDisplayImview.png|Data Display Panel after our imview call. Imview allowed us to set the stretch, range, and contour levels from the command line.<br />
</gallery><br />
</center><br />
<br />
====Estimate the Noise====<br />
<br />
We have already made a few offhand comparisons to the RMS noise. This quantity is often critical to know when exploring the data. Because the higher-order moments (especially the dispersion) are not at all robust to the inclusion of noise, we will calculate them only from regions of the cube that have intensity several times the RMS noise value or higher and are thus very likely to contain real astronomical emission. To proceed, we need to estimate the RMS noise for our data.<br />
<br />
The easiest way to do this is to calculate the RMS scatter of the data about zero from a part of the data that you suspect to be (mostly) free of astronomical signal. In a data cube the easiest way to do this will often be to identify signal-free planes (channels) of the cube and to simply calculate the RMS in these regions. We can do this straightforwardly using the '''imstat''' command in CASA.<br />
<br />
IMSTAT COMMAND<br />
<br />
IMSTAT OUTPUT<br />
<br />
Alternatively, you can get similar statistics on a region of an image or data cube selected manually inside the viewer. Drag out a region, for example a rectangle, using one of the mouse tools. Then <br />
<br />
IMAGES OF REGION SELECTION, OUTPUT, REGION MANAGER<br />
<br />
Suggested values for CO(3-2), HCO+(4-3), and continuum. Short discussion of dynamic range limited vs. line-free channels.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
A note on primary beam corrections and noise.<br />
</pre><br />
<br />
====Higher Order Moment Maps for CO(3-2)====<br />
<br />
For higher order moments it is very important to set a conservative flux <br />
threshold. Typically something like 6 sigma, using sigma from peak line channel, works well.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom')<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_coord')<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_dispersion_coord')<br />
immoments(imagename='TWHydra_CO3_2line.image',moments=[1,2],<br />
outfile='TWHydra_CO3_2line.image.mom',<br />
chans='40~76',includepix=[0.3,100])<br />
</source><br />
<br />
Display all three moment maps in the viewer, overlaid with continuum contours.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview( raster=[ {'file':'TWHydra_CO3_2line.image.mom0'},<br />
{'file':'TWHydra_CO3_2line.image.mom.weighted_coord'},<br />
{'file':'TWHydra_CO3_2line.image.mom.weighted_dispersion_coord'} ], <br />
contour={'file':'TWHydra_contall_apcal.image', 'base':0, 'unit':0.0025, 'levels':[3,100]} )<br />
</source><br />
<br />
To see all three raster images simultaneously, open the viewer's Panel Display Options (the "P-wrench" icon in the viewer tool bar), click "Number of panels", and change "Number of panels in x" to 3. Then select the "Blink" toggle (radio button) from the Animator panel.<br />
<br />
<figure id="TWHya_CO3_2_moments.png"><br />
[[Image:TWHya_CO3_2_moments.png|center|800px|frame|<caption>ALMA CO(3-2) moment maps, with white continuum contours at 3 and 100 sigma. From left to right: integrated intensity, intensity weighted velocity field, intensity weighted velocity dispersion are shown.</caption>]]<br />
</figure><br />
<br />
Repeat for HCO+(4-3) which has a bit narrower velocity extent than the CO(3-2), but similar rms noise.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom0')<br />
immoments(imagename='TWHydra_HCOplusline.image',moments=[0],<br />
outfile='TWHydra_HCOplusline.image.mom0',<br />
chans='43~74')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom')<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_coord')<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_dispersion_coord')<br />
immoments(imagename='TWHydra_HCOplusline.image',moments=[1,2],<br />
outfile='TWHydra_HCOplusline.image.mom',<br />
chans='43~74',includepix=[0.3,100])<br />
</source><br />
<br />
Display all three moment maps in the viewer using the same method described above for the CO(3-2) maps.<br />
<br />
<figure id="TWHya_HCOp4_3_moments.png"><br />
[[Image:TWHya_HCOp4_3_moments.png|center|800px|frame|<caption>ALMA HCO+(4-3) moment maps, with white continuum contours at 3 and 100 sigma. From left to right: integrated intensity, intensity weighted velocity field, intensity weighted velocity dispersion are shown.</caption>]]<br />
</figure><br />
<br />
=====Exporting Fits Images=====<br />
<br />
If you want to analyze the data using another software package it is easy to convert from CASA format to FITS. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image',fitsimage='TWHydra_CO3_2line.image.fits')<br />
</source><br />
<br />
Although "FITS format" is supposed to be a standard, in fact most packages expect slightly different things from a FITS image. If you are having difficulty, try setting '''velocity=T''' and/or '''dropstokes=T'''.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf TWHydra_HCOplusline.image.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image',fitsimage='TWHydra_HCOplusline.image.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom0.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image.mom0',<br />
fitsimage='TWHydra_CO3_2line.image.mom0.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_coord.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image.mom.weighted_coord',<br />
fitsimage='TWHydra_CO3_2line.image.mom.weighted_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_dispersion_coord.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image.mom.weighted_dispersion_coord',<br />
fitsimage='TWHydra_CO3_2line.image.mom.weighted_dispersion_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom0.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image.mom0',<br />
fitsimage='TWHydra_HCOplusline.image.mom0.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_coord.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image.mom.weighted_coord',<br />
fitsimage='TWHydra_HCOplusline.image.mom.weighted_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_dispersion_coord.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image.mom.weighted_dispersion_coord',<br />
fitsimage='TWHydra_HCOplusline.image.mom.weighted_dispersion_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_apcal.image.fits')<br />
exportfits(imagename='TWHydra_contall_apcal.image',fitsimage='TWHydra_contall_apcal.image.fits')<br />
</source><br />
<br />
===Display Channel Maps===<br />
<br />
Using the Viewer you can make channel map figures. Start the Viewer and then open the CO(3-2) cube as a raster image and then the continuum as a contour image. Then we use the "wrench" icon and "P wrench" icons to set up the channel images, contour levels etc. (If you need help setting up the viewer for this image, see a screen shot of the viewer setup windows, below.)<br />
<br />
<figure id="TWHya_channel_co3_2.png"><br />
[[Image:TWHya_channel_co3_2.png|center|frame|<caption>Channel maps of the CO(3-2) emission with white continuum contours at 3 and 100 sigma.</caption>]]<br />
</figure><br />
<br />
<figure id="Viewer_setup.png"><br />
[[Image:Viewer_setup.png|center|thumb|500px|<caption>The setup windows looked like this</caption>]]<br />
</figure><br />
<br />
Repeat for HCO+(4-3)<br />
<br />
<figure id="TWHya_channel_HCOp4_3.png"><br />
[[Image:TWHya_channel_HCOp4_3.png|center|thumb|800px|<caption>Channel maps of the HCO+(4-3) emission with white continuum contours at 3 and 100 sigma. The color intensity scale is the same as that used for CO(3-2).</caption>]]<br />
</figure><br />
<br />
<!--<br />
====Examine CO Contours on an HCO+ Raster====<br />
<br />
====Matched Movies====<br />
<br />
===Image Plane and Spectral Fits===<br />
<br />
====Fit a Gaussian to the Continuum====<br />
<br />
=====Fit In the Viewer=====<br />
<br />
=====Fit Using the Command Line=====<br />
<br />
====Fit a Gaussian to the CO Line====<br />
<br />
=====Fit In the Viewer=====<br />
<br />
=====Fit Using the Command Line=====<br />
<br />
===Extract a Sub-Image===<br />
<br />
===Align Image Cubes===<br />
--><br />
<br />
{{Checked 4.5.0}}</div>Sstierwahttps://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_4.5&diff=19491TWHydraBand7 Imaging 4.52016-05-18T05:51:50Z<p>Sstierwa: /* Prepare Continuum Data for Further Processing */</p>
<hr />
<div>[[Category:ALMA]][[Category:Imaging]][[Category:Spectral Line]]<br />
<br />
* '''This tutorial picks up where '''[[TWHydraBand7_Calibration_4.5]]''' leaves off, with fully calibrated, split science target MS. If you wish to skip the Calibration guide: obtain the calibrated data from [[TWHydraBand7#Getting_the_Data]]; extract it using <tt>tar -xzvf FILENAME</tt>; and <tt>cd</tt> into the extracted directory.'''<br />
<br />
*'''This guide is designed for CASA 4.5.2. If you are using an older version of CASA please see [[TWHydraBand7_Imaging_4.3]].<br />
<br />
* '''Details of the ALMA data are provided at [[TWHydraBand7]]'''<br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.5.2. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.5.0'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
== Prepare Continuum Data for Further Processing==<br />
<br />
In order to speed up imaging/self-calibration for the continuum data we will average channels together, and then flag the few spectral features. This method works well in the case of only a few spectral lines, while retaining enough channelization to aid in multi-frequency synthesis and being able to remove spectral features in the averaged data. When generalizing this process to other datasets, the amount of channel averaging will vary. '''Note for wide bandwidth data it is never a good idea to use the continuum estimate generated by uv-continuum subtraction as your continuum data'''. This worked OK in the past with the narrow band systems like the VLA and low dynamic range instruments like the SMA, but is not advised for ALMA wide bandwidth, high dynamic range data. <br />
<br />
<figure id="Cont_spw2.png"><br />
[[Image:Cont_spw2.png|thumb|<caption>CO(3-2) in spw=2 from the "continuum" channel averaged data.</caption>]]<br />
</figure><br />
<figure id="Cont_spw3.png"><br />
[[Image:Cont_spw3.png|thumb|<caption>Notice upswing at high channel numbers in spw=3.</caption>]]<br />
</figure><br />
<br />
One can also flag the spectral features first but in that case make a backup of the file that is analogous to TWHydra_corrected.ms as you will need it later (unflagged) for spectral line imaging. We begin by excluding ~20 channels on each edge, and averaging over 100 channel intervals:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_cont.ms*')<br />
split(vis='TWHydra_corrected.ms',outputvis='TWHydra_cont.ms',<br />
spw='0~3:21~3820',width=100,datacolumn='data')<br />
</source><br />
<br />
Now make a plot of amplitude vs. channel to see what needs to be flagged<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',spw='0~3',xaxis='channel',yaxis='amp',<br />
avgtime='1e8',avgscan=T,coloraxis='spw',iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
The CO(3-2) and HCO+(4-3) lines are obvious. The 4th spw; spw=3 also shows an upswing on the highest channels that is problematic, it was seen on the calibrators too and is likely due to a weak atmospheric feature, we will flag the worst of it.<br />
<br />
<figure id="Cont_uvplot.png"><br />
[[Image:Cont_uvplot.png|thumb|<caption>UV-plot of the continuum emission, colors show spws.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='TWHydra_cont.ms', mode='manual', <br />
spw='0:16~16, 2:21~21, 3:33~37')<br />
</source><br />
<br />
Have a look at the continuum as a function of uv-distance (in the plot to the right, the 4 spw are shown in different colors on top of each other). If the data are flat as a function of uv-distance, the source is completely unresolved. If instead you see structure (in this case decreasing amplitude with uv-distance), the source is resolved. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',spw='',xaxis='uvdist',yaxis='amp',field='',avgchannel='38',<br />
coloraxis='spw',plotfile='cont_uvplot.png')<br />
</source><br />
<br />
Notice that the spw do not have the same amplitude. Unfortunately, the red spw (highest frequency) should be higher than the green one (lowest frequency) because optically thin dust goes as nu^4, and optically thick as nu^2. This inconsistency is due to imperfect amplitude/absolute flux calibration. The self-calibration below will bring them into agreement with each other, but this is the sort of thing that results in considerable absolute flux uncertainty at submillimeter wavelengths. We are working on how to do this better.<br />
<br />
==A priori Noise Estimates==<br />
<br />
<figure id="Corrected_time.png"><br />
[[File:Corrected_time.png|thumb|<caption>Plot for estimating time.</caption>]]<br />
</figure><br />
<figure id="sensitivity_cont.png"><br />
[[File:sensitivity_cont.png|thumb|<caption>Sensitivity calculator setup with observed continuum parameters for these observations.</caption>]]<br />
</figure><br />
<br />
To estimate what the expected noise levels are, we first need to know how much time we had on source. Looking at <br />
a plot of amplitude vs time for the concatenated but pre-split data (see below) there are 9x8min scans + 6x6min scans + 3x1min + 2x2min scans for about 1.9 hours on source. There are 2 polarizations and about 1.75 GHz of total continuum bandwidth taking into account flagging.<br />
<br />
Using this information and https://almascience.nrao.edu/proposing/sensitivity-calculator, we find that the '''expected rms noise for the continuum is about 0.3 mJy/beam'''.<br />
<br />
For the spectral line data, which we will image below, with 0.12 km/s channels (needs to be entered in the field ''bandwidth per polarization''), the '''expected rms noise for the spectral lines is about 32 mJy/beam'''.<br />
<br />
==Image and Self-Calibrate the Continuum==<br />
<br />
====Create Initial Clean Image====<br />
<br />
First we will make an initial image using {{clean}}, this task will both deconvolve and clean. <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
If you are unfamiliar with the basic concepts of deconvolution and clean,<br />
pause here and review for example<br />
http://www.aoc.nrao.edu/events/synthesis/2010/lectures/wilner_synthesis10.pdf<br />
</pre><br />
<br />
In {{clean}}, we use '''mode='mfs'''' to do multifrequency synthesis, in other words grid each uv-channel independently. Since the uv-spacing is a function of frequency, this will actually achieve greater uv-coverage than if all the channels and spws had been averaged in advance. The '''imsize=100''' and '''cellsize=['0.3arcsec']''' were chosen to be appropriate for the Band and antenna configuration. At ALMA Band 7, the Full Width Half Power primary beam is about 20", so we want to make our image at least this big. We've made it a bit larger out to about the 25% power point. For the configuration used to take these data, the resolution is expected to be about 1.5" and it is a good idea to oversample the beam by setting the cell size to be a factor of 4 or 5 smaller than the beam (we have used 5 here). <br />
<br />
For doing self-calibration it is essential that only "real" signal be included in the image model, thus it is important to make a clean mask, and clean the first iteration rather conservatively (shallowly) so that you are sure that you do not have clean components in your model that do not represent real source emission. In the example below we set '''interactive=T''' so you can interactively make the clean mask and stop clean when the signal from the source starts to approach the surrounding "noise" areas in the residual map.<br />
<br />
'''NOTE:''' Real emission will not go away if you do not put a clean box on it. Conversely if you put a clean box on something that is NOT real and clean deeply you can amplify that feature. Thus, its best to be conservative and build up your clean box as you go, you can generally see fainter "real" features in the residuals.<br />
<br />
'''NOTE:''' If you start an interactive clean, and then do not make a mask, clean will stop when you tell it to go on because it has nothing to clean. There is no default mask.<br />
<br />
<figure id="Viewer_clean1.png"><br />
[[Image:Viewer_clean1.png|thumb|<caption>Interactive viewer.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall',<br />
mode='mfs', imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5, <br />
mask='',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
'''NOTE:'''{{clean}} will generate several files automatically with the '''imagename''' prepended:<br />
* <imagename>.image # the final restored image<br />
* <imagename>.flux # the effective primary beam response (e.g. for pbcor)<br />
* <imagename>.flux.pbcoverage # the primary beam coverage (ftmachine=’mosaic’ only)<br />
* <imagename>.model # the model image<br />
* <imagename>.residual # the residual image<br />
* <imagename>.psf # the synthesized (dirty) beam<br />
<br />
Once the Clean Viewer opens, click on the polygon tool with your left mouse button, and draw a polygon around the continuum emission with the left mouse button. Double click inside the region with the left mouse button when you are happy with it. It will turn from green to white when the clean mask is accepted. To continue with clean use the "Next action" buttons in the green area on the Viewer Display GUI. <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
The red X will stop clean where you are, the blue arrow will stop <br />
the interactive part of clean, but continue to clean non-interactively <br />
until reaching the number of iterations requested (niter) or the flux <br />
density threshold (whichever comes first), and the green circle arrow <br />
will clean until it reaches the "iterations" parameter on the left side <br />
of the green area. <br />
</pre><br />
<br />
'''You should chose the green circle arrow'''. It will clean 100 iterations (number under iteration in the green area on the Viewer GUI) and then show the '''residual image''' again. The middle mouse button is automatically assigned to the "plus" icon, which adjusts the colorscale. '''If you cannot easily access multiple mouse buttons, you can always assign your one mouse button the icon you want by clicking on it'''. Adjust the color scale so you can see the structure in the noise better. Also, note that the logger is telling you the amount of clean flux recovered so far, the min/max residuals, and the synthesized beam:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Model 0: max, min residuals = 0.0203454, 0.00267232 clean flux 1.30124<br />
Threshhold not reached yet.<br />
Beam used in restoration: 1.6962 by 1.54549 (arcsec) at pa 28.9043 (deg) <br />
</pre> <br />
<br />
Already with only 100 iterations, the residuals outside the clean mask are larger than that inside. So we will stop here by hitting the Red X symbol.<br />
<br />
====1st Round of Continuum Data Phase Self-calibration====<br />
<br />
Next we can use the clean model to self-calibrate the uv-data. The process of self-calibration tries to adjust the data to better match the model you give it. That is why it is important to make the model as good as you can. {{clean}} places a uv-model of the resulting image in the file <tt>TWHydra_cont.model</tt>. This model can then be used to self-calibrate the data using {{gaincal}}. We use '''gaintype='T'''' to tell it to average the polarizations before deriving solutions (which gains us a sqrt(2) in sensitivity). A critical parameter to play with is '''solint'''; we use '''solint=30s'''. From {{listobs}} the integration time of these data is about 10 seconds, so using '''solint=30s''' then gains us a sqrt(3) in sensitivity. It is often best to start with a larger '''solint''' and then work your way down to the integration time if the S/N of the data permits. For the same reasons as described in the [[TWHydraBand7_Calibration_4.5]] tutorial we want to fix up the phases before tackling amplitude by setting '''calmode='p''''.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='TWHydra_cont.ms',caltable='self_1.pcal',<br />
solint='30s',combine='',gaintype='T',<br />
refant='DV06',spw='',minblperant=4,<br />
calmode='p',minsnr=2)<br />
</source><br />
<br />
<figure id="Self_1_phase.png"><br />
[[Image:Self_1_phase.png|thumb|<caption>Phase solutions from self_1.pcal with solint=30s.</caption>]]<br />
</figure><br />
<br />
Because '''combine=' '''', we are getting independent solutions for each spw. If you are desperate for S/N, you can try combining them with combine='spw'. We have plenty of S/N in these data so we keep them separate. Look at the solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_1.pcal',xaxis='time',yaxis='phase',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,-80,80],figfile='self_1_phase.png')<br />
</source><br />
<br />
The magnitude of corrections gives you a sense of how accurate the phase transfer from the calibrators was. You are checking to see that the phases are being well tracked by the solutions, i.e. smoothly varying functions of time within a given scan. Also the solutions for each spw are lying basically on top of each other which indicates that the spw to spw phase offsets are well calibrated already. Overall, these solutions look quite good. If they didn't you could try increasing the solint and/or combining the spw into a single solution. <br />
<br />
After checking that you are happy with the solutions, apply them with {{applycal}}<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_cont.ms',field='',gaintable=['self_1.pcal'],calwt=F)<br />
</source><br />
<br />
<figure id="Viewer_pcal1.png"><br />
[[Image:Viewer_pcal1.png|thumb|<caption>Clean residuals after 100 iterations and the 1st phase only self-cal. Residuals inside mask are higher than the "noise" outside.</caption>]]<br />
</figure><br />
<br />
Next clean the source again, to save time we can start with the clean mask from the last iteration. If you make interactive adjustments to the clean mask, they will be written to the '''new''' mask TWHydra_contall_1pcal.mask, and not the old one. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_1pcal.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall_1pcal',<br />
mode='mfs',imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5, <br />
mask='TWHydra_contall.mask',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
Now after the first 100 iterations you see that the residuals inside the clean mask are higher than those outside. This is because flux that had been spread out in the map due to poorly correlated phases has been placed where it belongs on the source, thereby increasing its flux. You may also notice that your original clean mask is a little too small. If so, you can make it a bit larger, just by drawing a new polygon around the area you want to include. When you double click, it will incorporate the new mask into the current mask (if your box goes awry you can use the erase toggle [radio button] to erase and redo the mask). The new mask area need not overlap the original mask (though for this source it probably will). You might also want to use the magnifying glass to zoom in. Again, you assign mouse buttons by clicking on the icon you want. Clean another 100 iterations (for a total of 200) and stop by clicking the red X.<br />
<br />
Now open initial and 1st self-cal images to compare them using {{imview}}. This is an alternative version of the {{viewer}} that is somewhat scriptable. <br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(raster=[{'file':'TWHydra_contall.image','range':[-0.01,0.05]},<br />
{'file':'TWHydra_contall_1pcal.image','range':[-0.01,0.05]}])<br />
</source><br />
<br />
Once the Viewer Display panel opens, click on the box next in the "Images" panel and then use the tapedeck buttons in the panel to alternate between the two images. Because the range was explicitly set, they are on the same color scale. It is obvious that the self-calibrated image is better. To quantify, 1st toggle back to "normal" and then draw a region that excludes the central source with the polygon tool and then double click inside (if you stay in the "Images" view, only the statistics for the last image opened will appear on the terminal instead of both). The basic statistics of the polygon region will print to the '''terminal''':<br />
<br />
<pre style="background-color: #fffacd;"><br />
TWHydra_contall.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2357 -9.434800e-01 -2.858690e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-4.002885e-04 7.906752e-03 7.898289e-03 -2.541723e-02 2.172779e-02 <br />
<br />
TWHydra_contall_1pcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2357 6.326584e-01 1.916918e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
2.684168e-04 3.655786e-03 3.646692e-03 -1.215155e-02 1.109403e-02 <br />
</pre><br />
<br />
The self-calibrated image has more than a factor of 2 lower rms noise!<br />
<br />
====2nd Round of Continuum Data Phase Self-calibration====<br />
<br />
Now that we have a better model, we solve for solutions again. This time we will try making the solint smaller -- the integration time is about 10 seconds, so we set '''solint='int'''' to have it use the integration time.<br />
<br />
<figure id="Self_2_phase.png"><br />
[[Image:Self_2_phase.png|thumb|<caption>Phase solutions from self_2.pcal with solint='int'.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='TWHydra_cont.ms',caltable='self_2.pcal',<br />
solint='int',combine='',gaintype='T',<br />
refant='DV06',spw='',minblperant=4,<br />
calmode='p',minsnr=2)<br />
</source><br />
<br />
Now plot the new solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_2.pcal',xaxis='time',yaxis='phase',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,-80,80],figfile='self_2_phase.png')<br />
</source><br />
<br />
The phases on this shorter '''solint''' still seem to be tracking well so we will apply it and make a new image and check to see if there is improvement. <br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_cont.ms',field='',gaintable=['self_2.pcal'],calwt=F)<br />
</source><br />
<br />
<figure id="Viewer_pcal2.png"><br />
[[Image:Viewer_pcal2.png|thumb|<caption>Clean residuals after 2nd phase only self-cal and 250 iterations. The residuals inside the clean mask are lower than those outside, so its time to stop.</caption>]]<br />
</figure><br />
<br />
Now clean again, updating '''mask''' with the most recent mask file.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_2pcal.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall_2pcal',<br />
mode='mfs',imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5,usescratch=False,<br />
mask='TWHydra_contall_1pcal.mask',<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
After 200 iterations<br />
<br />
<pre style="background-color: #fffacd;"><br />
Model 0: max, min residuals = 0.00489776, -0.00464541 clean flux 1.44461<br />
</pre><br />
<br />
It looks like it could use just a little more cleaning, so set '''iterations=50 in the GUI'''.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Clean used 50 iterations to approach a threshhold of 0.0015067<br />
0.0107122 Jy <- cleaned in this cycle for model 0 (Total flux : 1.45532Jy)<br />
Final maximum residual = 0.00326382<br />
Model 0: max, min residuals = 0.00326382, -0.00321361 clean flux 1.45532<br />
</pre><br />
<br />
The small amount of flux cleaned this cycle indicates that clean is converging and it's about time to stop. Also the residuals inside the clean mask are now smaller than the residuals outside (i.e. the noise) also indicating it's time to stop by hitting the red X on the GUI.<br />
<br />
Now repeat the display, blinking, and image statistics steps described above for the 1st and 2nd phase-only self-cal iterations.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(raster=[{'file':'TWHydra_contall_1pcal.image','range':[-0.01,0.05]},<br />
{'file':'TWHydra_contall_2pcal.image','range':[-0.01,0.05]}])<br />
</source><br />
<br />
The difference is small:<br />
<pre style="background-color: #fffacd;"><br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2466 4.611597e-02 1.397287e-03 <br />
Mean Rms Std dev Minimum Maximum <br />
1.870072e-05 3.831524e-03 3.832255e-03 -1.414417e-02 1.109403e-02 <br />
<br />
TWHydra_contall_2pcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2466 1.159416e-01 3.512963e-03 <br />
Mean Rms Std dev Minimum Maximum <br />
4.701606e-05 3.811716e-03 3.812199e-03 -1.383034e-02 1.078456e-02 <br />
</pre><br />
<br />
This small improvement suggests that we have gone as far as we can with phase self-cal.<br />
<br />
===Continuum Data Amplitude Self-Calibration===<br />
<br />
Now we will apply the best phase solution table on-the-fly while solving for the amplitude self-cal solutions. Since amplitude changes more slowly and is less constrained than phase, we use a longer '''solint='inf'''', as long as '''combine=' '''' this means to do one solution per scan. <br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='TWHydra_cont.ms',caltable='self_ap.cal',<br />
solint='inf',combine='',gaintype='T',<br />
refant='DV06',spw='',minblperant=4,<br />
gaintable=['self_2.pcal'],<br />
calmode='ap',minsnr=2)<br />
</source><br />
<br />
It's useful to look at the residual phase in the amplitude calibration table, i.e. since we applied our best phase-only solution while solving for this new amplitude and phase ('''calmode='ap'''') solution, the phase should already be corrected.<br />
<br />
<figure id="Self_ap_phase.png"><br />
[[Image:Self_ap_phase.png|thumb|<caption>Residual phase solutions from self_ap.cal.</caption>]]<br />
</figure><br />
<figure id="Self_ap_amp.png"><br />
[[Image:Self_ap_amp.png|thumb|<caption>Amplitude solutions from self_ap.cal.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_ap.cal',xaxis='time',yaxis='phase',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,-1,1],figfile='self_ap_phase.png')<br />
</source><br />
<br />
The residuals are very small as expected. (If you see large residuals here, it means that the phase-only solution is suspect, and you were mostly just moving noise around.) Now look at the amplitude solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_ap.cal',xaxis='time',yaxis='amp',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,0.6,1.4],figfile='self_ap_amp.png')<br />
</source><br />
<br />
For the most part these look very good except one rather large deviation on DV06. Apply both the final phase and the amplitude calibration tables.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_cont.ms',field='',gaintable=['self_2.pcal','self_ap.cal'],calwt=F)<br />
</source><br />
<br />
Plot the corrected data as a function of both time and uv-distance. It is always a good idea to check these after an amplitude self-calbration to be sure that it worked properly. Occasionally, a few spurious bits of data will get blown up by the amplitude self-cal if it is not well-constrained. <br />
<br />
<figure id="Selfcal_time.png"><br />
[[Image:Selfcal_time.png|thumb|<caption>Post self-calibration amplitude vs. time</caption>]]<br />
</figure><br />
<figure id="Selfcal_uvdist.png"><br />
[[Image:Selfcal_uvdist.png|thumb|<caption>Post self-calibration amplitude vs. uv-distance</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',xaxis='time',yaxis='amp',<br />
avgchannel='38',ydatacolumn='corrected',coloraxis='spw',<br />
plotfile='selfcal_time.png')<br />
</source><br />
<br />
The time where we saw a large amplitude correction on DV06 looks consistent here so the large correction we saw in the solutions corrected a real issue. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',xaxis='uvdist',yaxis='amp',<br />
avgchannel='38',ydatacolumn='corrected',coloraxis='spw',<br />
plotfile='selfcal_uvdist.png')<br />
</source><br />
<br />
You will see that this plot looks much better than before. <br />
<br />
<figure id="Viewer_apcal.png"><br />
[[Image:Viewer_apcal.png|thumb|<caption>Clean residuals after final amplitude and phase self-cal.</caption>]]<br />
</figure><br />
<br />
Now make the final continuum image.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_apcal.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall_apcal',<br />
mode='mfs',imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5,usescratch=False,<br />
mask='TWHydra_contall_2pcal.mask',<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
We know we need to clean at least 300 iterations, so set this in the gui and hit the round green arrow. After this notice how much better the residual looks. Clean another 100 iterations. The "circular pattern", and 4 bright spots at each corner you see now in the residual is likely due to non-closing amplitude errors that cannot be removed with an antenna based self-calibration, so this is as good as it gets with pure self-cal. Hit the Red X to stop clean.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Clean used 100 iterations to approach a threshhold of 0.00105507<br />
0.0061808 Jy <- cleaned in this cycle for model 0<br />
Final maximum residual = 0.00242926<br />
Model 0: max, min residuals = 0.00238278, -0.00242926 clean flux 1.48201<br />
</pre><br />
<br />
Now repeat the display, blinking, and image statistics described above for the 2nd phase only and the new amplitude & phase self-cal'ed images.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(raster=[{'file':'TWHydra_contall_2pcal.image','range':[-0.01,0.05]},<br />
{'file':'TWHydra_contall_apcal.image','range':[-0.01,0.05]}])<br />
</source><br />
<br />
The amplitude and phase self cal'ed image is notably better than phase-only. Quantitatively:<br />
<pre style="background-color: #fffacd;"><br />
<br />
TWHydra_contall_2pcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 3542 2.053068e-01 6.220676e-03 <br />
Mean Rms Std dev Minimum Maximum <br />
5.796351e-05 3.955967e-03 3.956101e-03 -1.383034e-02 1.078456e-02 <br />
<br />
TWHydra_contall_apcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 3542 6.044652e-04 1.831495e-05 <br />
Mean Rms Std dev Minimum Maximum <br />
1.706565e-07 1.270183e-03 1.270362e-03 -4.980673e-03 4.137159e-03 <br />
</pre> <br />
<br />
and indeed, we've gained another factor of 3 in sensitivity. <br />
<br />
'''Overall with this self-calibration we've improved the noise by a factor of 6.7! With a peak flux density of 0.98 Jy, the S/N increased from 115 initially to 770 after. So, well worth the trouble.'''<br />
<br />
<div class="noprint" style="float:none; border:0px solid blue;background-color:#F6CEF5;padding:2px;"><br />
If you have used the '''standard='Butler-JPL-Horizons 2012' ''' model during the calibration process, you should see an increase in peak flux density of about 3%.<br />
</div><br />
<br />
It is notable that we are still a factor of more than 4 from the apriori noise estimate of 0.3 mJy/beam. This is likely due to residual sources of non-closing (not antenna based) errors in the data like baseline errors and baseline-dependent bandpass errors. Additionally, polarization errors (which we did not calibrate at all) can contribute, as well as imperfect uv-coverage with only 8 antennas. A dynamic range of 770 is actually quite good in the submillimeter.<br />
<br />
==Apply self-calibration to Full Dataset and Split Line Data==<br />
<br />
Now apply the self-calibration derived from the continuum emission to the full unchannel-averaged data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_corrected.ms',gaintable=['self_2.pcal','self_ap.cal'],calwt=F)<br />
</source><br />
<br />
Split off the CO(3-2) spectral line data in spw=2 and the HCO+(4-3) data in spw=0 for further processing.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2.ms*')<br />
split(vis='TWHydra_corrected.ms',outputvis='TWHydra_CO3_2.ms',datacolumn='corrected',spw='2')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplus.ms*')<br />
split(vis='TWHydra_corrected.ms',outputvis='TWHydra_HCOplus.ms',datacolumn='corrected',spw='0')<br />
</source><br />
<br />
==Continuum Subtraction== <br />
<br />
Next we need to subtract the continuum emission from the spectral line data. It is best to do this in the uv-plane. The first step is to make a channel plot of the spectral data to get the line-free channel ranges for both spectral lines. Since the line emission is simple (one spectral line per spw) and there are more than enough line-free channels we do not need to be very precise just stay well away from the line and whenever possible it is best to chose line-free channel ranges on either side of the line for the best possible baseline subtraction. <br />
<br />
<figure id="CO3_2_channel.png"><br />
[[Image:CO3_2_channel.png|thumb|<caption>CO(3-2) line in channel space.</caption>]]<br />
</figure><br />
<figure id="HCOp4_3_channel.png"><br />
[[Image:HCOp4_3_channel.png|thumb|<caption>HCO+(4-3) in channel space.</caption>]]<br />
</figure><br />
<br />
'''Note''': after the split above, the original spw ids will be relabeled as 0 in each file because there is only one spectral window in each file.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_CO3_2.ms',spw='0',xaxis='channel',yaxis='amp',<br />
avgtime='1e8',avgscan=T,coloraxis='spw',plotfile='CO3_2_channel.png')<br />
</source><br />
<br />
It is a good idea to stay a little away from the very edges of the baseband which can be noisy. The channel ranges <br />
20~2000 and 2400~3800 look like good choices for CO(3-2).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_HCOplus.ms',spw='0',xaxis='channel',yaxis='amp',<br />
avgtime='1e8',avgscan=T,coloraxis='spw',plotfile='HCOp4_3_channel.png')<br />
</source><br />
<br />
The channel ranges 20~1500 and 1900~3800 look like good choices for HCO+(4-3).<br />
<br />
Next use the identified line-free channel ranges and {{uvcontsub}} to subtract the continuum model from the line emission.<br />
<br />
<source lang="python"><br />
# In CASA<br />
uvcontsub(vis='TWHydra_CO3_2.ms',fitorder=1,fitspw='0:20~2000,0:2400~3800')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
uvcontsub(vis='TWHydra_HCOplus.ms',fitorder=1,fitspw='0:20~1500,0:1900~3800')<br />
</source><br />
<br />
Note: If you do not have line-free channels on both sides of the line emission, it is safer to use '''fitorder=0''', or the fit may diverge.<br />
<br />
==Spectral Line Imaging==<br />
<br />
Now we are ready to make cubes of the line emission. The imaging parameters are similar to the continuum except for <br />
those dealing with the spectral setup: '''mode''', '''start''', '''width''', '''nchan''', '''restfreq''', and '''outframe''' parameters. When making spectral images you have three choices for the '''mode''' parameter: '''channel''', '''velocity''', and '''frequency'''. Data are taken using constant frequency channels. For spectral line analysis it's often more useful to have constant velocity channels, and this is also the best way to make images of multiple lines with the exact same channelization for later comparison. For '''mode='velocity'''', the desired '''start''' and '''width''' also need to be given in velocity units for the desired output frame. <br />
<br />
It is important to note that ALMA does not do on-line Doppler Tracking and the native frame of the data is TOPO. If you do not specify '''outframe''' the output cube will also be in TOPO, which is not very useful for spectral line work. The Doppler Shift is taken out during the regridding to the desired outframe in {{clean}} or alternatively it can be done separately by the {{cvel}} task which would need to be run before {{clean}}. <br />
<br />
<figure id="CO3_2_vel.png"><br />
[[Image:CO3_2_vel.png|thumb|<caption>CO(3-2) spectrum in LSRK velocity space.</caption>]]<br />
</figure><br />
<figure id="HCOp4_3_vel.png"><br />
[[Image:HCOp4_3_vel.png|thumb|<caption>HCO+(4-3) spectrum in LSRK velocity space.</caption>]]<br />
</figure><br />
<br />
To see what velocity parameters you want to set in clean it is useful to make a plot in {{plotms}} in the desired output frame. To make it easier to see, we set a '''plotrange''' since we know the LSRK velocity of TW Hya is about 2.88 km/s. Note these plots take a little longer because of the frame shift.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_CO3_2.ms.contsub',xaxis='velocity',yaxis='amp',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',<br />
restfreq='345.79599GHz',plotrange=[-20,23,0,0],plotfile='CO3_2_vel.png')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_HCOplus.ms.contsub',xaxis='velocity',yaxis='amp',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',<br />
restfreq='356.7342GHz',plotrange=[-20,23,0,0],plotfile='HCOp4_3_vel.png') <br />
</source><br />
<br />
From these plots it looks like imaging the cubes from about -5 to +8 km/s will encompass the line, but still provide several line-free channels on either side so the noise level can be estimated. The channel width is 122 kHz, which at <br />
345.79599 GHz is 0.106 km/s. Recall that the spectral ''resolution'' is a factor of two poorer. We will use a velocity channel width of 0.12 km/s for a little oversampling, but the spectral resolution remains 0.2 km/s.<br />
<br />
As before, it is very important that you make a clean mask. There are many ways to do this ranging from the complicated to simple. For this example we will make a single clean mask that encompasses the line emission in every channel and apply it to all channels. This is much better than no clean mask, though not quite as good as making an individual mask for each channel. For some sources, one can use the continuum mask to clean the line, however TW Hya is a bit curious in that the continuum emission is not as extended as the line emission (Hughes et al. 2008).<br />
<br />
=== CO(3-2) Imaging ===<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.*')<br />
clean(vis='TWHydra_CO3_2.ms.contsub',imagename='TWHydra_CO3_2line',<br />
imagermode='csclean',spw='',<br />
imsize=100,cell=['0.3arcsec'],<br />
mode='velocity',start='-4km/s',width='0.12km/s',nchan=118,<br />
restfreq='345.79599GHz',outframe='LSRK',<br />
weighting='briggs',robust=0.5,<br />
mask='',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=100000)<br />
</source><br />
<br />
<figure id="Viewer_55.png"><br />
[[Image:Viewer_55.png|thumb|<caption>Interactive Viewer window with CO(3-2) clean mask, before cleaning starts.</caption>]]<br />
</figure><br />
<figure id="Viewer_500.png"><br />
[[Image:Viewer_500.png|thumb|<caption>Interactive Viewer window for CO(3-2), after 500 iterations, more cleaning is needed.</caption>]]<br />
</figure><br />
<br />
It will take a little while to grid the cube, when the interactive viewer opens, use the tapedeck to cycle through the channels. You should see a progress of line emission in channels 40 to 70 or so.<br />
*Go to channel 57 (about line center)<br />
*Select the polygon tool with the left mouse button<br />
*Select the "All Channels" toggle in the green area<br />
*Draw a polygon around the channel 57 emission, double click inside to activate.<br />
*Now go to channel 60, this is the channel with the most extent to the SE, draw another polygon that encompasses this emission if necessary,double click inside to activate.<br />
*Now go to channel 55, this is the channel with the most extent to the NW, draw another polygon that encompasses this emission if necessary,double click inside to activate. <br />
*Now double check the mask by cycling through channels with real line emission to be sure that your clean box encompasses the emission, but does not extend far beyond it. Again the "erase" toggle can come in handy if things go awry or if you want to just delete a small portion of an existing mask (just draw a polygon around what you want to erase and double click inside), be sure to switch back to "add" before going on.<br />
<br />
The figure shows what the final clean box should look like. Now clean using the green circle arrow. You can watch the progress in the logger. When 100 iterations are done, the viewer will show the residual map for each channel. Cycle through the channels and see whether you are still happy with the clean box in each signal channel. The "erase button" can help you fix mistakes. If necessary adjust. It is often useful to adjust the colorscale with the "plus" symbol icon. Keep going until the residual emission looks like the surrounding noise. If it seems to be going slowly, increase the iterations to 300 for a round or two. I stopped cleaning (Red x) when the logger showed (about 900 iterations). <br />
<pre style="background-color: #fffacd;"><br />
12.9846 Jy <- cleaned in this cycle for model 0<br />
Final maximum residual = 0.157312<br />
Model 0: max, min residuals = 0.157312, -0.0871295 clean flux 279.304<br />
</pre><br />
<br />
NOTE: The residuals are still a bit high in the strongest emission channels after it is well cleaned in the weaker channels. This is an indication that the sensitivity is "dynamic range" limited. In other words even with more <br />
intrinsic sensitivity per integration (i.e. better system temperature), the dynamic range limit would remain the same unless you get more uv-coverage. The fundamental dynamic range limitations of ALMA will be considerably better with 16 antennas in Early Science and MUCH better with the full 50-antenna array.<br />
<br />
=== HCO+(4-3) Imaging ===<br />
<br />
Now image and clean the HCO+(4-3) line using what you learned above.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.*')<br />
clean(vis='TWHydra_HCOplus.ms.contsub',imagename='TWHydra_HCOplusline',<br />
imagermode='csclean',spw='',<br />
imsize=100,cell=['0.3arcsec'],<br />
mode='velocity',start='-4km/s',nchan=118,width='0.12km/s',<br />
restfreq='356.7342GHz',outframe='LSRK',<br />
weighting='briggs',robust=0.5,<br />
mask='',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=100000)<br />
</source><br />
<br />
I stopped cleaning when: <br />
<pre style="background-color: #fffacd;"><br />
4.79833 Jy <- cleaned in this cycle for model 0<br />
Final maximum residual = 0.0977348<br />
Model 0: max, min residuals = 0.0977348, -0.060484 clean flux 192.066<br />
</pre><br />
<br />
==Image Analysis==<br />
<br />
After all that hard work you now have deconvolved images of the 350 GHz continuum, the CO (3-2) line, and the HCO+ (4-3) line. CASA includes tools to help you understand the contents of these images and make basic scientific measurements. These tools are divided between graphical exploration tools, accessible via the CASA viewer, and command line analysis tasks. To access the viewer, simply type '''viewer()''' and to see the list of analysis tasks available in CASA type '''tasklist''' at the CASA prompt and look under the Analysis sub-heading.<br />
<br />
If you want to do this portion of the guide and have downloaded the (.FITS) reference images, you can import them to be CASA images using '''importfits'''. If you are re-importing the images, use the commented remove command, here, to delete the previous import first.<br />
<br />
<source lang="python"><br />
# In CASA<br />
# os.system("rm -rf TWHydra_CO3_2line.image")<br />
importfits(fitsimage="TWHydra_CO3_2line.image.fits", imagename="TWHydra_CO3_2line.image")<br />
</source><br />
<br />
where '''fitsimage''' refers to the file to imported and '''imagename''' gives the output filename. If you are proceeding directly from the imaging step, your data are already CASA images and you may proceed without any importing.<br />
<br />
You can get the basic properties of any CASA image using the '''imhead''' command. For example, type <br />
<br />
<source lang="python"><br />
# In CASA<br />
imhead("TWHydra_CO3_2line.image")<br />
</source><br />
<br />
and look at the CASA logger. You will see an image summary like the following<br />
<br />
<pre style="background-color: #fffacd;"><br />
INFO imhead ##########################################<br />
INFO imhead ##### Begin Task: imhead #####<br />
INFO imhead imhead(imagename="TWHydra_CO3_2line.image",mode="summary",hdkey="",hdvalue="",<br />
INFO imhead hdtype="",hdcomment="",verbose=False)<br />
INFO ImageAnalysis <br />
INFO ImageAnalysis Image name : TWHydra_CO3_2line.image<br />
INFO ImageAnalysis Object name : TW Hya<br />
INFO ImageAnalysis Image type : PagedImage<br />
INFO ImageAnalysis Image quantity : Intensity<br />
INFO ImageAnalysis Pixel mask(s) : None<br />
INFO ImageAnalysis Region(s) : None<br />
INFO ImageAnalysis Image units : Jy/beam<br />
INFO ImageAnalysis Restoring Beam : 1.68065 arcsec, 1.53193 arcsec, 22.3015 deg<br />
INFO ImageAnalysis <br />
INFO ImageAnalysis Direction reference : J2000<br />
INFO ImageAnalysis Spectral reference : LSRK<br />
INFO ImageAnalysis Velocity type : RADIO<br />
INFO ImageAnalysis Rest frequency : 3.45796e+11 Hz<br />
INFO ImageAnalysis Pointing center : 11:01:51.844983 -34.42.17.160885<br />
INFO ImageAnalysis Telescope : ALMA<br />
INFO ImageAnalysis Observer : Unknown<br />
INFO ImageAnalysis Date observation : 2011/04/22/00:15:42<br />
INFO ImageAnalysis Telescope position: [2.22514e+06m, -5.44031e+06m, -2.48103e+06m] (ITRF)<br />
INFO ImageAnalysis <br />
INFO ImageAnalysis Axis Coord Type Name Proj Shape Tile Coord value at pixel Coord incr Units<br />
INFO ImageAnalysis -------------------------------------------------------------------------------------------------- <br />
INFO ImageAnalysis 0 0 Direction Right Ascension SIN 100 25 11:01:51.845 50.00 -3.000000e-01 arcsec<br />
INFO ImageAnalysis 1 0 Direction Declination SIN 100 25 -34.42.17.161 50.00 3.000000e-01 arcsec<br />
INFO ImageAnalysis 2 2 Spectral Frequency 118 59 3.45801e+11 0.00 -1.38414152e+05 Hz<br />
INFO ImageAnalysis Velocity -4 0.00 1.200000e-01 km/s<br />
INFO ImageAnalysis 3 1 Stokes Stokes 1 1 I<br />
INFO imhead ##### End Task: imhead #####<br />
INFO imhead ##########################################<br />
<br />
</pre><br />
<br />
This report tells you about the target, shape, and coordinates of the image. It also notes the rest frequency and some details of the observation. '''imhead''' may be used more generally to retrieve header keywords as python variables or to manipulate the header of an image. Consult the help for details.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
You may want to pay particular attention to the third and fourth axis of the CASA image. These are <br />
usually frequency (velocity) and Stokes (polarization) in some order. An occasional source of confusion <br />
is that this order is not always the same. Often CLEAN will output images with the Stokes axis third, <br />
while IMPORTFITS usually yields images with the frequency axis third. If you encounter problems with<br />
image analysis tasks, you may want to check whether this results from conflicting axis definitions. You<br />
can adjust the order of the axes using the IMTRANS task.<br />
</pre><br />
<br />
Before proceeding, make sure that you have all three data sets as CASA images: '''TWHydra_CO3_2line.image''', '''TWHydra_HCOPlusline.image''', and '''TWHydra_contall_apcal.image'''. If you do not, then import them from the provided reference images. If you are re-importing the FITS images, run the commented remove commands before running importfits.<br />
<br />
<source lang="python"><br />
# In CASA<br />
# os.system("rm -rf TWHydra_CO3_2line.image")<br />
importfits(fitsimage="TWHydra_CO3_2line.image.fits", imagename="TWHydra_CO3_2line.image")<br />
# os.system("rm -rf TWHydra_HCOplusline.image")<br />
importfits(fitsimage="TWHydra_HCOplusline.image.fits", imagename="TWHydra_HCOplusline.image")<br />
# os.system("rm -rf TWHydra_contall_apcal.image")<br />
importfits(fitsimage="TWHydra_contall_apcal.image.fits", imagename="TWHydra_contall_apcal.image")<br />
</source><br />
<br />
In the rest of this guide we will construct ''moment maps'' showing the integrates, velocity field, and line width of the two lines. We will carry out Gaussian fits to the continuum and line maps. We will also illustrate some of the additional analysis capabilities available in CASA: subcube extraction, retrieval of data into python arrays, cube alignment, smoothing, and overlays of multiple spectral lines.<br />
<br />
===Moment Maps===<br />
<br />
The line "images" of CO(3-2) and HCO+(4-3) are, of course, cubes rather than images. Two dimensional ''moment maps'' are a standard way to present such data. These are maps showing the result of various moments (or similar calculations) carried out along the frequency axis of the cube. For example, the "moment 0" map is the sum of emission along the frequency axis at each pixel. The first moment is the intensity-weighted velocity (or frequency). The second moment is the intensity-weighted velocity (or frequency) dispersion about the mean. These and a number of other calculations (for example the maximum intensity) can be calculated via the '''immoments''' task. Consult the help or the CASA cookbook for more details.<br />
<br />
In this section, we will calculate moments for our two spectral line data cubes. To make the highest quality moment maps, we will first identify the planes of the data cube that contain emission, so that we can carry out the sum only over these channels. Doing otherwise adds noise to the moment map without adding signal and so lowers the signal-to-noise ratio of the final image. For the first and second moments we will identify an intensity threshold above which the data are statistically very likely to correspond to real astronomical emission. We will restrict the calculation to consider only data above this threshold, yielding a cleaner calculation (the second moment, in particular, is not at all robust against the inclusion of outlying noise). Finally, we will inspect the resulting moment maps with the viewer and output them to .FITS files.<br />
<br />
====Estimate the Spectral Extent====<br />
<br />
First, we want to figure out what planes appear to contain real emission. Open the CO data cube with the CASA viewer via:<br />
<br />
<source lang="python"><br />
# In CASA<br />
viewer("TWHydra_CO3_2line.image")<br />
</source><br />
<br />
This will open the CO(3-2) data cube as a raster image. Use the Animator pane to scroll through the cube, noting that the emission is mostly confined to ~40 channels near the center of the cube. There are several ways to make a more rigorous estimate. <br />
<br />
''By-Plane Inspection:'' First, you could increase the stretch of the image to identify by hand the first and last channels with visible emission. To do open the Data Display Options panel in the viewer (the wrench icon) and manually set the data range and/or scaling power cycles to highlight faint emission (note that you can also do this using the mouse and the color stretch - sun - icon). I left the scaling power cycles at 0 and set the data range to [-0.15, 0.15]. Then scroll through the cube and note the first and last channels with obvious emission. If I do this, I find emission from about plane 30 through plane 86.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:DataDisplayPanelStretch.png|The Data Display Panel used to set the color stretch, here from [-0.15, 0.15] with a linear (0) stretch. Setting the stretch to a negative value will highlight lower emission (a more logarithmic stretch). We got to this panel by clicking the wrench icon. You can also get from the dropdown menus (Data->Adjust).<br />
File:TWHydraCOChan33.png|Channel 33 of the CO(3-2) cube on this stretch. This is about the first channel to show clear emission.<br />
File:TWHydraCOChan80.png|Channel 80 of the CO(3-2) cube on this stretch. This is about the last channel to show clear emission.<br />
</gallery><br />
</center><br />
<br />
To make this more rigorous, you can work out a noise estimate before hand (we'll find it to be about 0.025 Jy/beam) and overplot a contour to indicate significant emission. You can do this by hand by using the Data Manager (folder icon) to open TWHydra_CO3_2line.image as a "contour map" and then using the Data Display Options to manipulate the contour levels. To show a 3-sigma contour with sigma=0.025 Jy/beam set the Relative Contour Levels to [3], the Base Contour Level to 0, and the Unit Contour Level to 0.025. You can display a 5-sigma contour or change the RMS analogously. Scrolling through the cube, I see 3-sigma emission from channels 33 through 80.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:DataDisplayPanelContour.png|The Data Display Panel now being used to set the contour levels. We set the contour unit to 0.025 and ask for a single contour at 3 times this value. Notice that we clicked the tab along the top of the window to select the contour map.<br />
File:TWHydraCOChan33Contour.png|Channel 33 of the CO(3-2) cube on this stretch with a 3-sigma contour overlaid.<br />
File:TWHydraCOChan80Contour.png|Channel 80 of the CO(3-2) cube on this stretch with a 3-sigma contour overlaid.<br />
</gallery><br />
</center><br />
<br />
''Look at a Spectrum:'' You can also look at a spectrum of the source. To do this, scroll to a channel with a lot of emission (I went to 57) and then use the mouse to drag out a rectangle. To do this, left click on the rectangle box in the mouse toolbar (this assigns the left mouse button to define rectangle regions). Then drag out a box around the emission using the same button. Now click the spectrum in the toolbar to open the spectral profile tool. You will see the average profile for the selected region. You can set the bottom axis to show channels. You can zoom in within the spectral profile by dragging out a rectangle. When I do this, I find significant emission from channels 40-80.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:TWHydraRectangle.png|Defining a rectangular region around the main emission from TW Hydra. First we clicked the rectangle button on the mouse toolbar, then we held that button and dragged out the purple rectangle. After defining the rectangle, you can drag it around or delete it with <ESC>.<br />
File:TWHydraSpectrum.png|The spectrum of this rectangular region viewed in the spectral profile browser. Note that the bottom axis has been set to show channels. To get this spectrum, we defined the rectangular region and then clicked the spectrum button on the toolbar.<br />
File:TWHydraSpectrumZoom.png|A zoom in on the spectrum. The line extends from channels ~40-80.<br />
</gallery><br />
</center><br />
<br />
''Look at a Declination-Frequency Projection (or an R.A.-Frequency Projection):'' This is probably the least reliable way to do this, but illustrates a neat capability of the viewer. Open the Data Display Options (click the wrench icon) and open the "display axes" and "hidden axes" tabs. Use the dropdown menus to change the display so that the x-axis shows Declination, the y-axis shows Frequency, and the z-axis shows "Right Ascension." Now you are scrolling through planes of intensity as a function of Declination and Frequency. Use the animator to move to R.A. plane ~ 50 (the center of the source) and pull the stretch up (in the wrench tool; I used [-0.15,0.15] again). Mouse over the image and look at the "Position Tracking" pane in the bottom of the image, noting the pixel extent of emission in the frequency axis of this plane. I see traces of emission from channel ~30-90.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:DataDisplayPanelAxes.png|The Data Display Panel, here used to set which axes are displayed. We have adjusted the y-axis to show frequency and the x-axis to show Declination. The z-axis is now Right Ascension, so that we will scroll through planes of Right Ascension.<br />
File:DataDisplayPanelPixels.png|The Data Display Panel, here we are setting coordinates to show "pixels" rather than world coordinates.<br />
File:TWHydraDecFreqPixels.png|A Frequency-Declination plane of the cube near the central R.A. pixel (50). The rough extent of emission may be simply read off the y-coordinate. As above, we could overplot a 3-sigma contour to add more rigor.<br />
</gallery><br />
</center><br />
<br />
<br />
You can repeat this exercise for the HCO+ (4-3) emission. Using the Spectral Profile Browser, I find that the line extends from about channel 40 through channel 75.<br />
<br />
====Make Moment 0 Maps====<br />
<br />
With an estimate of the spectral extent of emission, we are now ready to make moment 0 maps of the CO(3-2) and HCO+(4-3) lines. We do this using the '''immmoments''' command,<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom0')<br />
immoments(imagename='TWHydra_CO3_2line.image',moments=[0],<br />
outfile='TWHydra_CO3_2line.image.mom0',<br />
chans='30~90')<br />
</source><br />
<br />
and<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom0')<br />
immoments(imagename='TWHydra_HCOplusline.image',moments=[0],<br />
outfile='TWHydra_HCOplusline.image.mom0',<br />
chans='40~75')<br />
</source><br />
<br />
immoments will sum across the channels specified by '''chans''' and produce new CASA images with the names specified by '''outfile'''. These can be inspected using the CASA viewer just like any other image. Note that unlike higher-order moments, the moment-0 map is robust to the inclusion of noisy signal-free channels (to within reason, you just decrease your signal-to-noise ratio) and indeed may be biased to miss faint emission by imposing a threshold. For that reason, we will eschew the '''includepix''' keyword as we make the moment 0 maps.<br />
<br />
Let's look at the output using the viewer. We can specify some of the display options in the call to start the viewer by using '''imview''' instead of '''viewer'''.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview( raster=[ {'file':'TWHydra_CO3_2line.image.mom0',<br />
'range':[0.0,10.],<br />
'scaling':-1},<br />
{'file':'TWHydra_HCOplusline.image.mom0',<br />
'range':[0.0,10.],<br />
'scaling':-1}], <br />
contour={'file':'TWHydra_contall_apcal.image', 'base':0, 'unit':0.0025, 'levels':[3,100]} )<br />
</source><br />
<br />
This does several things: It opens the viewer with raster images of the moment 0 maps of CO(3-2) and HCO+(4-3), sets the range of the color stretch from [0, 10] for each image and sets the scaling to be -1, which highlights faint emission compared to the normal (0) stretch. It also opens the continuum image as a contour and defines two contour levels. Once the viewer is open, you can blink between the images by going into the Animator pane, checking the white box next to "Images" to enable animation between images, and then sliding the bar back and forth. See the name of the image being shown change. You can also show two images side by side by going to the Viewer Canvas Manager (wrench+P icon) and opening the "Number of Panels" tab. Set the "Number of panels in x" to 2 and make sure that the Images box is checked in the Animator pane. You will see both images side by side.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:CanvasManagerPanels.png|The Viewer Canvas Manager, accessed via the Wrech+P icon (not to be confused with the plain old wrench). Here we have adjusted the number of x-panels from 1 to 2 so that we show the two moment maps side by side.<br />
File:TWHydraMoment0Maps.png|The moment-0 maps of CO(3-2) and HCO+(4-3) plotted side by side on the same color stretch, both with the continuum contours overlaid. To get the two images side by side, run the imview call above then set the number of panels to 2 and make sure that the Images box in the Animator Pane (here at the bottom of the window) is checked.<br />
File:DataDisplayImview.png|Data Display Panel after our imview call. Imview allowed us to set the stretch, range, and contour levels from the command line.<br />
</gallery><br />
</center><br />
<br />
====Estimate the Noise====<br />
<br />
We have already made a few offhand comparisons to the RMS noise. This quantity is often critical to know when exploring the data. Because the higher-order moments (especially the dispersion) are not at all robust to the inclusion of noise, we will calculate them only from regions of the cube that have intensity several times the RMS noise value or higher and are thus very likely to contain real astronomical emission. To proceed, we need to estimate the RMS noise for our data.<br />
<br />
The easiest way to do this is to calculate the RMS scatter of the data about zero from a part of the data that you suspect to be (mostly) free of astronomical signal. In a data cube the easiest way to do this will often be to identify signal-free planes (channels) of the cube and to simply calculate the RMS in these regions. We can do this straightforwardly using the '''imstat''' command in CASA.<br />
<br />
IMSTAT COMMAND<br />
<br />
IMSTAT OUTPUT<br />
<br />
Alternatively, you can get similar statistics on a region of an image or data cube selected manually inside the viewer. Drag out a region, for example a rectangle, using one of the mouse tools. Then <br />
<br />
IMAGES OF REGION SELECTION, OUTPUT, REGION MANAGER<br />
<br />
Suggested values for CO(3-2), HCO+(4-3), and continuum. Short discussion of dynamic range limited vs. line-free channels.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
A note on primary beam corrections and noise.<br />
</pre><br />
<br />
====Higher Order Moment Maps for CO(3-2)====<br />
<br />
For higher order moments it is very important to set a conservative flux <br />
threshold. Typically something like 6 sigma, using sigma from peak line channel, works well.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom')<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_coord')<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_dispersion_coord')<br />
immoments(imagename='TWHydra_CO3_2line.image',moments=[1,2],<br />
outfile='TWHydra_CO3_2line.image.mom',<br />
chans='40~76',includepix=[0.3,100])<br />
</source><br />
<br />
Display all three moment maps in the viewer, overlaid with continuum contours.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview( raster=[ {'file':'TWHydra_CO3_2line.image.mom0'},<br />
{'file':'TWHydra_CO3_2line.image.mom.weighted_coord'},<br />
{'file':'TWHydra_CO3_2line.image.mom.weighted_dispersion_coord'} ], <br />
contour={'file':'TWHydra_contall_apcal.image', 'base':0, 'unit':0.0025, 'levels':[3,100]} )<br />
</source><br />
<br />
To see all three raster images simultaneously, open the viewer's Panel Display Options (the "P-wrench" icon in the viewer tool bar), click "Number of panels", and change "Number of panels in x" to 3. Then select the "Blink" toggle (radio button) from the Animator panel.<br />
<br />
<figure id="TWHya_CO3_2_moments.png"><br />
[[Image:TWHya_CO3_2_moments.png|center|800px|frame|<caption>ALMA CO(3-2) moment maps, with white continuum contours at 3 and 100 sigma. From left to right: integrated intensity, intensity weighted velocity field, intensity weighted velocity dispersion are shown.</caption>]]<br />
</figure><br />
<br />
Repeat for HCO+(4-3) which has a bit narrower velocity extent than the CO(3-2), but similar rms noise.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom0')<br />
immoments(imagename='TWHydra_HCOplusline.image',moments=[0],<br />
outfile='TWHydra_HCOplusline.image.mom0',<br />
chans='43~74')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom')<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_coord')<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_dispersion_coord')<br />
immoments(imagename='TWHydra_HCOplusline.image',moments=[1,2],<br />
outfile='TWHydra_HCOplusline.image.mom',<br />
chans='43~74',includepix=[0.3,100])<br />
</source><br />
<br />
Display all three moment maps in the viewer using the same method described above for the CO(3-2) maps.<br />
<br />
<figure id="TWHya_HCOp4_3_moments.png"><br />
[[Image:TWHya_HCOp4_3_moments.png|center|800px|frame|<caption>ALMA HCO+(4-3) moment maps, with white continuum contours at 3 and 100 sigma. From left to right: integrated intensity, intensity weighted velocity field, intensity weighted velocity dispersion are shown.</caption>]]<br />
</figure><br />
<br />
=====Exporting Fits Images=====<br />
<br />
If you want to analyze the data using another software package it is easy to convert from CASA format to FITS. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image',fitsimage='TWHydra_CO3_2line.image.fits')<br />
</source><br />
<br />
Although "FITS format" is supposed to be a standard, in fact most packages expect slightly different things from a FITS image. If you are having difficulty, try setting '''velocity=T''' and/or '''dropstokes=T'''.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf TWHydra_HCOplusline.image.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image',fitsimage='TWHydra_HCOplusline.image.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom0.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image.mom0',<br />
fitsimage='TWHydra_CO3_2line.image.mom0.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_coord.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image.mom.weighted_coord',<br />
fitsimage='TWHydra_CO3_2line.image.mom.weighted_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_dispersion_coord.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image.mom.weighted_dispersion_coord',<br />
fitsimage='TWHydra_CO3_2line.image.mom.weighted_dispersion_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom0.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image.mom0',<br />
fitsimage='TWHydra_HCOplusline.image.mom0.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_coord.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image.mom.weighted_coord',<br />
fitsimage='TWHydra_HCOplusline.image.mom.weighted_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_dispersion_coord.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image.mom.weighted_dispersion_coord',<br />
fitsimage='TWHydra_HCOplusline.image.mom.weighted_dispersion_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_apcal.image.fits')<br />
exportfits(imagename='TWHydra_contall_apcal.image',fitsimage='TWHydra_contall_apcal.image.fits')<br />
</source><br />
<br />
===Display Channel Maps===<br />
<br />
Using the Viewer you can make channel map figures. Start the Viewer and then open the CO(3-2) cube as a raster image and then the continuum as a contour image. Then we use the "wrench" icon and "P wrench" icons to set up the channel images, contour levels etc. (If you need help setting up the viewer for this image, see a screen shot of the viewer setup windows, below.)<br />
<br />
<figure id="TWHya_channel_co3_2.png"><br />
[[Image:TWHya_channel_co3_2.png|center|frame|<caption>Channel maps of the CO(3-2) emission with white continuum contours at 3 and 100 sigma.</caption>]]<br />
</figure><br />
<br />
<figure id="Viewer_setup.png"><br />
[[Image:Viewer_setup.png|center|thumb|500px|<caption>The setup windows looked like this</caption>]]<br />
</figure><br />
<br />
Repeat for HCO+(4-3)<br />
<br />
<figure id="TWHya_channel_HCOp4_3.png"><br />
[[Image:TWHya_channel_HCOp4_3.png|center|thumb|800px|<caption>Channel maps of the HCO+(4-3) emission with white continuum contours at 3 and 100 sigma. The color intensity scale is the same as that used for CO(3-2).</caption>]]<br />
</figure><br />
<br />
<!--<br />
====Examine CO Contours on an HCO+ Raster====<br />
<br />
====Matched Movies====<br />
<br />
===Image Plane and Spectral Fits===<br />
<br />
====Fit a Gaussian to the Continuum====<br />
<br />
=====Fit In the Viewer=====<br />
<br />
=====Fit Using the Command Line=====<br />
<br />
====Fit a Gaussian to the CO Line====<br />
<br />
=====Fit In the Viewer=====<br />
<br />
=====Fit Using the Command Line=====<br />
<br />
===Extract a Sub-Image===<br />
<br />
===Align Image Cubes===<br />
--><br />
<br />
{{Checked 4.5.0}}</div>Sstierwahttps://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_4.5&diff=19490TWHydraBand7 Imaging 4.52016-05-18T05:50:54Z<p>Sstierwa: /* Estimate the Spectral Extent */</p>
<hr />
<div>[[Category:ALMA]][[Category:Imaging]][[Category:Spectral Line]]<br />
<br />
* '''This tutorial picks up where '''[[TWHydraBand7_Calibration_4.5]]''' leaves off, with fully calibrated, split science target MS. If you wish to skip the Calibration guide: obtain the calibrated data from [[TWHydraBand7#Getting_the_Data]]; extract it using <tt>tar -xzvf FILENAME</tt>; and <tt>cd</tt> into the extracted directory.'''<br />
<br />
*'''This guide is designed for CASA 4.5.2. If you are using an older version of CASA please see [[TWHydraBand7_Imaging_4.3]].<br />
<br />
* '''Details of the ALMA data are provided at [[TWHydraBand7]]'''<br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.5.2. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.5.0'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
== Prepare Continuum Data for Further Processing==<br />
<br />
In order to speed up imaging/self-calibration for the continuum data we will average channels together, and then flag the few spectral features. This method works well in the case of only a few spectral lines, while retaining enough channelization to aid in multi-frequency synthesis and being able to remove spectral features in the averaged data. The amount of channel averaging should be adjusted to your particular data. '''Note for wide bandwidth data it is never a good idea to use the continuum estimate generated by uv-continuum subtraction as your continuum data'''. This worked OK in the past with the narrow band systems like the VLA and low dynamic range instruments like the SMA, but is not advised for ALMA wide bandwidth, high dynamic range data. <br />
<br />
<figure id="Cont_spw2.png"><br />
[[Image:Cont_spw2.png|thumb|<caption>CO(3-2) in spw=2 from the "continuum" channel averaged data.</caption>]]<br />
</figure><br />
<figure id="Cont_spw3.png"><br />
[[Image:Cont_spw3.png|thumb|<caption>Notice upswing at high channel numbers in spw=3.</caption>]]<br />
</figure><br />
<br />
One can also flag the spectral features first but in that case make a backup of the file that is analogous to TWHydra_corrected.ms as you will need it later (unflagged) for spectral line imaging. We begin by excluding ~20 channels on each edge, and averaging over 100 channel intervals:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_cont.ms*')<br />
split(vis='TWHydra_corrected.ms',outputvis='TWHydra_cont.ms',<br />
spw='0~3:21~3820',width=100,datacolumn='data')<br />
</source><br />
<br />
Now make a plot of amplitude vs. channel to see what needs to be flagged<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',spw='0~3',xaxis='channel',yaxis='amp',<br />
avgtime='1e8',avgscan=T,coloraxis='spw',iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
The CO(3-2) and HCO+(4-3) lines are obvious. The 4th spw; spw=3 also shows an upswing on the highest channels that is problematic, it was seen on the calibrators too and is likely due to a weak atmospheric feature, we will flag the worst of it.<br />
<br />
<figure id="Cont_uvplot.png"><br />
[[Image:Cont_uvplot.png|thumb|<caption>UV-plot of the continuum emission, colors show spws.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='TWHydra_cont.ms', mode='manual', <br />
spw='0:16~16, 2:21~21, 3:33~37')<br />
</source><br />
<br />
Have a look at the continuum as a function of uv-distance (in the plot to the right, the 4 spw are shown in different colors on top of each other). If the data are flat as a function of uv-distance, the source is completely unresolved. If instead you see structure (in this case decreasing amplitude with uv-distance), the source is resolved. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',spw='',xaxis='uvdist',yaxis='amp',field='',avgchannel='38',<br />
coloraxis='spw',plotfile='cont_uvplot.png')<br />
</source><br />
<br />
Notice that the spw do not have the same amplitude. Unfortunately, the red spw (highest frequency) should be higher than the green one (lowest frequency) because optically thin dust goes as nu^4, and optically thick as nu^2. This inconsistency is due to imperfect amplitude/absolute flux calibration. The self-calibration below will bring them into agreement with each other, but this is the sort of thing that results in considerable absolute flux uncertainty at submillimeter wavelengths. We are working on how to do this better.<br />
<br />
==A priori Noise Estimates==<br />
<br />
<figure id="Corrected_time.png"><br />
[[File:Corrected_time.png|thumb|<caption>Plot for estimating time.</caption>]]<br />
</figure><br />
<figure id="sensitivity_cont.png"><br />
[[File:sensitivity_cont.png|thumb|<caption>Sensitivity calculator setup with observed continuum parameters for these observations.</caption>]]<br />
</figure><br />
<br />
To estimate what the expected noise levels are, we first need to know how much time we had on source. Looking at <br />
a plot of amplitude vs time for the concatenated but pre-split data (see below) there are 9x8min scans + 6x6min scans + 3x1min + 2x2min scans for about 1.9 hours on source. There are 2 polarizations and about 1.75 GHz of total continuum bandwidth taking into account flagging.<br />
<br />
Using this information and https://almascience.nrao.edu/proposing/sensitivity-calculator, we find that the '''expected rms noise for the continuum is about 0.3 mJy/beam'''.<br />
<br />
For the spectral line data, which we will image below, with 0.12 km/s channels (needs to be entered in the field ''bandwidth per polarization''), the '''expected rms noise for the spectral lines is about 32 mJy/beam'''.<br />
<br />
==Image and Self-Calibrate the Continuum==<br />
<br />
====Create Initial Clean Image====<br />
<br />
First we will make an initial image using {{clean}}, this task will both deconvolve and clean. <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
If you are unfamiliar with the basic concepts of deconvolution and clean,<br />
pause here and review for example<br />
http://www.aoc.nrao.edu/events/synthesis/2010/lectures/wilner_synthesis10.pdf<br />
</pre><br />
<br />
In {{clean}}, we use '''mode='mfs'''' to do multifrequency synthesis, in other words grid each uv-channel independently. Since the uv-spacing is a function of frequency, this will actually achieve greater uv-coverage than if all the channels and spws had been averaged in advance. The '''imsize=100''' and '''cellsize=['0.3arcsec']''' were chosen to be appropriate for the Band and antenna configuration. At ALMA Band 7, the Full Width Half Power primary beam is about 20", so we want to make our image at least this big. We've made it a bit larger out to about the 25% power point. For the configuration used to take these data, the resolution is expected to be about 1.5" and it is a good idea to oversample the beam by setting the cell size to be a factor of 4 or 5 smaller than the beam (we have used 5 here). <br />
<br />
For doing self-calibration it is essential that only "real" signal be included in the image model, thus it is important to make a clean mask, and clean the first iteration rather conservatively (shallowly) so that you are sure that you do not have clean components in your model that do not represent real source emission. In the example below we set '''interactive=T''' so you can interactively make the clean mask and stop clean when the signal from the source starts to approach the surrounding "noise" areas in the residual map.<br />
<br />
'''NOTE:''' Real emission will not go away if you do not put a clean box on it. Conversely if you put a clean box on something that is NOT real and clean deeply you can amplify that feature. Thus, its best to be conservative and build up your clean box as you go, you can generally see fainter "real" features in the residuals.<br />
<br />
'''NOTE:''' If you start an interactive clean, and then do not make a mask, clean will stop when you tell it to go on because it has nothing to clean. There is no default mask.<br />
<br />
<figure id="Viewer_clean1.png"><br />
[[Image:Viewer_clean1.png|thumb|<caption>Interactive viewer.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall',<br />
mode='mfs', imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5, <br />
mask='',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
'''NOTE:'''{{clean}} will generate several files automatically with the '''imagename''' prepended:<br />
* <imagename>.image # the final restored image<br />
* <imagename>.flux # the effective primary beam response (e.g. for pbcor)<br />
* <imagename>.flux.pbcoverage # the primary beam coverage (ftmachine=’mosaic’ only)<br />
* <imagename>.model # the model image<br />
* <imagename>.residual # the residual image<br />
* <imagename>.psf # the synthesized (dirty) beam<br />
<br />
Once the Clean Viewer opens, click on the polygon tool with your left mouse button, and draw a polygon around the continuum emission with the left mouse button. Double click inside the region with the left mouse button when you are happy with it. It will turn from green to white when the clean mask is accepted. To continue with clean use the "Next action" buttons in the green area on the Viewer Display GUI. <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
The red X will stop clean where you are, the blue arrow will stop <br />
the interactive part of clean, but continue to clean non-interactively <br />
until reaching the number of iterations requested (niter) or the flux <br />
density threshold (whichever comes first), and the green circle arrow <br />
will clean until it reaches the "iterations" parameter on the left side <br />
of the green area. <br />
</pre><br />
<br />
'''You should chose the green circle arrow'''. It will clean 100 iterations (number under iteration in the green area on the Viewer GUI) and then show the '''residual image''' again. The middle mouse button is automatically assigned to the "plus" icon, which adjusts the colorscale. '''If you cannot easily access multiple mouse buttons, you can always assign your one mouse button the icon you want by clicking on it'''. Adjust the color scale so you can see the structure in the noise better. Also, note that the logger is telling you the amount of clean flux recovered so far, the min/max residuals, and the synthesized beam:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Model 0: max, min residuals = 0.0203454, 0.00267232 clean flux 1.30124<br />
Threshhold not reached yet.<br />
Beam used in restoration: 1.6962 by 1.54549 (arcsec) at pa 28.9043 (deg) <br />
</pre> <br />
<br />
Already with only 100 iterations, the residuals outside the clean mask are larger than that inside. So we will stop here by hitting the Red X symbol.<br />
<br />
====1st Round of Continuum Data Phase Self-calibration====<br />
<br />
Next we can use the clean model to self-calibrate the uv-data. The process of self-calibration tries to adjust the data to better match the model you give it. That is why it is important to make the model as good as you can. {{clean}} places a uv-model of the resulting image in the file <tt>TWHydra_cont.model</tt>. This model can then be used to self-calibrate the data using {{gaincal}}. We use '''gaintype='T'''' to tell it to average the polarizations before deriving solutions (which gains us a sqrt(2) in sensitivity). A critical parameter to play with is '''solint'''; we use '''solint=30s'''. From {{listobs}} the integration time of these data is about 10 seconds, so using '''solint=30s''' then gains us a sqrt(3) in sensitivity. It is often best to start with a larger '''solint''' and then work your way down to the integration time if the S/N of the data permits. For the same reasons as described in the [[TWHydraBand7_Calibration_4.5]] tutorial we want to fix up the phases before tackling amplitude by setting '''calmode='p''''.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='TWHydra_cont.ms',caltable='self_1.pcal',<br />
solint='30s',combine='',gaintype='T',<br />
refant='DV06',spw='',minblperant=4,<br />
calmode='p',minsnr=2)<br />
</source><br />
<br />
<figure id="Self_1_phase.png"><br />
[[Image:Self_1_phase.png|thumb|<caption>Phase solutions from self_1.pcal with solint=30s.</caption>]]<br />
</figure><br />
<br />
Because '''combine=' '''', we are getting independent solutions for each spw. If you are desperate for S/N, you can try combining them with combine='spw'. We have plenty of S/N in these data so we keep them separate. Look at the solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_1.pcal',xaxis='time',yaxis='phase',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,-80,80],figfile='self_1_phase.png')<br />
</source><br />
<br />
The magnitude of corrections gives you a sense of how accurate the phase transfer from the calibrators was. You are checking to see that the phases are being well tracked by the solutions, i.e. smoothly varying functions of time within a given scan. Also the solutions for each spw are lying basically on top of each other which indicates that the spw to spw phase offsets are well calibrated already. Overall, these solutions look quite good. If they didn't you could try increasing the solint and/or combining the spw into a single solution. <br />
<br />
After checking that you are happy with the solutions, apply them with {{applycal}}<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_cont.ms',field='',gaintable=['self_1.pcal'],calwt=F)<br />
</source><br />
<br />
<figure id="Viewer_pcal1.png"><br />
[[Image:Viewer_pcal1.png|thumb|<caption>Clean residuals after 100 iterations and the 1st phase only self-cal. Residuals inside mask are higher than the "noise" outside.</caption>]]<br />
</figure><br />
<br />
Next clean the source again, to save time we can start with the clean mask from the last iteration. If you make interactive adjustments to the clean mask, they will be written to the '''new''' mask TWHydra_contall_1pcal.mask, and not the old one. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_1pcal.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall_1pcal',<br />
mode='mfs',imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5, <br />
mask='TWHydra_contall.mask',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
Now after the first 100 iterations you see that the residuals inside the clean mask are higher than those outside. This is because flux that had been spread out in the map due to poorly correlated phases has been placed where it belongs on the source, thereby increasing its flux. You may also notice that your original clean mask is a little too small. If so, you can make it a bit larger, just by drawing a new polygon around the area you want to include. When you double click, it will incorporate the new mask into the current mask (if your box goes awry you can use the erase toggle [radio button] to erase and redo the mask). The new mask area need not overlap the original mask (though for this source it probably will). You might also want to use the magnifying glass to zoom in. Again, you assign mouse buttons by clicking on the icon you want. Clean another 100 iterations (for a total of 200) and stop by clicking the red X.<br />
<br />
Now open initial and 1st self-cal images to compare them using {{imview}}. This is an alternative version of the {{viewer}} that is somewhat scriptable. <br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(raster=[{'file':'TWHydra_contall.image','range':[-0.01,0.05]},<br />
{'file':'TWHydra_contall_1pcal.image','range':[-0.01,0.05]}])<br />
</source><br />
<br />
Once the Viewer Display panel opens, click on the box next in the "Images" panel and then use the tapedeck buttons in the panel to alternate between the two images. Because the range was explicitly set, they are on the same color scale. It is obvious that the self-calibrated image is better. To quantify, 1st toggle back to "normal" and then draw a region that excludes the central source with the polygon tool and then double click inside (if you stay in the "Images" view, only the statistics for the last image opened will appear on the terminal instead of both). The basic statistics of the polygon region will print to the '''terminal''':<br />
<br />
<pre style="background-color: #fffacd;"><br />
TWHydra_contall.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2357 -9.434800e-01 -2.858690e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-4.002885e-04 7.906752e-03 7.898289e-03 -2.541723e-02 2.172779e-02 <br />
<br />
TWHydra_contall_1pcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2357 6.326584e-01 1.916918e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
2.684168e-04 3.655786e-03 3.646692e-03 -1.215155e-02 1.109403e-02 <br />
</pre><br />
<br />
The self-calibrated image has more than a factor of 2 lower rms noise!<br />
<br />
====2nd Round of Continuum Data Phase Self-calibration====<br />
<br />
Now that we have a better model, we solve for solutions again. This time we will try making the solint smaller -- the integration time is about 10 seconds, so we set '''solint='int'''' to have it use the integration time.<br />
<br />
<figure id="Self_2_phase.png"><br />
[[Image:Self_2_phase.png|thumb|<caption>Phase solutions from self_2.pcal with solint='int'.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='TWHydra_cont.ms',caltable='self_2.pcal',<br />
solint='int',combine='',gaintype='T',<br />
refant='DV06',spw='',minblperant=4,<br />
calmode='p',minsnr=2)<br />
</source><br />
<br />
Now plot the new solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_2.pcal',xaxis='time',yaxis='phase',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,-80,80],figfile='self_2_phase.png')<br />
</source><br />
<br />
The phases on this shorter '''solint''' still seem to be tracking well so we will apply it and make a new image and check to see if there is improvement. <br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_cont.ms',field='',gaintable=['self_2.pcal'],calwt=F)<br />
</source><br />
<br />
<figure id="Viewer_pcal2.png"><br />
[[Image:Viewer_pcal2.png|thumb|<caption>Clean residuals after 2nd phase only self-cal and 250 iterations. The residuals inside the clean mask are lower than those outside, so its time to stop.</caption>]]<br />
</figure><br />
<br />
Now clean again, updating '''mask''' with the most recent mask file.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_2pcal.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall_2pcal',<br />
mode='mfs',imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5,usescratch=False,<br />
mask='TWHydra_contall_1pcal.mask',<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
After 200 iterations<br />
<br />
<pre style="background-color: #fffacd;"><br />
Model 0: max, min residuals = 0.00489776, -0.00464541 clean flux 1.44461<br />
</pre><br />
<br />
It looks like it could use just a little more cleaning, so set '''iterations=50 in the GUI'''.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Clean used 50 iterations to approach a threshhold of 0.0015067<br />
0.0107122 Jy <- cleaned in this cycle for model 0 (Total flux : 1.45532Jy)<br />
Final maximum residual = 0.00326382<br />
Model 0: max, min residuals = 0.00326382, -0.00321361 clean flux 1.45532<br />
</pre><br />
<br />
The small amount of flux cleaned this cycle indicates that clean is converging and it's about time to stop. Also the residuals inside the clean mask are now smaller than the residuals outside (i.e. the noise) also indicating it's time to stop by hitting the red X on the GUI.<br />
<br />
Now repeat the display, blinking, and image statistics steps described above for the 1st and 2nd phase-only self-cal iterations.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(raster=[{'file':'TWHydra_contall_1pcal.image','range':[-0.01,0.05]},<br />
{'file':'TWHydra_contall_2pcal.image','range':[-0.01,0.05]}])<br />
</source><br />
<br />
The difference is small:<br />
<pre style="background-color: #fffacd;"><br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2466 4.611597e-02 1.397287e-03 <br />
Mean Rms Std dev Minimum Maximum <br />
1.870072e-05 3.831524e-03 3.832255e-03 -1.414417e-02 1.109403e-02 <br />
<br />
TWHydra_contall_2pcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2466 1.159416e-01 3.512963e-03 <br />
Mean Rms Std dev Minimum Maximum <br />
4.701606e-05 3.811716e-03 3.812199e-03 -1.383034e-02 1.078456e-02 <br />
</pre><br />
<br />
This small improvement suggests that we have gone as far as we can with phase self-cal.<br />
<br />
===Continuum Data Amplitude Self-Calibration===<br />
<br />
Now we will apply the best phase solution table on-the-fly while solving for the amplitude self-cal solutions. Since amplitude changes more slowly and is less constrained than phase, we use a longer '''solint='inf'''', as long as '''combine=' '''' this means to do one solution per scan. <br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='TWHydra_cont.ms',caltable='self_ap.cal',<br />
solint='inf',combine='',gaintype='T',<br />
refant='DV06',spw='',minblperant=4,<br />
gaintable=['self_2.pcal'],<br />
calmode='ap',minsnr=2)<br />
</source><br />
<br />
It's useful to look at the residual phase in the amplitude calibration table, i.e. since we applied our best phase-only solution while solving for this new amplitude and phase ('''calmode='ap'''') solution, the phase should already be corrected.<br />
<br />
<figure id="Self_ap_phase.png"><br />
[[Image:Self_ap_phase.png|thumb|<caption>Residual phase solutions from self_ap.cal.</caption>]]<br />
</figure><br />
<figure id="Self_ap_amp.png"><br />
[[Image:Self_ap_amp.png|thumb|<caption>Amplitude solutions from self_ap.cal.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_ap.cal',xaxis='time',yaxis='phase',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,-1,1],figfile='self_ap_phase.png')<br />
</source><br />
<br />
The residuals are very small as expected. (If you see large residuals here, it means that the phase-only solution is suspect, and you were mostly just moving noise around.) Now look at the amplitude solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_ap.cal',xaxis='time',yaxis='amp',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,0.6,1.4],figfile='self_ap_amp.png')<br />
</source><br />
<br />
For the most part these look very good except one rather large deviation on DV06. Apply both the final phase and the amplitude calibration tables.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_cont.ms',field='',gaintable=['self_2.pcal','self_ap.cal'],calwt=F)<br />
</source><br />
<br />
Plot the corrected data as a function of both time and uv-distance. It is always a good idea to check these after an amplitude self-calbration to be sure that it worked properly. Occasionally, a few spurious bits of data will get blown up by the amplitude self-cal if it is not well-constrained. <br />
<br />
<figure id="Selfcal_time.png"><br />
[[Image:Selfcal_time.png|thumb|<caption>Post self-calibration amplitude vs. time</caption>]]<br />
</figure><br />
<figure id="Selfcal_uvdist.png"><br />
[[Image:Selfcal_uvdist.png|thumb|<caption>Post self-calibration amplitude vs. uv-distance</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',xaxis='time',yaxis='amp',<br />
avgchannel='38',ydatacolumn='corrected',coloraxis='spw',<br />
plotfile='selfcal_time.png')<br />
</source><br />
<br />
The time where we saw a large amplitude correction on DV06 looks consistent here so the large correction we saw in the solutions corrected a real issue. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',xaxis='uvdist',yaxis='amp',<br />
avgchannel='38',ydatacolumn='corrected',coloraxis='spw',<br />
plotfile='selfcal_uvdist.png')<br />
</source><br />
<br />
You will see that this plot looks much better than before. <br />
<br />
<figure id="Viewer_apcal.png"><br />
[[Image:Viewer_apcal.png|thumb|<caption>Clean residuals after final amplitude and phase self-cal.</caption>]]<br />
</figure><br />
<br />
Now make the final continuum image.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_apcal.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall_apcal',<br />
mode='mfs',imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5,usescratch=False,<br />
mask='TWHydra_contall_2pcal.mask',<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
We know we need to clean at least 300 iterations, so set this in the gui and hit the round green arrow. After this notice how much better the residual looks. Clean another 100 iterations. The "circular pattern", and 4 bright spots at each corner you see now in the residual is likely due to non-closing amplitude errors that cannot be removed with an antenna based self-calibration, so this is as good as it gets with pure self-cal. Hit the Red X to stop clean.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Clean used 100 iterations to approach a threshhold of 0.00105507<br />
0.0061808 Jy <- cleaned in this cycle for model 0<br />
Final maximum residual = 0.00242926<br />
Model 0: max, min residuals = 0.00238278, -0.00242926 clean flux 1.48201<br />
</pre><br />
<br />
Now repeat the display, blinking, and image statistics described above for the 2nd phase only and the new amplitude & phase self-cal'ed images.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(raster=[{'file':'TWHydra_contall_2pcal.image','range':[-0.01,0.05]},<br />
{'file':'TWHydra_contall_apcal.image','range':[-0.01,0.05]}])<br />
</source><br />
<br />
The amplitude and phase self cal'ed image is notably better than phase-only. Quantitatively:<br />
<pre style="background-color: #fffacd;"><br />
<br />
TWHydra_contall_2pcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 3542 2.053068e-01 6.220676e-03 <br />
Mean Rms Std dev Minimum Maximum <br />
5.796351e-05 3.955967e-03 3.956101e-03 -1.383034e-02 1.078456e-02 <br />
<br />
TWHydra_contall_apcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 3542 6.044652e-04 1.831495e-05 <br />
Mean Rms Std dev Minimum Maximum <br />
1.706565e-07 1.270183e-03 1.270362e-03 -4.980673e-03 4.137159e-03 <br />
</pre> <br />
<br />
and indeed, we've gained another factor of 3 in sensitivity. <br />
<br />
'''Overall with this self-calibration we've improved the noise by a factor of 6.7! With a peak flux density of 0.98 Jy, the S/N increased from 115 initially to 770 after. So, well worth the trouble.'''<br />
<br />
<div class="noprint" style="float:none; border:0px solid blue;background-color:#F6CEF5;padding:2px;"><br />
If you have used the '''standard='Butler-JPL-Horizons 2012' ''' model during the calibration process, you should see an increase in peak flux density of about 3%.<br />
</div><br />
<br />
It is notable that we are still a factor of more than 4 from the apriori noise estimate of 0.3 mJy/beam. This is likely due to residual sources of non-closing (not antenna based) errors in the data like baseline errors and baseline-dependent bandpass errors. Additionally, polarization errors (which we did not calibrate at all) can contribute, as well as imperfect uv-coverage with only 8 antennas. A dynamic range of 770 is actually quite good in the submillimeter.<br />
<br />
==Apply self-calibration to Full Dataset and Split Line Data==<br />
<br />
Now apply the self-calibration derived from the continuum emission to the full unchannel-averaged data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_corrected.ms',gaintable=['self_2.pcal','self_ap.cal'],calwt=F)<br />
</source><br />
<br />
Split off the CO(3-2) spectral line data in spw=2 and the HCO+(4-3) data in spw=0 for further processing.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2.ms*')<br />
split(vis='TWHydra_corrected.ms',outputvis='TWHydra_CO3_2.ms',datacolumn='corrected',spw='2')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplus.ms*')<br />
split(vis='TWHydra_corrected.ms',outputvis='TWHydra_HCOplus.ms',datacolumn='corrected',spw='0')<br />
</source><br />
<br />
==Continuum Subtraction== <br />
<br />
Next we need to subtract the continuum emission from the spectral line data. It is best to do this in the uv-plane. The first step is to make a channel plot of the spectral data to get the line-free channel ranges for both spectral lines. Since the line emission is simple (one spectral line per spw) and there are more than enough line-free channels we do not need to be very precise just stay well away from the line and whenever possible it is best to chose line-free channel ranges on either side of the line for the best possible baseline subtraction. <br />
<br />
<figure id="CO3_2_channel.png"><br />
[[Image:CO3_2_channel.png|thumb|<caption>CO(3-2) line in channel space.</caption>]]<br />
</figure><br />
<figure id="HCOp4_3_channel.png"><br />
[[Image:HCOp4_3_channel.png|thumb|<caption>HCO+(4-3) in channel space.</caption>]]<br />
</figure><br />
<br />
'''Note''': after the split above, the original spw ids will be relabeled as 0 in each file because there is only one spectral window in each file.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_CO3_2.ms',spw='0',xaxis='channel',yaxis='amp',<br />
avgtime='1e8',avgscan=T,coloraxis='spw',plotfile='CO3_2_channel.png')<br />
</source><br />
<br />
It is a good idea to stay a little away from the very edges of the baseband which can be noisy. The channel ranges <br />
20~2000 and 2400~3800 look like good choices for CO(3-2).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_HCOplus.ms',spw='0',xaxis='channel',yaxis='amp',<br />
avgtime='1e8',avgscan=T,coloraxis='spw',plotfile='HCOp4_3_channel.png')<br />
</source><br />
<br />
The channel ranges 20~1500 and 1900~3800 look like good choices for HCO+(4-3).<br />
<br />
Next use the identified line-free channel ranges and {{uvcontsub}} to subtract the continuum model from the line emission.<br />
<br />
<source lang="python"><br />
# In CASA<br />
uvcontsub(vis='TWHydra_CO3_2.ms',fitorder=1,fitspw='0:20~2000,0:2400~3800')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
uvcontsub(vis='TWHydra_HCOplus.ms',fitorder=1,fitspw='0:20~1500,0:1900~3800')<br />
</source><br />
<br />
Note: If you do not have line-free channels on both sides of the line emission, it is safer to use '''fitorder=0''', or the fit may diverge.<br />
<br />
==Spectral Line Imaging==<br />
<br />
Now we are ready to make cubes of the line emission. The imaging parameters are similar to the continuum except for <br />
those dealing with the spectral setup: '''mode''', '''start''', '''width''', '''nchan''', '''restfreq''', and '''outframe''' parameters. When making spectral images you have three choices for the '''mode''' parameter: '''channel''', '''velocity''', and '''frequency'''. Data are taken using constant frequency channels. For spectral line analysis it's often more useful to have constant velocity channels, and this is also the best way to make images of multiple lines with the exact same channelization for later comparison. For '''mode='velocity'''', the desired '''start''' and '''width''' also need to be given in velocity units for the desired output frame. <br />
<br />
It is important to note that ALMA does not do on-line Doppler Tracking and the native frame of the data is TOPO. If you do not specify '''outframe''' the output cube will also be in TOPO, which is not very useful for spectral line work. The Doppler Shift is taken out during the regridding to the desired outframe in {{clean}} or alternatively it can be done separately by the {{cvel}} task which would need to be run before {{clean}}. <br />
<br />
<figure id="CO3_2_vel.png"><br />
[[Image:CO3_2_vel.png|thumb|<caption>CO(3-2) spectrum in LSRK velocity space.</caption>]]<br />
</figure><br />
<figure id="HCOp4_3_vel.png"><br />
[[Image:HCOp4_3_vel.png|thumb|<caption>HCO+(4-3) spectrum in LSRK velocity space.</caption>]]<br />
</figure><br />
<br />
To see what velocity parameters you want to set in clean it is useful to make a plot in {{plotms}} in the desired output frame. To make it easier to see, we set a '''plotrange''' since we know the LSRK velocity of TW Hya is about 2.88 km/s. Note these plots take a little longer because of the frame shift.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_CO3_2.ms.contsub',xaxis='velocity',yaxis='amp',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',<br />
restfreq='345.79599GHz',plotrange=[-20,23,0,0],plotfile='CO3_2_vel.png')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_HCOplus.ms.contsub',xaxis='velocity',yaxis='amp',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',<br />
restfreq='356.7342GHz',plotrange=[-20,23,0,0],plotfile='HCOp4_3_vel.png') <br />
</source><br />
<br />
From these plots it looks like imaging the cubes from about -5 to +8 km/s will encompass the line, but still provide several line-free channels on either side so the noise level can be estimated. The channel width is 122 kHz, which at <br />
345.79599 GHz is 0.106 km/s. Recall that the spectral ''resolution'' is a factor of two poorer. We will use a velocity channel width of 0.12 km/s for a little oversampling, but the spectral resolution remains 0.2 km/s.<br />
<br />
As before, it is very important that you make a clean mask. There are many ways to do this ranging from the complicated to simple. For this example we will make a single clean mask that encompasses the line emission in every channel and apply it to all channels. This is much better than no clean mask, though not quite as good as making an individual mask for each channel. For some sources, one can use the continuum mask to clean the line, however TW Hya is a bit curious in that the continuum emission is not as extended as the line emission (Hughes et al. 2008).<br />
<br />
=== CO(3-2) Imaging ===<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.*')<br />
clean(vis='TWHydra_CO3_2.ms.contsub',imagename='TWHydra_CO3_2line',<br />
imagermode='csclean',spw='',<br />
imsize=100,cell=['0.3arcsec'],<br />
mode='velocity',start='-4km/s',width='0.12km/s',nchan=118,<br />
restfreq='345.79599GHz',outframe='LSRK',<br />
weighting='briggs',robust=0.5,<br />
mask='',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=100000)<br />
</source><br />
<br />
<figure id="Viewer_55.png"><br />
[[Image:Viewer_55.png|thumb|<caption>Interactive Viewer window with CO(3-2) clean mask, before cleaning starts.</caption>]]<br />
</figure><br />
<figure id="Viewer_500.png"><br />
[[Image:Viewer_500.png|thumb|<caption>Interactive Viewer window for CO(3-2), after 500 iterations, more cleaning is needed.</caption>]]<br />
</figure><br />
<br />
It will take a little while to grid the cube, when the interactive viewer opens, use the tapedeck to cycle through the channels. You should see a progress of line emission in channels 40 to 70 or so.<br />
*Go to channel 57 (about line center)<br />
*Select the polygon tool with the left mouse button<br />
*Select the "All Channels" toggle in the green area<br />
*Draw a polygon around the channel 57 emission, double click inside to activate.<br />
*Now go to channel 60, this is the channel with the most extent to the SE, draw another polygon that encompasses this emission if necessary,double click inside to activate.<br />
*Now go to channel 55, this is the channel with the most extent to the NW, draw another polygon that encompasses this emission if necessary,double click inside to activate. <br />
*Now double check the mask by cycling through channels with real line emission to be sure that your clean box encompasses the emission, but does not extend far beyond it. Again the "erase" toggle can come in handy if things go awry or if you want to just delete a small portion of an existing mask (just draw a polygon around what you want to erase and double click inside), be sure to switch back to "add" before going on.<br />
<br />
The figure shows what the final clean box should look like. Now clean using the green circle arrow. You can watch the progress in the logger. When 100 iterations are done, the viewer will show the residual map for each channel. Cycle through the channels and see whether you are still happy with the clean box in each signal channel. The "erase button" can help you fix mistakes. If necessary adjust. It is often useful to adjust the colorscale with the "plus" symbol icon. Keep going until the residual emission looks like the surrounding noise. If it seems to be going slowly, increase the iterations to 300 for a round or two. I stopped cleaning (Red x) when the logger showed (about 900 iterations). <br />
<pre style="background-color: #fffacd;"><br />
12.9846 Jy <- cleaned in this cycle for model 0<br />
Final maximum residual = 0.157312<br />
Model 0: max, min residuals = 0.157312, -0.0871295 clean flux 279.304<br />
</pre><br />
<br />
NOTE: The residuals are still a bit high in the strongest emission channels after it is well cleaned in the weaker channels. This is an indication that the sensitivity is "dynamic range" limited. In other words even with more <br />
intrinsic sensitivity per integration (i.e. better system temperature), the dynamic range limit would remain the same unless you get more uv-coverage. The fundamental dynamic range limitations of ALMA will be considerably better with 16 antennas in Early Science and MUCH better with the full 50-antenna array.<br />
<br />
=== HCO+(4-3) Imaging ===<br />
<br />
Now image and clean the HCO+(4-3) line using what you learned above.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.*')<br />
clean(vis='TWHydra_HCOplus.ms.contsub',imagename='TWHydra_HCOplusline',<br />
imagermode='csclean',spw='',<br />
imsize=100,cell=['0.3arcsec'],<br />
mode='velocity',start='-4km/s',nchan=118,width='0.12km/s',<br />
restfreq='356.7342GHz',outframe='LSRK',<br />
weighting='briggs',robust=0.5,<br />
mask='',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=100000)<br />
</source><br />
<br />
I stopped cleaning when: <br />
<pre style="background-color: #fffacd;"><br />
4.79833 Jy <- cleaned in this cycle for model 0<br />
Final maximum residual = 0.0977348<br />
Model 0: max, min residuals = 0.0977348, -0.060484 clean flux 192.066<br />
</pre><br />
<br />
==Image Analysis==<br />
<br />
After all that hard work you now have deconvolved images of the 350 GHz continuum, the CO (3-2) line, and the HCO+ (4-3) line. CASA includes tools to help you understand the contents of these images and make basic scientific measurements. These tools are divided between graphical exploration tools, accessible via the CASA viewer, and command line analysis tasks. To access the viewer, simply type '''viewer()''' and to see the list of analysis tasks available in CASA type '''tasklist''' at the CASA prompt and look under the Analysis sub-heading.<br />
<br />
If you want to do this portion of the guide and have downloaded the (.FITS) reference images, you can import them to be CASA images using '''importfits'''. If you are re-importing the images, use the commented remove command, here, to delete the previous import first.<br />
<br />
<source lang="python"><br />
# In CASA<br />
# os.system("rm -rf TWHydra_CO3_2line.image")<br />
importfits(fitsimage="TWHydra_CO3_2line.image.fits", imagename="TWHydra_CO3_2line.image")<br />
</source><br />
<br />
where '''fitsimage''' refers to the file to imported and '''imagename''' gives the output filename. If you are proceeding directly from the imaging step, your data are already CASA images and you may proceed without any importing.<br />
<br />
You can get the basic properties of any CASA image using the '''imhead''' command. For example, type <br />
<br />
<source lang="python"><br />
# In CASA<br />
imhead("TWHydra_CO3_2line.image")<br />
</source><br />
<br />
and look at the CASA logger. You will see an image summary like the following<br />
<br />
<pre style="background-color: #fffacd;"><br />
INFO imhead ##########################################<br />
INFO imhead ##### Begin Task: imhead #####<br />
INFO imhead imhead(imagename="TWHydra_CO3_2line.image",mode="summary",hdkey="",hdvalue="",<br />
INFO imhead hdtype="",hdcomment="",verbose=False)<br />
INFO ImageAnalysis <br />
INFO ImageAnalysis Image name : TWHydra_CO3_2line.image<br />
INFO ImageAnalysis Object name : TW Hya<br />
INFO ImageAnalysis Image type : PagedImage<br />
INFO ImageAnalysis Image quantity : Intensity<br />
INFO ImageAnalysis Pixel mask(s) : None<br />
INFO ImageAnalysis Region(s) : None<br />
INFO ImageAnalysis Image units : Jy/beam<br />
INFO ImageAnalysis Restoring Beam : 1.68065 arcsec, 1.53193 arcsec, 22.3015 deg<br />
INFO ImageAnalysis <br />
INFO ImageAnalysis Direction reference : J2000<br />
INFO ImageAnalysis Spectral reference : LSRK<br />
INFO ImageAnalysis Velocity type : RADIO<br />
INFO ImageAnalysis Rest frequency : 3.45796e+11 Hz<br />
INFO ImageAnalysis Pointing center : 11:01:51.844983 -34.42.17.160885<br />
INFO ImageAnalysis Telescope : ALMA<br />
INFO ImageAnalysis Observer : Unknown<br />
INFO ImageAnalysis Date observation : 2011/04/22/00:15:42<br />
INFO ImageAnalysis Telescope position: [2.22514e+06m, -5.44031e+06m, -2.48103e+06m] (ITRF)<br />
INFO ImageAnalysis <br />
INFO ImageAnalysis Axis Coord Type Name Proj Shape Tile Coord value at pixel Coord incr Units<br />
INFO ImageAnalysis -------------------------------------------------------------------------------------------------- <br />
INFO ImageAnalysis 0 0 Direction Right Ascension SIN 100 25 11:01:51.845 50.00 -3.000000e-01 arcsec<br />
INFO ImageAnalysis 1 0 Direction Declination SIN 100 25 -34.42.17.161 50.00 3.000000e-01 arcsec<br />
INFO ImageAnalysis 2 2 Spectral Frequency 118 59 3.45801e+11 0.00 -1.38414152e+05 Hz<br />
INFO ImageAnalysis Velocity -4 0.00 1.200000e-01 km/s<br />
INFO ImageAnalysis 3 1 Stokes Stokes 1 1 I<br />
INFO imhead ##### End Task: imhead #####<br />
INFO imhead ##########################################<br />
<br />
</pre><br />
<br />
This report tells you about the target, shape, and coordinates of the image. It also notes the rest frequency and some details of the observation. '''imhead''' may be used more generally to retrieve header keywords as python variables or to manipulate the header of an image. Consult the help for details.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
You may want to pay particular attention to the third and fourth axis of the CASA image. These are <br />
usually frequency (velocity) and Stokes (polarization) in some order. An occasional source of confusion <br />
is that this order is not always the same. Often CLEAN will output images with the Stokes axis third, <br />
while IMPORTFITS usually yields images with the frequency axis third. If you encounter problems with<br />
image analysis tasks, you may want to check whether this results from conflicting axis definitions. You<br />
can adjust the order of the axes using the IMTRANS task.<br />
</pre><br />
<br />
Before proceeding, make sure that you have all three data sets as CASA images: '''TWHydra_CO3_2line.image''', '''TWHydra_HCOPlusline.image''', and '''TWHydra_contall_apcal.image'''. If you do not, then import them from the provided reference images. If you are re-importing the FITS images, run the commented remove commands before running importfits.<br />
<br />
<source lang="python"><br />
# In CASA<br />
# os.system("rm -rf TWHydra_CO3_2line.image")<br />
importfits(fitsimage="TWHydra_CO3_2line.image.fits", imagename="TWHydra_CO3_2line.image")<br />
# os.system("rm -rf TWHydra_HCOplusline.image")<br />
importfits(fitsimage="TWHydra_HCOplusline.image.fits", imagename="TWHydra_HCOplusline.image")<br />
# os.system("rm -rf TWHydra_contall_apcal.image")<br />
importfits(fitsimage="TWHydra_contall_apcal.image.fits", imagename="TWHydra_contall_apcal.image")<br />
</source><br />
<br />
In the rest of this guide we will construct ''moment maps'' showing the integrates, velocity field, and line width of the two lines. We will carry out Gaussian fits to the continuum and line maps. We will also illustrate some of the additional analysis capabilities available in CASA: subcube extraction, retrieval of data into python arrays, cube alignment, smoothing, and overlays of multiple spectral lines.<br />
<br />
===Moment Maps===<br />
<br />
The line "images" of CO(3-2) and HCO+(4-3) are, of course, cubes rather than images. Two dimensional ''moment maps'' are a standard way to present such data. These are maps showing the result of various moments (or similar calculations) carried out along the frequency axis of the cube. For example, the "moment 0" map is the sum of emission along the frequency axis at each pixel. The first moment is the intensity-weighted velocity (or frequency). The second moment is the intensity-weighted velocity (or frequency) dispersion about the mean. These and a number of other calculations (for example the maximum intensity) can be calculated via the '''immoments''' task. Consult the help or the CASA cookbook for more details.<br />
<br />
In this section, we will calculate moments for our two spectral line data cubes. To make the highest quality moment maps, we will first identify the planes of the data cube that contain emission, so that we can carry out the sum only over these channels. Doing otherwise adds noise to the moment map without adding signal and so lowers the signal-to-noise ratio of the final image. For the first and second moments we will identify an intensity threshold above which the data are statistically very likely to correspond to real astronomical emission. We will restrict the calculation to consider only data above this threshold, yielding a cleaner calculation (the second moment, in particular, is not at all robust against the inclusion of outlying noise). Finally, we will inspect the resulting moment maps with the viewer and output them to .FITS files.<br />
<br />
====Estimate the Spectral Extent====<br />
<br />
First, we want to figure out what planes appear to contain real emission. Open the CO data cube with the CASA viewer via:<br />
<br />
<source lang="python"><br />
# In CASA<br />
viewer("TWHydra_CO3_2line.image")<br />
</source><br />
<br />
This will open the CO(3-2) data cube as a raster image. Use the Animator pane to scroll through the cube, noting that the emission is mostly confined to ~40 channels near the center of the cube. There are several ways to make a more rigorous estimate. <br />
<br />
''By-Plane Inspection:'' First, you could increase the stretch of the image to identify by hand the first and last channels with visible emission. To do open the Data Display Options panel in the viewer (the wrench icon) and manually set the data range and/or scaling power cycles to highlight faint emission (note that you can also do this using the mouse and the color stretch - sun - icon). I left the scaling power cycles at 0 and set the data range to [-0.15, 0.15]. Then scroll through the cube and note the first and last channels with obvious emission. If I do this, I find emission from about plane 30 through plane 86.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:DataDisplayPanelStretch.png|The Data Display Panel used to set the color stretch, here from [-0.15, 0.15] with a linear (0) stretch. Setting the stretch to a negative value will highlight lower emission (a more logarithmic stretch). We got to this panel by clicking the wrench icon. You can also get from the dropdown menus (Data->Adjust).<br />
File:TWHydraCOChan33.png|Channel 33 of the CO(3-2) cube on this stretch. This is about the first channel to show clear emission.<br />
File:TWHydraCOChan80.png|Channel 80 of the CO(3-2) cube on this stretch. This is about the last channel to show clear emission.<br />
</gallery><br />
</center><br />
<br />
To make this more rigorous, you can work out a noise estimate before hand (we'll find it to be about 0.025 Jy/beam) and overplot a contour to indicate significant emission. You can do this by hand by using the Data Manager (folder icon) to open TWHydra_CO3_2line.image as a "contour map" and then using the Data Display Options to manipulate the contour levels. To show a 3-sigma contour with sigma=0.025 Jy/beam set the Relative Contour Levels to [3], the Base Contour Level to 0, and the Unit Contour Level to 0.025. You can display a 5-sigma contour or change the RMS analogously. Scrolling through the cube, I see 3-sigma emission from channels 33 through 80.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:DataDisplayPanelContour.png|The Data Display Panel now being used to set the contour levels. We set the contour unit to 0.025 and ask for a single contour at 3 times this value. Notice that we clicked the tab along the top of the window to select the contour map.<br />
File:TWHydraCOChan33Contour.png|Channel 33 of the CO(3-2) cube on this stretch with a 3-sigma contour overlaid.<br />
File:TWHydraCOChan80Contour.png|Channel 80 of the CO(3-2) cube on this stretch with a 3-sigma contour overlaid.<br />
</gallery><br />
</center><br />
<br />
''Look at a Spectrum:'' You can also look at a spectrum of the source. To do this, scroll to a channel with a lot of emission (I went to 57) and then use the mouse to drag out a rectangle. To do this, left click on the rectangle box in the mouse toolbar (this assigns the left mouse button to define rectangle regions). Then drag out a box around the emission using the same button. Now click the spectrum in the toolbar to open the spectral profile tool. You will see the average profile for the selected region. You can set the bottom axis to show channels. You can zoom in within the spectral profile by dragging out a rectangle. When I do this, I find significant emission from channels 40-80.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:TWHydraRectangle.png|Defining a rectangular region around the main emission from TW Hydra. First we clicked the rectangle button on the mouse toolbar, then we held that button and dragged out the purple rectangle. After defining the rectangle, you can drag it around or delete it with <ESC>.<br />
File:TWHydraSpectrum.png|The spectrum of this rectangular region viewed in the spectral profile browser. Note that the bottom axis has been set to show channels. To get this spectrum, we defined the rectangular region and then clicked the spectrum button on the toolbar.<br />
File:TWHydraSpectrumZoom.png|A zoom in on the spectrum. The line extends from channels ~40-80.<br />
</gallery><br />
</center><br />
<br />
''Look at a Declination-Frequency Projection (or an R.A.-Frequency Projection):'' This is probably the least reliable way to do this, but illustrates a neat capability of the viewer. Open the Data Display Options (click the wrench icon) and open the "display axes" and "hidden axes" tabs. Use the dropdown menus to change the display so that the x-axis shows Declination, the y-axis shows Frequency, and the z-axis shows "Right Ascension." Now you are scrolling through planes of intensity as a function of Declination and Frequency. Use the animator to move to R.A. plane ~ 50 (the center of the source) and pull the stretch up (in the wrench tool; I used [-0.15,0.15] again). Mouse over the image and look at the "Position Tracking" pane in the bottom of the image, noting the pixel extent of emission in the frequency axis of this plane. I see traces of emission from channel ~30-90.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:DataDisplayPanelAxes.png|The Data Display Panel, here used to set which axes are displayed. We have adjusted the y-axis to show frequency and the x-axis to show Declination. The z-axis is now Right Ascension, so that we will scroll through planes of Right Ascension.<br />
File:DataDisplayPanelPixels.png|The Data Display Panel, here we are setting coordinates to show "pixels" rather than world coordinates.<br />
File:TWHydraDecFreqPixels.png|A Frequency-Declination plane of the cube near the central R.A. pixel (50). The rough extent of emission may be simply read off the y-coordinate. As above, we could overplot a 3-sigma contour to add more rigor.<br />
</gallery><br />
</center><br />
<br />
<br />
You can repeat this exercise for the HCO+ (4-3) emission. Using the Spectral Profile Browser, I find that the line extends from about channel 40 through channel 75.<br />
<br />
====Make Moment 0 Maps====<br />
<br />
With an estimate of the spectral extent of emission, we are now ready to make moment 0 maps of the CO(3-2) and HCO+(4-3) lines. We do this using the '''immmoments''' command,<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom0')<br />
immoments(imagename='TWHydra_CO3_2line.image',moments=[0],<br />
outfile='TWHydra_CO3_2line.image.mom0',<br />
chans='30~90')<br />
</source><br />
<br />
and<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom0')<br />
immoments(imagename='TWHydra_HCOplusline.image',moments=[0],<br />
outfile='TWHydra_HCOplusline.image.mom0',<br />
chans='40~75')<br />
</source><br />
<br />
immoments will sum across the channels specified by '''chans''' and produce new CASA images with the names specified by '''outfile'''. These can be inspected using the CASA viewer just like any other image. Note that unlike higher-order moments, the moment-0 map is robust to the inclusion of noisy signal-free channels (to within reason, you just decrease your signal-to-noise ratio) and indeed may be biased to miss faint emission by imposing a threshold. For that reason, we will eschew the '''includepix''' keyword as we make the moment 0 maps.<br />
<br />
Let's look at the output using the viewer. We can specify some of the display options in the call to start the viewer by using '''imview''' instead of '''viewer'''.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview( raster=[ {'file':'TWHydra_CO3_2line.image.mom0',<br />
'range':[0.0,10.],<br />
'scaling':-1},<br />
{'file':'TWHydra_HCOplusline.image.mom0',<br />
'range':[0.0,10.],<br />
'scaling':-1}], <br />
contour={'file':'TWHydra_contall_apcal.image', 'base':0, 'unit':0.0025, 'levels':[3,100]} )<br />
</source><br />
<br />
This does several things: It opens the viewer with raster images of the moment 0 maps of CO(3-2) and HCO+(4-3), sets the range of the color stretch from [0, 10] for each image and sets the scaling to be -1, which highlights faint emission compared to the normal (0) stretch. It also opens the continuum image as a contour and defines two contour levels. Once the viewer is open, you can blink between the images by going into the Animator pane, checking the white box next to "Images" to enable animation between images, and then sliding the bar back and forth. See the name of the image being shown change. You can also show two images side by side by going to the Viewer Canvas Manager (wrench+P icon) and opening the "Number of Panels" tab. Set the "Number of panels in x" to 2 and make sure that the Images box is checked in the Animator pane. You will see both images side by side.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:CanvasManagerPanels.png|The Viewer Canvas Manager, accessed via the Wrech+P icon (not to be confused with the plain old wrench). Here we have adjusted the number of x-panels from 1 to 2 so that we show the two moment maps side by side.<br />
File:TWHydraMoment0Maps.png|The moment-0 maps of CO(3-2) and HCO+(4-3) plotted side by side on the same color stretch, both with the continuum contours overlaid. To get the two images side by side, run the imview call above then set the number of panels to 2 and make sure that the Images box in the Animator Pane (here at the bottom of the window) is checked.<br />
File:DataDisplayImview.png|Data Display Panel after our imview call. Imview allowed us to set the stretch, range, and contour levels from the command line.<br />
</gallery><br />
</center><br />
<br />
====Estimate the Noise====<br />
<br />
We have already made a few offhand comparisons to the RMS noise. This quantity is often critical to know when exploring the data. Because the higher-order moments (especially the dispersion) are not at all robust to the inclusion of noise, we will calculate them only from regions of the cube that have intensity several times the RMS noise value or higher and are thus very likely to contain real astronomical emission. To proceed, we need to estimate the RMS noise for our data.<br />
<br />
The easiest way to do this is to calculate the RMS scatter of the data about zero from a part of the data that you suspect to be (mostly) free of astronomical signal. In a data cube the easiest way to do this will often be to identify signal-free planes (channels) of the cube and to simply calculate the RMS in these regions. We can do this straightforwardly using the '''imstat''' command in CASA.<br />
<br />
IMSTAT COMMAND<br />
<br />
IMSTAT OUTPUT<br />
<br />
Alternatively, you can get similar statistics on a region of an image or data cube selected manually inside the viewer. Drag out a region, for example a rectangle, using one of the mouse tools. Then <br />
<br />
IMAGES OF REGION SELECTION, OUTPUT, REGION MANAGER<br />
<br />
Suggested values for CO(3-2), HCO+(4-3), and continuum. Short discussion of dynamic range limited vs. line-free channels.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
A note on primary beam corrections and noise.<br />
</pre><br />
<br />
====Higher Order Moment Maps for CO(3-2)====<br />
<br />
For higher order moments it is very important to set a conservative flux <br />
threshold. Typically something like 6 sigma, using sigma from peak line channel, works well.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom')<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_coord')<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_dispersion_coord')<br />
immoments(imagename='TWHydra_CO3_2line.image',moments=[1,2],<br />
outfile='TWHydra_CO3_2line.image.mom',<br />
chans='40~76',includepix=[0.3,100])<br />
</source><br />
<br />
Display all three moment maps in the viewer, overlaid with continuum contours.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview( raster=[ {'file':'TWHydra_CO3_2line.image.mom0'},<br />
{'file':'TWHydra_CO3_2line.image.mom.weighted_coord'},<br />
{'file':'TWHydra_CO3_2line.image.mom.weighted_dispersion_coord'} ], <br />
contour={'file':'TWHydra_contall_apcal.image', 'base':0, 'unit':0.0025, 'levels':[3,100]} )<br />
</source><br />
<br />
To see all three raster images simultaneously, open the viewer's Panel Display Options (the "P-wrench" icon in the viewer tool bar), click "Number of panels", and change "Number of panels in x" to 3. Then select the "Blink" toggle (radio button) from the Animator panel.<br />
<br />
<figure id="TWHya_CO3_2_moments.png"><br />
[[Image:TWHya_CO3_2_moments.png|center|800px|frame|<caption>ALMA CO(3-2) moment maps, with white continuum contours at 3 and 100 sigma. From left to right: integrated intensity, intensity weighted velocity field, intensity weighted velocity dispersion are shown.</caption>]]<br />
</figure><br />
<br />
Repeat for HCO+(4-3) which has a bit narrower velocity extent than the CO(3-2), but similar rms noise.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom0')<br />
immoments(imagename='TWHydra_HCOplusline.image',moments=[0],<br />
outfile='TWHydra_HCOplusline.image.mom0',<br />
chans='43~74')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom')<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_coord')<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_dispersion_coord')<br />
immoments(imagename='TWHydra_HCOplusline.image',moments=[1,2],<br />
outfile='TWHydra_HCOplusline.image.mom',<br />
chans='43~74',includepix=[0.3,100])<br />
</source><br />
<br />
Display all three moment maps in the viewer using the same method described above for the CO(3-2) maps.<br />
<br />
<figure id="TWHya_HCOp4_3_moments.png"><br />
[[Image:TWHya_HCOp4_3_moments.png|center|800px|frame|<caption>ALMA HCO+(4-3) moment maps, with white continuum contours at 3 and 100 sigma. From left to right: integrated intensity, intensity weighted velocity field, intensity weighted velocity dispersion are shown.</caption>]]<br />
</figure><br />
<br />
=====Exporting Fits Images=====<br />
<br />
If you want to analyze the data using another software package it is easy to convert from CASA format to FITS. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image',fitsimage='TWHydra_CO3_2line.image.fits')<br />
</source><br />
<br />
Although "FITS format" is supposed to be a standard, in fact most packages expect slightly different things from a FITS image. If you are having difficulty, try setting '''velocity=T''' and/or '''dropstokes=T'''.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf TWHydra_HCOplusline.image.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image',fitsimage='TWHydra_HCOplusline.image.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom0.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image.mom0',<br />
fitsimage='TWHydra_CO3_2line.image.mom0.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_coord.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image.mom.weighted_coord',<br />
fitsimage='TWHydra_CO3_2line.image.mom.weighted_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_dispersion_coord.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image.mom.weighted_dispersion_coord',<br />
fitsimage='TWHydra_CO3_2line.image.mom.weighted_dispersion_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom0.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image.mom0',<br />
fitsimage='TWHydra_HCOplusline.image.mom0.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_coord.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image.mom.weighted_coord',<br />
fitsimage='TWHydra_HCOplusline.image.mom.weighted_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_dispersion_coord.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image.mom.weighted_dispersion_coord',<br />
fitsimage='TWHydra_HCOplusline.image.mom.weighted_dispersion_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_apcal.image.fits')<br />
exportfits(imagename='TWHydra_contall_apcal.image',fitsimage='TWHydra_contall_apcal.image.fits')<br />
</source><br />
<br />
===Display Channel Maps===<br />
<br />
Using the Viewer you can make channel map figures. Start the Viewer and then open the CO(3-2) cube as a raster image and then the continuum as a contour image. Then we use the "wrench" icon and "P wrench" icons to set up the channel images, contour levels etc. (If you need help setting up the viewer for this image, see a screen shot of the viewer setup windows, below.)<br />
<br />
<figure id="TWHya_channel_co3_2.png"><br />
[[Image:TWHya_channel_co3_2.png|center|frame|<caption>Channel maps of the CO(3-2) emission with white continuum contours at 3 and 100 sigma.</caption>]]<br />
</figure><br />
<br />
<figure id="Viewer_setup.png"><br />
[[Image:Viewer_setup.png|center|thumb|500px|<caption>The setup windows looked like this</caption>]]<br />
</figure><br />
<br />
Repeat for HCO+(4-3)<br />
<br />
<figure id="TWHya_channel_HCOp4_3.png"><br />
[[Image:TWHya_channel_HCOp4_3.png|center|thumb|800px|<caption>Channel maps of the HCO+(4-3) emission with white continuum contours at 3 and 100 sigma. The color intensity scale is the same as that used for CO(3-2).</caption>]]<br />
</figure><br />
<br />
<!--<br />
====Examine CO Contours on an HCO+ Raster====<br />
<br />
====Matched Movies====<br />
<br />
===Image Plane and Spectral Fits===<br />
<br />
====Fit a Gaussian to the Continuum====<br />
<br />
=====Fit In the Viewer=====<br />
<br />
=====Fit Using the Command Line=====<br />
<br />
====Fit a Gaussian to the CO Line====<br />
<br />
=====Fit In the Viewer=====<br />
<br />
=====Fit Using the Command Line=====<br />
<br />
===Extract a Sub-Image===<br />
<br />
===Align Image Cubes===<br />
--><br />
<br />
{{Checked 4.5.0}}</div>Sstierwahttps://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_4.5&diff=19489TWHydraBand7 Imaging 4.52016-05-18T05:49:20Z<p>Sstierwa: </p>
<hr />
<div>[[Category:ALMA]][[Category:Imaging]][[Category:Spectral Line]]<br />
<br />
* '''This tutorial picks up where '''[[TWHydraBand7_Calibration_4.5]]''' leaves off, with fully calibrated, split science target MS. If you wish to skip the Calibration guide: obtain the calibrated data from [[TWHydraBand7#Getting_the_Data]]; extract it using <tt>tar -xzvf FILENAME</tt>; and <tt>cd</tt> into the extracted directory.'''<br />
<br />
*'''This guide is designed for CASA 4.5.2. If you are using an older version of CASA please see [[TWHydraBand7_Imaging_4.3]].<br />
<br />
* '''Details of the ALMA data are provided at [[TWHydraBand7]]'''<br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.5.2. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.5.0'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
== Prepare Continuum Data for Further Processing==<br />
<br />
In order to speed up imaging/self-calibration for the continuum data we will average channels together, and then flag the few spectral features. This method works well in the case of only a few spectral lines, while retaining enough channelization to aid in multi-frequency synthesis and being able to remove spectral features in the averaged data. The amount of channel averaging should be adjusted to your particular data. '''Note for wide bandwidth data it is never a good idea to use the continuum estimate generated by uv-continuum subtraction as your continuum data'''. This worked OK in the past with the narrow band systems like the VLA and low dynamic range instruments like the SMA, but is not advised for ALMA wide bandwidth, high dynamic range data. <br />
<br />
<figure id="Cont_spw2.png"><br />
[[Image:Cont_spw2.png|thumb|<caption>CO(3-2) in spw=2 from the "continuum" channel averaged data.</caption>]]<br />
</figure><br />
<figure id="Cont_spw3.png"><br />
[[Image:Cont_spw3.png|thumb|<caption>Notice upswing at high channel numbers in spw=3.</caption>]]<br />
</figure><br />
<br />
One can also flag the spectral features first but in that case make a backup of the file that is analogous to TWHydra_corrected.ms as you will need it later (unflagged) for spectral line imaging. We begin by excluding ~20 channels on each edge, and averaging over 100 channel intervals:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_cont.ms*')<br />
split(vis='TWHydra_corrected.ms',outputvis='TWHydra_cont.ms',<br />
spw='0~3:21~3820',width=100,datacolumn='data')<br />
</source><br />
<br />
Now make a plot of amplitude vs. channel to see what needs to be flagged<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',spw='0~3',xaxis='channel',yaxis='amp',<br />
avgtime='1e8',avgscan=T,coloraxis='spw',iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
The CO(3-2) and HCO+(4-3) lines are obvious. The 4th spw; spw=3 also shows an upswing on the highest channels that is problematic, it was seen on the calibrators too and is likely due to a weak atmospheric feature, we will flag the worst of it.<br />
<br />
<figure id="Cont_uvplot.png"><br />
[[Image:Cont_uvplot.png|thumb|<caption>UV-plot of the continuum emission, colors show spws.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='TWHydra_cont.ms', mode='manual', <br />
spw='0:16~16, 2:21~21, 3:33~37')<br />
</source><br />
<br />
Have a look at the continuum as a function of uv-distance (in the plot to the right, the 4 spw are shown in different colors on top of each other). If the data are flat as a function of uv-distance, the source is completely unresolved. If instead you see structure (in this case decreasing amplitude with uv-distance), the source is resolved. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',spw='',xaxis='uvdist',yaxis='amp',field='',avgchannel='38',<br />
coloraxis='spw',plotfile='cont_uvplot.png')<br />
</source><br />
<br />
Notice that the spw do not have the same amplitude. Unfortunately, the red spw (highest frequency) should be higher than the green one (lowest frequency) because optically thin dust goes as nu^4, and optically thick as nu^2. This inconsistency is due to imperfect amplitude/absolute flux calibration. The self-calibration below will bring them into agreement with each other, but this is the sort of thing that results in considerable absolute flux uncertainty at submillimeter wavelengths. We are working on how to do this better.<br />
<br />
==A priori Noise Estimates==<br />
<br />
<figure id="Corrected_time.png"><br />
[[File:Corrected_time.png|thumb|<caption>Plot for estimating time.</caption>]]<br />
</figure><br />
<figure id="sensitivity_cont.png"><br />
[[File:sensitivity_cont.png|thumb|<caption>Sensitivity calculator setup with observed continuum parameters for these observations.</caption>]]<br />
</figure><br />
<br />
To estimate what the expected noise levels are, we first need to know how much time we had on source. Looking at <br />
a plot of amplitude vs time for the concatenated but pre-split data (see below) there are 9x8min scans + 6x6min scans + 3x1min + 2x2min scans for about 1.9 hours on source. There are 2 polarizations and about 1.75 GHz of total continuum bandwidth taking into account flagging.<br />
<br />
Using this information and https://almascience.nrao.edu/proposing/sensitivity-calculator, we find that the '''expected rms noise for the continuum is about 0.3 mJy/beam'''.<br />
<br />
For the spectral line data, which we will image below, with 0.12 km/s channels (needs to be entered in the field ''bandwidth per polarization''), the '''expected rms noise for the spectral lines is about 32 mJy/beam'''.<br />
<br />
==Image and Self-Calibrate the Continuum==<br />
<br />
====Create Initial Clean Image====<br />
<br />
First we will make an initial image using {{clean}}, this task will both deconvolve and clean. <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
If you are unfamiliar with the basic concepts of deconvolution and clean,<br />
pause here and review for example<br />
http://www.aoc.nrao.edu/events/synthesis/2010/lectures/wilner_synthesis10.pdf<br />
</pre><br />
<br />
In {{clean}}, we use '''mode='mfs'''' to do multifrequency synthesis, in other words grid each uv-channel independently. Since the uv-spacing is a function of frequency, this will actually achieve greater uv-coverage than if all the channels and spws had been averaged in advance. The '''imsize=100''' and '''cellsize=['0.3arcsec']''' were chosen to be appropriate for the Band and antenna configuration. At ALMA Band 7, the Full Width Half Power primary beam is about 20", so we want to make our image at least this big. We've made it a bit larger out to about the 25% power point. For the configuration used to take these data, the resolution is expected to be about 1.5" and it is a good idea to oversample the beam by setting the cell size to be a factor of 4 or 5 smaller than the beam (we have used 5 here). <br />
<br />
For doing self-calibration it is essential that only "real" signal be included in the image model, thus it is important to make a clean mask, and clean the first iteration rather conservatively (shallowly) so that you are sure that you do not have clean components in your model that do not represent real source emission. In the example below we set '''interactive=T''' so you can interactively make the clean mask and stop clean when the signal from the source starts to approach the surrounding "noise" areas in the residual map.<br />
<br />
'''NOTE:''' Real emission will not go away if you do not put a clean box on it. Conversely if you put a clean box on something that is NOT real and clean deeply you can amplify that feature. Thus, its best to be conservative and build up your clean box as you go, you can generally see fainter "real" features in the residuals.<br />
<br />
'''NOTE:''' If you start an interactive clean, and then do not make a mask, clean will stop when you tell it to go on because it has nothing to clean. There is no default mask.<br />
<br />
<figure id="Viewer_clean1.png"><br />
[[Image:Viewer_clean1.png|thumb|<caption>Interactive viewer.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall',<br />
mode='mfs', imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5, <br />
mask='',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
'''NOTE:'''{{clean}} will generate several files automatically with the '''imagename''' prepended:<br />
* <imagename>.image # the final restored image<br />
* <imagename>.flux # the effective primary beam response (e.g. for pbcor)<br />
* <imagename>.flux.pbcoverage # the primary beam coverage (ftmachine=’mosaic’ only)<br />
* <imagename>.model # the model image<br />
* <imagename>.residual # the residual image<br />
* <imagename>.psf # the synthesized (dirty) beam<br />
<br />
Once the Clean Viewer opens, click on the polygon tool with your left mouse button, and draw a polygon around the continuum emission with the left mouse button. Double click inside the region with the left mouse button when you are happy with it. It will turn from green to white when the clean mask is accepted. To continue with clean use the "Next action" buttons in the green area on the Viewer Display GUI. <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
The red X will stop clean where you are, the blue arrow will stop <br />
the interactive part of clean, but continue to clean non-interactively <br />
until reaching the number of iterations requested (niter) or the flux <br />
density threshold (whichever comes first), and the green circle arrow <br />
will clean until it reaches the "iterations" parameter on the left side <br />
of the green area. <br />
</pre><br />
<br />
'''You should chose the green circle arrow'''. It will clean 100 iterations (number under iteration in the green area on the Viewer GUI) and then show the '''residual image''' again. The middle mouse button is automatically assigned to the "plus" icon, which adjusts the colorscale. '''If you cannot easily access multiple mouse buttons, you can always assign your one mouse button the icon you want by clicking on it'''. Adjust the color scale so you can see the structure in the noise better. Also, note that the logger is telling you the amount of clean flux recovered so far, the min/max residuals, and the synthesized beam:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Model 0: max, min residuals = 0.0203454, 0.00267232 clean flux 1.30124<br />
Threshhold not reached yet.<br />
Beam used in restoration: 1.6962 by 1.54549 (arcsec) at pa 28.9043 (deg) <br />
</pre> <br />
<br />
Already with only 100 iterations, the residuals outside the clean mask are larger than that inside. So we will stop here by hitting the Red X symbol.<br />
<br />
====1st Round of Continuum Data Phase Self-calibration====<br />
<br />
Next we can use the clean model to self-calibrate the uv-data. The process of self-calibration tries to adjust the data to better match the model you give it. That is why it is important to make the model as good as you can. {{clean}} places a uv-model of the resulting image in the file <tt>TWHydra_cont.model</tt>. This model can then be used to self-calibrate the data using {{gaincal}}. We use '''gaintype='T'''' to tell it to average the polarizations before deriving solutions (which gains us a sqrt(2) in sensitivity). A critical parameter to play with is '''solint'''; we use '''solint=30s'''. From {{listobs}} the integration time of these data is about 10 seconds, so using '''solint=30s''' then gains us a sqrt(3) in sensitivity. It is often best to start with a larger '''solint''' and then work your way down to the integration time if the S/N of the data permits. For the same reasons as described in the [[TWHydraBand7_Calibration_4.5]] tutorial we want to fix up the phases before tackling amplitude by setting '''calmode='p''''.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='TWHydra_cont.ms',caltable='self_1.pcal',<br />
solint='30s',combine='',gaintype='T',<br />
refant='DV06',spw='',minblperant=4,<br />
calmode='p',minsnr=2)<br />
</source><br />
<br />
<figure id="Self_1_phase.png"><br />
[[Image:Self_1_phase.png|thumb|<caption>Phase solutions from self_1.pcal with solint=30s.</caption>]]<br />
</figure><br />
<br />
Because '''combine=' '''', we are getting independent solutions for each spw. If you are desperate for S/N, you can try combining them with combine='spw'. We have plenty of S/N in these data so we keep them separate. Look at the solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_1.pcal',xaxis='time',yaxis='phase',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,-80,80],figfile='self_1_phase.png')<br />
</source><br />
<br />
The magnitude of corrections gives you a sense of how accurate the phase transfer from the calibrators was. You are checking to see that the phases are being well tracked by the solutions, i.e. smoothly varying functions of time within a given scan. Also the solutions for each spw are lying basically on top of each other which indicates that the spw to spw phase offsets are well calibrated already. Overall, these solutions look quite good. If they didn't you could try increasing the solint and/or combining the spw into a single solution. <br />
<br />
After checking that you are happy with the solutions, apply them with {{applycal}}<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_cont.ms',field='',gaintable=['self_1.pcal'],calwt=F)<br />
</source><br />
<br />
<figure id="Viewer_pcal1.png"><br />
[[Image:Viewer_pcal1.png|thumb|<caption>Clean residuals after 100 iterations and the 1st phase only self-cal. Residuals inside mask are higher than the "noise" outside.</caption>]]<br />
</figure><br />
<br />
Next clean the source again, to save time we can start with the clean mask from the last iteration. If you make interactive adjustments to the clean mask, they will be written to the '''new''' mask TWHydra_contall_1pcal.mask, and not the old one. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_1pcal.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall_1pcal',<br />
mode='mfs',imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5, <br />
mask='TWHydra_contall.mask',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
Now after the first 100 iterations you see that the residuals inside the clean mask are higher than those outside. This is because flux that had been spread out in the map due to poorly correlated phases has been placed where it belongs on the source, thereby increasing its flux. You may also notice that your original clean mask is a little too small. If so, you can make it a bit larger, just by drawing a new polygon around the area you want to include. When you double click, it will incorporate the new mask into the current mask (if your box goes awry you can use the erase toggle [radio button] to erase and redo the mask). The new mask area need not overlap the original mask (though for this source it probably will). You might also want to use the magnifying glass to zoom in. Again, you assign mouse buttons by clicking on the icon you want. Clean another 100 iterations (for a total of 200) and stop by clicking the red X.<br />
<br />
Now open initial and 1st self-cal images to compare them using {{imview}}. This is an alternative version of the {{viewer}} that is somewhat scriptable. <br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(raster=[{'file':'TWHydra_contall.image','range':[-0.01,0.05]},<br />
{'file':'TWHydra_contall_1pcal.image','range':[-0.01,0.05]}])<br />
</source><br />
<br />
Once the Viewer Display panel opens, click on the box next in the "Images" panel and then use the tapedeck buttons in the panel to alternate between the two images. Because the range was explicitly set, they are on the same color scale. It is obvious that the self-calibrated image is better. To quantify, 1st toggle back to "normal" and then draw a region that excludes the central source with the polygon tool and then double click inside (if you stay in the "Images" view, only the statistics for the last image opened will appear on the terminal instead of both). The basic statistics of the polygon region will print to the '''terminal''':<br />
<br />
<pre style="background-color: #fffacd;"><br />
TWHydra_contall.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2357 -9.434800e-01 -2.858690e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-4.002885e-04 7.906752e-03 7.898289e-03 -2.541723e-02 2.172779e-02 <br />
<br />
TWHydra_contall_1pcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2357 6.326584e-01 1.916918e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
2.684168e-04 3.655786e-03 3.646692e-03 -1.215155e-02 1.109403e-02 <br />
</pre><br />
<br />
The self-calibrated image has more than a factor of 2 lower rms noise!<br />
<br />
====2nd Round of Continuum Data Phase Self-calibration====<br />
<br />
Now that we have a better model, we solve for solutions again. This time we will try making the solint smaller -- the integration time is about 10 seconds, so we set '''solint='int'''' to have it use the integration time.<br />
<br />
<figure id="Self_2_phase.png"><br />
[[Image:Self_2_phase.png|thumb|<caption>Phase solutions from self_2.pcal with solint='int'.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='TWHydra_cont.ms',caltable='self_2.pcal',<br />
solint='int',combine='',gaintype='T',<br />
refant='DV06',spw='',minblperant=4,<br />
calmode='p',minsnr=2)<br />
</source><br />
<br />
Now plot the new solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_2.pcal',xaxis='time',yaxis='phase',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,-80,80],figfile='self_2_phase.png')<br />
</source><br />
<br />
The phases on this shorter '''solint''' still seem to be tracking well so we will apply it and make a new image and check to see if there is improvement. <br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_cont.ms',field='',gaintable=['self_2.pcal'],calwt=F)<br />
</source><br />
<br />
<figure id="Viewer_pcal2.png"><br />
[[Image:Viewer_pcal2.png|thumb|<caption>Clean residuals after 2nd phase only self-cal and 250 iterations. The residuals inside the clean mask are lower than those outside, so its time to stop.</caption>]]<br />
</figure><br />
<br />
Now clean again, updating '''mask''' with the most recent mask file.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_2pcal.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall_2pcal',<br />
mode='mfs',imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5,usescratch=False,<br />
mask='TWHydra_contall_1pcal.mask',<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
After 200 iterations<br />
<br />
<pre style="background-color: #fffacd;"><br />
Model 0: max, min residuals = 0.00489776, -0.00464541 clean flux 1.44461<br />
</pre><br />
<br />
It looks like it could use just a little more cleaning, so set '''iterations=50 in the GUI'''.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Clean used 50 iterations to approach a threshhold of 0.0015067<br />
0.0107122 Jy <- cleaned in this cycle for model 0 (Total flux : 1.45532Jy)<br />
Final maximum residual = 0.00326382<br />
Model 0: max, min residuals = 0.00326382, -0.00321361 clean flux 1.45532<br />
</pre><br />
<br />
The small amount of flux cleaned this cycle indicates that clean is converging and it's about time to stop. Also the residuals inside the clean mask are now smaller than the residuals outside (i.e. the noise) also indicating it's time to stop by hitting the red X on the GUI.<br />
<br />
Now repeat the display, blinking, and image statistics steps described above for the 1st and 2nd phase-only self-cal iterations.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(raster=[{'file':'TWHydra_contall_1pcal.image','range':[-0.01,0.05]},<br />
{'file':'TWHydra_contall_2pcal.image','range':[-0.01,0.05]}])<br />
</source><br />
<br />
The difference is small:<br />
<pre style="background-color: #fffacd;"><br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2466 4.611597e-02 1.397287e-03 <br />
Mean Rms Std dev Minimum Maximum <br />
1.870072e-05 3.831524e-03 3.832255e-03 -1.414417e-02 1.109403e-02 <br />
<br />
TWHydra_contall_2pcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2466 1.159416e-01 3.512963e-03 <br />
Mean Rms Std dev Minimum Maximum <br />
4.701606e-05 3.811716e-03 3.812199e-03 -1.383034e-02 1.078456e-02 <br />
</pre><br />
<br />
This small improvement suggests that we have gone as far as we can with phase self-cal.<br />
<br />
===Continuum Data Amplitude Self-Calibration===<br />
<br />
Now we will apply the best phase solution table on-the-fly while solving for the amplitude self-cal solutions. Since amplitude changes more slowly and is less constrained than phase, we use a longer '''solint='inf'''', as long as '''combine=' '''' this means to do one solution per scan. <br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='TWHydra_cont.ms',caltable='self_ap.cal',<br />
solint='inf',combine='',gaintype='T',<br />
refant='DV06',spw='',minblperant=4,<br />
gaintable=['self_2.pcal'],<br />
calmode='ap',minsnr=2)<br />
</source><br />
<br />
It's useful to look at the residual phase in the amplitude calibration table, i.e. since we applied our best phase-only solution while solving for this new amplitude and phase ('''calmode='ap'''') solution, the phase should already be corrected.<br />
<br />
<figure id="Self_ap_phase.png"><br />
[[Image:Self_ap_phase.png|thumb|<caption>Residual phase solutions from self_ap.cal.</caption>]]<br />
</figure><br />
<figure id="Self_ap_amp.png"><br />
[[Image:Self_ap_amp.png|thumb|<caption>Amplitude solutions from self_ap.cal.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_ap.cal',xaxis='time',yaxis='phase',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,-1,1],figfile='self_ap_phase.png')<br />
</source><br />
<br />
The residuals are very small as expected. (If you see large residuals here, it means that the phase-only solution is suspect, and you were mostly just moving noise around.) Now look at the amplitude solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_ap.cal',xaxis='time',yaxis='amp',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,0.6,1.4],figfile='self_ap_amp.png')<br />
</source><br />
<br />
For the most part these look very good except one rather large deviation on DV06. Apply both the final phase and the amplitude calibration tables.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_cont.ms',field='',gaintable=['self_2.pcal','self_ap.cal'],calwt=F)<br />
</source><br />
<br />
Plot the corrected data as a function of both time and uv-distance. It is always a good idea to check these after an amplitude self-calbration to be sure that it worked properly. Occasionally, a few spurious bits of data will get blown up by the amplitude self-cal if it is not well-constrained. <br />
<br />
<figure id="Selfcal_time.png"><br />
[[Image:Selfcal_time.png|thumb|<caption>Post self-calibration amplitude vs. time</caption>]]<br />
</figure><br />
<figure id="Selfcal_uvdist.png"><br />
[[Image:Selfcal_uvdist.png|thumb|<caption>Post self-calibration amplitude vs. uv-distance</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',xaxis='time',yaxis='amp',<br />
avgchannel='38',ydatacolumn='corrected',coloraxis='spw',<br />
plotfile='selfcal_time.png')<br />
</source><br />
<br />
The time where we saw a large amplitude correction on DV06 looks consistent here so the large correction we saw in the solutions corrected a real issue. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',xaxis='uvdist',yaxis='amp',<br />
avgchannel='38',ydatacolumn='corrected',coloraxis='spw',<br />
plotfile='selfcal_uvdist.png')<br />
</source><br />
<br />
You will see that this plot looks much better than before. <br />
<br />
<figure id="Viewer_apcal.png"><br />
[[Image:Viewer_apcal.png|thumb|<caption>Clean residuals after final amplitude and phase self-cal.</caption>]]<br />
</figure><br />
<br />
Now make the final continuum image.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_apcal.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall_apcal',<br />
mode='mfs',imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5,usescratch=False,<br />
mask='TWHydra_contall_2pcal.mask',<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
We know we need to clean at least 300 iterations, so set this in the gui and hit the round green arrow. After this notice how much better the residual looks. Clean another 100 iterations. The "circular pattern", and 4 bright spots at each corner you see now in the residual is likely due to non-closing amplitude errors that cannot be removed with an antenna based self-calibration, so this is as good as it gets with pure self-cal. Hit the Red X to stop clean.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Clean used 100 iterations to approach a threshhold of 0.00105507<br />
0.0061808 Jy <- cleaned in this cycle for model 0<br />
Final maximum residual = 0.00242926<br />
Model 0: max, min residuals = 0.00238278, -0.00242926 clean flux 1.48201<br />
</pre><br />
<br />
Now repeat the display, blinking, and image statistics described above for the 2nd phase only and the new amplitude & phase self-cal'ed images.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(raster=[{'file':'TWHydra_contall_2pcal.image','range':[-0.01,0.05]},<br />
{'file':'TWHydra_contall_apcal.image','range':[-0.01,0.05]}])<br />
</source><br />
<br />
The amplitude and phase self cal'ed image is notably better than phase-only. Quantitatively:<br />
<pre style="background-color: #fffacd;"><br />
<br />
TWHydra_contall_2pcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 3542 2.053068e-01 6.220676e-03 <br />
Mean Rms Std dev Minimum Maximum <br />
5.796351e-05 3.955967e-03 3.956101e-03 -1.383034e-02 1.078456e-02 <br />
<br />
TWHydra_contall_apcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 3542 6.044652e-04 1.831495e-05 <br />
Mean Rms Std dev Minimum Maximum <br />
1.706565e-07 1.270183e-03 1.270362e-03 -4.980673e-03 4.137159e-03 <br />
</pre> <br />
<br />
and indeed, we've gained another factor of 3 in sensitivity. <br />
<br />
'''Overall with this self-calibration we've improved the noise by a factor of 6.7! With a peak flux density of 0.98 Jy, the S/N increased from 115 initially to 770 after. So, well worth the trouble.'''<br />
<br />
<div class="noprint" style="float:none; border:0px solid blue;background-color:#F6CEF5;padding:2px;"><br />
If you have used the '''standard='Butler-JPL-Horizons 2012' ''' model during the calibration process, you should see an increase in peak flux density of about 3%.<br />
</div><br />
<br />
It is notable that we are still a factor of more than 4 from the apriori noise estimate of 0.3 mJy/beam. This is likely due to residual sources of non-closing (not antenna based) errors in the data like baseline errors and baseline-dependent bandpass errors. Additionally, polarization errors (which we did not calibrate at all) can contribute, as well as imperfect uv-coverage with only 8 antennas. A dynamic range of 770 is actually quite good in the submillimeter.<br />
<br />
==Apply self-calibration to Full Dataset and Split Line Data==<br />
<br />
Now apply the self-calibration derived from the continuum emission to the full unchannel-averaged data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_corrected.ms',gaintable=['self_2.pcal','self_ap.cal'],calwt=F)<br />
</source><br />
<br />
Split off the CO(3-2) spectral line data in spw=2 and the HCO+(4-3) data in spw=0 for further processing.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2.ms*')<br />
split(vis='TWHydra_corrected.ms',outputvis='TWHydra_CO3_2.ms',datacolumn='corrected',spw='2')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplus.ms*')<br />
split(vis='TWHydra_corrected.ms',outputvis='TWHydra_HCOplus.ms',datacolumn='corrected',spw='0')<br />
</source><br />
<br />
==Continuum Subtraction== <br />
<br />
Next we need to subtract the continuum emission from the spectral line data. It is best to do this in the uv-plane. The first step is to make a channel plot of the spectral data to get the line-free channel ranges for both spectral lines. Since the line emission is simple (one spectral line per spw) and there are more than enough line-free channels we do not need to be very precise just stay well away from the line and whenever possible it is best to chose line-free channel ranges on either side of the line for the best possible baseline subtraction. <br />
<br />
<figure id="CO3_2_channel.png"><br />
[[Image:CO3_2_channel.png|thumb|<caption>CO(3-2) line in channel space.</caption>]]<br />
</figure><br />
<figure id="HCOp4_3_channel.png"><br />
[[Image:HCOp4_3_channel.png|thumb|<caption>HCO+(4-3) in channel space.</caption>]]<br />
</figure><br />
<br />
'''Note''': after the split above, the original spw ids will be relabeled as 0 in each file because there is only one spectral window in each file.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_CO3_2.ms',spw='0',xaxis='channel',yaxis='amp',<br />
avgtime='1e8',avgscan=T,coloraxis='spw',plotfile='CO3_2_channel.png')<br />
</source><br />
<br />
It is a good idea to stay a little away from the very edges of the baseband which can be noisy. The channel ranges <br />
20~2000 and 2400~3800 look like good choices for CO(3-2).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_HCOplus.ms',spw='0',xaxis='channel',yaxis='amp',<br />
avgtime='1e8',avgscan=T,coloraxis='spw',plotfile='HCOp4_3_channel.png')<br />
</source><br />
<br />
The channel ranges 20~1500 and 1900~3800 look like good choices for HCO+(4-3).<br />
<br />
Next use the identified line-free channel ranges and {{uvcontsub}} to subtract the continuum model from the line emission.<br />
<br />
<source lang="python"><br />
# In CASA<br />
uvcontsub(vis='TWHydra_CO3_2.ms',fitorder=1,fitspw='0:20~2000,0:2400~3800')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
uvcontsub(vis='TWHydra_HCOplus.ms',fitorder=1,fitspw='0:20~1500,0:1900~3800')<br />
</source><br />
<br />
Note: If you do not have line-free channels on both sides of the line emission, it is safer to use '''fitorder=0''', or the fit may diverge.<br />
<br />
==Spectral Line Imaging==<br />
<br />
Now we are ready to make cubes of the line emission. The imaging parameters are similar to the continuum except for <br />
those dealing with the spectral setup: '''mode''', '''start''', '''width''', '''nchan''', '''restfreq''', and '''outframe''' parameters. When making spectral images you have three choices for the '''mode''' parameter: '''channel''', '''velocity''', and '''frequency'''. Data are taken using constant frequency channels. For spectral line analysis it's often more useful to have constant velocity channels, and this is also the best way to make images of multiple lines with the exact same channelization for later comparison. For '''mode='velocity'''', the desired '''start''' and '''width''' also need to be given in velocity units for the desired output frame. <br />
<br />
It is important to note that ALMA does not do on-line Doppler Tracking and the native frame of the data is TOPO. If you do not specify '''outframe''' the output cube will also be in TOPO, which is not very useful for spectral line work. The Doppler Shift is taken out during the regridding to the desired outframe in {{clean}} or alternatively it can be done separately by the {{cvel}} task which would need to be run before {{clean}}. <br />
<br />
<figure id="CO3_2_vel.png"><br />
[[Image:CO3_2_vel.png|thumb|<caption>CO(3-2) spectrum in LSRK velocity space.</caption>]]<br />
</figure><br />
<figure id="HCOp4_3_vel.png"><br />
[[Image:HCOp4_3_vel.png|thumb|<caption>HCO+(4-3) spectrum in LSRK velocity space.</caption>]]<br />
</figure><br />
<br />
To see what velocity parameters you want to set in clean it is useful to make a plot in {{plotms}} in the desired output frame. To make it easier to see, we set a '''plotrange''' since we know the LSRK velocity of TW Hya is about 2.88 km/s. Note these plots take a little longer because of the frame shift.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_CO3_2.ms.contsub',xaxis='velocity',yaxis='amp',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',<br />
restfreq='345.79599GHz',plotrange=[-20,23,0,0],plotfile='CO3_2_vel.png')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_HCOplus.ms.contsub',xaxis='velocity',yaxis='amp',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',<br />
restfreq='356.7342GHz',plotrange=[-20,23,0,0],plotfile='HCOp4_3_vel.png') <br />
</source><br />
<br />
From these plots it looks like imaging the cubes from about -5 to +8 km/s will encompass the line, but still provide several line-free channels on either side so the noise level can be estimated. The channel width is 122 kHz, which at <br />
345.79599 GHz is 0.106 km/s. Recall that the spectral ''resolution'' is a factor of two poorer. We will use a velocity channel width of 0.12 km/s for a little oversampling, but the spectral resolution remains 0.2 km/s.<br />
<br />
As before, it is very important that you make a clean mask. There are many ways to do this ranging from the complicated to simple. For this example we will make a single clean mask that encompasses the line emission in every channel and apply it to all channels. This is much better than no clean mask, though not quite as good as making an individual mask for each channel. For some sources, one can use the continuum mask to clean the line, however TW Hya is a bit curious in that the continuum emission is not as extended as the line emission (Hughes et al. 2008).<br />
<br />
=== CO(3-2) Imaging ===<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.*')<br />
clean(vis='TWHydra_CO3_2.ms.contsub',imagename='TWHydra_CO3_2line',<br />
imagermode='csclean',spw='',<br />
imsize=100,cell=['0.3arcsec'],<br />
mode='velocity',start='-4km/s',width='0.12km/s',nchan=118,<br />
restfreq='345.79599GHz',outframe='LSRK',<br />
weighting='briggs',robust=0.5,<br />
mask='',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=100000)<br />
</source><br />
<br />
<figure id="Viewer_55.png"><br />
[[Image:Viewer_55.png|thumb|<caption>Interactive Viewer window with CO(3-2) clean mask, before cleaning starts.</caption>]]<br />
</figure><br />
<figure id="Viewer_500.png"><br />
[[Image:Viewer_500.png|thumb|<caption>Interactive Viewer window for CO(3-2), after 500 iterations, more cleaning is needed.</caption>]]<br />
</figure><br />
<br />
It will take a little while to grid the cube, when the interactive viewer opens, use the tapedeck to cycle through the channels. You should see a progress of line emission in channels 40 to 70 or so.<br />
*Go to channel 57 (about line center)<br />
*Select the polygon tool with the left mouse button<br />
*Select the "All Channels" toggle in the green area<br />
*Draw a polygon around the channel 57 emission, double click inside to activate.<br />
*Now go to channel 60, this is the channel with the most extent to the SE, draw another polygon that encompasses this emission if necessary,double click inside to activate.<br />
*Now go to channel 55, this is the channel with the most extent to the NW, draw another polygon that encompasses this emission if necessary,double click inside to activate. <br />
*Now double check the mask by cycling through channels with real line emission to be sure that your clean box encompasses the emission, but does not extend far beyond it. Again the "erase" toggle can come in handy if things go awry or if you want to just delete a small portion of an existing mask (just draw a polygon around what you want to erase and double click inside), be sure to switch back to "add" before going on.<br />
<br />
The figure shows what the final clean box should look like. Now clean using the green circle arrow. You can watch the progress in the logger. When 100 iterations are done, the viewer will show the residual map for each channel. Cycle through the channels and see whether you are still happy with the clean box in each signal channel. The "erase button" can help you fix mistakes. If necessary adjust. It is often useful to adjust the colorscale with the "plus" symbol icon. Keep going until the residual emission looks like the surrounding noise. If it seems to be going slowly, increase the iterations to 300 for a round or two. I stopped cleaning (Red x) when the logger showed (about 900 iterations). <br />
<pre style="background-color: #fffacd;"><br />
12.9846 Jy <- cleaned in this cycle for model 0<br />
Final maximum residual = 0.157312<br />
Model 0: max, min residuals = 0.157312, -0.0871295 clean flux 279.304<br />
</pre><br />
<br />
NOTE: The residuals are still a bit high in the strongest emission channels after it is well cleaned in the weaker channels. This is an indication that the sensitivity is "dynamic range" limited. In other words even with more <br />
intrinsic sensitivity per integration (i.e. better system temperature), the dynamic range limit would remain the same unless you get more uv-coverage. The fundamental dynamic range limitations of ALMA will be considerably better with 16 antennas in Early Science and MUCH better with the full 50-antenna array.<br />
<br />
=== HCO+(4-3) Imaging ===<br />
<br />
Now image and clean the HCO+(4-3) line using what you learned above.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.*')<br />
clean(vis='TWHydra_HCOplus.ms.contsub',imagename='TWHydra_HCOplusline',<br />
imagermode='csclean',spw='',<br />
imsize=100,cell=['0.3arcsec'],<br />
mode='velocity',start='-4km/s',nchan=118,width='0.12km/s',<br />
restfreq='356.7342GHz',outframe='LSRK',<br />
weighting='briggs',robust=0.5,<br />
mask='',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=100000)<br />
</source><br />
<br />
I stopped cleaning when: <br />
<pre style="background-color: #fffacd;"><br />
4.79833 Jy <- cleaned in this cycle for model 0<br />
Final maximum residual = 0.0977348<br />
Model 0: max, min residuals = 0.0977348, -0.060484 clean flux 192.066<br />
</pre><br />
<br />
==Image Analysis==<br />
<br />
After all that hard work you now have deconvolved images of the 350 GHz continuum, the CO (3-2) line, and the HCO+ (4-3) line. CASA includes tools to help you understand the contents of these images and make basic scientific measurements. These tools are divided between graphical exploration tools, accessible via the CASA viewer, and command line analysis tasks. To access the viewer, simply type '''viewer()''' and to see the list of analysis tasks available in CASA type '''tasklist''' at the CASA prompt and look under the Analysis sub-heading.<br />
<br />
If you want to do this portion of the guide and have downloaded the (.FITS) reference images, you can import them to be CASA images using '''importfits'''. If you are re-importing the images, use the commented remove command, here, to delete the previous import first.<br />
<br />
<source lang="python"><br />
# In CASA<br />
# os.system("rm -rf TWHydra_CO3_2line.image")<br />
importfits(fitsimage="TWHydra_CO3_2line.image.fits", imagename="TWHydra_CO3_2line.image")<br />
</source><br />
<br />
where '''fitsimage''' refers to the file to imported and '''imagename''' gives the output filename. If you are proceeding directly from the imaging step, your data are already CASA images and you may proceed without any importing.<br />
<br />
You can get the basic properties of any CASA image using the '''imhead''' command. For example, type <br />
<br />
<source lang="python"><br />
# In CASA<br />
imhead("TWHydra_CO3_2line.image")<br />
</source><br />
<br />
and look at the CASA logger. You will see an image summary like the following<br />
<br />
<pre style="background-color: #fffacd;"><br />
INFO imhead ##########################################<br />
INFO imhead ##### Begin Task: imhead #####<br />
INFO imhead imhead(imagename="TWHydra_CO3_2line.image",mode="summary",hdkey="",hdvalue="",<br />
INFO imhead hdtype="",hdcomment="",verbose=False)<br />
INFO ImageAnalysis <br />
INFO ImageAnalysis Image name : TWHydra_CO3_2line.image<br />
INFO ImageAnalysis Object name : TW Hya<br />
INFO ImageAnalysis Image type : PagedImage<br />
INFO ImageAnalysis Image quantity : Intensity<br />
INFO ImageAnalysis Pixel mask(s) : None<br />
INFO ImageAnalysis Region(s) : None<br />
INFO ImageAnalysis Image units : Jy/beam<br />
INFO ImageAnalysis Restoring Beam : 1.68065 arcsec, 1.53193 arcsec, 22.3015 deg<br />
INFO ImageAnalysis <br />
INFO ImageAnalysis Direction reference : J2000<br />
INFO ImageAnalysis Spectral reference : LSRK<br />
INFO ImageAnalysis Velocity type : RADIO<br />
INFO ImageAnalysis Rest frequency : 3.45796e+11 Hz<br />
INFO ImageAnalysis Pointing center : 11:01:51.844983 -34.42.17.160885<br />
INFO ImageAnalysis Telescope : ALMA<br />
INFO ImageAnalysis Observer : Unknown<br />
INFO ImageAnalysis Date observation : 2011/04/22/00:15:42<br />
INFO ImageAnalysis Telescope position: [2.22514e+06m, -5.44031e+06m, -2.48103e+06m] (ITRF)<br />
INFO ImageAnalysis <br />
INFO ImageAnalysis Axis Coord Type Name Proj Shape Tile Coord value at pixel Coord incr Units<br />
INFO ImageAnalysis -------------------------------------------------------------------------------------------------- <br />
INFO ImageAnalysis 0 0 Direction Right Ascension SIN 100 25 11:01:51.845 50.00 -3.000000e-01 arcsec<br />
INFO ImageAnalysis 1 0 Direction Declination SIN 100 25 -34.42.17.161 50.00 3.000000e-01 arcsec<br />
INFO ImageAnalysis 2 2 Spectral Frequency 118 59 3.45801e+11 0.00 -1.38414152e+05 Hz<br />
INFO ImageAnalysis Velocity -4 0.00 1.200000e-01 km/s<br />
INFO ImageAnalysis 3 1 Stokes Stokes 1 1 I<br />
INFO imhead ##### End Task: imhead #####<br />
INFO imhead ##########################################<br />
<br />
</pre><br />
<br />
This report tells you about the target, shape, and coordinates of the image. It also notes the rest frequency and some details of the observation. '''imhead''' may be used more generally to retrieve header keywords as python variables or to manipulate the header of an image. Consult the help for details.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
You may want to pay particular attention to the third and fourth axis of the CASA image. These are <br />
usually frequency (velocity) and Stokes (polarization) in some order. An occasional source of confusion <br />
is that this order is not always the same. Often CLEAN will output images with the Stokes axis third, <br />
while IMPORTFITS usually yields images with the frequency axis third. If you encounter problems with<br />
image analysis tasks, you may want to check whether this results from conflicting axis definitions. You<br />
can adjust the order of the axes using the IMTRANS task.<br />
</pre><br />
<br />
Before proceeding, make sure that you have all three data sets as CASA images: '''TWHydra_CO3_2line.image''', '''TWHydra_HCOPlusline.image''', and '''TWHydra_contall_apcal.image'''. If you do not, then import them from the provided reference images. If you are re-importing the FITS images, run the commented remove commands before running importfits.<br />
<br />
<source lang="python"><br />
# In CASA<br />
# os.system("rm -rf TWHydra_CO3_2line.image")<br />
importfits(fitsimage="TWHydra_CO3_2line.image.fits", imagename="TWHydra_CO3_2line.image")<br />
# os.system("rm -rf TWHydra_HCOplusline.image")<br />
importfits(fitsimage="TWHydra_HCOplusline.image.fits", imagename="TWHydra_HCOplusline.image")<br />
# os.system("rm -rf TWHydra_contall_apcal.image")<br />
importfits(fitsimage="TWHydra_contall_apcal.image.fits", imagename="TWHydra_contall_apcal.image")<br />
</source><br />
<br />
In the rest of this guide we will construct ''moment maps'' showing the integrates, velocity field, and line width of the two lines. We will carry out Gaussian fits to the continuum and line maps. We will also illustrate some of the additional analysis capabilities available in CASA: subcube extraction, retrieval of data into python arrays, cube alignment, smoothing, and overlays of multiple spectral lines.<br />
<br />
===Moment Maps===<br />
<br />
The line "images" of CO(3-2) and HCO+(4-3) are, of course, cubes rather than images. Two dimensional ''moment maps'' are a standard way to present such data. These are maps showing the result of various moments (or similar calculations) carried out along the frequency axis of the cube. For example, the "moment 0" map is the sum of emission along the frequency axis at each pixel. The first moment is the intensity-weighted velocity (or frequency). The second moment is the intensity-weighted velocity (or frequency) dispersion about the mean. These and a number of other calculations (for example the maximum intensity) can be calculated via the '''immoments''' task. Consult the help or the CASA cookbook for more details.<br />
<br />
In this section, we will calculate moments for our two spectral line data cubes. To make the highest quality moment maps, we will first identify the planes of the data cube that contain emission, so that we can carry out the sum only over these channels. Doing otherwise adds noise to the moment map without adding signal and so lowers the signal-to-noise ratio of the final image. For the first and second moments we will identify an intensity threshold above which the data are statistically very likely to correspond to real astronomical emission. We will restrict the calculation to consider only data above this threshold, yielding a cleaner calculation (the second moment, in particular, is not at all robust against the inclusion of outlying noise). Finally, we will inspect the resulting moment maps with the viewer and output them to .FITS files.<br />
<br />
====Estimate the Spectral Extent====<br />
<br />
First, we want to figure out what planes appear to contain real emission. Open the CO data cube with the CASA viewer via:<br />
<br />
<source lang="python"><br />
# In CASA<br />
viewer("TWHydra_CO3_2line.image")<br />
</source><br />
<br />
This will open the CO(3-2) data cube as a raster image. Use the Animator pane to scroll through the cube, noting that the emission is mostly confined to ~40 channels near the center of the cube. There are several ways to make a more rigorous estimate. <br />
<br />
''By-Plane Inspection:'' First, you could increase the stretch of the image to identify by hand the first and last channels with visible emission. To do open the Data Display Options panel in the viewer (the wrench icon) and manually set the data range and/or scaling power cycles to highlight faint emission (note that you can also do this using the mouse and the color stretch - sun - icon). I left the scaling power cycles at 0 and set the data range to [-0.5, 0.5]. Then scroll through the cube and note the first and last channels with obvious emission. If I do this, I find emission from about plane 30 through plane 86.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:DataDisplayPanelStretch.png|The Data Display Panel used to set the color stretch, here from [-0.15, 0.15] with a linear (0) stretch. Setting the stretch to a negative value will highlight lower emission (a more logarithmic stretch). We got to this panel by clicking the wrench icon. You can also get from the dropdown menus (Data->Adjust).<br />
File:TWHydraCOChan33.png|Channel 33 of the CO(3-2) cube on this stretch. This is about the first channel to show clear emission.<br />
File:TWHydraCOChan80.png|Channel 80 of the CO(3-2) cube on this stretch. This is about the last channel to show clear emission.<br />
</gallery><br />
</center><br />
<br />
To make this more rigorous, you can work out a noise estimate before hand (we'll find it to be about 0.025 Jy/beam) and overplot a contour to indicate significant emission. You can do this by hand by using the Data Manager (folder icon) to open TWHydra_CO3_2line.image as a "contour map" and then using the Data Display Options to manipulate the contour levels. To show a 3-sigma contour with sigma=0.025 Jy/beam set the Relative Contour Levels to [3], the Base Contour Level to 0, and the Unit Contour Level to 0.025. You can display a 5-sigma contour or change the RMS analogously. Scrolling through the cube, I see 3-sigma emission from channels 33 through 80.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:DataDisplayPanelContour.png|The Data Display Panel now being used to set the contour levels. We set the contour unit to 0.025 and ask for a single contour at 3 times this value. Notice that we clicked the tab along the top of the window to select the contour map.<br />
File:TWHydraCOChan33Contour.png|Channel 33 of the CO(3-2) cube on this stretch with a 3-sigma contour overlaid.<br />
File:TWHydraCOChan80Contour.png|Channel 80 of the CO(3-2) cube on this stretch with a 3-sigma contour overlaid.<br />
</gallery><br />
</center><br />
<br />
''Look at a Spectrum:'' You can also look at a spectrum of the source. To do this, scroll to a channel with a lot of emission (I went to 57) and then use the mouse to drag out a rectangle. To do this, left click on the rectangle box in the mouse toolbar (this assigns the left mouse button to define rectangle regions). Then drag out a box around the emission using the same button. Now click the spectrum in the toolbar to open the spectral profile tool. You will see the average profile for the selected region. You can set the bottom axis to show channels. You can zoom in within the spectral profile by dragging out a rectangle. When I do this, I find significant emission from channels 40-80.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:TWHydraRectangle.png|Defining a rectangular region around the main emission from TW Hydra. First we clicked the rectangle button on the mouse toolbar, then we held that button and dragged out the purple rectangle. After defining the rectangle, you can drag it around or delete it with <ESC>.<br />
File:TWHydraSpectrum.png|The spectrum of this rectangular region viewed in the spectral profile browser. Note that the bottom axis has been set to show channels. To get this spectrum, we defined the rectangular region and then clicked the spectrum button on the toolbar.<br />
File:TWHydraSpectrumZoom.png|A zoom in on the spectrum. The line extends from channels ~40-80.<br />
</gallery><br />
</center><br />
<br />
''Look at a Declination-Frequency Projection (or an R.A.-Frequency Projection):'' This is probably the least reliable way to do this, but illustrates a neat capability of the viewer. Open the Data Display Options (click the wrench icon) and open the "display axes" and "hidden axes" tabs. Use the dropdown menus to change the display so that the x-axis shows Declination, the y-axis shows Frequency, and the z-axis shows "Right Ascension." Now you are scrolling through planes of intensity as a function of Declination and Frequency. Use the animator to move to R.A. plane ~ 50 (the center of the source) and pull the stretch up (in the wrench tool; I used [-0.15,0.15] again). Mouse over the image and look at the "Position Tracking" pane in the bottom of the image, noting the pixel extent of emission in the frequency axis of this plane. I see traces of emission from channel ~30-90.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:DataDisplayPanelAxes.png|The Data Display Panel, here used to set which axes are displayed. We have adjusted the y-axis to show frequency and the x-axis to show Declination. The z-axis is now Right Ascension, so that we will scroll through planes of Right Ascension.<br />
File:DataDisplayPanelPixels.png|The Data Display Panel, here we are setting coordinates to show "pixels" rather than world coordinates.<br />
File:TWHydraDecFreqPixels.png|A Frequency-Declination plane of the cube near the central R.A. pixel (50). The rough extent of emission may be simply read off the y-coordinate. As above, we could overplot a 3-sigma contour to add more rigor.<br />
</gallery><br />
</center><br />
<br />
<br />
You can repeat this exercise for the HCO+ (4-3) emission. Using the Spectral Profile Browser, I find that the line extends from about channel 40 through channel 75.<br />
<br />
====Make Moment 0 Maps====<br />
<br />
With an estimate of the spectral extent of emission, we are now ready to make moment 0 maps of the CO(3-2) and HCO+(4-3) lines. We do this using the '''immmoments''' command,<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom0')<br />
immoments(imagename='TWHydra_CO3_2line.image',moments=[0],<br />
outfile='TWHydra_CO3_2line.image.mom0',<br />
chans='30~90')<br />
</source><br />
<br />
and<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom0')<br />
immoments(imagename='TWHydra_HCOplusline.image',moments=[0],<br />
outfile='TWHydra_HCOplusline.image.mom0',<br />
chans='40~75')<br />
</source><br />
<br />
immoments will sum across the channels specified by '''chans''' and produce new CASA images with the names specified by '''outfile'''. These can be inspected using the CASA viewer just like any other image. Note that unlike higher-order moments, the moment-0 map is robust to the inclusion of noisy signal-free channels (to within reason, you just decrease your signal-to-noise ratio) and indeed may be biased to miss faint emission by imposing a threshold. For that reason, we will eschew the '''includepix''' keyword as we make the moment 0 maps.<br />
<br />
Let's look at the output using the viewer. We can specify some of the display options in the call to start the viewer by using '''imview''' instead of '''viewer'''.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview( raster=[ {'file':'TWHydra_CO3_2line.image.mom0',<br />
'range':[0.0,10.],<br />
'scaling':-1},<br />
{'file':'TWHydra_HCOplusline.image.mom0',<br />
'range':[0.0,10.],<br />
'scaling':-1}], <br />
contour={'file':'TWHydra_contall_apcal.image', 'base':0, 'unit':0.0025, 'levels':[3,100]} )<br />
</source><br />
<br />
This does several things: It opens the viewer with raster images of the moment 0 maps of CO(3-2) and HCO+(4-3), sets the range of the color stretch from [0, 10] for each image and sets the scaling to be -1, which highlights faint emission compared to the normal (0) stretch. It also opens the continuum image as a contour and defines two contour levels. Once the viewer is open, you can blink between the images by going into the Animator pane, checking the white box next to "Images" to enable animation between images, and then sliding the bar back and forth. See the name of the image being shown change. You can also show two images side by side by going to the Viewer Canvas Manager (wrench+P icon) and opening the "Number of Panels" tab. Set the "Number of panels in x" to 2 and make sure that the Images box is checked in the Animator pane. You will see both images side by side.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:CanvasManagerPanels.png|The Viewer Canvas Manager, accessed via the Wrech+P icon (not to be confused with the plain old wrench). Here we have adjusted the number of x-panels from 1 to 2 so that we show the two moment maps side by side.<br />
File:TWHydraMoment0Maps.png|The moment-0 maps of CO(3-2) and HCO+(4-3) plotted side by side on the same color stretch, both with the continuum contours overlaid. To get the two images side by side, run the imview call above then set the number of panels to 2 and make sure that the Images box in the Animator Pane (here at the bottom of the window) is checked.<br />
File:DataDisplayImview.png|Data Display Panel after our imview call. Imview allowed us to set the stretch, range, and contour levels from the command line.<br />
</gallery><br />
</center><br />
<br />
====Estimate the Noise====<br />
<br />
We have already made a few offhand comparisons to the RMS noise. This quantity is often critical to know when exploring the data. Because the higher-order moments (especially the dispersion) are not at all robust to the inclusion of noise, we will calculate them only from regions of the cube that have intensity several times the RMS noise value or higher and are thus very likely to contain real astronomical emission. To proceed, we need to estimate the RMS noise for our data.<br />
<br />
The easiest way to do this is to calculate the RMS scatter of the data about zero from a part of the data that you suspect to be (mostly) free of astronomical signal. In a data cube the easiest way to do this will often be to identify signal-free planes (channels) of the cube and to simply calculate the RMS in these regions. We can do this straightforwardly using the '''imstat''' command in CASA.<br />
<br />
IMSTAT COMMAND<br />
<br />
IMSTAT OUTPUT<br />
<br />
Alternatively, you can get similar statistics on a region of an image or data cube selected manually inside the viewer. Drag out a region, for example a rectangle, using one of the mouse tools. Then <br />
<br />
IMAGES OF REGION SELECTION, OUTPUT, REGION MANAGER<br />
<br />
Suggested values for CO(3-2), HCO+(4-3), and continuum. Short discussion of dynamic range limited vs. line-free channels.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
A note on primary beam corrections and noise.<br />
</pre><br />
<br />
====Higher Order Moment Maps for CO(3-2)====<br />
<br />
For higher order moments it is very important to set a conservative flux <br />
threshold. Typically something like 6 sigma, using sigma from peak line channel, works well.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom')<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_coord')<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_dispersion_coord')<br />
immoments(imagename='TWHydra_CO3_2line.image',moments=[1,2],<br />
outfile='TWHydra_CO3_2line.image.mom',<br />
chans='40~76',includepix=[0.3,100])<br />
</source><br />
<br />
Display all three moment maps in the viewer, overlaid with continuum contours.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview( raster=[ {'file':'TWHydra_CO3_2line.image.mom0'},<br />
{'file':'TWHydra_CO3_2line.image.mom.weighted_coord'},<br />
{'file':'TWHydra_CO3_2line.image.mom.weighted_dispersion_coord'} ], <br />
contour={'file':'TWHydra_contall_apcal.image', 'base':0, 'unit':0.0025, 'levels':[3,100]} )<br />
</source><br />
<br />
To see all three raster images simultaneously, open the viewer's Panel Display Options (the "P-wrench" icon in the viewer tool bar), click "Number of panels", and change "Number of panels in x" to 3. Then select the "Blink" toggle (radio button) from the Animator panel.<br />
<br />
<figure id="TWHya_CO3_2_moments.png"><br />
[[Image:TWHya_CO3_2_moments.png|center|800px|frame|<caption>ALMA CO(3-2) moment maps, with white continuum contours at 3 and 100 sigma. From left to right: integrated intensity, intensity weighted velocity field, intensity weighted velocity dispersion are shown.</caption>]]<br />
</figure><br />
<br />
Repeat for HCO+(4-3) which has a bit narrower velocity extent than the CO(3-2), but similar rms noise.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom0')<br />
immoments(imagename='TWHydra_HCOplusline.image',moments=[0],<br />
outfile='TWHydra_HCOplusline.image.mom0',<br />
chans='43~74')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom')<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_coord')<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_dispersion_coord')<br />
immoments(imagename='TWHydra_HCOplusline.image',moments=[1,2],<br />
outfile='TWHydra_HCOplusline.image.mom',<br />
chans='43~74',includepix=[0.3,100])<br />
</source><br />
<br />
Display all three moment maps in the viewer using the same method described above for the CO(3-2) maps.<br />
<br />
<figure id="TWHya_HCOp4_3_moments.png"><br />
[[Image:TWHya_HCOp4_3_moments.png|center|800px|frame|<caption>ALMA HCO+(4-3) moment maps, with white continuum contours at 3 and 100 sigma. From left to right: integrated intensity, intensity weighted velocity field, intensity weighted velocity dispersion are shown.</caption>]]<br />
</figure><br />
<br />
=====Exporting Fits Images=====<br />
<br />
If you want to analyze the data using another software package it is easy to convert from CASA format to FITS. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image',fitsimage='TWHydra_CO3_2line.image.fits')<br />
</source><br />
<br />
Although "FITS format" is supposed to be a standard, in fact most packages expect slightly different things from a FITS image. If you are having difficulty, try setting '''velocity=T''' and/or '''dropstokes=T'''.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf TWHydra_HCOplusline.image.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image',fitsimage='TWHydra_HCOplusline.image.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom0.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image.mom0',<br />
fitsimage='TWHydra_CO3_2line.image.mom0.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_coord.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image.mom.weighted_coord',<br />
fitsimage='TWHydra_CO3_2line.image.mom.weighted_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_dispersion_coord.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image.mom.weighted_dispersion_coord',<br />
fitsimage='TWHydra_CO3_2line.image.mom.weighted_dispersion_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom0.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image.mom0',<br />
fitsimage='TWHydra_HCOplusline.image.mom0.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_coord.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image.mom.weighted_coord',<br />
fitsimage='TWHydra_HCOplusline.image.mom.weighted_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_dispersion_coord.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image.mom.weighted_dispersion_coord',<br />
fitsimage='TWHydra_HCOplusline.image.mom.weighted_dispersion_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_apcal.image.fits')<br />
exportfits(imagename='TWHydra_contall_apcal.image',fitsimage='TWHydra_contall_apcal.image.fits')<br />
</source><br />
<br />
===Display Channel Maps===<br />
<br />
Using the Viewer you can make channel map figures. Start the Viewer and then open the CO(3-2) cube as a raster image and then the continuum as a contour image. Then we use the "wrench" icon and "P wrench" icons to set up the channel images, contour levels etc. (If you need help setting up the viewer for this image, see a screen shot of the viewer setup windows, below.)<br />
<br />
<figure id="TWHya_channel_co3_2.png"><br />
[[Image:TWHya_channel_co3_2.png|center|frame|<caption>Channel maps of the CO(3-2) emission with white continuum contours at 3 and 100 sigma.</caption>]]<br />
</figure><br />
<br />
<figure id="Viewer_setup.png"><br />
[[Image:Viewer_setup.png|center|thumb|500px|<caption>The setup windows looked like this</caption>]]<br />
</figure><br />
<br />
Repeat for HCO+(4-3)<br />
<br />
<figure id="TWHya_channel_HCOp4_3.png"><br />
[[Image:TWHya_channel_HCOp4_3.png|center|thumb|800px|<caption>Channel maps of the HCO+(4-3) emission with white continuum contours at 3 and 100 sigma. The color intensity scale is the same as that used for CO(3-2).</caption>]]<br />
</figure><br />
<br />
<!--<br />
====Examine CO Contours on an HCO+ Raster====<br />
<br />
====Matched Movies====<br />
<br />
===Image Plane and Spectral Fits===<br />
<br />
====Fit a Gaussian to the Continuum====<br />
<br />
=====Fit In the Viewer=====<br />
<br />
=====Fit Using the Command Line=====<br />
<br />
====Fit a Gaussian to the CO Line====<br />
<br />
=====Fit In the Viewer=====<br />
<br />
=====Fit Using the Command Line=====<br />
<br />
===Extract a Sub-Image===<br />
<br />
===Align Image Cubes===<br />
--><br />
<br />
{{Checked 4.5.0}}</div>Sstierwahttps://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_4.3&diff=19488TWHydraBand7 Imaging 4.32016-05-18T04:50:00Z<p>Sstierwa: </p>
<hr />
<div>[[Category:ALMA]][[Category:Imaging]][[Category:Spectral Line]]<br />
<br />
* '''This tutorial picks up where '''[[TWHydraBand7_Calibration_4.3]]''' leaves off, with fully calibrated, split science target MS. If you wish to skip the Calibration guide: obtain the calibrated data from [[TWHydraBand7#Getting_the_Data]]; extract it using <tt>tar -xzvf FILENAME</tt>; and <tt>cd</tt> into the extracted directory.'''<br />
<br />
*'''This guide is designed for CASA 4.3. If you are using an older version of CASA please see [[TWHydraBand7_Imaging_4.3]].<br />
<br />
* '''Details of the ALMA data are provided at [[TWHydraBand7]]'''<br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.3. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.3.0'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
== Prepare Continuum Data for Further Processing==<br />
<br />
In order to speed up imaging/self-calibration for the continuum data we will average channels together, and then flag the few spectral features. This method works well in the case of only a few spectral lines, while retaining enough channelization to aid in multi-frequency synthesis and being able to remove spectral features in the averaged data. When generalizing this process to other datasets, the amount of channel averaging will vary. '''Note for wide bandwidth data it is never a good idea to use the continuum estimate generated by uv-continuum subtraction as your continuum data'''. This worked OK in the past with the narrow band systems like the VLA and low dynamic range instruments like the SMA, but is not advised for ALMA wide bandwidth, high dynamic range data. <br />
<br />
<figure id="Cont_spw2.png"><br />
[[Image:Cont_spw2.png|thumb|<caption>CO(3-2) in spw=2 from the "continuum" channel averaged data.</caption>]]<br />
</figure><br />
<figure id="Cont_spw3.png"><br />
[[Image:Cont_spw3.png|thumb|<caption>Notice upswing at high channel numbers in spw=3.</caption>]]<br />
</figure><br />
<br />
One can also flag the spectral features first but in that case make a backup of the file that is analogous to TWHydra_corrected.ms as you will need it later (unflagged) for spectral line imaging. We begin by excluding ~20 channels on each edge, and averaging over 100 channel intervals:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_cont.ms*')<br />
split(vis='TWHydra_corrected.ms',outputvis='TWHydra_cont.ms',<br />
spw='0~3:21~3820',width=100,datacolumn='data')<br />
</source><br />
<br />
Now make a plot of amplitude vs. channel to see what needs to be flagged<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',spw='0~3',xaxis='channel',yaxis='amp',<br />
avgtime='1e8',avgscan=T,coloraxis='spw',iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
The CO(3-2) and HCO+(4-3) lines are obvious. The 4th spw; spw=3 also shows an upswing on the highest channels that is problematic, it was seen on the calibrators too and is likely due to a weak atmospheric feature, we will flag the worst of it.<br />
<br />
<figure id="Cont_uvplot.png"><br />
[[Image:Cont_uvplot.png|thumb|<caption>UV-plot of the continuum emission, colors show spws.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='TWHydra_cont.ms', mode='manual', <br />
spw='0:16~16, 2:21~21, 3:33~37')<br />
</source><br />
<br />
Have a look at the continuum as a function of uv-distance (in the plot to the right, the 4 spw are shown in different colors on top of each other). If the data are flat as a function of uv-distance, the source is completely unresolved. If instead you see structure (in this case decreasing amplitude with uv-distance), the source is resolved. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',spw='',xaxis='uvdist',yaxis='amp',field='',avgchannel='38',<br />
coloraxis='spw',plotfile='cont_uvplot.png')<br />
</source><br />
<br />
Notice that the spw do not have the same amplitude. Unfortunately, the red spw (highest frequency) should be higher than the green one (lowest frequency) because optically thin dust goes as nu^4, and optically thick as nu^2. This inconsistency is due to imperfect amplitude/absolute flux calibration. The self-calibration below will bring them into agreement with each other, but this is the sort of thing that results in considerable absolute flux uncertainty at submillimeter wavelengths. We are working on how to do this better.<br />
<br />
==A priori Noise Estimates==<br />
<br />
<figure id="Corrected_time.png"><br />
[[File:Corrected_time.png|thumb|<caption>Plot for estimating time.</caption>]]<br />
</figure><br />
<figure id="sensitivity_cont.png"><br />
[[File:sensitivity_cont.png|thumb|<caption>Sensitivity calculator setup with observed continuum parameters for these observations.</caption>]]<br />
</figure><br />
<br />
To estimate what the expected noise levels are, we first need to know how much time we had on source. Looking at <br />
a plot of amplitude vs time for the concatenated but pre-split data (see below) there are 9x8min scans + 6x6min scans + 3x1min + 2x2min scans for about 1.9 hours on source. There are 2 polarizations and about 1.75 GHz of total continuum bandwidth taking into account flagging.<br />
<br />
Using this information and https://almascience.nrao.edu/proposing/sensitivity-calculator, we find that the '''expected rms noise for the continuum is about 0.3 mJy/beam'''.<br />
<br />
For the spectral line data, which we will image below, with 0.12 km/s channels (needs to be entered in the field ''bandwidth per polarization''), the '''expected rms noise for the spectral lines is about 32 mJy/beam'''.<br />
<br />
==Image and Self-Calibrate the Continuum==<br />
<br />
====Create Initial Clean Image====<br />
<br />
First we will make an initial image using {{clean}}, this task will both deconvolve and clean. <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
If you are unfamiliar with the basic concepts of deconvolution and clean,<br />
pause here and review for example<br />
http://www.aoc.nrao.edu/events/synthesis/2010/lectures/wilner_synthesis10.pdf<br />
</pre><br />
<br />
In {{clean}}, we use '''mode='mfs'''' to do multifrequency synthesis, in other words grid each uv-channel independently. Since the uv-spacing is a function of frequency, this will actually achieve greater uv-coverage than if all the channels and spws had been averaged in advance. The '''imsize=100''' and '''cellsize=['0.3arcsec']''' were chosen to be appropriate for the Band and antenna configuration. At ALMA Band 7, the Full Width Half Power primary beam is about 20", so we want to make our image at least this big. We've made it a bit larger out to about the 25% power point. For the configuration used to take these data, the resolution is expected to be about 1.5" and it is a good idea to oversample the beam by setting the cell size to be a factor of 4 or 5 smaller than the beam (we have used 5 here). <br />
<br />
For doing self-calibration it is essential that only "real" signal be included in the image model, thus it is important to make a clean mask, and clean the first iteration rather conservatively (shallowly) so that you are sure that you do not have clean components in your model that do not represent real source emission. In the example below we set '''interactive=T''' so you can interactively make the clean mask and stop clean when the signal from the source starts to approach the surrounding "noise" areas in the residual map.<br />
<br />
'''NOTE:''' Real emission will not go away if you do not put a clean box on it. Conversely if you put a clean box on something that is NOT real and clean deeply you can amplify that feature. Thus, its best to be conservative and build up your clean box as you go, you can generally see fainter "real" features in the residuals.<br />
<br />
'''NOTE:''' If you start an interactive clean, and then do not make a mask, clean will stop when you tell it to go on because it has nothing to clean. There is no default mask.<br />
<br />
<figure id="Viewer_clean1.png"><br />
[[Image:Viewer_clean1.png|thumb|<caption>Interactive viewer.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall',<br />
mode='mfs', imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5, <br />
mask='',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
'''NOTE:'''{{clean}} will generate several files automatically with the '''imagename''' prepended:<br />
* <imagename>.image # the final restored image<br />
* <imagename>.flux # the effective primary beam response (e.g. for pbcor)<br />
* <imagename>.flux.pbcoverage # the primary beam coverage (ftmachine=’mosaic’ only)<br />
* <imagename>.model # the model image<br />
* <imagename>.residual # the residual image<br />
* <imagename>.psf # the synthesized (dirty) beam<br />
<br />
Once the Clean Viewer opens, click on the polygon tool with your left mouse button, and draw a polygon around the continuum emission with the left mouse button. Double click inside the region with the left mouse button when you are happy with it. It will turn from green to white when the clean mask is accepted. To continue with clean use the "Next action" buttons in the green area on the Viewer Display GUI. <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
The red X will stop clean where you are, the blue arrow will stop <br />
the interactive part of clean, but continue to clean non-interactively <br />
until reaching the number of iterations requested (niter) or the flux <br />
density threshold (whichever comes first), and the green circle arrow <br />
will clean until it reaches the "iterations" parameter on the left side <br />
of the green area. <br />
</pre><br />
<br />
'''You should chose the green circle arrow'''. It will clean 100 iterations (number under iteration in the green area on the Viewer GUI) and then show the '''residual image''' again. The middle mouse button is automatically assigned to the "plus" icon, which adjusts the colorscale. '''If you cannot easily access multiple mouse buttons, you can always assign your one mouse button the icon you want by clicking on it'''. Adjust the color scale so you can see the structure in the noise better. Also, note that the logger is telling you the amount of clean flux recovered so far, the min/max residuals, and the synthesized beam:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Model 0: max, min residuals = 0.0203454, 0.00267232 clean flux 1.30124<br />
Threshhold not reached yet.<br />
Beam used in restoration: 1.6962 by 1.54549 (arcsec) at pa 28.9043 (deg) <br />
</pre> <br />
<br />
Already with only 100 iterations, the residuals outside the clean mask are larger than that inside. So we will stop here by hitting the Red X symbol.<br />
<br />
====1st Round of Continuum Data Phase Self-calibration====<br />
<br />
Next we can use the clean model to self-calibrate the uv-data. The process of self-calibration tries to adjust the data to better match the model you give it. That is why it is important to make the model as good as you can. {{clean}} places a uv-model of the resulting image in the file <tt>TWHydra_cont.model</tt>. This model can then be used to self-calibrate the data using {{gaincal}}. We use '''gaintype='T'''' to tell it to average the polarizations before deriving solutions (which gains us a sqrt(2) in sensitivity). A critical parameter to play with is '''solint'''; we use '''solint=30s'''. From {{listobs}} the integration time of these data is about 10 seconds, so using '''solint=30s''' then gains us a sqrt(3) in sensitivity. It is often best to start with a larger '''solint''' and then work your way down to the integration time if the S/N of the data permits. For the same reasons as described in the [[TWHydraBand7_Calibration_4.3]] tutorial we want to fix up the phases before tackling amplitude by setting '''calmode='p''''.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='TWHydra_cont.ms',caltable='self_1.pcal',<br />
solint='30s',combine='',gaintype='T',<br />
refant='DV06',spw='',minblperant=4,<br />
calmode='p',minsnr=2)<br />
</source><br />
<br />
<figure id="Self_1_phase.png"><br />
[[Image:Self_1_phase.png|thumb|<caption>Phase solutions from self_1.pcal with solint=30s.</caption>]]<br />
</figure><br />
<br />
Because '''combine=' '''', we are getting independent solutions for each spw. If you are desperate for S/N, you can try combining them with combine='spw'. We have plenty of S/N in these data so we keep them separate. Look at the solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_1.pcal',xaxis='time',yaxis='phase',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,-80,80],figfile='self_1_phase.png')<br />
</source><br />
<br />
The magnitude of corrections gives you a sense of how accurate the phase transfer from the calibrators was. You are checking to see that the phases are being well tracked by the solutions, i.e. smoothly varying functions of time within a given scan. Also the solutions for each spw are lying basically on top of each other which indicates that the spw to spw phase offsets are well calibrated already. Overall, these solutions look quite good. If they didn't you could try increasing the solint and/or combining the spw into a single solution. <br />
<br />
After checking that you are happy with the solutions, apply them with {{applycal}}<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_cont.ms',field='',gaintable=['self_1.pcal'],calwt=F)<br />
</source><br />
<br />
<figure id="Viewer_pcal1.png"><br />
[[Image:Viewer_pcal1.png|thumb|<caption>Clean residuals after 100 iterations and the 1st phase only self-cal. Residuals inside mask are higher than the "noise" outside.</caption>]]<br />
</figure><br />
<br />
Next clean the source again, to save time we can start with the clean mask from the last iteration. If you make interactive adjustments to the clean mask, they will be written to the '''new''' mask TWHydra_contall_1pcal.mask, and not the old one. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_1pcal.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall_1pcal',<br />
mode='mfs',imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5, <br />
mask='TWHydra_contall.mask',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
Now after the first 100 iterations you see that the residuals inside the clean mask are higher than those outside. This is because flux that had been spread out in the map due to poorly correlated phases has been placed where it belongs on the source, thereby increasing its flux. You may also notice that your original clean mask is a little too small. If so, you can make it a bit larger, just by drawing a new polygon around the area you want to include. When you double click, it will incorporate the new mask into the current mask (if your box goes awry you can use the erase toggle [radio button] to erase and redo the mask). The new mask area need not overlap the original mask (though for this source it probably will). You might also want to use the magnifying glass to zoom in. Again, you assign mouse buttons by clicking on the icon you want. Clean another 100 iterations (for a total of 200) and stop by clicking the red X.<br />
<br />
Now open initial and 1st self-cal images to compare them using {{imview}}. This is an alternative version of the {{viewer}} that is somewhat scriptable. <br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(raster=[{'file':'TWHydra_contall.image','range':[-0.01,0.05]},<br />
{'file':'TWHydra_contall_1pcal.image','range':[-0.01,0.05]}])<br />
</source><br />
<br />
Once the Viewer Display panel opens, click on the box next in the "Images" panel and then use the tapedeck buttons in the panel to alternate between the two images. Because the range was explicitly set, they are on the same color scale. It is obvious that the self-calibrated image is better. To quantify, 1st toggle back to "normal" and then draw a region that excludes the central source with the polygon tool and then double click inside (if you stay in the "Images" view, only the statistics for the last image opened will appear on the terminal instead of both). The basic statistics of the polygon region will print to the '''terminal''':<br />
<br />
<pre style="background-color: #fffacd;"><br />
TWHydra_contall.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2357 -9.434800e-01 -2.858690e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-4.002885e-04 7.906752e-03 7.898289e-03 -2.541723e-02 2.172779e-02 <br />
<br />
TWHydra_contall_1pcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2357 6.326584e-01 1.916918e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
2.684168e-04 3.655786e-03 3.646692e-03 -1.215155e-02 1.109403e-02 <br />
</pre><br />
<br />
The self-calibrated image has more than a factor of 2 lower rms noise!<br />
<br />
====2nd Round of Continuum Data Phase Self-calibration====<br />
<br />
Now that we have a better model, we solve for solutions again. This time we will try making the solint smaller -- the integration time is about 10 seconds, so we set '''solint='int'''' to have it use the integration time.<br />
<br />
<figure id="Self_2_phase.png"><br />
[[Image:Self_2_phase.png|thumb|<caption>Phase solutions from self_2.pcal with solint='int'.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='TWHydra_cont.ms',caltable='self_2.pcal',<br />
solint='int',combine='',gaintype='T',<br />
refant='DV06',spw='',minblperant=4,<br />
calmode='p',minsnr=2)<br />
</source><br />
<br />
Now plot the new solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_2.pcal',xaxis='time',yaxis='phase',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,-80,80],figfile='self_2_phase.png')<br />
</source><br />
<br />
The phases on this shorter '''solint''' still seem to be tracking well so we will apply it and make a new image and check to see if there is improvement. <br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_cont.ms',field='',gaintable=['self_2.pcal'],calwt=F)<br />
</source><br />
<br />
<figure id="Viewer_pcal2.png"><br />
[[Image:Viewer_pcal2.png|thumb|<caption>Clean residuals after 2nd phase only self-cal and 250 iterations. The residuals inside the clean mask are lower than those outside, so its time to stop.</caption>]]<br />
</figure><br />
<br />
Now clean again, updating '''mask''' with the most recent mask file.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_2pcal.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall_2pcal',<br />
mode='mfs',imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5,usescratch=False,<br />
mask='TWHydra_contall_1pcal.mask',<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
After 200 iterations<br />
<br />
<pre style="background-color: #fffacd;"><br />
Model 0: max, min residuals = 0.00489776, -0.00464541 clean flux 1.44461<br />
</pre><br />
<br />
It looks like it could use just a little more cleaning, so set '''iterations=50 in the GUI'''.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Clean used 50 iterations to approach a threshhold of 0.0015067<br />
0.0107122 Jy <- cleaned in this cycle for model 0 (Total flux : 1.45532Jy)<br />
Final maximum residual = 0.00326382<br />
Model 0: max, min residuals = 0.00326382, -0.00321361 clean flux 1.45532<br />
</pre><br />
<br />
The small amount of flux cleaned this cycle indicates that clean is converging and it's about time to stop. Also the residuals inside the clean mask are now smaller than the residuals outside (i.e. the noise) also indicating it's time to stop by hitting the red X on the GUI.<br />
<br />
Now repeat the display, blinking, and image statistics steps described above for the 1st and 2nd phase-only self-cal iterations.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(raster=[{'file':'TWHydra_contall_1pcal.image','range':[-0.01,0.05]},<br />
{'file':'TWHydra_contall_2pcal.image','range':[-0.01,0.05]}])<br />
</source><br />
<br />
The difference is small:<br />
<pre style="background-color: #fffacd;"><br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2466 4.611597e-02 1.397287e-03 <br />
Mean Rms Std dev Minimum Maximum <br />
1.870072e-05 3.831524e-03 3.832255e-03 -1.414417e-02 1.109403e-02 <br />
<br />
TWHydra_contall_2pcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2466 1.159416e-01 3.512963e-03 <br />
Mean Rms Std dev Minimum Maximum <br />
4.701606e-05 3.811716e-03 3.812199e-03 -1.383034e-02 1.078456e-02 <br />
</pre><br />
<br />
This small improvement suggests that we have gone as far as we can with phase self-cal.<br />
<br />
===Continuum Data Amplitude Self-Calibration===<br />
<br />
Now we will apply the best phase solution table on-the-fly while solving for the amplitude self-cal solutions. Since amplitude changes more slowly and is less constrained than phase, we use a longer '''solint='inf'''', as long as '''combine=' '''' this means to do one solution per scan. <br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='TWHydra_cont.ms',caltable='self_ap.cal',<br />
solint='inf',combine='',gaintype='T',<br />
refant='DV06',spw='',minblperant=4,<br />
gaintable=['self_2.pcal'],<br />
calmode='ap',minsnr=2)<br />
</source><br />
<br />
It's useful to look at the residual phase in the amplitude calibration table, i.e. since we applied our best phase-only solution while solving for this new amplitude and phase ('''calmode='ap'''') solution, the phase should already be corrected.<br />
<br />
<figure id="Self_ap_phase.png"><br />
[[Image:Self_ap_phase.png|thumb|<caption>Residual phase solutions from self_ap.cal.</caption>]]<br />
</figure><br />
<figure id="Self_ap_amp.png"><br />
[[Image:Self_ap_amp.png|thumb|<caption>Amplitude solutions from self_ap.cal.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_ap.cal',xaxis='time',yaxis='phase',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,-1,1],figfile='self_ap_phase.png')<br />
</source><br />
<br />
The residuals are very small as expected. (If you see large residuals here, it means that the phase-only solution is suspect, and you were mostly just moving noise around.) Now look at the amplitude solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_ap.cal',xaxis='time',yaxis='amp',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,0.6,1.4],figfile='self_ap_amp.png')<br />
</source><br />
<br />
For the most part these look very good except one rather large deviation on DV06. Apply both the final phase and the amplitude calibration tables.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_cont.ms',field='',gaintable=['self_2.pcal','self_ap.cal'],calwt=F)<br />
</source><br />
<br />
Plot the corrected data as a function of both time and uv-distance. It is always a good idea to check these after an amplitude self-calbration to be sure that it worked properly. Occasionally, a few spurious bits of data will get blown up by the amplitude self-cal if it is not well-constrained. <br />
<br />
<figure id="Selfcal_time.png"><br />
[[Image:Selfcal_time.png|thumb|<caption>Post self-calibration amplitude vs. time</caption>]]<br />
</figure><br />
<figure id="Selfcal_uvdist.png"><br />
[[Image:Selfcal_uvdist.png|thumb|<caption>Post self-calibration amplitude vs. uv-distance</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',xaxis='time',yaxis='amp',<br />
avgchannel='38',ydatacolumn='corrected',coloraxis='spw',<br />
plotfile='selfcal_time.png')<br />
</source><br />
<br />
The time where we saw a large amplitude correction on DV06 looks consistent here so the large correction we saw in the solutions corrected a real issue. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',xaxis='uvdist',yaxis='amp',<br />
avgchannel='38',ydatacolumn='corrected',coloraxis='spw',<br />
plotfile='selfcal_uvdist.png')<br />
</source><br />
<br />
You will see that this plot looks much better than before. <br />
<br />
<figure id="Viewer_apcal.png"><br />
[[Image:Viewer_apcal.png|thumb|<caption>Clean residuals after final amplitude and phase self-cal.</caption>]]<br />
</figure><br />
<br />
Now make the final continuum image.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_apcal.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall_apcal',<br />
mode='mfs',imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5,usescratch=False,<br />
mask='TWHydra_contall_2pcal.mask',<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
We know we need to clean at least 250 iterations (i.e. 100+100+50=250), so set iterations to 300 in the gui and hit the round green arrow. After this notice how much better the residual looks. Clean another 100 iterations. The "circular pattern", and 4 bright spots at each corner you see now in the residual is likely due to non-closing amplitude errors that cannot be removed with an antenna based self-calibration, so this is as good as it gets with pure self-cal. Hit the Red X to stop clean.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Clean used 100 iterations to approach a threshhold of 0.00105507<br />
0.0061808 Jy <- cleaned in this cycle for model 0<br />
Final maximum residual = 0.00242926<br />
Model 0: max, min residuals = 0.00238278, -0.00242926 clean flux 1.48201<br />
</pre><br />
<br />
Now repeat the display, blinking, and image statistics described above for the 2nd phase only and the new amplitude & phase self-cal'ed images.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(raster=[{'file':'TWHydra_contall_2pcal.image','range':[-0.01,0.05]},<br />
{'file':'TWHydra_contall_apcal.image','range':[-0.01,0.05]}])<br />
</source><br />
<br />
The amplitude and phase self cal'ed image is notably better than phase-only. Quantitatively:<br />
<pre style="background-color: #fffacd;"><br />
<br />
TWHydra_contall_2pcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 3542 2.053068e-01 6.220676e-03 <br />
Mean Rms Std dev Minimum Maximum <br />
5.796351e-05 3.955967e-03 3.956101e-03 -1.383034e-02 1.078456e-02 <br />
<br />
TWHydra_contall_apcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 3542 6.044652e-04 1.831495e-05 <br />
Mean Rms Std dev Minimum Maximum <br />
1.706565e-07 1.270183e-03 1.270362e-03 -4.980673e-03 4.137159e-03 <br />
</pre> <br />
<br />
and indeed, we've gained another factor of 3 in sensitivity. <br />
<br />
'''Overall with this self-calibration we've improved the noise by a factor of 6.7! With a peak flux density of 0.98 Jy, the S/N increased from 115 initially to 770 after. So, well worth the trouble.'''<br />
<br />
<div class="noprint" style="float:none; border:0px solid blue;background-color:#F6CEF5;padding:2px;"><br />
If you have used the '''standard='Butler-JPL-Horizons 2012' ''' model during the calibration process, you should see an increase in peak flux density of about 3%.<br />
</div><br />
<br />
It is notable that we are still a factor of more than 4 from the apriori noise estimate of 0.3 mJy/beam. This is likely due to residual sources of non-closing (not antenna based) errors in the data like baseline errors and baseline-dependent bandpass errors. Additionally, polarization errors (which we did not calibrate at all) can contribute, as well as imperfect uv-coverage with only 8 antennas. A dynamic range of 770 is actually quite good in the submillimeter.<br />
<br />
==Apply self-calibration to Full Dataset and Split Line Data==<br />
<br />
Now apply the self-calibration derived from the continuum emission to the full unchannel-averaged data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_corrected.ms',gaintable=['self_2.pcal','self_ap.cal'],calwt=F)<br />
</source><br />
<br />
Split off the CO(3-2) spectral line data in spw=2 and the HCO+(4-3) data in spw=0 for further processing.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2.ms*')<br />
split(vis='TWHydra_corrected.ms',outputvis='TWHydra_CO3_2.ms',datacolumn='corrected',spw='2')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplus.ms*')<br />
split(vis='TWHydra_corrected.ms',outputvis='TWHydra_HCOplus.ms',datacolumn='corrected',spw='0')<br />
</source><br />
<br />
==Continuum Subtraction== <br />
<br />
Next we need to subtract the continuum emission from the spectral line data. It is best to do this in the uv-plane. The first step is to make a channel plot of the spectral data to get the line-free channel ranges for both spectral lines. Since the line emission is simple (one spectral line per spw) and there are more than enough line-free channels we do not need to be very precise just stay well away from the line and whenever possible it is best to chose line-free channel ranges on either side of the line for the best possible baseline subtraction. <br />
<br />
<figure id="CO3_2_channel.png"><br />
[[Image:CO3_2_channel.png|thumb|<caption>CO(3-2) line in channel space.</caption>]]<br />
</figure><br />
<figure id="HCOp4_3_channel.png"><br />
[[Image:HCOp4_3_channel.png|thumb|<caption>HCO+(4-3) in channel space.</caption>]]<br />
</figure><br />
<br />
'''Note''': after the split above, the original spw ids will be relabeled as 0 in each file because there is only one spectral window in each file.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_CO3_2.ms',spw='0',xaxis='channel',yaxis='amp',<br />
avgtime='1e8',avgscan=T,coloraxis='spw',plotfile='CO3_2_channel.png')<br />
</source><br />
<br />
It is a good idea to stay a little away from the very edges of the baseband which can be noisy. The channel ranges <br />
20~2000 and 2400~3800 look like good choices for CO(3-2).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_HCOplus.ms',spw='0',xaxis='channel',yaxis='amp',<br />
avgtime='1e8',avgscan=T,coloraxis='spw',plotfile='HCOp4_3_channel.png')<br />
</source><br />
<br />
The channel ranges 20~1500 and 1900~3800 look like good choices for HCO+(4-3).<br />
<br />
Next use the identified line-free channel ranges and {{uvcontsub}} to subtract the continuum model from the line emission.<br />
<br />
<source lang="python"><br />
# In CASA<br />
uvcontsub(vis='TWHydra_CO3_2.ms',fitorder=1,fitspw='0:20~2000,0:2400~3800')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
uvcontsub(vis='TWHydra_HCOplus.ms',fitorder=1,fitspw='0:20~1500,0:1900~3800')<br />
</source><br />
<br />
Note: If you do not have line-free channels on both sides of the line emission, it is safer to use '''fitorder=0''', or the fit may diverge.<br />
<br />
==Spectral Line Imaging==<br />
<br />
Now we are ready to make cubes of the line emission. The imaging parameters are similar to the continuum except for <br />
those dealing with the spectral setup: '''mode''', '''start''', '''width''', '''nchan''', '''restfreq''', and '''outframe''' parameters. When making spectral images you have three choices for the '''mode''' parameter: '''channel''', '''velocity''', and '''frequency'''. Data are taken using constant frequency channels. For spectral line analysis it's often more useful to have constant velocity channels, and this is also the best way to make images of multiple lines with the exact same channelization for later comparison. For '''mode='velocity'''', the desired '''start''' and '''width''' also need to be given in velocity units for the desired output frame. <br />
<br />
It is important to note that ALMA does not do on-line Doppler Tracking and the native frame of the data is TOPO. If you do not specify '''outframe''' the output cube will also be in TOPO, which is not very useful for spectral line work. The Doppler Shift is taken out during the regridding to the desired outframe in {{clean}} or alternatively it can be done separately by the {{cvel}} task which would need to be run before {{clean}}. <br />
<br />
<figure id="CO3_2_vel.png"><br />
[[Image:CO3_2_vel.png|thumb|<caption>CO(3-2) spectrum in LSRK velocity space.</caption>]]<br />
</figure><br />
<figure id="HCOp4_3_vel.png"><br />
[[Image:HCOp4_3_vel.png|thumb|<caption>HCO+(4-3) spectrum in LSRK velocity space.</caption>]]<br />
</figure><br />
<br />
To see what velocity parameters you want to set in clean it is useful to make a plot in {{plotms}} in the desired output frame. To make it easier to see, we set a '''plotrange''' since we know the LSRK velocity of TW Hya is about 2.88 km/s. Note these plots take a little longer because of the frame shift.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_CO3_2.ms.contsub',xaxis='velocity',yaxis='amp',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',<br />
restfreq='345.79599GHz',plotrange=[-20,23,0,0],plotfile='CO3_2_vel.png')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_HCOplus.ms.contsub',xaxis='velocity',yaxis='amp',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',<br />
restfreq='356.7342GHz',plotrange=[-20,23,0,0],plotfile='HCOp4_3_vel.png') <br />
</source><br />
<br />
From these plots it looks like imaging the cubes from about -5 to +8 km/s will encompass the line, but still provide several line-free channels on either side so the noise level can be estimated. The channel width is 122 kHz, which at <br />
345.79599 GHz is 0.106 km/s. Recall that the spectral ''resolution'' is a factor of two poorer. We will use a velocity channel width of 0.12 km/s for a little oversampling, but the spectral resolution remains 0.2 km/s.<br />
<br />
As before, it is very important that you make a clean mask. There are many ways to do this ranging from the complicated to simple. For this example we will make a single clean mask that encompasses the line emission in every channel and apply it to all channels. This is much better than no clean mask, though not quite as good as making an individual mask for each channel. For some sources, one can use the continuum mask to clean the line, however TW Hya is a bit curious in that the continuum emission is not as extended as the line emission (Hughes et al. 2008).<br />
<br />
=== CO(3-2) Imaging ===<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.*')<br />
clean(vis='TWHydra_CO3_2.ms.contsub',imagename='TWHydra_CO3_2line',<br />
imagermode='csclean',spw='',<br />
imsize=100,cell=['0.3arcsec'],<br />
mode='velocity',start='-4km/s',width='0.12km/s',nchan=118,<br />
restfreq='345.79599GHz',outframe='LSRK',<br />
weighting='briggs',robust=0.5,<br />
mask='',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=100000)<br />
</source><br />
<br />
<figure id="Viewer_55.png"><br />
[[Image:Viewer_55.png|thumb|<caption>Interactive Viewer window with CO(3-2) clean mask, before cleaning starts.</caption>]]<br />
</figure><br />
<figure id="Viewer_500.png"><br />
[[Image:Viewer_500.png|thumb|<caption>Interactive Viewer window for CO(3-2), after 500 iterations, more cleaning is needed.</caption>]]<br />
</figure><br />
<br />
It will take a little while to grid the cube, when the interactive viewer opens, use the tapedeck to cycle through the channels. You should see a progress of line emission in channels 40 to 70 or so.<br />
*Go to channel 57 (about line center)<br />
*Select the polygon tool with the left mouse button<br />
*Select the "All Channels" toggle in the green area<br />
*Draw a polygon around the channel 57 emission, double click inside to activate.<br />
*Now go to channel 60, this is the channel with the most extent to the SE, draw another polygon that encompasses this emission if necessary,double click inside to activate.<br />
*Now go to channel 55, this is the channel with the most extent to the NW, draw another polygon that encompasses this emission if necessary,double click inside to activate. <br />
*Now double check the mask by cycling through channels with real line emission to be sure that your clean box encompasses the emission, but does not extend far beyond it. Again the "erase" toggle can come in handy if things go awry or if you want to just delete a small portion of an existing mask (just draw a polygon around what you want to erase and double click inside), be sure to switch back to "add" before going on.<br />
<br />
The figure shows what the final clean box should look like. Now clean using the green circle arrow. You can watch the progress in the logger. When 100 iterations are done, the viewer will show the residual map for each channel. Cycle through the channels and see whether you are still happy with the clean box in each signal channel. The "erase button" can help you fix mistakes. If necessary adjust. It is often useful to adjust the colorscale with the "plus" symbol icon. Keep going until the residual emission looks like the surrounding noise. If it seems to be going slowly, increase the iterations to 300 for a round or two. I stopped cleaning (Red x) when the logger showed (about 900 iterations). <br />
<pre style="background-color: #fffacd;"><br />
12.9846 Jy <- cleaned in this cycle for model 0<br />
Final maximum residual = 0.157312<br />
Model 0: max, min residuals = 0.157312, -0.0871295 clean flux 279.304<br />
</pre><br />
<br />
NOTE: The residuals are still a bit high in the strongest emission channels after it is well cleaned in the weaker channels. This is an indication that the sensitivity is "dynamic range" limited. In other words even with more <br />
intrinsic sensitivity per integration (i.e. better system temperature), the dynamic range limit would remain the same unless you get more uv-coverage. The fundamental dynamic range limitations of ALMA will be considerably better with 16 antennas in Early Science and MUCH better with the full 50-antenna array.<br />
<br />
=== HCO+(4-3) Imaging ===<br />
<br />
Now image and clean the HCO+(4-3) line using what you learned above.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.*')<br />
clean(vis='TWHydra_HCOplus.ms.contsub',imagename='TWHydra_HCOplusline',<br />
imagermode='csclean',spw='',<br />
imsize=100,cell=['0.3arcsec'],<br />
mode='velocity',start='-4km/s',nchan=118,width='0.12km/s',<br />
restfreq='356.7342GHz',outframe='LSRK',<br />
weighting='briggs',robust=0.5,<br />
mask='',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=100000)<br />
</source><br />
<br />
I stopped cleaning when: <br />
<pre style="background-color: #fffacd;"><br />
4.79833 Jy <- cleaned in this cycle for model 0<br />
Final maximum residual = 0.0977348<br />
Model 0: max, min residuals = 0.0977348, -0.060484 clean flux 192.066<br />
</pre><br />
<br />
==Image Analysis==<br />
<br />
After all that hard work you now have deconvolved images of the 350 GHz continuum, the CO (3-2) line, and the HCO+ (4-3) line. CASA includes tools to help you understand the contents of these images and make basic scientific measurements. These tools are divided between graphical exploration tools, accessible via the CASA viewer, and command line analysis tasks. To access the viewer, simply type '''viewer()''' and to see the list of analysis tasks available in CASA type '''tasklist''' at the CASA prompt and look under the Analysis sub-heading.<br />
<br />
If you want to do this portion of the guide and have downloaded the (.FITS) reference images, you can import them to be CASA images using '''importfits'''. If you are re-importing the images, use the commented remove command, here, to delete the previous import first.<br />
<br />
<source lang="python"><br />
# In CASA<br />
# os.system("rm -rf TWHydra_CO3_2line.image")<br />
importfits(fitsimage="TWHydra_CO3_2line.image.fits", imagename="TWHydra_CO3_2line.image")<br />
</source><br />
<br />
where '''fitsimage''' refers to the file to imported and '''imagename''' gives the output filename. If you are proceeding directly from the imaging step, your data are already CASA images and you may proceed without any importing.<br />
<br />
You can get the basic properties of any CASA image using the '''imhead''' command. For example, type <br />
<br />
<source lang="python"><br />
# In CASA<br />
imhead("TWHydra_CO3_2line.image")<br />
</source><br />
<br />
and look at the CASA logger. You will see an image summary like the following<br />
<br />
<pre style="background-color: #fffacd;"><br />
INFO imhead ##########################################<br />
INFO imhead ##### Begin Task: imhead #####<br />
INFO imhead imhead(imagename="TWHydra_CO3_2line.image",mode="summary",hdkey="",hdvalue="",<br />
INFO imhead hdtype="",hdcomment="",verbose=False)<br />
INFO ImageAnalysis <br />
INFO ImageAnalysis Image name : TWHydra_CO3_2line.image<br />
INFO ImageAnalysis Object name : TW Hya<br />
INFO ImageAnalysis Image type : PagedImage<br />
INFO ImageAnalysis Image quantity : Intensity<br />
INFO ImageAnalysis Pixel mask(s) : None<br />
INFO ImageAnalysis Region(s) : None<br />
INFO ImageAnalysis Image units : Jy/beam<br />
INFO ImageAnalysis Restoring Beam : 1.68065 arcsec, 1.53193 arcsec, 22.3015 deg<br />
INFO ImageAnalysis <br />
INFO ImageAnalysis Direction reference : J2000<br />
INFO ImageAnalysis Spectral reference : LSRK<br />
INFO ImageAnalysis Velocity type : RADIO<br />
INFO ImageAnalysis Rest frequency : 3.45796e+11 Hz<br />
INFO ImageAnalysis Pointing center : 11:01:51.844983 -34.42.17.160885<br />
INFO ImageAnalysis Telescope : ALMA<br />
INFO ImageAnalysis Observer : Unknown<br />
INFO ImageAnalysis Date observation : 2011/04/22/00:15:42<br />
INFO ImageAnalysis Telescope position: [2.22514e+06m, -5.44031e+06m, -2.48103e+06m] (ITRF)<br />
INFO ImageAnalysis <br />
INFO ImageAnalysis Axis Coord Type Name Proj Shape Tile Coord value at pixel Coord incr Units<br />
INFO ImageAnalysis -------------------------------------------------------------------------------------------------- <br />
INFO ImageAnalysis 0 0 Direction Right Ascension SIN 100 25 11:01:51.845 50.00 -3.000000e-01 arcsec<br />
INFO ImageAnalysis 1 0 Direction Declination SIN 100 25 -34.42.17.161 50.00 3.000000e-01 arcsec<br />
INFO ImageAnalysis 2 2 Spectral Frequency 118 59 3.45801e+11 0.00 -1.38414152e+05 Hz<br />
INFO ImageAnalysis Velocity -4 0.00 1.200000e-01 km/s<br />
INFO ImageAnalysis 3 1 Stokes Stokes 1 1 I<br />
INFO imhead ##### End Task: imhead #####<br />
INFO imhead ##########################################<br />
<br />
</pre><br />
<br />
This report tells you about the target, shape, and coordinates of the image. It also notes the rest frequency and some details of the observation. '''imhead''' may be used more generally to retrieve header keywords as python variables or to manipulate the header of an image. Consult the help for details.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
You may want to pay particular attention to the third and fourth axis of the CASA image. These are <br />
usually frequency (velocity) and Stokes (polarization) in some order. An occasional source of confusion <br />
is that this order is not always the same. Often CLEAN will output images with the Stokes axis third, <br />
while IMPORTFITS usually yields images with the frequency axis third. If you encounter problems with<br />
image analysis tasks, you may want to check whether this results from conflicting axis definitions. You<br />
can adjust the order of the axes using the IMTRANS task.<br />
</pre><br />
<br />
Before proceeding, make sure that you have all three data sets as CASA images: '''TWHydra_CO3_2line.image''', '''TWHydra_HCOPlusline.image''', and '''TWHydra_contall_apcal.image'''. If you do not, then import them from the provided reference images. If you are re-importing the FITS images, run the commented remove commands before running importfits.<br />
<br />
<source lang="python"><br />
# In CASA<br />
# os.system("rm -rf TWHydra_CO3_2line.image")<br />
importfits(fitsimage="TWHydra_CO3_2line.image.fits", imagename="TWHydra_CO3_2line.image")<br />
# os.system("rm -rf TWHydra_HCOplusline.image")<br />
importfits(fitsimage="TWHydra_HCOplusline.image.fits", imagename="TWHydra_HCOplusline.image")<br />
# os.system("rm -rf TWHydra_contall_apcal.image")<br />
importfits(fitsimage="TWHydra_contall_apcal.image.fits", imagename="TWHydra_contall_apcal.image")<br />
</source><br />
<br />
In the rest of this guide we will construct ''moment maps'' showing the integrates, velocity field, and line width of the two lines. We will carry out Gaussian fits to the continuum and line maps. We will also illustrate some of the additional analysis capabilities available in CASA: subcube extraction, retrieval of data into python arrays, cube alignment, smoothing, and overlays of multiple spectral lines.<br />
<br />
===Moment Maps===<br />
<br />
The line "images" of CO(3-2) and HCO+(4-3) are, of course, cubes rather than images. Two dimensional ''moment maps'' are a standard way to present such data. These are maps showing the result of various moments (or similar calculations) carried out along the frequency axis of the cube. For example, the "moment 0" map is the sum of emission along the frequency axis at each pixel. The first moment is the intensity-weighted velocity (or frequency). The second moment is the intensity-weighted velocity (or frequency) dispersion about the mean. These and a number of other calculations (for example the maximum intensity) can be calculated via the '''immoments''' task. Consult the help or the CASA cookbook for more details.<br />
<br />
In this section, we will calculate moments for our two spectral line data cubes. To make the highest quality moment maps, we will first identify the planes of the data cube that contain emission, so that we can carry out the sum only over these channels. Doing otherwise adds noise to the moment map without adding signal and so lowers the signal-to-noise ratio of the final image. For the first and second moments we will identify an intensity threshold above which the data are statistically very likely to correspond to real astronomical emission. We will restrict the calculation to consider only data above this threshold, yielding a cleaner calculation (the second moment, in particular, is not at all robust against the inclusion of outlying noise). Finally, we will inspect the resulting moment maps with the viewer and output them to .FITS files.<br />
<br />
====Estimate the Spectral Extent====<br />
<br />
First, we want to figure out what planes appear to contain real emission. Open the CO data cube with the CASA viewer via:<br />
<br />
<source lang="python"><br />
# In CASA<br />
viewer("TWHydra_CO3_2line.image")<br />
</source><br />
<br />
This will open the CO(3-2) data cube as a raster image. Use the Animator pane to scroll through the cube, noting that the emission is mostly confined to ~40 channels near the center of the cube. There are several ways to make a more rigorous estimate. <br />
<br />
''By-Plane Inspection:'' First, you could increase the stretch of the image to identify by hand the first and last channels with visible emission. To do open the Data Display Options panel in the viewer (the wrench icon) and manually set the data range and/or scaling power cycles to highlight faint emission (note that you can also do this using the mouse and the color stretch - sun - icon). I left the scaling power cycles at 0 and set the data range to [-0.15, 0.15]. Then scroll through the cube and note the first and last channels with obvious emission. If I do this, I find emission from about plane 30 through plane 86.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:DataDisplayPanelStretch.png|The Data Display Panel used to set the color stretch, here from [-0.15, 0.15] with a linear (0) stretch. Setting the stretch to a negative value will highlight lower emission (a more logarithmic stretch). We got to this panel by clicking the wrench icon. You can also get from the dropdown menus (Data->Adjust).<br />
File:TWHydraCOChan33.png|Channel 33 of the CO(3-2) cube on this stretch. This is about the first channel to show clear emission.<br />
File:TWHydraCOChan80.png|Channel 80 of the CO(3-2) cube on this stretch. This is about the last channel to show clear emission.<br />
</gallery><br />
</center><br />
<br />
To make this more rigorous, you can work out a noise estimate before hand (we'll find it to be about 0.025 Jy/beam) and overplot a contour to indicate significant emission. You can do this by hand by using the Data Manager (folder icon) to open TWHydra_CO3_2line.image as a "contour map" and then using the Data Display Options to manipulate the contour levels. To show a 3-sigma contour with sigma=0.025 Jy/beam set the Relative Contour Levels to [3], the Base Contour Level to 0, and the Unit Contour Level to 0.025. You can display a 5-sigma contour or change the RMS analogously. Scrolling through the cube, I see 3-sigma emission from channels 33 through 80.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:DataDisplayPanelContour.png|The Data Display Panel now being used to set the contour levels. We set the contour unit to 0.025 and ask for a single contour at 3 times this value. Notice that we clicked the tab along the top of the window to select the contour map.<br />
File:TWHydraCOChan33Contour.png|Channel 33 of the CO(3-2) cube on this stretch with a 3-sigma contour overlaid.<br />
File:TWHydraCOChan80Contour.png|Channel 80 of the CO(3-2) cube on this stretch with a 3-sigma contour overlaid.<br />
</gallery><br />
</center><br />
<br />
''Look at a Spectrum:'' You can also look at a spectrum of the source. To do this, scroll to a channel with a lot of emission (I went to 57) and then use the mouse to drag out a rectangle. To do this, left click on the rectangle box in the mouse toolbar (this assigns the left mouse button to define rectangle regions). Then drag out a box around the emission using the same button. Now click the spectrum in the toolbar to open the spectral profile tool. You will see the average profile for the selected region. You can set the bottom axis to show channels. You can zoom in within the spectral profile by dragging out a rectangle. When I do this, I find significant emission from channels 40-80.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:TWHydraRectangle.png|Defining a rectangular region around the main emission from TW Hydra. First we clicked the rectangle button on the mouse toolbar, then we held that button and dragged out the purple rectangle. After defining the rectangle, you can drag it around or delete it with <ESC>.<br />
File:TWHydraSpectrum.png|The spectrum of this rectangular region viewed in the spectral profile browser. Note that the bottom axis has been set to show channels. To get this spectrum, we defined the rectangular region and then clicked the spectrum button on the toolbar.<br />
File:TWHydraSpectrumZoom.png|A zoom in on the spectrum. The line extends from channels ~40-80.<br />
</gallery><br />
</center><br />
<br />
''Look at a Declination-Frequency Projection (or an R.A.-Frequency Projection):'' This is probably the least reliable way to do this, but illustrates a neat capability of the viewer. Open the Data Display Options (click the wrench icon) and open the "display axes" and "hidden axes" tabs. Use the dropdown menus to change the display so that the x-axis shows Declination, the y-axis shows Frequency, and the z-axis shows "Right Ascension." Now you are scrolling through planes of intensity as a function of Declination and Frequency. Use the animator to move to R.A. plane ~ 50 (the center of the source) and pull the stretch up (in the wrench tool; I used [-0.15,0.15] again). Mouse over the image and look at the "Position Tracking" pane in the bottom of the image, noting the pixel extent of emission in the frequency axis of this plane. I see traces of emission from channel ~30-90.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:DataDisplayPanelAxes.png|The Data Display Panel, here used to set which axes are displayed. We have adjusted the y-axis to show frequency and the x-axis to show Declination. The z-axis is now Right Ascension, so that we will scroll through planes of Right Ascension.<br />
File:DataDisplayPanelPixels.png|The Data Display Panel, here we are setting coordinates to show "pixels" rather than world coordinates.<br />
File:TWHydraDecFreqPixels.png|A Frequency-Declination plane of the cube near the central R.A. pixel (50). The rough extent of emission may be simply read off the y-coordinate. As above, we could overplot a 3-sigma contour to add more rigor.<br />
</gallery><br />
</center><br />
<br />
<br />
You can repeat this exercise for the HCO+ (4-3) emission. Using the Spectral Profile Browser, I find that the line extends from about channel 40 through channel 75.<br />
<br />
====Make Moment 0 Maps====<br />
<br />
With an estimate of the spectral extent of emission, we are now ready to make moment 0 maps of the CO(3-2) and HCO+(4-3) lines. It is possible to do this using the 'Calculate Moments/Spectral Profile tool' in the viewer, but here we do this using the '''immmoments''' command,<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom0')<br />
immoments(imagename='TWHydra_CO3_2line.image',moments=[0],<br />
outfile='TWHydra_CO3_2line.image.mom0',<br />
chans='30~90')<br />
</source><br />
<br />
and<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom0')<br />
immoments(imagename='TWHydra_HCOplusline.image',moments=[0],<br />
outfile='TWHydra_HCOplusline.image.mom0',<br />
chans='40~75')<br />
</source><br />
<br />
immoments will sum across the channels specified by '''chans''' and produce new CASA images with the names specified by '''outfile'''. These can be inspected using the CASA viewer just like any other image. Note that unlike higher-order moments, the moment-0 map is robust to the inclusion of noisy signal-free channels (to within reason, you just decrease your signal-to-noise ratio) and indeed may be biased to miss faint emission by imposing a threshold. For that reason, we will eschew the '''includepix''' keyword as we make the moment 0 maps.<br />
<br />
Let's look at the output using the viewer. We can specify some of the display options in the call to start the viewer by using '''imview''' instead of '''viewer'''.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview( raster=[ {'file':'TWHydra_CO3_2line.image.mom0',<br />
'range':[0.0,10.],<br />
'scaling':-1},<br />
{'file':'TWHydra_HCOplusline.image.mom0',<br />
'range':[0.0,10.],<br />
'scaling':-1}], <br />
contour={'file':'TWHydra_contall_apcal.image', 'base':0, 'unit':0.0025, 'levels':[3,100]} )<br />
</source><br />
<br />
This does several things: It opens the viewer with raster images of the moment 0 maps of CO(3-2) and HCO+(4-3), sets the range of the color stretch from [0, 10] for each image and sets the scaling to be -1, which highlights faint emission compared to the normal (0) stretch. It also opens the continuum image as a contour and defines two contour levels. Once the viewer is open, you can blink between the images by going into the Animator pane, checking the white box next to "Images" to enable animation between images, and then sliding the bar back and forth. See the name of the image being shown change. You can also show two images side by side by going to the Viewer Canvas Manager (wrench+P icon) and opening the "Number of Panels" tab. Set the "Number of panels in x" to 2 and make sure that the Images box is checked in the Animator pane. You will see both images side by side.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:CanvasManagerPanels.png|The Viewer Canvas Manager, accessed via the Wrech+P icon (not to be confused with the plain old wrench). Here we have adjusted the number of x-panels from 1 to 2 so that we show the two moment maps side by side.<br />
File:TWHydraMoment0Maps.png|The moment-0 maps of CO(3-2) and HCO+(4-3) plotted side by side on the same color stretch, both with the continuum contours overlaid. To get the two images side by side, run the imview call above then set the number of panels to 2 and make sure that the Images box in the Animator Pane (here at the bottom of the window) is checked.<br />
File:DataDisplayImview.png|Data Display Panel after our imview call. Imview allowed us to set the stretch, range, and contour levels from the command line.<br />
</gallery><br />
</center><br />
<br />
====Estimate the Noise====<br />
<br />
We have already made a few offhand comparisons to the RMS noise. This quantity is often critical to know when exploring the data. Because the higher-order moments (especially the dispersion) are not at all robust to the inclusion of noise, we will calculate them only from regions of the cube that have intensity several times the RMS noise value or higher and are thus very likely to contain real astronomical emission. To proceed, we need to estimate the RMS noise for our data.<br />
<br />
The easiest way to do this is to calculate the RMS scatter of the data about zero from a part of the data that you suspect to be (mostly) free of astronomical signal. In a data cube the easiest way to do this will often be to identify signal-free planes (channels) of the cube and to simply calculate the RMS in these regions. We can do this straightforwardly using the '''imstat''' command in CASA.<br />
<br />
IMSTAT COMMAND<br />
<br />
IMSTAT OUTPUT<br />
<br />
Alternatively, you can get similar statistics on a region of an image or data cube selected manually inside the viewer. Drag out a region, for example a rectangle, using one of the mouse tools. Then <br />
<br />
IMAGES OF REGION SELECTION, OUTPUT, REGION MANAGER<br />
<br />
Suggested values for CO(3-2), HCO+(4-3), and continuum. Short discussion of dynamic range limited vs. line-free channels.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
A note on primary beam corrections and noise.<br />
</pre><br />
<br />
====Higher Order Moment Maps for CO(3-2)====<br />
<br />
For higher order moments it is very important to set a conservative flux <br />
threshold. Typically something like 6 sigma, using sigma from peak line channel, works well.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom')<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_coord')<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_dispersion_coord')<br />
immoments(imagename='TWHydra_CO3_2line.image',moments=[1,2],<br />
outfile='TWHydra_CO3_2line.image.mom',<br />
chans='40~76',includepix=[0.3,100])<br />
</source><br />
<br />
Display all three moment maps in the viewer, overlaid with continuum contours.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview( raster=[ {'file':'TWHydra_CO3_2line.image.mom0'},<br />
{'file':'TWHydra_CO3_2line.image.mom.weighted_coord'},<br />
{'file':'TWHydra_CO3_2line.image.mom.weighted_dispersion_coord'} ], <br />
contour={'file':'TWHydra_contall_apcal.image', 'base':0, 'unit':0.0025, 'levels':[3,100]} )<br />
</source><br />
<br />
To see all three raster images simultaneously, open the viewer's Panel Display Options (the "P-wrench" icon in the viewer tool bar), click "Number of panels", and change "Number of panels in x" to 3. Then select the "Blink" toggle (radio button) from the Animator panel.<br />
<br />
<figure id="TWHya_CO3_2_moments.png"><br />
[[Image:TWHya_CO3_2_moments.png|center|800px|frame|<caption>ALMA CO(3-2) moment maps, with white continuum contours at 3 and 100 sigma. From left to right: integrated intensity, intensity weighted velocity field, intensity weighted velocity dispersion are shown.</caption>]]<br />
</figure><br />
<br />
Repeat for HCO+(4-3) which has a bit narrower velocity extent than the CO(3-2), but similar rms noise.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom0')<br />
immoments(imagename='TWHydra_HCOplusline.image',moments=[0],<br />
outfile='TWHydra_HCOplusline.image.mom0',<br />
chans='43~74')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom')<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_coord')<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_dispersion_coord')<br />
immoments(imagename='TWHydra_HCOplusline.image',moments=[1,2],<br />
outfile='TWHydra_HCOplusline.image.mom',<br />
chans='43~74',includepix=[0.3,100])<br />
</source><br />
<br />
Display all three moment maps in the viewer using the same method described above for the CO(3-2) maps.<br />
<br />
<figure id="TWHya_HCOp4_3_moments.png"><br />
[[Image:TWHya_HCOp4_3_moments.png|center|800px|frame|<caption>ALMA HCO+(4-3) moment maps, with white continuum contours at 3 and 100 sigma. From left to right: integrated intensity, intensity weighted velocity field, intensity weighted velocity dispersion are shown.</caption>]]<br />
</figure><br />
<br />
=====Exporting Fits Images=====<br />
<br />
If you want to analyze the data using another software package it is easy to convert from CASA format to FITS. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image',fitsimage='TWHydra_CO3_2line.image.fits')<br />
</source><br />
<br />
Although "FITS format" is supposed to be a standard, in fact most packages expect slightly different things from a FITS image. If you are having difficulty, try setting '''velocity=T''' and/or '''dropstokes=T'''.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf TWHydra_HCOplusline.image.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image',fitsimage='TWHydra_HCOplusline.image.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom0.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image.mom0',<br />
fitsimage='TWHydra_CO3_2line.image.mom0.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_coord.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image.mom.weighted_coord',<br />
fitsimage='TWHydra_CO3_2line.image.mom.weighted_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_dispersion_coord.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image.mom.weighted_dispersion_coord',<br />
fitsimage='TWHydra_CO3_2line.image.mom.weighted_dispersion_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom0.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image.mom0',<br />
fitsimage='TWHydra_HCOplusline.image.mom0.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_coord.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image.mom.weighted_coord',<br />
fitsimage='TWHydra_HCOplusline.image.mom.weighted_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_dispersion_coord.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image.mom.weighted_dispersion_coord',<br />
fitsimage='TWHydra_HCOplusline.image.mom.weighted_dispersion_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_apcal.image.fits')<br />
exportfits(imagename='TWHydra_contall_apcal.image',fitsimage='TWHydra_contall_apcal.image.fits')<br />
</source><br />
<br />
===Display Channel Maps===<br />
<br />
Using the Viewer you can make channel map figures. Start the Viewer and then open the CO(3-2) cube as a raster image and then the continuum as a contour image. Then we use the "wrench" icon and "P wrench" icons to set up the channel images, contour levels etc. (If you need help setting up the viewer for this image, see a screen shot of the viewer setup windows, below.)<br />
<br />
<figure id="TWHya_channel_co3_2.png"><br />
[[Image:TWHya_channel_co3_2.png|center|frame|<caption>Channel maps of the CO(3-2) emission with white continuum contours at 3 and 100 sigma.</caption>]]<br />
</figure><br />
<br />
<figure id="Viewer_setup.png"><br />
[[Image:Viewer_setup.png|center|thumb|500px|<caption>The setup windows looked like this</caption>]]<br />
</figure><br />
<br />
Repeat for HCO+(4-3)<br />
<br />
<figure id="TWHya_channel_HCOp4_3.png"><br />
[[Image:TWHya_channel_HCOp4_3.png|center|thumb|800px|<caption>Channel maps of the HCO+(4-3) emission with white continuum contours at 3 and 100 sigma. The color intensity scale is the same as that used for CO(3-2).</caption>]]<br />
</figure><br />
<br />
<!--<br />
====Examine CO Contours on an HCO+ Raster====<br />
<br />
====Matched Movies====<br />
<br />
===Image Plane and Spectral Fits===<br />
<br />
====Fit a Gaussian to the Continuum====<br />
<br />
=====Fit In the Viewer=====<br />
<br />
=====Fit Using the Command Line=====<br />
<br />
====Fit a Gaussian to the CO Line====<br />
<br />
=====Fit In the Viewer=====<br />
<br />
=====Fit Using the Command Line=====<br />
<br />
===Extract a Sub-Image===<br />
<br />
===Align Image Cubes===<br />
--><br />
<br />
{{Checked 4.3.0}}</div>Sstierwahttps://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_4.3&diff=19487TWHydraBand7 Imaging 4.32016-05-18T04:48:05Z<p>Sstierwa: /* Make Moment 0 Maps */</p>
<hr />
<div>[[Category:ALMA]][[Category:Imaging]][[Category:Spectral Line]]<br />
<br />
* '''This tutorial picks up where '''[[TWHydraBand7_Calibration_4.5.2]]''' leaves off, with fully calibrated, split science target MS. If you wish to skip the Calibration guide: obtain the calibrated data from [[TWHydraBand7#Getting_the_Data]]; extract it using <tt>tar -xzvf FILENAME</tt>; and <tt>cd</tt> into the extracted directory.'''<br />
<br />
*'''This guide is designed for CASA 4.3. If you are using an older version of CASA please see [[TWHydraBand7_Imaging_4.3]].<br />
<br />
* '''Details of the ALMA data are provided at [[TWHydraBand7]]'''<br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.5.2. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.3.0'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
== Prepare Continuum Data for Further Processing==<br />
<br />
In order to speed up imaging/self-calibration for the continuum data we will average channels together, and then flag the few spectral features. This method works well in the case of only a few spectral lines, while retaining enough channelization to aid in multi-frequency synthesis and being able to remove spectral features in the averaged data. When generalizing this process to other datasets, the amount of channel averaging will vary. '''Note for wide bandwidth data it is never a good idea to use the continuum estimate generated by uv-continuum subtraction as your continuum data'''. This worked OK in the past with the narrow band systems like the VLA and low dynamic range instruments like the SMA, but is not advised for ALMA wide bandwidth, high dynamic range data. <br />
<br />
<figure id="Cont_spw2.png"><br />
[[Image:Cont_spw2.png|thumb|<caption>CO(3-2) in spw=2 from the "continuum" channel averaged data.</caption>]]<br />
</figure><br />
<figure id="Cont_spw3.png"><br />
[[Image:Cont_spw3.png|thumb|<caption>Notice upswing at high channel numbers in spw=3.</caption>]]<br />
</figure><br />
<br />
One can also flag the spectral features first but in that case make a backup of the file that is analogous to TWHydra_corrected.ms as you will need it later (unflagged) for spectral line imaging. We begin by excluding ~20 channels on each edge, and averaging over 100 channel intervals:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_cont.ms*')<br />
split(vis='TWHydra_corrected.ms',outputvis='TWHydra_cont.ms',<br />
spw='0~3:21~3820',width=100,datacolumn='data')<br />
</source><br />
<br />
Now make a plot of amplitude vs. channel to see what needs to be flagged<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',spw='0~3',xaxis='channel',yaxis='amp',<br />
avgtime='1e8',avgscan=T,coloraxis='spw',iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
The CO(3-2) and HCO+(4-3) lines are obvious. The 4th spw; spw=3 also shows an upswing on the highest channels that is problematic, it was seen on the calibrators too and is likely due to a weak atmospheric feature, we will flag the worst of it.<br />
<br />
<figure id="Cont_uvplot.png"><br />
[[Image:Cont_uvplot.png|thumb|<caption>UV-plot of the continuum emission, colors show spws.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='TWHydra_cont.ms', mode='manual', <br />
spw='0:16~16, 2:21~21, 3:33~37')<br />
</source><br />
<br />
Have a look at the continuum as a function of uv-distance (in the plot to the right, the 4 spw are shown in different colors on top of each other). If the data are flat as a function of uv-distance, the source is completely unresolved. If instead you see structure (in this case decreasing amplitude with uv-distance), the source is resolved. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',spw='',xaxis='uvdist',yaxis='amp',field='',avgchannel='38',<br />
coloraxis='spw',plotfile='cont_uvplot.png')<br />
</source><br />
<br />
Notice that the spw do not have the same amplitude. Unfortunately, the red spw (highest frequency) should be higher than the green one (lowest frequency) because optically thin dust goes as nu^4, and optically thick as nu^2. This inconsistency is due to imperfect amplitude/absolute flux calibration. The self-calibration below will bring them into agreement with each other, but this is the sort of thing that results in considerable absolute flux uncertainty at submillimeter wavelengths. We are working on how to do this better.<br />
<br />
==A priori Noise Estimates==<br />
<br />
<figure id="Corrected_time.png"><br />
[[File:Corrected_time.png|thumb|<caption>Plot for estimating time.</caption>]]<br />
</figure><br />
<figure id="sensitivity_cont.png"><br />
[[File:sensitivity_cont.png|thumb|<caption>Sensitivity calculator setup with observed continuum parameters for these observations.</caption>]]<br />
</figure><br />
<br />
To estimate what the expected noise levels are, we first need to know how much time we had on source. Looking at <br />
a plot of amplitude vs time for the concatenated but pre-split data (see below) there are 9x8min scans + 6x6min scans + 3x1min + 2x2min scans for about 1.9 hours on source. There are 2 polarizations and about 1.75 GHz of total continuum bandwidth taking into account flagging.<br />
<br />
Using this information and https://almascience.nrao.edu/proposing/sensitivity-calculator, we find that the '''expected rms noise for the continuum is about 0.3 mJy/beam'''.<br />
<br />
For the spectral line data, which we will image below, with 0.12 km/s channels (needs to be entered in the field ''bandwidth per polarization''), the '''expected rms noise for the spectral lines is about 32 mJy/beam'''.<br />
<br />
==Image and Self-Calibrate the Continuum==<br />
<br />
====Create Initial Clean Image====<br />
<br />
First we will make an initial image using {{clean}}, this task will both deconvolve and clean. <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
If you are unfamiliar with the basic concepts of deconvolution and clean,<br />
pause here and review for example<br />
http://www.aoc.nrao.edu/events/synthesis/2010/lectures/wilner_synthesis10.pdf<br />
</pre><br />
<br />
In {{clean}}, we use '''mode='mfs'''' to do multifrequency synthesis, in other words grid each uv-channel independently. Since the uv-spacing is a function of frequency, this will actually achieve greater uv-coverage than if all the channels and spws had been averaged in advance. The '''imsize=100''' and '''cellsize=['0.3arcsec']''' were chosen to be appropriate for the Band and antenna configuration. At ALMA Band 7, the Full Width Half Power primary beam is about 20", so we want to make our image at least this big. We've made it a bit larger out to about the 25% power point. For the configuration used to take these data, the resolution is expected to be about 1.5" and it is a good idea to oversample the beam by setting the cell size to be a factor of 4 or 5 smaller than the beam (we have used 5 here). <br />
<br />
For doing self-calibration it is essential that only "real" signal be included in the image model, thus it is important to make a clean mask, and clean the first iteration rather conservatively (shallowly) so that you are sure that you do not have clean components in your model that do not represent real source emission. In the example below we set '''interactive=T''' so you can interactively make the clean mask and stop clean when the signal from the source starts to approach the surrounding "noise" areas in the residual map.<br />
<br />
'''NOTE:''' Real emission will not go away if you do not put a clean box on it. Conversely if you put a clean box on something that is NOT real and clean deeply you can amplify that feature. Thus, its best to be conservative and build up your clean box as you go, you can generally see fainter "real" features in the residuals.<br />
<br />
'''NOTE:''' If you start an interactive clean, and then do not make a mask, clean will stop when you tell it to go on because it has nothing to clean. There is no default mask.<br />
<br />
<figure id="Viewer_clean1.png"><br />
[[Image:Viewer_clean1.png|thumb|<caption>Interactive viewer.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall',<br />
mode='mfs', imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5, <br />
mask='',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
'''NOTE:'''{{clean}} will generate several files automatically with the '''imagename''' prepended:<br />
* <imagename>.image # the final restored image<br />
* <imagename>.flux # the effective primary beam response (e.g. for pbcor)<br />
* <imagename>.flux.pbcoverage # the primary beam coverage (ftmachine=’mosaic’ only)<br />
* <imagename>.model # the model image<br />
* <imagename>.residual # the residual image<br />
* <imagename>.psf # the synthesized (dirty) beam<br />
<br />
Once the Clean Viewer opens, click on the polygon tool with your left mouse button, and draw a polygon around the continuum emission with the left mouse button. Double click inside the region with the left mouse button when you are happy with it. It will turn from green to white when the clean mask is accepted. To continue with clean use the "Next action" buttons in the green area on the Viewer Display GUI. <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
The red X will stop clean where you are, the blue arrow will stop <br />
the interactive part of clean, but continue to clean non-interactively <br />
until reaching the number of iterations requested (niter) or the flux <br />
density threshold (whichever comes first), and the green circle arrow <br />
will clean until it reaches the "iterations" parameter on the left side <br />
of the green area. <br />
</pre><br />
<br />
'''You should chose the green circle arrow'''. It will clean 100 iterations (number under iteration in the green area on the Viewer GUI) and then show the '''residual image''' again. The middle mouse button is automatically assigned to the "plus" icon, which adjusts the colorscale. '''If you cannot easily access multiple mouse buttons, you can always assign your one mouse button the icon you want by clicking on it'''. Adjust the color scale so you can see the structure in the noise better. Also, note that the logger is telling you the amount of clean flux recovered so far, the min/max residuals, and the synthesized beam:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Model 0: max, min residuals = 0.0203454, 0.00267232 clean flux 1.30124<br />
Threshhold not reached yet.<br />
Beam used in restoration: 1.6962 by 1.54549 (arcsec) at pa 28.9043 (deg) <br />
</pre> <br />
<br />
Already with only 100 iterations, the residuals outside the clean mask are larger than that inside. So we will stop here by hitting the Red X symbol.<br />
<br />
====1st Round of Continuum Data Phase Self-calibration====<br />
<br />
Next we can use the clean model to self-calibrate the uv-data. The process of self-calibration tries to adjust the data to better match the model you give it. That is why it is important to make the model as good as you can. {{clean}} places a uv-model of the resulting image in the file <tt>TWHydra_cont.model</tt>. This model can then be used to self-calibrate the data using {{gaincal}}. We use '''gaintype='T'''' to tell it to average the polarizations before deriving solutions (which gains us a sqrt(2) in sensitivity). A critical parameter to play with is '''solint'''; we use '''solint=30s'''. From {{listobs}} the integration time of these data is about 10 seconds, so using '''solint=30s''' then gains us a sqrt(3) in sensitivity. It is often best to start with a larger '''solint''' and then work your way down to the integration time if the S/N of the data permits. For the same reasons as described in the [[TWHydraBand7_Calibration_4.3]] tutorial we want to fix up the phases before tackling amplitude by setting '''calmode='p''''.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='TWHydra_cont.ms',caltable='self_1.pcal',<br />
solint='30s',combine='',gaintype='T',<br />
refant='DV06',spw='',minblperant=4,<br />
calmode='p',minsnr=2)<br />
</source><br />
<br />
<figure id="Self_1_phase.png"><br />
[[Image:Self_1_phase.png|thumb|<caption>Phase solutions from self_1.pcal with solint=30s.</caption>]]<br />
</figure><br />
<br />
Because '''combine=' '''', we are getting independent solutions for each spw. If you are desperate for S/N, you can try combining them with combine='spw'. We have plenty of S/N in these data so we keep them separate. Look at the solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_1.pcal',xaxis='time',yaxis='phase',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,-80,80],figfile='self_1_phase.png')<br />
</source><br />
<br />
The magnitude of corrections gives you a sense of how accurate the phase transfer from the calibrators was. You are checking to see that the phases are being well tracked by the solutions, i.e. smoothly varying functions of time within a given scan. Also the solutions for each spw are lying basically on top of each other which indicates that the spw to spw phase offsets are well calibrated already. Overall, these solutions look quite good. If they didn't you could try increasing the solint and/or combining the spw into a single solution. <br />
<br />
After checking that you are happy with the solutions, apply them with {{applycal}}<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_cont.ms',field='',gaintable=['self_1.pcal'],calwt=F)<br />
</source><br />
<br />
<figure id="Viewer_pcal1.png"><br />
[[Image:Viewer_pcal1.png|thumb|<caption>Clean residuals after 100 iterations and the 1st phase only self-cal. Residuals inside mask are higher than the "noise" outside.</caption>]]<br />
</figure><br />
<br />
Next clean the source again, to save time we can start with the clean mask from the last iteration. If you make interactive adjustments to the clean mask, they will be written to the '''new''' mask TWHydra_contall_1pcal.mask, and not the old one. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_1pcal.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall_1pcal',<br />
mode='mfs',imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5, <br />
mask='TWHydra_contall.mask',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
Now after the first 100 iterations you see that the residuals inside the clean mask are higher than those outside. This is because flux that had been spread out in the map due to poorly correlated phases has been placed where it belongs on the source, thereby increasing its flux. You may also notice that your original clean mask is a little too small. If so, you can make it a bit larger, just by drawing a new polygon around the area you want to include. When you double click, it will incorporate the new mask into the current mask (if your box goes awry you can use the erase toggle [radio button] to erase and redo the mask). The new mask area need not overlap the original mask (though for this source it probably will). You might also want to use the magnifying glass to zoom in. Again, you assign mouse buttons by clicking on the icon you want. Clean another 100 iterations (for a total of 200) and stop by clicking the red X.<br />
<br />
Now open initial and 1st self-cal images to compare them using {{imview}}. This is an alternative version of the {{viewer}} that is somewhat scriptable. <br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(raster=[{'file':'TWHydra_contall.image','range':[-0.01,0.05]},<br />
{'file':'TWHydra_contall_1pcal.image','range':[-0.01,0.05]}])<br />
</source><br />
<br />
Once the Viewer Display panel opens, click on the box next in the "Images" panel and then use the tapedeck buttons in the panel to alternate between the two images. Because the range was explicitly set, they are on the same color scale. It is obvious that the self-calibrated image is better. To quantify, 1st toggle back to "normal" and then draw a region that excludes the central source with the polygon tool and then double click inside (if you stay in the "Images" view, only the statistics for the last image opened will appear on the terminal instead of both). The basic statistics of the polygon region will print to the '''terminal''':<br />
<br />
<pre style="background-color: #fffacd;"><br />
TWHydra_contall.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2357 -9.434800e-01 -2.858690e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-4.002885e-04 7.906752e-03 7.898289e-03 -2.541723e-02 2.172779e-02 <br />
<br />
TWHydra_contall_1pcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2357 6.326584e-01 1.916918e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
2.684168e-04 3.655786e-03 3.646692e-03 -1.215155e-02 1.109403e-02 <br />
</pre><br />
<br />
The self-calibrated image has more than a factor of 2 lower rms noise!<br />
<br />
====2nd Round of Continuum Data Phase Self-calibration====<br />
<br />
Now that we have a better model, we solve for solutions again. This time we will try making the solint smaller -- the integration time is about 10 seconds, so we set '''solint='int'''' to have it use the integration time.<br />
<br />
<figure id="Self_2_phase.png"><br />
[[Image:Self_2_phase.png|thumb|<caption>Phase solutions from self_2.pcal with solint='int'.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='TWHydra_cont.ms',caltable='self_2.pcal',<br />
solint='int',combine='',gaintype='T',<br />
refant='DV06',spw='',minblperant=4,<br />
calmode='p',minsnr=2)<br />
</source><br />
<br />
Now plot the new solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_2.pcal',xaxis='time',yaxis='phase',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,-80,80],figfile='self_2_phase.png')<br />
</source><br />
<br />
The phases on this shorter '''solint''' still seem to be tracking well so we will apply it and make a new image and check to see if there is improvement. <br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_cont.ms',field='',gaintable=['self_2.pcal'],calwt=F)<br />
</source><br />
<br />
<figure id="Viewer_pcal2.png"><br />
[[Image:Viewer_pcal2.png|thumb|<caption>Clean residuals after 2nd phase only self-cal and 250 iterations. The residuals inside the clean mask are lower than those outside, so its time to stop.</caption>]]<br />
</figure><br />
<br />
Now clean again, updating '''mask''' with the most recent mask file.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_2pcal.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall_2pcal',<br />
mode='mfs',imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5,usescratch=False,<br />
mask='TWHydra_contall_1pcal.mask',<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
After 200 iterations<br />
<br />
<pre style="background-color: #fffacd;"><br />
Model 0: max, min residuals = 0.00489776, -0.00464541 clean flux 1.44461<br />
</pre><br />
<br />
It looks like it could use just a little more cleaning, so set '''iterations=50 in the GUI'''.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Clean used 50 iterations to approach a threshhold of 0.0015067<br />
0.0107122 Jy <- cleaned in this cycle for model 0 (Total flux : 1.45532Jy)<br />
Final maximum residual = 0.00326382<br />
Model 0: max, min residuals = 0.00326382, -0.00321361 clean flux 1.45532<br />
</pre><br />
<br />
The small amount of flux cleaned this cycle indicates that clean is converging and it's about time to stop. Also the residuals inside the clean mask are now smaller than the residuals outside (i.e. the noise) also indicating it's time to stop by hitting the red X on the GUI.<br />
<br />
Now repeat the display, blinking, and image statistics steps described above for the 1st and 2nd phase-only self-cal iterations.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(raster=[{'file':'TWHydra_contall_1pcal.image','range':[-0.01,0.05]},<br />
{'file':'TWHydra_contall_2pcal.image','range':[-0.01,0.05]}])<br />
</source><br />
<br />
The difference is small:<br />
<pre style="background-color: #fffacd;"><br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2466 4.611597e-02 1.397287e-03 <br />
Mean Rms Std dev Minimum Maximum <br />
1.870072e-05 3.831524e-03 3.832255e-03 -1.414417e-02 1.109403e-02 <br />
<br />
TWHydra_contall_2pcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2466 1.159416e-01 3.512963e-03 <br />
Mean Rms Std dev Minimum Maximum <br />
4.701606e-05 3.811716e-03 3.812199e-03 -1.383034e-02 1.078456e-02 <br />
</pre><br />
<br />
This small improvement suggests that we have gone as far as we can with phase self-cal.<br />
<br />
===Continuum Data Amplitude Self-Calibration===<br />
<br />
Now we will apply the best phase solution table on-the-fly while solving for the amplitude self-cal solutions. Since amplitude changes more slowly and is less constrained than phase, we use a longer '''solint='inf'''', as long as '''combine=' '''' this means to do one solution per scan. <br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='TWHydra_cont.ms',caltable='self_ap.cal',<br />
solint='inf',combine='',gaintype='T',<br />
refant='DV06',spw='',minblperant=4,<br />
gaintable=['self_2.pcal'],<br />
calmode='ap',minsnr=2)<br />
</source><br />
<br />
It's useful to look at the residual phase in the amplitude calibration table, i.e. since we applied our best phase-only solution while solving for this new amplitude and phase ('''calmode='ap'''') solution, the phase should already be corrected.<br />
<br />
<figure id="Self_ap_phase.png"><br />
[[Image:Self_ap_phase.png|thumb|<caption>Residual phase solutions from self_ap.cal.</caption>]]<br />
</figure><br />
<figure id="Self_ap_amp.png"><br />
[[Image:Self_ap_amp.png|thumb|<caption>Amplitude solutions from self_ap.cal.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_ap.cal',xaxis='time',yaxis='phase',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,-1,1],figfile='self_ap_phase.png')<br />
</source><br />
<br />
The residuals are very small as expected. (If you see large residuals here, it means that the phase-only solution is suspect, and you were mostly just moving noise around.) Now look at the amplitude solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_ap.cal',xaxis='time',yaxis='amp',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,0.6,1.4],figfile='self_ap_amp.png')<br />
</source><br />
<br />
For the most part these look very good except one rather large deviation on DV06. Apply both the final phase and the amplitude calibration tables.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_cont.ms',field='',gaintable=['self_2.pcal','self_ap.cal'],calwt=F)<br />
</source><br />
<br />
Plot the corrected data as a function of both time and uv-distance. It is always a good idea to check these after an amplitude self-calbration to be sure that it worked properly. Occasionally, a few spurious bits of data will get blown up by the amplitude self-cal if it is not well-constrained. <br />
<br />
<figure id="Selfcal_time.png"><br />
[[Image:Selfcal_time.png|thumb|<caption>Post self-calibration amplitude vs. time</caption>]]<br />
</figure><br />
<figure id="Selfcal_uvdist.png"><br />
[[Image:Selfcal_uvdist.png|thumb|<caption>Post self-calibration amplitude vs. uv-distance</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',xaxis='time',yaxis='amp',<br />
avgchannel='38',ydatacolumn='corrected',coloraxis='spw',<br />
plotfile='selfcal_time.png')<br />
</source><br />
<br />
The time where we saw a large amplitude correction on DV06 looks consistent here so the large correction we saw in the solutions corrected a real issue. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',xaxis='uvdist',yaxis='amp',<br />
avgchannel='38',ydatacolumn='corrected',coloraxis='spw',<br />
plotfile='selfcal_uvdist.png')<br />
</source><br />
<br />
You will see that this plot looks much better than before. <br />
<br />
<figure id="Viewer_apcal.png"><br />
[[Image:Viewer_apcal.png|thumb|<caption>Clean residuals after final amplitude and phase self-cal.</caption>]]<br />
</figure><br />
<br />
Now make the final continuum image.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_apcal.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall_apcal',<br />
mode='mfs',imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5,usescratch=False,<br />
mask='TWHydra_contall_2pcal.mask',<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
We know we need to clean at least 250 iterations (i.e. 100+100+50=250), so set iterations to 300 in the gui and hit the round green arrow. After this notice how much better the residual looks. Clean another 100 iterations. The "circular pattern", and 4 bright spots at each corner you see now in the residual is likely due to non-closing amplitude errors that cannot be removed with an antenna based self-calibration, so this is as good as it gets with pure self-cal. Hit the Red X to stop clean.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Clean used 100 iterations to approach a threshhold of 0.00105507<br />
0.0061808 Jy <- cleaned in this cycle for model 0<br />
Final maximum residual = 0.00242926<br />
Model 0: max, min residuals = 0.00238278, -0.00242926 clean flux 1.48201<br />
</pre><br />
<br />
Now repeat the display, blinking, and image statistics described above for the 2nd phase only and the new amplitude & phase self-cal'ed images.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(raster=[{'file':'TWHydra_contall_2pcal.image','range':[-0.01,0.05]},<br />
{'file':'TWHydra_contall_apcal.image','range':[-0.01,0.05]}])<br />
</source><br />
<br />
The amplitude and phase self cal'ed image is notably better than phase-only. Quantitatively:<br />
<pre style="background-color: #fffacd;"><br />
<br />
TWHydra_contall_2pcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 3542 2.053068e-01 6.220676e-03 <br />
Mean Rms Std dev Minimum Maximum <br />
5.796351e-05 3.955967e-03 3.956101e-03 -1.383034e-02 1.078456e-02 <br />
<br />
TWHydra_contall_apcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 3542 6.044652e-04 1.831495e-05 <br />
Mean Rms Std dev Minimum Maximum <br />
1.706565e-07 1.270183e-03 1.270362e-03 -4.980673e-03 4.137159e-03 <br />
</pre> <br />
<br />
and indeed, we've gained another factor of 3 in sensitivity. <br />
<br />
'''Overall with this self-calibration we've improved the noise by a factor of 6.7! With a peak flux density of 0.98 Jy, the S/N increased from 115 initially to 770 after. So, well worth the trouble.'''<br />
<br />
<div class="noprint" style="float:none; border:0px solid blue;background-color:#F6CEF5;padding:2px;"><br />
If you have used the '''standard='Butler-JPL-Horizons 2012' ''' model during the calibration process, you should see an increase in peak flux density of about 3%.<br />
</div><br />
<br />
It is notable that we are still a factor of more than 4 from the apriori noise estimate of 0.3 mJy/beam. This is likely due to residual sources of non-closing (not antenna based) errors in the data like baseline errors and baseline-dependent bandpass errors. Additionally, polarization errors (which we did not calibrate at all) can contribute, as well as imperfect uv-coverage with only 8 antennas. A dynamic range of 770 is actually quite good in the submillimeter.<br />
<br />
==Apply self-calibration to Full Dataset and Split Line Data==<br />
<br />
Now apply the self-calibration derived from the continuum emission to the full unchannel-averaged data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_corrected.ms',gaintable=['self_2.pcal','self_ap.cal'],calwt=F)<br />
</source><br />
<br />
Split off the CO(3-2) spectral line data in spw=2 and the HCO+(4-3) data in spw=0 for further processing.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2.ms*')<br />
split(vis='TWHydra_corrected.ms',outputvis='TWHydra_CO3_2.ms',datacolumn='corrected',spw='2')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplus.ms*')<br />
split(vis='TWHydra_corrected.ms',outputvis='TWHydra_HCOplus.ms',datacolumn='corrected',spw='0')<br />
</source><br />
<br />
==Continuum Subtraction== <br />
<br />
Next we need to subtract the continuum emission from the spectral line data. It is best to do this in the uv-plane. The first step is to make a channel plot of the spectral data to get the line-free channel ranges for both spectral lines. Since the line emission is simple (one spectral line per spw) and there are more than enough line-free channels we do not need to be very precise just stay well away from the line and whenever possible it is best to chose line-free channel ranges on either side of the line for the best possible baseline subtraction. <br />
<br />
<figure id="CO3_2_channel.png"><br />
[[Image:CO3_2_channel.png|thumb|<caption>CO(3-2) line in channel space.</caption>]]<br />
</figure><br />
<figure id="HCOp4_3_channel.png"><br />
[[Image:HCOp4_3_channel.png|thumb|<caption>HCO+(4-3) in channel space.</caption>]]<br />
</figure><br />
<br />
'''Note''': after the split above, the original spw ids will be relabeled as 0 in each file because there is only one spectral window in each file.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_CO3_2.ms',spw='0',xaxis='channel',yaxis='amp',<br />
avgtime='1e8',avgscan=T,coloraxis='spw',plotfile='CO3_2_channel.png')<br />
</source><br />
<br />
It is a good idea to stay a little away from the very edges of the baseband which can be noisy. The channel ranges <br />
20~2000 and 2400~3800 look like good choices for CO(3-2).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_HCOplus.ms',spw='0',xaxis='channel',yaxis='amp',<br />
avgtime='1e8',avgscan=T,coloraxis='spw',plotfile='HCOp4_3_channel.png')<br />
</source><br />
<br />
The channel ranges 20~1500 and 1900~3800 look like good choices for HCO+(4-3).<br />
<br />
Next use the identified line-free channel ranges and {{uvcontsub}} to subtract the continuum model from the line emission.<br />
<br />
<source lang="python"><br />
# In CASA<br />
uvcontsub(vis='TWHydra_CO3_2.ms',fitorder=1,fitspw='0:20~2000,0:2400~3800')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
uvcontsub(vis='TWHydra_HCOplus.ms',fitorder=1,fitspw='0:20~1500,0:1900~3800')<br />
</source><br />
<br />
Note: If you do not have line-free channels on both sides of the line emission, it is safer to use '''fitorder=0''', or the fit may diverge.<br />
<br />
==Spectral Line Imaging==<br />
<br />
Now we are ready to make cubes of the line emission. The imaging parameters are similar to the continuum except for <br />
those dealing with the spectral setup: '''mode''', '''start''', '''width''', '''nchan''', '''restfreq''', and '''outframe''' parameters. When making spectral images you have three choices for the '''mode''' parameter: '''channel''', '''velocity''', and '''frequency'''. Data are taken using constant frequency channels. For spectral line analysis it's often more useful to have constant velocity channels, and this is also the best way to make images of multiple lines with the exact same channelization for later comparison. For '''mode='velocity'''', the desired '''start''' and '''width''' also need to be given in velocity units for the desired output frame. <br />
<br />
It is important to note that ALMA does not do on-line Doppler Tracking and the native frame of the data is TOPO. If you do not specify '''outframe''' the output cube will also be in TOPO, which is not very useful for spectral line work. The Doppler Shift is taken out during the regridding to the desired outframe in {{clean}} or alternatively it can be done separately by the {{cvel}} task which would need to be run before {{clean}}. <br />
<br />
<figure id="CO3_2_vel.png"><br />
[[Image:CO3_2_vel.png|thumb|<caption>CO(3-2) spectrum in LSRK velocity space.</caption>]]<br />
</figure><br />
<figure id="HCOp4_3_vel.png"><br />
[[Image:HCOp4_3_vel.png|thumb|<caption>HCO+(4-3) spectrum in LSRK velocity space.</caption>]]<br />
</figure><br />
<br />
To see what velocity parameters you want to set in clean it is useful to make a plot in {{plotms}} in the desired output frame. To make it easier to see, we set a '''plotrange''' since we know the LSRK velocity of TW Hya is about 2.88 km/s. Note these plots take a little longer because of the frame shift.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_CO3_2.ms.contsub',xaxis='velocity',yaxis='amp',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',<br />
restfreq='345.79599GHz',plotrange=[-20,23,0,0],plotfile='CO3_2_vel.png')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_HCOplus.ms.contsub',xaxis='velocity',yaxis='amp',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',<br />
restfreq='356.7342GHz',plotrange=[-20,23,0,0],plotfile='HCOp4_3_vel.png') <br />
</source><br />
<br />
From these plots it looks like imaging the cubes from about -5 to +8 km/s will encompass the line, but still provide several line-free channels on either side so the noise level can be estimated. The channel width is 122 kHz, which at <br />
345.79599 GHz is 0.106 km/s. Recall that the spectral ''resolution'' is a factor of two poorer. We will use a velocity channel width of 0.12 km/s for a little oversampling, but the spectral resolution remains 0.2 km/s.<br />
<br />
As before, it is very important that you make a clean mask. There are many ways to do this ranging from the complicated to simple. For this example we will make a single clean mask that encompasses the line emission in every channel and apply it to all channels. This is much better than no clean mask, though not quite as good as making an individual mask for each channel. For some sources, one can use the continuum mask to clean the line, however TW Hya is a bit curious in that the continuum emission is not as extended as the line emission (Hughes et al. 2008).<br />
<br />
=== CO(3-2) Imaging ===<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.*')<br />
clean(vis='TWHydra_CO3_2.ms.contsub',imagename='TWHydra_CO3_2line',<br />
imagermode='csclean',spw='',<br />
imsize=100,cell=['0.3arcsec'],<br />
mode='velocity',start='-4km/s',width='0.12km/s',nchan=118,<br />
restfreq='345.79599GHz',outframe='LSRK',<br />
weighting='briggs',robust=0.5,<br />
mask='',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=100000)<br />
</source><br />
<br />
<figure id="Viewer_55.png"><br />
[[Image:Viewer_55.png|thumb|<caption>Interactive Viewer window with CO(3-2) clean mask, before cleaning starts.</caption>]]<br />
</figure><br />
<figure id="Viewer_500.png"><br />
[[Image:Viewer_500.png|thumb|<caption>Interactive Viewer window for CO(3-2), after 500 iterations, more cleaning is needed.</caption>]]<br />
</figure><br />
<br />
It will take a little while to grid the cube, when the interactive viewer opens, use the tapedeck to cycle through the channels. You should see a progress of line emission in channels 40 to 70 or so.<br />
*Go to channel 57 (about line center)<br />
*Select the polygon tool with the left mouse button<br />
*Select the "All Channels" toggle in the green area<br />
*Draw a polygon around the channel 57 emission, double click inside to activate.<br />
*Now go to channel 60, this is the channel with the most extent to the SE, draw another polygon that encompasses this emission if necessary,double click inside to activate.<br />
*Now go to channel 55, this is the channel with the most extent to the NW, draw another polygon that encompasses this emission if necessary,double click inside to activate. <br />
*Now double check the mask by cycling through channels with real line emission to be sure that your clean box encompasses the emission, but does not extend far beyond it. Again the "erase" toggle can come in handy if things go awry or if you want to just delete a small portion of an existing mask (just draw a polygon around what you want to erase and double click inside), be sure to switch back to "add" before going on.<br />
<br />
The figure shows what the final clean box should look like. Now clean using the green circle arrow. You can watch the progress in the logger. When 100 iterations are done, the viewer will show the residual map for each channel. Cycle through the channels and see whether you are still happy with the clean box in each signal channel. The "erase button" can help you fix mistakes. If necessary adjust. It is often useful to adjust the colorscale with the "plus" symbol icon. Keep going until the residual emission looks like the surrounding noise. If it seems to be going slowly, increase the iterations to 300 for a round or two. I stopped cleaning (Red x) when the logger showed (about 900 iterations). <br />
<pre style="background-color: #fffacd;"><br />
12.9846 Jy <- cleaned in this cycle for model 0<br />
Final maximum residual = 0.157312<br />
Model 0: max, min residuals = 0.157312, -0.0871295 clean flux 279.304<br />
</pre><br />
<br />
NOTE: The residuals are still a bit high in the strongest emission channels after it is well cleaned in the weaker channels. This is an indication that the sensitivity is "dynamic range" limited. In other words even with more <br />
intrinsic sensitivity per integration (i.e. better system temperature), the dynamic range limit would remain the same unless you get more uv-coverage. The fundamental dynamic range limitations of ALMA will be considerably better with 16 antennas in Early Science and MUCH better with the full 50-antenna array.<br />
<br />
=== HCO+(4-3) Imaging ===<br />
<br />
Now image and clean the HCO+(4-3) line using what you learned above.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.*')<br />
clean(vis='TWHydra_HCOplus.ms.contsub',imagename='TWHydra_HCOplusline',<br />
imagermode='csclean',spw='',<br />
imsize=100,cell=['0.3arcsec'],<br />
mode='velocity',start='-4km/s',nchan=118,width='0.12km/s',<br />
restfreq='356.7342GHz',outframe='LSRK',<br />
weighting='briggs',robust=0.5,<br />
mask='',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=100000)<br />
</source><br />
<br />
I stopped cleaning when: <br />
<pre style="background-color: #fffacd;"><br />
4.79833 Jy <- cleaned in this cycle for model 0<br />
Final maximum residual = 0.0977348<br />
Model 0: max, min residuals = 0.0977348, -0.060484 clean flux 192.066<br />
</pre><br />
<br />
==Image Analysis==<br />
<br />
After all that hard work you now have deconvolved images of the 350 GHz continuum, the CO (3-2) line, and the HCO+ (4-3) line. CASA includes tools to help you understand the contents of these images and make basic scientific measurements. These tools are divided between graphical exploration tools, accessible via the CASA viewer, and command line analysis tasks. To access the viewer, simply type '''viewer()''' and to see the list of analysis tasks available in CASA type '''tasklist''' at the CASA prompt and look under the Analysis sub-heading.<br />
<br />
If you want to do this portion of the guide and have downloaded the (.FITS) reference images, you can import them to be CASA images using '''importfits'''. If you are re-importing the images, use the commented remove command, here, to delete the previous import first.<br />
<br />
<source lang="python"><br />
# In CASA<br />
# os.system("rm -rf TWHydra_CO3_2line.image")<br />
importfits(fitsimage="TWHydra_CO3_2line.image.fits", imagename="TWHydra_CO3_2line.image")<br />
</source><br />
<br />
where '''fitsimage''' refers to the file to imported and '''imagename''' gives the output filename. If you are proceeding directly from the imaging step, your data are already CASA images and you may proceed without any importing.<br />
<br />
You can get the basic properties of any CASA image using the '''imhead''' command. For example, type <br />
<br />
<source lang="python"><br />
# In CASA<br />
imhead("TWHydra_CO3_2line.image")<br />
</source><br />
<br />
and look at the CASA logger. You will see an image summary like the following<br />
<br />
<pre style="background-color: #fffacd;"><br />
INFO imhead ##########################################<br />
INFO imhead ##### Begin Task: imhead #####<br />
INFO imhead imhead(imagename="TWHydra_CO3_2line.image",mode="summary",hdkey="",hdvalue="",<br />
INFO imhead hdtype="",hdcomment="",verbose=False)<br />
INFO ImageAnalysis <br />
INFO ImageAnalysis Image name : TWHydra_CO3_2line.image<br />
INFO ImageAnalysis Object name : TW Hya<br />
INFO ImageAnalysis Image type : PagedImage<br />
INFO ImageAnalysis Image quantity : Intensity<br />
INFO ImageAnalysis Pixel mask(s) : None<br />
INFO ImageAnalysis Region(s) : None<br />
INFO ImageAnalysis Image units : Jy/beam<br />
INFO ImageAnalysis Restoring Beam : 1.68065 arcsec, 1.53193 arcsec, 22.3015 deg<br />
INFO ImageAnalysis <br />
INFO ImageAnalysis Direction reference : J2000<br />
INFO ImageAnalysis Spectral reference : LSRK<br />
INFO ImageAnalysis Velocity type : RADIO<br />
INFO ImageAnalysis Rest frequency : 3.45796e+11 Hz<br />
INFO ImageAnalysis Pointing center : 11:01:51.844983 -34.42.17.160885<br />
INFO ImageAnalysis Telescope : ALMA<br />
INFO ImageAnalysis Observer : Unknown<br />
INFO ImageAnalysis Date observation : 2011/04/22/00:15:42<br />
INFO ImageAnalysis Telescope position: [2.22514e+06m, -5.44031e+06m, -2.48103e+06m] (ITRF)<br />
INFO ImageAnalysis <br />
INFO ImageAnalysis Axis Coord Type Name Proj Shape Tile Coord value at pixel Coord incr Units<br />
INFO ImageAnalysis -------------------------------------------------------------------------------------------------- <br />
INFO ImageAnalysis 0 0 Direction Right Ascension SIN 100 25 11:01:51.845 50.00 -3.000000e-01 arcsec<br />
INFO ImageAnalysis 1 0 Direction Declination SIN 100 25 -34.42.17.161 50.00 3.000000e-01 arcsec<br />
INFO ImageAnalysis 2 2 Spectral Frequency 118 59 3.45801e+11 0.00 -1.38414152e+05 Hz<br />
INFO ImageAnalysis Velocity -4 0.00 1.200000e-01 km/s<br />
INFO ImageAnalysis 3 1 Stokes Stokes 1 1 I<br />
INFO imhead ##### End Task: imhead #####<br />
INFO imhead ##########################################<br />
<br />
</pre><br />
<br />
This report tells you about the target, shape, and coordinates of the image. It also notes the rest frequency and some details of the observation. '''imhead''' may be used more generally to retrieve header keywords as python variables or to manipulate the header of an image. Consult the help for details.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
You may want to pay particular attention to the third and fourth axis of the CASA image. These are <br />
usually frequency (velocity) and Stokes (polarization) in some order. An occasional source of confusion <br />
is that this order is not always the same. Often CLEAN will output images with the Stokes axis third, <br />
while IMPORTFITS usually yields images with the frequency axis third. If you encounter problems with<br />
image analysis tasks, you may want to check whether this results from conflicting axis definitions. You<br />
can adjust the order of the axes using the IMTRANS task.<br />
</pre><br />
<br />
Before proceeding, make sure that you have all three data sets as CASA images: '''TWHydra_CO3_2line.image''', '''TWHydra_HCOPlusline.image''', and '''TWHydra_contall_apcal.image'''. If you do not, then import them from the provided reference images. If you are re-importing the FITS images, run the commented remove commands before running importfits.<br />
<br />
<source lang="python"><br />
# In CASA<br />
# os.system("rm -rf TWHydra_CO3_2line.image")<br />
importfits(fitsimage="TWHydra_CO3_2line.image.fits", imagename="TWHydra_CO3_2line.image")<br />
# os.system("rm -rf TWHydra_HCOplusline.image")<br />
importfits(fitsimage="TWHydra_HCOplusline.image.fits", imagename="TWHydra_HCOplusline.image")<br />
# os.system("rm -rf TWHydra_contall_apcal.image")<br />
importfits(fitsimage="TWHydra_contall_apcal.image.fits", imagename="TWHydra_contall_apcal.image")<br />
</source><br />
<br />
In the rest of this guide we will construct ''moment maps'' showing the integrates, velocity field, and line width of the two lines. We will carry out Gaussian fits to the continuum and line maps. We will also illustrate some of the additional analysis capabilities available in CASA: subcube extraction, retrieval of data into python arrays, cube alignment, smoothing, and overlays of multiple spectral lines.<br />
<br />
===Moment Maps===<br />
<br />
The line "images" of CO(3-2) and HCO+(4-3) are, of course, cubes rather than images. Two dimensional ''moment maps'' are a standard way to present such data. These are maps showing the result of various moments (or similar calculations) carried out along the frequency axis of the cube. For example, the "moment 0" map is the sum of emission along the frequency axis at each pixel. The first moment is the intensity-weighted velocity (or frequency). The second moment is the intensity-weighted velocity (or frequency) dispersion about the mean. These and a number of other calculations (for example the maximum intensity) can be calculated via the '''immoments''' task. Consult the help or the CASA cookbook for more details.<br />
<br />
In this section, we will calculate moments for our two spectral line data cubes. To make the highest quality moment maps, we will first identify the planes of the data cube that contain emission, so that we can carry out the sum only over these channels. Doing otherwise adds noise to the moment map without adding signal and so lowers the signal-to-noise ratio of the final image. For the first and second moments we will identify an intensity threshold above which the data are statistically very likely to correspond to real astronomical emission. We will restrict the calculation to consider only data above this threshold, yielding a cleaner calculation (the second moment, in particular, is not at all robust against the inclusion of outlying noise). Finally, we will inspect the resulting moment maps with the viewer and output them to .FITS files.<br />
<br />
====Estimate the Spectral Extent====<br />
<br />
First, we want to figure out what planes appear to contain real emission. Open the CO data cube with the CASA viewer via:<br />
<br />
<source lang="python"><br />
# In CASA<br />
viewer("TWHydra_CO3_2line.image")<br />
</source><br />
<br />
This will open the CO(3-2) data cube as a raster image. Use the Animator pane to scroll through the cube, noting that the emission is mostly confined to ~40 channels near the center of the cube. There are several ways to make a more rigorous estimate. <br />
<br />
''By-Plane Inspection:'' First, you could increase the stretch of the image to identify by hand the first and last channels with visible emission. To do open the Data Display Options panel in the viewer (the wrench icon) and manually set the data range and/or scaling power cycles to highlight faint emission (note that you can also do this using the mouse and the color stretch - sun - icon). I left the scaling power cycles at 0 and set the data range to [-0.15, 0.15]. Then scroll through the cube and note the first and last channels with obvious emission. If I do this, I find emission from about plane 30 through plane 86.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:DataDisplayPanelStretch.png|The Data Display Panel used to set the color stretch, here from [-0.15, 0.15] with a linear (0) stretch. Setting the stretch to a negative value will highlight lower emission (a more logarithmic stretch). We got to this panel by clicking the wrench icon. You can also get from the dropdown menus (Data->Adjust).<br />
File:TWHydraCOChan33.png|Channel 33 of the CO(3-2) cube on this stretch. This is about the first channel to show clear emission.<br />
File:TWHydraCOChan80.png|Channel 80 of the CO(3-2) cube on this stretch. This is about the last channel to show clear emission.<br />
</gallery><br />
</center><br />
<br />
To make this more rigorous, you can work out a noise estimate before hand (we'll find it to be about 0.025 Jy/beam) and overplot a contour to indicate significant emission. You can do this by hand by using the Data Manager (folder icon) to open TWHydra_CO3_2line.image as a "contour map" and then using the Data Display Options to manipulate the contour levels. To show a 3-sigma contour with sigma=0.025 Jy/beam set the Relative Contour Levels to [3], the Base Contour Level to 0, and the Unit Contour Level to 0.025. You can display a 5-sigma contour or change the RMS analogously. Scrolling through the cube, I see 3-sigma emission from channels 33 through 80.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:DataDisplayPanelContour.png|The Data Display Panel now being used to set the contour levels. We set the contour unit to 0.025 and ask for a single contour at 3 times this value. Notice that we clicked the tab along the top of the window to select the contour map.<br />
File:TWHydraCOChan33Contour.png|Channel 33 of the CO(3-2) cube on this stretch with a 3-sigma contour overlaid.<br />
File:TWHydraCOChan80Contour.png|Channel 80 of the CO(3-2) cube on this stretch with a 3-sigma contour overlaid.<br />
</gallery><br />
</center><br />
<br />
''Look at a Spectrum:'' You can also look at a spectrum of the source. To do this, scroll to a channel with a lot of emission (I went to 57) and then use the mouse to drag out a rectangle. To do this, left click on the rectangle box in the mouse toolbar (this assigns the left mouse button to define rectangle regions). Then drag out a box around the emission using the same button. Now click the spectrum in the toolbar to open the spectral profile tool. You will see the average profile for the selected region. You can set the bottom axis to show channels. You can zoom in within the spectral profile by dragging out a rectangle. When I do this, I find significant emission from channels 40-80.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:TWHydraRectangle.png|Defining a rectangular region around the main emission from TW Hydra. First we clicked the rectangle button on the mouse toolbar, then we held that button and dragged out the purple rectangle. After defining the rectangle, you can drag it around or delete it with <ESC>.<br />
File:TWHydraSpectrum.png|The spectrum of this rectangular region viewed in the spectral profile browser. Note that the bottom axis has been set to show channels. To get this spectrum, we defined the rectangular region and then clicked the spectrum button on the toolbar.<br />
File:TWHydraSpectrumZoom.png|A zoom in on the spectrum. The line extends from channels ~40-80.<br />
</gallery><br />
</center><br />
<br />
''Look at a Declination-Frequency Projection (or an R.A.-Frequency Projection):'' This is probably the least reliable way to do this, but illustrates a neat capability of the viewer. Open the Data Display Options (click the wrench icon) and open the "display axes" and "hidden axes" tabs. Use the dropdown menus to change the display so that the x-axis shows Declination, the y-axis shows Frequency, and the z-axis shows "Right Ascension." Now you are scrolling through planes of intensity as a function of Declination and Frequency. Use the animator to move to R.A. plane ~ 50 (the center of the source) and pull the stretch up (in the wrench tool; I used [-0.15,0.15] again). Mouse over the image and look at the "Position Tracking" pane in the bottom of the image, noting the pixel extent of emission in the frequency axis of this plane. I see traces of emission from channel ~30-90.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:DataDisplayPanelAxes.png|The Data Display Panel, here used to set which axes are displayed. We have adjusted the y-axis to show frequency and the x-axis to show Declination. The z-axis is now Right Ascension, so that we will scroll through planes of Right Ascension.<br />
File:DataDisplayPanelPixels.png|The Data Display Panel, here we are setting coordinates to show "pixels" rather than world coordinates.<br />
File:TWHydraDecFreqPixels.png|A Frequency-Declination plane of the cube near the central R.A. pixel (50). The rough extent of emission may be simply read off the y-coordinate. As above, we could overplot a 3-sigma contour to add more rigor.<br />
</gallery><br />
</center><br />
<br />
<br />
You can repeat this exercise for the HCO+ (4-3) emission. Using the Spectral Profile Browser, I find that the line extends from about channel 40 through channel 75.<br />
<br />
====Make Moment 0 Maps====<br />
<br />
With an estimate of the spectral extent of emission, we are now ready to make moment 0 maps of the CO(3-2) and HCO+(4-3) lines. It is possible to do this using the 'Calculate Moments/Spectral Profile tool' in the viewer, but here we do this using the '''immmoments''' command,<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom0')<br />
immoments(imagename='TWHydra_CO3_2line.image',moments=[0],<br />
outfile='TWHydra_CO3_2line.image.mom0',<br />
chans='30~90')<br />
</source><br />
<br />
and<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom0')<br />
immoments(imagename='TWHydra_HCOplusline.image',moments=[0],<br />
outfile='TWHydra_HCOplusline.image.mom0',<br />
chans='40~75')<br />
</source><br />
<br />
immoments will sum across the channels specified by '''chans''' and produce new CASA images with the names specified by '''outfile'''. These can be inspected using the CASA viewer just like any other image. Note that unlike higher-order moments, the moment-0 map is robust to the inclusion of noisy signal-free channels (to within reason, you just decrease your signal-to-noise ratio) and indeed may be biased to miss faint emission by imposing a threshold. For that reason, we will eschew the '''includepix''' keyword as we make the moment 0 maps.<br />
<br />
Let's look at the output using the viewer. We can specify some of the display options in the call to start the viewer by using '''imview''' instead of '''viewer'''.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview( raster=[ {'file':'TWHydra_CO3_2line.image.mom0',<br />
'range':[0.0,10.],<br />
'scaling':-1},<br />
{'file':'TWHydra_HCOplusline.image.mom0',<br />
'range':[0.0,10.],<br />
'scaling':-1}], <br />
contour={'file':'TWHydra_contall_apcal.image', 'base':0, 'unit':0.0025, 'levels':[3,100]} )<br />
</source><br />
<br />
This does several things: It opens the viewer with raster images of the moment 0 maps of CO(3-2) and HCO+(4-3), sets the range of the color stretch from [0, 10] for each image and sets the scaling to be -1, which highlights faint emission compared to the normal (0) stretch. It also opens the continuum image as a contour and defines two contour levels. Once the viewer is open, you can blink between the images by going into the Animator pane, checking the white box next to "Images" to enable animation between images, and then sliding the bar back and forth. See the name of the image being shown change. You can also show two images side by side by going to the Viewer Canvas Manager (wrench+P icon) and opening the "Number of Panels" tab. Set the "Number of panels in x" to 2 and make sure that the Images box is checked in the Animator pane. You will see both images side by side.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:CanvasManagerPanels.png|The Viewer Canvas Manager, accessed via the Wrech+P icon (not to be confused with the plain old wrench). Here we have adjusted the number of x-panels from 1 to 2 so that we show the two moment maps side by side.<br />
File:TWHydraMoment0Maps.png|The moment-0 maps of CO(3-2) and HCO+(4-3) plotted side by side on the same color stretch, both with the continuum contours overlaid. To get the two images side by side, run the imview call above then set the number of panels to 2 and make sure that the Images box in the Animator Pane (here at the bottom of the window) is checked.<br />
File:DataDisplayImview.png|Data Display Panel after our imview call. Imview allowed us to set the stretch, range, and contour levels from the command line.<br />
</gallery><br />
</center><br />
<br />
====Estimate the Noise====<br />
<br />
We have already made a few offhand comparisons to the RMS noise. This quantity is often critical to know when exploring the data. Because the higher-order moments (especially the dispersion) are not at all robust to the inclusion of noise, we will calculate them only from regions of the cube that have intensity several times the RMS noise value or higher and are thus very likely to contain real astronomical emission. To proceed, we need to estimate the RMS noise for our data.<br />
<br />
The easiest way to do this is to calculate the RMS scatter of the data about zero from a part of the data that you suspect to be (mostly) free of astronomical signal. In a data cube the easiest way to do this will often be to identify signal-free planes (channels) of the cube and to simply calculate the RMS in these regions. We can do this straightforwardly using the '''imstat''' command in CASA.<br />
<br />
IMSTAT COMMAND<br />
<br />
IMSTAT OUTPUT<br />
<br />
Alternatively, you can get similar statistics on a region of an image or data cube selected manually inside the viewer. Drag out a region, for example a rectangle, using one of the mouse tools. Then <br />
<br />
IMAGES OF REGION SELECTION, OUTPUT, REGION MANAGER<br />
<br />
Suggested values for CO(3-2), HCO+(4-3), and continuum. Short discussion of dynamic range limited vs. line-free channels.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
A note on primary beam corrections and noise.<br />
</pre><br />
<br />
====Higher Order Moment Maps for CO(3-2)====<br />
<br />
For higher order moments it is very important to set a conservative flux <br />
threshold. Typically something like 6 sigma, using sigma from peak line channel, works well.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom')<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_coord')<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_dispersion_coord')<br />
immoments(imagename='TWHydra_CO3_2line.image',moments=[1,2],<br />
outfile='TWHydra_CO3_2line.image.mom',<br />
chans='40~76',includepix=[0.3,100])<br />
</source><br />
<br />
Display all three moment maps in the viewer, overlaid with continuum contours.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview( raster=[ {'file':'TWHydra_CO3_2line.image.mom0'},<br />
{'file':'TWHydra_CO3_2line.image.mom.weighted_coord'},<br />
{'file':'TWHydra_CO3_2line.image.mom.weighted_dispersion_coord'} ], <br />
contour={'file':'TWHydra_contall_apcal.image', 'base':0, 'unit':0.0025, 'levels':[3,100]} )<br />
</source><br />
<br />
To see all three raster images simultaneously, open the viewer's Panel Display Options (the "P-wrench" icon in the viewer tool bar), click "Number of panels", and change "Number of panels in x" to 3. Then select the "Blink" toggle (radio button) from the Animator panel.<br />
<br />
<figure id="TWHya_CO3_2_moments.png"><br />
[[Image:TWHya_CO3_2_moments.png|center|800px|frame|<caption>ALMA CO(3-2) moment maps, with white continuum contours at 3 and 100 sigma. From left to right: integrated intensity, intensity weighted velocity field, intensity weighted velocity dispersion are shown.</caption>]]<br />
</figure><br />
<br />
Repeat for HCO+(4-3) which has a bit narrower velocity extent than the CO(3-2), but similar rms noise.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom0')<br />
immoments(imagename='TWHydra_HCOplusline.image',moments=[0],<br />
outfile='TWHydra_HCOplusline.image.mom0',<br />
chans='43~74')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom')<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_coord')<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_dispersion_coord')<br />
immoments(imagename='TWHydra_HCOplusline.image',moments=[1,2],<br />
outfile='TWHydra_HCOplusline.image.mom',<br />
chans='43~74',includepix=[0.3,100])<br />
</source><br />
<br />
Display all three moment maps in the viewer using the same method described above for the CO(3-2) maps.<br />
<br />
<figure id="TWHya_HCOp4_3_moments.png"><br />
[[Image:TWHya_HCOp4_3_moments.png|center|800px|frame|<caption>ALMA HCO+(4-3) moment maps, with white continuum contours at 3 and 100 sigma. From left to right: integrated intensity, intensity weighted velocity field, intensity weighted velocity dispersion are shown.</caption>]]<br />
</figure><br />
<br />
=====Exporting Fits Images=====<br />
<br />
If you want to analyze the data using another software package it is easy to convert from CASA format to FITS. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image',fitsimage='TWHydra_CO3_2line.image.fits')<br />
</source><br />
<br />
Although "FITS format" is supposed to be a standard, in fact most packages expect slightly different things from a FITS image. If you are having difficulty, try setting '''velocity=T''' and/or '''dropstokes=T'''.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf TWHydra_HCOplusline.image.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image',fitsimage='TWHydra_HCOplusline.image.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom0.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image.mom0',<br />
fitsimage='TWHydra_CO3_2line.image.mom0.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_coord.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image.mom.weighted_coord',<br />
fitsimage='TWHydra_CO3_2line.image.mom.weighted_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_dispersion_coord.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image.mom.weighted_dispersion_coord',<br />
fitsimage='TWHydra_CO3_2line.image.mom.weighted_dispersion_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom0.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image.mom0',<br />
fitsimage='TWHydra_HCOplusline.image.mom0.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_coord.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image.mom.weighted_coord',<br />
fitsimage='TWHydra_HCOplusline.image.mom.weighted_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_dispersion_coord.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image.mom.weighted_dispersion_coord',<br />
fitsimage='TWHydra_HCOplusline.image.mom.weighted_dispersion_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_apcal.image.fits')<br />
exportfits(imagename='TWHydra_contall_apcal.image',fitsimage='TWHydra_contall_apcal.image.fits')<br />
</source><br />
<br />
===Display Channel Maps===<br />
<br />
Using the Viewer you can make channel map figures. Start the Viewer and then open the CO(3-2) cube as a raster image and then the continuum as a contour image. Then we use the "wrench" icon and "P wrench" icons to set up the channel images, contour levels etc. (If you need help setting up the viewer for this image, see a screen shot of the viewer setup windows, below.)<br />
<br />
<figure id="TWHya_channel_co3_2.png"><br />
[[Image:TWHya_channel_co3_2.png|center|frame|<caption>Channel maps of the CO(3-2) emission with white continuum contours at 3 and 100 sigma.</caption>]]<br />
</figure><br />
<br />
<figure id="Viewer_setup.png"><br />
[[Image:Viewer_setup.png|center|thumb|500px|<caption>The setup windows looked like this</caption>]]<br />
</figure><br />
<br />
Repeat for HCO+(4-3)<br />
<br />
<figure id="TWHya_channel_HCOp4_3.png"><br />
[[Image:TWHya_channel_HCOp4_3.png|center|thumb|800px|<caption>Channel maps of the HCO+(4-3) emission with white continuum contours at 3 and 100 sigma. The color intensity scale is the same as that used for CO(3-2).</caption>]]<br />
</figure><br />
<br />
<!--<br />
====Examine CO Contours on an HCO+ Raster====<br />
<br />
====Matched Movies====<br />
<br />
===Image Plane and Spectral Fits===<br />
<br />
====Fit a Gaussian to the Continuum====<br />
<br />
=====Fit In the Viewer=====<br />
<br />
=====Fit Using the Command Line=====<br />
<br />
====Fit a Gaussian to the CO Line====<br />
<br />
=====Fit In the Viewer=====<br />
<br />
=====Fit Using the Command Line=====<br />
<br />
===Extract a Sub-Image===<br />
<br />
===Align Image Cubes===<br />
--><br />
<br />
{{Checked 4.3.0}}</div>Sstierwahttps://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_4.3&diff=19486TWHydraBand7 Imaging 4.32016-05-18T04:45:33Z<p>Sstierwa: /* Continuum Data Amplitude Self-Calibration */</p>
<hr />
<div>[[Category:ALMA]][[Category:Imaging]][[Category:Spectral Line]]<br />
<br />
* '''This tutorial picks up where '''[[TWHydraBand7_Calibration_4.5.2]]''' leaves off, with fully calibrated, split science target MS. If you wish to skip the Calibration guide: obtain the calibrated data from [[TWHydraBand7#Getting_the_Data]]; extract it using <tt>tar -xzvf FILENAME</tt>; and <tt>cd</tt> into the extracted directory.'''<br />
<br />
*'''This guide is designed for CASA 4.3. If you are using an older version of CASA please see [[TWHydraBand7_Imaging_4.3]].<br />
<br />
* '''Details of the ALMA data are provided at [[TWHydraBand7]]'''<br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.5.2. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.3.0'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
== Prepare Continuum Data for Further Processing==<br />
<br />
In order to speed up imaging/self-calibration for the continuum data we will average channels together, and then flag the few spectral features. This method works well in the case of only a few spectral lines, while retaining enough channelization to aid in multi-frequency synthesis and being able to remove spectral features in the averaged data. When generalizing this process to other datasets, the amount of channel averaging will vary. '''Note for wide bandwidth data it is never a good idea to use the continuum estimate generated by uv-continuum subtraction as your continuum data'''. This worked OK in the past with the narrow band systems like the VLA and low dynamic range instruments like the SMA, but is not advised for ALMA wide bandwidth, high dynamic range data. <br />
<br />
<figure id="Cont_spw2.png"><br />
[[Image:Cont_spw2.png|thumb|<caption>CO(3-2) in spw=2 from the "continuum" channel averaged data.</caption>]]<br />
</figure><br />
<figure id="Cont_spw3.png"><br />
[[Image:Cont_spw3.png|thumb|<caption>Notice upswing at high channel numbers in spw=3.</caption>]]<br />
</figure><br />
<br />
One can also flag the spectral features first but in that case make a backup of the file that is analogous to TWHydra_corrected.ms as you will need it later (unflagged) for spectral line imaging. We begin by excluding ~20 channels on each edge, and averaging over 100 channel intervals:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_cont.ms*')<br />
split(vis='TWHydra_corrected.ms',outputvis='TWHydra_cont.ms',<br />
spw='0~3:21~3820',width=100,datacolumn='data')<br />
</source><br />
<br />
Now make a plot of amplitude vs. channel to see what needs to be flagged<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',spw='0~3',xaxis='channel',yaxis='amp',<br />
avgtime='1e8',avgscan=T,coloraxis='spw',iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
The CO(3-2) and HCO+(4-3) lines are obvious. The 4th spw; spw=3 also shows an upswing on the highest channels that is problematic, it was seen on the calibrators too and is likely due to a weak atmospheric feature, we will flag the worst of it.<br />
<br />
<figure id="Cont_uvplot.png"><br />
[[Image:Cont_uvplot.png|thumb|<caption>UV-plot of the continuum emission, colors show spws.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='TWHydra_cont.ms', mode='manual', <br />
spw='0:16~16, 2:21~21, 3:33~37')<br />
</source><br />
<br />
Have a look at the continuum as a function of uv-distance (in the plot to the right, the 4 spw are shown in different colors on top of each other). If the data are flat as a function of uv-distance, the source is completely unresolved. If instead you see structure (in this case decreasing amplitude with uv-distance), the source is resolved. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',spw='',xaxis='uvdist',yaxis='amp',field='',avgchannel='38',<br />
coloraxis='spw',plotfile='cont_uvplot.png')<br />
</source><br />
<br />
Notice that the spw do not have the same amplitude. Unfortunately, the red spw (highest frequency) should be higher than the green one (lowest frequency) because optically thin dust goes as nu^4, and optically thick as nu^2. This inconsistency is due to imperfect amplitude/absolute flux calibration. The self-calibration below will bring them into agreement with each other, but this is the sort of thing that results in considerable absolute flux uncertainty at submillimeter wavelengths. We are working on how to do this better.<br />
<br />
==A priori Noise Estimates==<br />
<br />
<figure id="Corrected_time.png"><br />
[[File:Corrected_time.png|thumb|<caption>Plot for estimating time.</caption>]]<br />
</figure><br />
<figure id="sensitivity_cont.png"><br />
[[File:sensitivity_cont.png|thumb|<caption>Sensitivity calculator setup with observed continuum parameters for these observations.</caption>]]<br />
</figure><br />
<br />
To estimate what the expected noise levels are, we first need to know how much time we had on source. Looking at <br />
a plot of amplitude vs time for the concatenated but pre-split data (see below) there are 9x8min scans + 6x6min scans + 3x1min + 2x2min scans for about 1.9 hours on source. There are 2 polarizations and about 1.75 GHz of total continuum bandwidth taking into account flagging.<br />
<br />
Using this information and https://almascience.nrao.edu/proposing/sensitivity-calculator, we find that the '''expected rms noise for the continuum is about 0.3 mJy/beam'''.<br />
<br />
For the spectral line data, which we will image below, with 0.12 km/s channels (needs to be entered in the field ''bandwidth per polarization''), the '''expected rms noise for the spectral lines is about 32 mJy/beam'''.<br />
<br />
==Image and Self-Calibrate the Continuum==<br />
<br />
====Create Initial Clean Image====<br />
<br />
First we will make an initial image using {{clean}}, this task will both deconvolve and clean. <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
If you are unfamiliar with the basic concepts of deconvolution and clean,<br />
pause here and review for example<br />
http://www.aoc.nrao.edu/events/synthesis/2010/lectures/wilner_synthesis10.pdf<br />
</pre><br />
<br />
In {{clean}}, we use '''mode='mfs'''' to do multifrequency synthesis, in other words grid each uv-channel independently. Since the uv-spacing is a function of frequency, this will actually achieve greater uv-coverage than if all the channels and spws had been averaged in advance. The '''imsize=100''' and '''cellsize=['0.3arcsec']''' were chosen to be appropriate for the Band and antenna configuration. At ALMA Band 7, the Full Width Half Power primary beam is about 20", so we want to make our image at least this big. We've made it a bit larger out to about the 25% power point. For the configuration used to take these data, the resolution is expected to be about 1.5" and it is a good idea to oversample the beam by setting the cell size to be a factor of 4 or 5 smaller than the beam (we have used 5 here). <br />
<br />
For doing self-calibration it is essential that only "real" signal be included in the image model, thus it is important to make a clean mask, and clean the first iteration rather conservatively (shallowly) so that you are sure that you do not have clean components in your model that do not represent real source emission. In the example below we set '''interactive=T''' so you can interactively make the clean mask and stop clean when the signal from the source starts to approach the surrounding "noise" areas in the residual map.<br />
<br />
'''NOTE:''' Real emission will not go away if you do not put a clean box on it. Conversely if you put a clean box on something that is NOT real and clean deeply you can amplify that feature. Thus, its best to be conservative and build up your clean box as you go, you can generally see fainter "real" features in the residuals.<br />
<br />
'''NOTE:''' If you start an interactive clean, and then do not make a mask, clean will stop when you tell it to go on because it has nothing to clean. There is no default mask.<br />
<br />
<figure id="Viewer_clean1.png"><br />
[[Image:Viewer_clean1.png|thumb|<caption>Interactive viewer.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall',<br />
mode='mfs', imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5, <br />
mask='',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
'''NOTE:'''{{clean}} will generate several files automatically with the '''imagename''' prepended:<br />
* <imagename>.image # the final restored image<br />
* <imagename>.flux # the effective primary beam response (e.g. for pbcor)<br />
* <imagename>.flux.pbcoverage # the primary beam coverage (ftmachine=’mosaic’ only)<br />
* <imagename>.model # the model image<br />
* <imagename>.residual # the residual image<br />
* <imagename>.psf # the synthesized (dirty) beam<br />
<br />
Once the Clean Viewer opens, click on the polygon tool with your left mouse button, and draw a polygon around the continuum emission with the left mouse button. Double click inside the region with the left mouse button when you are happy with it. It will turn from green to white when the clean mask is accepted. To continue with clean use the "Next action" buttons in the green area on the Viewer Display GUI. <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
The red X will stop clean where you are, the blue arrow will stop <br />
the interactive part of clean, but continue to clean non-interactively <br />
until reaching the number of iterations requested (niter) or the flux <br />
density threshold (whichever comes first), and the green circle arrow <br />
will clean until it reaches the "iterations" parameter on the left side <br />
of the green area. <br />
</pre><br />
<br />
'''You should chose the green circle arrow'''. It will clean 100 iterations (number under iteration in the green area on the Viewer GUI) and then show the '''residual image''' again. The middle mouse button is automatically assigned to the "plus" icon, which adjusts the colorscale. '''If you cannot easily access multiple mouse buttons, you can always assign your one mouse button the icon you want by clicking on it'''. Adjust the color scale so you can see the structure in the noise better. Also, note that the logger is telling you the amount of clean flux recovered so far, the min/max residuals, and the synthesized beam:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Model 0: max, min residuals = 0.0203454, 0.00267232 clean flux 1.30124<br />
Threshhold not reached yet.<br />
Beam used in restoration: 1.6962 by 1.54549 (arcsec) at pa 28.9043 (deg) <br />
</pre> <br />
<br />
Already with only 100 iterations, the residuals outside the clean mask are larger than that inside. So we will stop here by hitting the Red X symbol.<br />
<br />
====1st Round of Continuum Data Phase Self-calibration====<br />
<br />
Next we can use the clean model to self-calibrate the uv-data. The process of self-calibration tries to adjust the data to better match the model you give it. That is why it is important to make the model as good as you can. {{clean}} places a uv-model of the resulting image in the file <tt>TWHydra_cont.model</tt>. This model can then be used to self-calibrate the data using {{gaincal}}. We use '''gaintype='T'''' to tell it to average the polarizations before deriving solutions (which gains us a sqrt(2) in sensitivity). A critical parameter to play with is '''solint'''; we use '''solint=30s'''. From {{listobs}} the integration time of these data is about 10 seconds, so using '''solint=30s''' then gains us a sqrt(3) in sensitivity. It is often best to start with a larger '''solint''' and then work your way down to the integration time if the S/N of the data permits. For the same reasons as described in the [[TWHydraBand7_Calibration_4.3]] tutorial we want to fix up the phases before tackling amplitude by setting '''calmode='p''''.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='TWHydra_cont.ms',caltable='self_1.pcal',<br />
solint='30s',combine='',gaintype='T',<br />
refant='DV06',spw='',minblperant=4,<br />
calmode='p',minsnr=2)<br />
</source><br />
<br />
<figure id="Self_1_phase.png"><br />
[[Image:Self_1_phase.png|thumb|<caption>Phase solutions from self_1.pcal with solint=30s.</caption>]]<br />
</figure><br />
<br />
Because '''combine=' '''', we are getting independent solutions for each spw. If you are desperate for S/N, you can try combining them with combine='spw'. We have plenty of S/N in these data so we keep them separate. Look at the solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_1.pcal',xaxis='time',yaxis='phase',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,-80,80],figfile='self_1_phase.png')<br />
</source><br />
<br />
The magnitude of corrections gives you a sense of how accurate the phase transfer from the calibrators was. You are checking to see that the phases are being well tracked by the solutions, i.e. smoothly varying functions of time within a given scan. Also the solutions for each spw are lying basically on top of each other which indicates that the spw to spw phase offsets are well calibrated already. Overall, these solutions look quite good. If they didn't you could try increasing the solint and/or combining the spw into a single solution. <br />
<br />
After checking that you are happy with the solutions, apply them with {{applycal}}<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_cont.ms',field='',gaintable=['self_1.pcal'],calwt=F)<br />
</source><br />
<br />
<figure id="Viewer_pcal1.png"><br />
[[Image:Viewer_pcal1.png|thumb|<caption>Clean residuals after 100 iterations and the 1st phase only self-cal. Residuals inside mask are higher than the "noise" outside.</caption>]]<br />
</figure><br />
<br />
Next clean the source again, to save time we can start with the clean mask from the last iteration. If you make interactive adjustments to the clean mask, they will be written to the '''new''' mask TWHydra_contall_1pcal.mask, and not the old one. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_1pcal.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall_1pcal',<br />
mode='mfs',imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5, <br />
mask='TWHydra_contall.mask',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
Now after the first 100 iterations you see that the residuals inside the clean mask are higher than those outside. This is because flux that had been spread out in the map due to poorly correlated phases has been placed where it belongs on the source, thereby increasing its flux. You may also notice that your original clean mask is a little too small. If so, you can make it a bit larger, just by drawing a new polygon around the area you want to include. When you double click, it will incorporate the new mask into the current mask (if your box goes awry you can use the erase toggle [radio button] to erase and redo the mask). The new mask area need not overlap the original mask (though for this source it probably will). You might also want to use the magnifying glass to zoom in. Again, you assign mouse buttons by clicking on the icon you want. Clean another 100 iterations (for a total of 200) and stop by clicking the red X.<br />
<br />
Now open initial and 1st self-cal images to compare them using {{imview}}. This is an alternative version of the {{viewer}} that is somewhat scriptable. <br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(raster=[{'file':'TWHydra_contall.image','range':[-0.01,0.05]},<br />
{'file':'TWHydra_contall_1pcal.image','range':[-0.01,0.05]}])<br />
</source><br />
<br />
Once the Viewer Display panel opens, click on the box next in the "Images" panel and then use the tapedeck buttons in the panel to alternate between the two images. Because the range was explicitly set, they are on the same color scale. It is obvious that the self-calibrated image is better. To quantify, 1st toggle back to "normal" and then draw a region that excludes the central source with the polygon tool and then double click inside (if you stay in the "Images" view, only the statistics for the last image opened will appear on the terminal instead of both). The basic statistics of the polygon region will print to the '''terminal''':<br />
<br />
<pre style="background-color: #fffacd;"><br />
TWHydra_contall.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2357 -9.434800e-01 -2.858690e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-4.002885e-04 7.906752e-03 7.898289e-03 -2.541723e-02 2.172779e-02 <br />
<br />
TWHydra_contall_1pcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2357 6.326584e-01 1.916918e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
2.684168e-04 3.655786e-03 3.646692e-03 -1.215155e-02 1.109403e-02 <br />
</pre><br />
<br />
The self-calibrated image has more than a factor of 2 lower rms noise!<br />
<br />
====2nd Round of Continuum Data Phase Self-calibration====<br />
<br />
Now that we have a better model, we solve for solutions again. This time we will try making the solint smaller -- the integration time is about 10 seconds, so we set '''solint='int'''' to have it use the integration time.<br />
<br />
<figure id="Self_2_phase.png"><br />
[[Image:Self_2_phase.png|thumb|<caption>Phase solutions from self_2.pcal with solint='int'.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='TWHydra_cont.ms',caltable='self_2.pcal',<br />
solint='int',combine='',gaintype='T',<br />
refant='DV06',spw='',minblperant=4,<br />
calmode='p',minsnr=2)<br />
</source><br />
<br />
Now plot the new solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_2.pcal',xaxis='time',yaxis='phase',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,-80,80],figfile='self_2_phase.png')<br />
</source><br />
<br />
The phases on this shorter '''solint''' still seem to be tracking well so we will apply it and make a new image and check to see if there is improvement. <br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_cont.ms',field='',gaintable=['self_2.pcal'],calwt=F)<br />
</source><br />
<br />
<figure id="Viewer_pcal2.png"><br />
[[Image:Viewer_pcal2.png|thumb|<caption>Clean residuals after 2nd phase only self-cal and 250 iterations. The residuals inside the clean mask are lower than those outside, so its time to stop.</caption>]]<br />
</figure><br />
<br />
Now clean again, updating '''mask''' with the most recent mask file.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_2pcal.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall_2pcal',<br />
mode='mfs',imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5,usescratch=False,<br />
mask='TWHydra_contall_1pcal.mask',<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
After 200 iterations<br />
<br />
<pre style="background-color: #fffacd;"><br />
Model 0: max, min residuals = 0.00489776, -0.00464541 clean flux 1.44461<br />
</pre><br />
<br />
It looks like it could use just a little more cleaning, so set '''iterations=50 in the GUI'''.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Clean used 50 iterations to approach a threshhold of 0.0015067<br />
0.0107122 Jy <- cleaned in this cycle for model 0 (Total flux : 1.45532Jy)<br />
Final maximum residual = 0.00326382<br />
Model 0: max, min residuals = 0.00326382, -0.00321361 clean flux 1.45532<br />
</pre><br />
<br />
The small amount of flux cleaned this cycle indicates that clean is converging and it's about time to stop. Also the residuals inside the clean mask are now smaller than the residuals outside (i.e. the noise) also indicating it's time to stop by hitting the red X on the GUI.<br />
<br />
Now repeat the display, blinking, and image statistics steps described above for the 1st and 2nd phase-only self-cal iterations.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(raster=[{'file':'TWHydra_contall_1pcal.image','range':[-0.01,0.05]},<br />
{'file':'TWHydra_contall_2pcal.image','range':[-0.01,0.05]}])<br />
</source><br />
<br />
The difference is small:<br />
<pre style="background-color: #fffacd;"><br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2466 4.611597e-02 1.397287e-03 <br />
Mean Rms Std dev Minimum Maximum <br />
1.870072e-05 3.831524e-03 3.832255e-03 -1.414417e-02 1.109403e-02 <br />
<br />
TWHydra_contall_2pcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2466 1.159416e-01 3.512963e-03 <br />
Mean Rms Std dev Minimum Maximum <br />
4.701606e-05 3.811716e-03 3.812199e-03 -1.383034e-02 1.078456e-02 <br />
</pre><br />
<br />
This small improvement suggests that we have gone as far as we can with phase self-cal.<br />
<br />
===Continuum Data Amplitude Self-Calibration===<br />
<br />
Now we will apply the best phase solution table on-the-fly while solving for the amplitude self-cal solutions. Since amplitude changes more slowly and is less constrained than phase, we use a longer '''solint='inf'''', as long as '''combine=' '''' this means to do one solution per scan. <br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='TWHydra_cont.ms',caltable='self_ap.cal',<br />
solint='inf',combine='',gaintype='T',<br />
refant='DV06',spw='',minblperant=4,<br />
gaintable=['self_2.pcal'],<br />
calmode='ap',minsnr=2)<br />
</source><br />
<br />
It's useful to look at the residual phase in the amplitude calibration table, i.e. since we applied our best phase-only solution while solving for this new amplitude and phase ('''calmode='ap'''') solution, the phase should already be corrected.<br />
<br />
<figure id="Self_ap_phase.png"><br />
[[Image:Self_ap_phase.png|thumb|<caption>Residual phase solutions from self_ap.cal.</caption>]]<br />
</figure><br />
<figure id="Self_ap_amp.png"><br />
[[Image:Self_ap_amp.png|thumb|<caption>Amplitude solutions from self_ap.cal.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_ap.cal',xaxis='time',yaxis='phase',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,-1,1],figfile='self_ap_phase.png')<br />
</source><br />
<br />
The residuals are very small as expected. (If you see large residuals here, it means that the phase-only solution is suspect, and you were mostly just moving noise around.) Now look at the amplitude solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_ap.cal',xaxis='time',yaxis='amp',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,0.6,1.4],figfile='self_ap_amp.png')<br />
</source><br />
<br />
For the most part these look very good except one rather large deviation on DV06. Apply both the final phase and the amplitude calibration tables.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_cont.ms',field='',gaintable=['self_2.pcal','self_ap.cal'],calwt=F)<br />
</source><br />
<br />
Plot the corrected data as a function of both time and uv-distance. It is always a good idea to check these after an amplitude self-calbration to be sure that it worked properly. Occasionally, a few spurious bits of data will get blown up by the amplitude self-cal if it is not well-constrained. <br />
<br />
<figure id="Selfcal_time.png"><br />
[[Image:Selfcal_time.png|thumb|<caption>Post self-calibration amplitude vs. time</caption>]]<br />
</figure><br />
<figure id="Selfcal_uvdist.png"><br />
[[Image:Selfcal_uvdist.png|thumb|<caption>Post self-calibration amplitude vs. uv-distance</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',xaxis='time',yaxis='amp',<br />
avgchannel='38',ydatacolumn='corrected',coloraxis='spw',<br />
plotfile='selfcal_time.png')<br />
</source><br />
<br />
The time where we saw a large amplitude correction on DV06 looks consistent here so the large correction we saw in the solutions corrected a real issue. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',xaxis='uvdist',yaxis='amp',<br />
avgchannel='38',ydatacolumn='corrected',coloraxis='spw',<br />
plotfile='selfcal_uvdist.png')<br />
</source><br />
<br />
You will see that this plot looks much better than before. <br />
<br />
<figure id="Viewer_apcal.png"><br />
[[Image:Viewer_apcal.png|thumb|<caption>Clean residuals after final amplitude and phase self-cal.</caption>]]<br />
</figure><br />
<br />
Now make the final continuum image.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_apcal.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall_apcal',<br />
mode='mfs',imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5,usescratch=False,<br />
mask='TWHydra_contall_2pcal.mask',<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
We know we need to clean at least 250 iterations (i.e. 100+100+50=250), so set iterations to 300 in the gui and hit the round green arrow. After this notice how much better the residual looks. Clean another 100 iterations. The "circular pattern", and 4 bright spots at each corner you see now in the residual is likely due to non-closing amplitude errors that cannot be removed with an antenna based self-calibration, so this is as good as it gets with pure self-cal. Hit the Red X to stop clean.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Clean used 100 iterations to approach a threshhold of 0.00105507<br />
0.0061808 Jy <- cleaned in this cycle for model 0<br />
Final maximum residual = 0.00242926<br />
Model 0: max, min residuals = 0.00238278, -0.00242926 clean flux 1.48201<br />
</pre><br />
<br />
Now repeat the display, blinking, and image statistics described above for the 2nd phase only and the new amplitude & phase self-cal'ed images.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(raster=[{'file':'TWHydra_contall_2pcal.image','range':[-0.01,0.05]},<br />
{'file':'TWHydra_contall_apcal.image','range':[-0.01,0.05]}])<br />
</source><br />
<br />
The amplitude and phase self cal'ed image is notably better than phase-only. Quantitatively:<br />
<pre style="background-color: #fffacd;"><br />
<br />
TWHydra_contall_2pcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 3542 2.053068e-01 6.220676e-03 <br />
Mean Rms Std dev Minimum Maximum <br />
5.796351e-05 3.955967e-03 3.956101e-03 -1.383034e-02 1.078456e-02 <br />
<br />
TWHydra_contall_apcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 3542 6.044652e-04 1.831495e-05 <br />
Mean Rms Std dev Minimum Maximum <br />
1.706565e-07 1.270183e-03 1.270362e-03 -4.980673e-03 4.137159e-03 <br />
</pre> <br />
<br />
and indeed, we've gained another factor of 3 in sensitivity. <br />
<br />
'''Overall with this self-calibration we've improved the noise by a factor of 6.7! With a peak flux density of 0.98 Jy, the S/N increased from 115 initially to 770 after. So, well worth the trouble.'''<br />
<br />
<div class="noprint" style="float:none; border:0px solid blue;background-color:#F6CEF5;padding:2px;"><br />
If you have used the '''standard='Butler-JPL-Horizons 2012' ''' model during the calibration process, you should see an increase in peak flux density of about 3%.<br />
</div><br />
<br />
It is notable that we are still a factor of more than 4 from the apriori noise estimate of 0.3 mJy/beam. This is likely due to residual sources of non-closing (not antenna based) errors in the data like baseline errors and baseline-dependent bandpass errors. Additionally, polarization errors (which we did not calibrate at all) can contribute, as well as imperfect uv-coverage with only 8 antennas. A dynamic range of 770 is actually quite good in the submillimeter.<br />
<br />
==Apply self-calibration to Full Dataset and Split Line Data==<br />
<br />
Now apply the self-calibration derived from the continuum emission to the full unchannel-averaged data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_corrected.ms',gaintable=['self_2.pcal','self_ap.cal'],calwt=F)<br />
</source><br />
<br />
Split off the CO(3-2) spectral line data in spw=2 and the HCO+(4-3) data in spw=0 for further processing.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2.ms*')<br />
split(vis='TWHydra_corrected.ms',outputvis='TWHydra_CO3_2.ms',datacolumn='corrected',spw='2')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplus.ms*')<br />
split(vis='TWHydra_corrected.ms',outputvis='TWHydra_HCOplus.ms',datacolumn='corrected',spw='0')<br />
</source><br />
<br />
==Continuum Subtraction== <br />
<br />
Next we need to subtract the continuum emission from the spectral line data. It is best to do this in the uv-plane. The first step is to make a channel plot of the spectral data to get the line-free channel ranges for both spectral lines. Since the line emission is simple (one spectral line per spw) and there are more than enough line-free channels we do not need to be very precise just stay well away from the line and whenever possible it is best to chose line-free channel ranges on either side of the line for the best possible baseline subtraction. <br />
<br />
<figure id="CO3_2_channel.png"><br />
[[Image:CO3_2_channel.png|thumb|<caption>CO(3-2) line in channel space.</caption>]]<br />
</figure><br />
<figure id="HCOp4_3_channel.png"><br />
[[Image:HCOp4_3_channel.png|thumb|<caption>HCO+(4-3) in channel space.</caption>]]<br />
</figure><br />
<br />
'''Note''': after the split above, the original spw ids will be relabeled as 0 in each file because there is only one spectral window in each file.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_CO3_2.ms',spw='0',xaxis='channel',yaxis='amp',<br />
avgtime='1e8',avgscan=T,coloraxis='spw',plotfile='CO3_2_channel.png')<br />
</source><br />
<br />
It is a good idea to stay a little away from the very edges of the baseband which can be noisy. The channel ranges <br />
20~2000 and 2400~3800 look like good choices for CO(3-2).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_HCOplus.ms',spw='0',xaxis='channel',yaxis='amp',<br />
avgtime='1e8',avgscan=T,coloraxis='spw',plotfile='HCOp4_3_channel.png')<br />
</source><br />
<br />
The channel ranges 20~1500 and 1900~3800 look like good choices for HCO+(4-3).<br />
<br />
Next use the identified line-free channel ranges and {{uvcontsub}} to subtract the continuum model from the line emission.<br />
<br />
<source lang="python"><br />
# In CASA<br />
uvcontsub(vis='TWHydra_CO3_2.ms',fitorder=1,fitspw='0:20~2000,0:2400~3800')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
uvcontsub(vis='TWHydra_HCOplus.ms',fitorder=1,fitspw='0:20~1500,0:1900~3800')<br />
</source><br />
<br />
Note: If you do not have line-free channels on both sides of the line emission, it is safer to use '''fitorder=0''', or the fit may diverge.<br />
<br />
==Spectral Line Imaging==<br />
<br />
Now we are ready to make cubes of the line emission. The imaging parameters are similar to the continuum except for <br />
those dealing with the spectral setup: '''mode''', '''start''', '''width''', '''nchan''', '''restfreq''', and '''outframe''' parameters. When making spectral images you have three choices for the '''mode''' parameter: '''channel''', '''velocity''', and '''frequency'''. Data are taken using constant frequency channels. For spectral line analysis it's often more useful to have constant velocity channels, and this is also the best way to make images of multiple lines with the exact same channelization for later comparison. For '''mode='velocity'''', the desired '''start''' and '''width''' also need to be given in velocity units for the desired output frame. <br />
<br />
It is important to note that ALMA does not do on-line Doppler Tracking and the native frame of the data is TOPO. If you do not specify '''outframe''' the output cube will also be in TOPO, which is not very useful for spectral line work. The Doppler Shift is taken out during the regridding to the desired outframe in {{clean}} or alternatively it can be done separately by the {{cvel}} task which would need to be run before {{clean}}. <br />
<br />
<figure id="CO3_2_vel.png"><br />
[[Image:CO3_2_vel.png|thumb|<caption>CO(3-2) spectrum in LSRK velocity space.</caption>]]<br />
</figure><br />
<figure id="HCOp4_3_vel.png"><br />
[[Image:HCOp4_3_vel.png|thumb|<caption>HCO+(4-3) spectrum in LSRK velocity space.</caption>]]<br />
</figure><br />
<br />
To see what velocity parameters you want to set in clean it is useful to make a plot in {{plotms}} in the desired output frame. To make it easier to see, we set a '''plotrange''' since we know the LSRK velocity of TW Hya is about 2.88 km/s. Note these plots take a little longer because of the frame shift.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_CO3_2.ms.contsub',xaxis='velocity',yaxis='amp',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',<br />
restfreq='345.79599GHz',plotrange=[-20,23,0,0],plotfile='CO3_2_vel.png')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_HCOplus.ms.contsub',xaxis='velocity',yaxis='amp',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',<br />
restfreq='356.7342GHz',plotrange=[-20,23,0,0],plotfile='HCOp4_3_vel.png') <br />
</source><br />
<br />
From these plots it looks like imaging the cubes from about -5 to +8 km/s will encompass the line, but still provide several line-free channels on either side so the noise level can be estimated. The channel width is 122 kHz, which at <br />
345.79599 GHz is 0.106 km/s. Recall that the spectral ''resolution'' is a factor of two poorer. We will use a velocity channel width of 0.12 km/s for a little oversampling, but the spectral resolution remains 0.2 km/s.<br />
<br />
As before, it is very important that you make a clean mask. There are many ways to do this ranging from the complicated to simple. For this example we will make a single clean mask that encompasses the line emission in every channel and apply it to all channels. This is much better than no clean mask, though not quite as good as making an individual mask for each channel. For some sources, one can use the continuum mask to clean the line, however TW Hya is a bit curious in that the continuum emission is not as extended as the line emission (Hughes et al. 2008).<br />
<br />
=== CO(3-2) Imaging ===<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.*')<br />
clean(vis='TWHydra_CO3_2.ms.contsub',imagename='TWHydra_CO3_2line',<br />
imagermode='csclean',spw='',<br />
imsize=100,cell=['0.3arcsec'],<br />
mode='velocity',start='-4km/s',width='0.12km/s',nchan=118,<br />
restfreq='345.79599GHz',outframe='LSRK',<br />
weighting='briggs',robust=0.5,<br />
mask='',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=100000)<br />
</source><br />
<br />
<figure id="Viewer_55.png"><br />
[[Image:Viewer_55.png|thumb|<caption>Interactive Viewer window with CO(3-2) clean mask, before cleaning starts.</caption>]]<br />
</figure><br />
<figure id="Viewer_500.png"><br />
[[Image:Viewer_500.png|thumb|<caption>Interactive Viewer window for CO(3-2), after 500 iterations, more cleaning is needed.</caption>]]<br />
</figure><br />
<br />
It will take a little while to grid the cube, when the interactive viewer opens, use the tapedeck to cycle through the channels. You should see a progress of line emission in channels 40 to 70 or so.<br />
*Go to channel 57 (about line center)<br />
*Select the polygon tool with the left mouse button<br />
*Select the "All Channels" toggle in the green area<br />
*Draw a polygon around the channel 57 emission, double click inside to activate.<br />
*Now go to channel 60, this is the channel with the most extent to the SE, draw another polygon that encompasses this emission if necessary,double click inside to activate.<br />
*Now go to channel 55, this is the channel with the most extent to the NW, draw another polygon that encompasses this emission if necessary,double click inside to activate. <br />
*Now double check the mask by cycling through channels with real line emission to be sure that your clean box encompasses the emission, but does not extend far beyond it. Again the "erase" toggle can come in handy if things go awry or if you want to just delete a small portion of an existing mask (just draw a polygon around what you want to erase and double click inside), be sure to switch back to "add" before going on.<br />
<br />
The figure shows what the final clean box should look like. Now clean using the green circle arrow. You can watch the progress in the logger. When 100 iterations are done, the viewer will show the residual map for each channel. Cycle through the channels and see whether you are still happy with the clean box in each signal channel. The "erase button" can help you fix mistakes. If necessary adjust. It is often useful to adjust the colorscale with the "plus" symbol icon. Keep going until the residual emission looks like the surrounding noise. If it seems to be going slowly, increase the iterations to 300 for a round or two. I stopped cleaning (Red x) when the logger showed (about 900 iterations). <br />
<pre style="background-color: #fffacd;"><br />
12.9846 Jy <- cleaned in this cycle for model 0<br />
Final maximum residual = 0.157312<br />
Model 0: max, min residuals = 0.157312, -0.0871295 clean flux 279.304<br />
</pre><br />
<br />
NOTE: The residuals are still a bit high in the strongest emission channels after it is well cleaned in the weaker channels. This is an indication that the sensitivity is "dynamic range" limited. In other words even with more <br />
intrinsic sensitivity per integration (i.e. better system temperature), the dynamic range limit would remain the same unless you get more uv-coverage. The fundamental dynamic range limitations of ALMA will be considerably better with 16 antennas in Early Science and MUCH better with the full 50-antenna array.<br />
<br />
=== HCO+(4-3) Imaging ===<br />
<br />
Now image and clean the HCO+(4-3) line using what you learned above.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.*')<br />
clean(vis='TWHydra_HCOplus.ms.contsub',imagename='TWHydra_HCOplusline',<br />
imagermode='csclean',spw='',<br />
imsize=100,cell=['0.3arcsec'],<br />
mode='velocity',start='-4km/s',nchan=118,width='0.12km/s',<br />
restfreq='356.7342GHz',outframe='LSRK',<br />
weighting='briggs',robust=0.5,<br />
mask='',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=100000)<br />
</source><br />
<br />
I stopped cleaning when: <br />
<pre style="background-color: #fffacd;"><br />
4.79833 Jy <- cleaned in this cycle for model 0<br />
Final maximum residual = 0.0977348<br />
Model 0: max, min residuals = 0.0977348, -0.060484 clean flux 192.066<br />
</pre><br />
<br />
==Image Analysis==<br />
<br />
After all that hard work you now have deconvolved images of the 350 GHz continuum, the CO (3-2) line, and the HCO+ (4-3) line. CASA includes tools to help you understand the contents of these images and make basic scientific measurements. These tools are divided between graphical exploration tools, accessible via the CASA viewer, and command line analysis tasks. To access the viewer, simply type '''viewer()''' and to see the list of analysis tasks available in CASA type '''tasklist''' at the CASA prompt and look under the Analysis sub-heading.<br />
<br />
If you want to do this portion of the guide and have downloaded the (.FITS) reference images, you can import them to be CASA images using '''importfits'''. If you are re-importing the images, use the commented remove command, here, to delete the previous import first.<br />
<br />
<source lang="python"><br />
# In CASA<br />
# os.system("rm -rf TWHydra_CO3_2line.image")<br />
importfits(fitsimage="TWHydra_CO3_2line.image.fits", imagename="TWHydra_CO3_2line.image")<br />
</source><br />
<br />
where '''fitsimage''' refers to the file to imported and '''imagename''' gives the output filename. If you are proceeding directly from the imaging step, your data are already CASA images and you may proceed without any importing.<br />
<br />
You can get the basic properties of any CASA image using the '''imhead''' command. For example, type <br />
<br />
<source lang="python"><br />
# In CASA<br />
imhead("TWHydra_CO3_2line.image")<br />
</source><br />
<br />
and look at the CASA logger. You will see an image summary like the following<br />
<br />
<pre style="background-color: #fffacd;"><br />
INFO imhead ##########################################<br />
INFO imhead ##### Begin Task: imhead #####<br />
INFO imhead imhead(imagename="TWHydra_CO3_2line.image",mode="summary",hdkey="",hdvalue="",<br />
INFO imhead hdtype="",hdcomment="",verbose=False)<br />
INFO ImageAnalysis <br />
INFO ImageAnalysis Image name : TWHydra_CO3_2line.image<br />
INFO ImageAnalysis Object name : TW Hya<br />
INFO ImageAnalysis Image type : PagedImage<br />
INFO ImageAnalysis Image quantity : Intensity<br />
INFO ImageAnalysis Pixel mask(s) : None<br />
INFO ImageAnalysis Region(s) : None<br />
INFO ImageAnalysis Image units : Jy/beam<br />
INFO ImageAnalysis Restoring Beam : 1.68065 arcsec, 1.53193 arcsec, 22.3015 deg<br />
INFO ImageAnalysis <br />
INFO ImageAnalysis Direction reference : J2000<br />
INFO ImageAnalysis Spectral reference : LSRK<br />
INFO ImageAnalysis Velocity type : RADIO<br />
INFO ImageAnalysis Rest frequency : 3.45796e+11 Hz<br />
INFO ImageAnalysis Pointing center : 11:01:51.844983 -34.42.17.160885<br />
INFO ImageAnalysis Telescope : ALMA<br />
INFO ImageAnalysis Observer : Unknown<br />
INFO ImageAnalysis Date observation : 2011/04/22/00:15:42<br />
INFO ImageAnalysis Telescope position: [2.22514e+06m, -5.44031e+06m, -2.48103e+06m] (ITRF)<br />
INFO ImageAnalysis <br />
INFO ImageAnalysis Axis Coord Type Name Proj Shape Tile Coord value at pixel Coord incr Units<br />
INFO ImageAnalysis -------------------------------------------------------------------------------------------------- <br />
INFO ImageAnalysis 0 0 Direction Right Ascension SIN 100 25 11:01:51.845 50.00 -3.000000e-01 arcsec<br />
INFO ImageAnalysis 1 0 Direction Declination SIN 100 25 -34.42.17.161 50.00 3.000000e-01 arcsec<br />
INFO ImageAnalysis 2 2 Spectral Frequency 118 59 3.45801e+11 0.00 -1.38414152e+05 Hz<br />
INFO ImageAnalysis Velocity -4 0.00 1.200000e-01 km/s<br />
INFO ImageAnalysis 3 1 Stokes Stokes 1 1 I<br />
INFO imhead ##### End Task: imhead #####<br />
INFO imhead ##########################################<br />
<br />
</pre><br />
<br />
This report tells you about the target, shape, and coordinates of the image. It also notes the rest frequency and some details of the observation. '''imhead''' may be used more generally to retrieve header keywords as python variables or to manipulate the header of an image. Consult the help for details.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
You may want to pay particular attention to the third and fourth axis of the CASA image. These are <br />
usually frequency (velocity) and Stokes (polarization) in some order. An occasional source of confusion <br />
is that this order is not always the same. Often CLEAN will output images with the Stokes axis third, <br />
while IMPORTFITS usually yields images with the frequency axis third. If you encounter problems with<br />
image analysis tasks, you may want to check whether this results from conflicting axis definitions. You<br />
can adjust the order of the axes using the IMTRANS task.<br />
</pre><br />
<br />
Before proceeding, make sure that you have all three data sets as CASA images: '''TWHydra_CO3_2line.image''', '''TWHydra_HCOPlusline.image''', and '''TWHydra_contall_apcal.image'''. If you do not, then import them from the provided reference images. If you are re-importing the FITS images, run the commented remove commands before running importfits.<br />
<br />
<source lang="python"><br />
# In CASA<br />
# os.system("rm -rf TWHydra_CO3_2line.image")<br />
importfits(fitsimage="TWHydra_CO3_2line.image.fits", imagename="TWHydra_CO3_2line.image")<br />
# os.system("rm -rf TWHydra_HCOplusline.image")<br />
importfits(fitsimage="TWHydra_HCOplusline.image.fits", imagename="TWHydra_HCOplusline.image")<br />
# os.system("rm -rf TWHydra_contall_apcal.image")<br />
importfits(fitsimage="TWHydra_contall_apcal.image.fits", imagename="TWHydra_contall_apcal.image")<br />
</source><br />
<br />
In the rest of this guide we will construct ''moment maps'' showing the integrates, velocity field, and line width of the two lines. We will carry out Gaussian fits to the continuum and line maps. We will also illustrate some of the additional analysis capabilities available in CASA: subcube extraction, retrieval of data into python arrays, cube alignment, smoothing, and overlays of multiple spectral lines.<br />
<br />
===Moment Maps===<br />
<br />
The line "images" of CO(3-2) and HCO+(4-3) are, of course, cubes rather than images. Two dimensional ''moment maps'' are a standard way to present such data. These are maps showing the result of various moments (or similar calculations) carried out along the frequency axis of the cube. For example, the "moment 0" map is the sum of emission along the frequency axis at each pixel. The first moment is the intensity-weighted velocity (or frequency). The second moment is the intensity-weighted velocity (or frequency) dispersion about the mean. These and a number of other calculations (for example the maximum intensity) can be calculated via the '''immoments''' task. Consult the help or the CASA cookbook for more details.<br />
<br />
In this section, we will calculate moments for our two spectral line data cubes. To make the highest quality moment maps, we will first identify the planes of the data cube that contain emission, so that we can carry out the sum only over these channels. Doing otherwise adds noise to the moment map without adding signal and so lowers the signal-to-noise ratio of the final image. For the first and second moments we will identify an intensity threshold above which the data are statistically very likely to correspond to real astronomical emission. We will restrict the calculation to consider only data above this threshold, yielding a cleaner calculation (the second moment, in particular, is not at all robust against the inclusion of outlying noise). Finally, we will inspect the resulting moment maps with the viewer and output them to .FITS files.<br />
<br />
====Estimate the Spectral Extent====<br />
<br />
First, we want to figure out what planes appear to contain real emission. Open the CO data cube with the CASA viewer via:<br />
<br />
<source lang="python"><br />
# In CASA<br />
viewer("TWHydra_CO3_2line.image")<br />
</source><br />
<br />
This will open the CO(3-2) data cube as a raster image. Use the Animator pane to scroll through the cube, noting that the emission is mostly confined to ~40 channels near the center of the cube. There are several ways to make a more rigorous estimate. <br />
<br />
''By-Plane Inspection:'' First, you could increase the stretch of the image to identify by hand the first and last channels with visible emission. To do open the Data Display Options panel in the viewer (the wrench icon) and manually set the data range and/or scaling power cycles to highlight faint emission (note that you can also do this using the mouse and the color stretch - sun - icon). I left the scaling power cycles at 0 and set the data range to [-0.15, 0.15]. Then scroll through the cube and note the first and last channels with obvious emission. If I do this, I find emission from about plane 30 through plane 86.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:DataDisplayPanelStretch.png|The Data Display Panel used to set the color stretch, here from [-0.15, 0.15] with a linear (0) stretch. Setting the stretch to a negative value will highlight lower emission (a more logarithmic stretch). We got to this panel by clicking the wrench icon. You can also get from the dropdown menus (Data->Adjust).<br />
File:TWHydraCOChan33.png|Channel 33 of the CO(3-2) cube on this stretch. This is about the first channel to show clear emission.<br />
File:TWHydraCOChan80.png|Channel 80 of the CO(3-2) cube on this stretch. This is about the last channel to show clear emission.<br />
</gallery><br />
</center><br />
<br />
To make this more rigorous, you can work out a noise estimate before hand (we'll find it to be about 0.025 Jy/beam) and overplot a contour to indicate significant emission. You can do this by hand by using the Data Manager (folder icon) to open TWHydra_CO3_2line.image as a "contour map" and then using the Data Display Options to manipulate the contour levels. To show a 3-sigma contour with sigma=0.025 Jy/beam set the Relative Contour Levels to [3], the Base Contour Level to 0, and the Unit Contour Level to 0.025. You can display a 5-sigma contour or change the RMS analogously. Scrolling through the cube, I see 3-sigma emission from channels 33 through 80.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:DataDisplayPanelContour.png|The Data Display Panel now being used to set the contour levels. We set the contour unit to 0.025 and ask for a single contour at 3 times this value. Notice that we clicked the tab along the top of the window to select the contour map.<br />
File:TWHydraCOChan33Contour.png|Channel 33 of the CO(3-2) cube on this stretch with a 3-sigma contour overlaid.<br />
File:TWHydraCOChan80Contour.png|Channel 80 of the CO(3-2) cube on this stretch with a 3-sigma contour overlaid.<br />
</gallery><br />
</center><br />
<br />
''Look at a Spectrum:'' You can also look at a spectrum of the source. To do this, scroll to a channel with a lot of emission (I went to 57) and then use the mouse to drag out a rectangle. To do this, left click on the rectangle box in the mouse toolbar (this assigns the left mouse button to define rectangle regions). Then drag out a box around the emission using the same button. Now click the spectrum in the toolbar to open the spectral profile tool. You will see the average profile for the selected region. You can set the bottom axis to show channels. You can zoom in within the spectral profile by dragging out a rectangle. When I do this, I find significant emission from channels 40-80.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:TWHydraRectangle.png|Defining a rectangular region around the main emission from TW Hydra. First we clicked the rectangle button on the mouse toolbar, then we held that button and dragged out the purple rectangle. After defining the rectangle, you can drag it around or delete it with <ESC>.<br />
File:TWHydraSpectrum.png|The spectrum of this rectangular region viewed in the spectral profile browser. Note that the bottom axis has been set to show channels. To get this spectrum, we defined the rectangular region and then clicked the spectrum button on the toolbar.<br />
File:TWHydraSpectrumZoom.png|A zoom in on the spectrum. The line extends from channels ~40-80.<br />
</gallery><br />
</center><br />
<br />
''Look at a Declination-Frequency Projection (or an R.A.-Frequency Projection):'' This is probably the least reliable way to do this, but illustrates a neat capability of the viewer. Open the Data Display Options (click the wrench icon) and open the "display axes" and "hidden axes" tabs. Use the dropdown menus to change the display so that the x-axis shows Declination, the y-axis shows Frequency, and the z-axis shows "Right Ascension." Now you are scrolling through planes of intensity as a function of Declination and Frequency. Use the animator to move to R.A. plane ~ 50 (the center of the source) and pull the stretch up (in the wrench tool; I used [-0.15,0.15] again). Mouse over the image and look at the "Position Tracking" pane in the bottom of the image, noting the pixel extent of emission in the frequency axis of this plane. I see traces of emission from channel ~30-90.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:DataDisplayPanelAxes.png|The Data Display Panel, here used to set which axes are displayed. We have adjusted the y-axis to show frequency and the x-axis to show Declination. The z-axis is now Right Ascension, so that we will scroll through planes of Right Ascension.<br />
File:DataDisplayPanelPixels.png|The Data Display Panel, here we are setting coordinates to show "pixels" rather than world coordinates.<br />
File:TWHydraDecFreqPixels.png|A Frequency-Declination plane of the cube near the central R.A. pixel (50). The rough extent of emission may be simply read off the y-coordinate. As above, we could overplot a 3-sigma contour to add more rigor.<br />
</gallery><br />
</center><br />
<br />
<br />
You can repeat this exercise for the HCO+ (4-3) emission. Using the Spectral Profile Browser, I find that the line extends from about channel 40 through channel 75.<br />
<br />
====Make Moment 0 Maps====<br />
<br />
With an estimate of the spectral extent of emission, we are now ready to make moment 0 maps of the CO(3-2) and HCO+(4-3) lines. We do this using the '''immmoments''' command,<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom0')<br />
immoments(imagename='TWHydra_CO3_2line.image',moments=[0],<br />
outfile='TWHydra_CO3_2line.image.mom0',<br />
chans='30~90')<br />
</source><br />
<br />
and<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom0')<br />
immoments(imagename='TWHydra_HCOplusline.image',moments=[0],<br />
outfile='TWHydra_HCOplusline.image.mom0',<br />
chans='40~75')<br />
</source><br />
<br />
immoments will sum across the channels specified by '''chans''' and produce new CASA images with the names specified by '''outfile'''. These can be inspected using the CASA viewer just like any other image. Note that unlike higher-order moments, the moment-0 map is robust to the inclusion of noisy signal-free channels (to within reason, you just decrease your signal-to-noise ratio) and indeed may be biased to miss faint emission by imposing a threshold. For that reason, we will eschew the '''includepix''' keyword as we make the moment 0 maps.<br />
<br />
Let's look at the output using the viewer. We can specify some of the display options in the call to start the viewer by using '''imview''' instead of '''viewer'''.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview( raster=[ {'file':'TWHydra_CO3_2line.image.mom0',<br />
'range':[0.0,10.],<br />
'scaling':-1},<br />
{'file':'TWHydra_HCOplusline.image.mom0',<br />
'range':[0.0,10.],<br />
'scaling':-1}], <br />
contour={'file':'TWHydra_contall_apcal.image', 'base':0, 'unit':0.0025, 'levels':[3,100]} )<br />
</source><br />
<br />
This does several things: It opens the viewer with raster images of the moment 0 maps of CO(3-2) and HCO+(4-3), sets the range of the color stretch from [0, 10] for each image and sets the scaling to be -1, which highlights faint emission compared to the normal (0) stretch. It also opens the continuum image as a contour and defines two contour levels. Once the viewer is open, you can blink between the images by going into the Animator pane, checking the white box next to "Images" to enable animation between images, and then sliding the bar back and forth. See the name of the image being shown change. You can also show two images side by side by going to the Viewer Canvas Manager (wrench+P icon) and opening the "Number of Panels" tab. Set the "Number of panels in x" to 2 and make sure that the Images box is checked in the Animator pane. You will see both images side by side.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:CanvasManagerPanels.png|The Viewer Canvas Manager, accessed via the Wrech+P icon (not to be confused with the plain old wrench). Here we have adjusted the number of x-panels from 1 to 2 so that we show the two moment maps side by side.<br />
File:TWHydraMoment0Maps.png|The moment-0 maps of CO(3-2) and HCO+(4-3) plotted side by side on the same color stretch, both with the continuum contours overlaid. To get the two images side by side, run the imview call above then set the number of panels to 2 and make sure that the Images box in the Animator Pane (here at the bottom of the window) is checked.<br />
File:DataDisplayImview.png|Data Display Panel after our imview call. Imview allowed us to set the stretch, range, and contour levels from the command line.<br />
</gallery><br />
</center><br />
<br />
====Estimate the Noise====<br />
<br />
We have already made a few offhand comparisons to the RMS noise. This quantity is often critical to know when exploring the data. Because the higher-order moments (especially the dispersion) are not at all robust to the inclusion of noise, we will calculate them only from regions of the cube that have intensity several times the RMS noise value or higher and are thus very likely to contain real astronomical emission. To proceed, we need to estimate the RMS noise for our data.<br />
<br />
The easiest way to do this is to calculate the RMS scatter of the data about zero from a part of the data that you suspect to be (mostly) free of astronomical signal. In a data cube the easiest way to do this will often be to identify signal-free planes (channels) of the cube and to simply calculate the RMS in these regions. We can do this straightforwardly using the '''imstat''' command in CASA.<br />
<br />
IMSTAT COMMAND<br />
<br />
IMSTAT OUTPUT<br />
<br />
Alternatively, you can get similar statistics on a region of an image or data cube selected manually inside the viewer. Drag out a region, for example a rectangle, using one of the mouse tools. Then <br />
<br />
IMAGES OF REGION SELECTION, OUTPUT, REGION MANAGER<br />
<br />
Suggested values for CO(3-2), HCO+(4-3), and continuum. Short discussion of dynamic range limited vs. line-free channels.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
A note on primary beam corrections and noise.<br />
</pre><br />
<br />
====Higher Order Moment Maps for CO(3-2)====<br />
<br />
For higher order moments it is very important to set a conservative flux <br />
threshold. Typically something like 6 sigma, using sigma from peak line channel, works well.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom')<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_coord')<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_dispersion_coord')<br />
immoments(imagename='TWHydra_CO3_2line.image',moments=[1,2],<br />
outfile='TWHydra_CO3_2line.image.mom',<br />
chans='40~76',includepix=[0.3,100])<br />
</source><br />
<br />
Display all three moment maps in the viewer, overlaid with continuum contours.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview( raster=[ {'file':'TWHydra_CO3_2line.image.mom0'},<br />
{'file':'TWHydra_CO3_2line.image.mom.weighted_coord'},<br />
{'file':'TWHydra_CO3_2line.image.mom.weighted_dispersion_coord'} ], <br />
contour={'file':'TWHydra_contall_apcal.image', 'base':0, 'unit':0.0025, 'levels':[3,100]} )<br />
</source><br />
<br />
To see all three raster images simultaneously, open the viewer's Panel Display Options (the "P-wrench" icon in the viewer tool bar), click "Number of panels", and change "Number of panels in x" to 3. Then select the "Blink" toggle (radio button) from the Animator panel.<br />
<br />
<figure id="TWHya_CO3_2_moments.png"><br />
[[Image:TWHya_CO3_2_moments.png|center|800px|frame|<caption>ALMA CO(3-2) moment maps, with white continuum contours at 3 and 100 sigma. From left to right: integrated intensity, intensity weighted velocity field, intensity weighted velocity dispersion are shown.</caption>]]<br />
</figure><br />
<br />
Repeat for HCO+(4-3) which has a bit narrower velocity extent than the CO(3-2), but similar rms noise.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom0')<br />
immoments(imagename='TWHydra_HCOplusline.image',moments=[0],<br />
outfile='TWHydra_HCOplusline.image.mom0',<br />
chans='43~74')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom')<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_coord')<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_dispersion_coord')<br />
immoments(imagename='TWHydra_HCOplusline.image',moments=[1,2],<br />
outfile='TWHydra_HCOplusline.image.mom',<br />
chans='43~74',includepix=[0.3,100])<br />
</source><br />
<br />
Display all three moment maps in the viewer using the same method described above for the CO(3-2) maps.<br />
<br />
<figure id="TWHya_HCOp4_3_moments.png"><br />
[[Image:TWHya_HCOp4_3_moments.png|center|800px|frame|<caption>ALMA HCO+(4-3) moment maps, with white continuum contours at 3 and 100 sigma. From left to right: integrated intensity, intensity weighted velocity field, intensity weighted velocity dispersion are shown.</caption>]]<br />
</figure><br />
<br />
=====Exporting Fits Images=====<br />
<br />
If you want to analyze the data using another software package it is easy to convert from CASA format to FITS. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image',fitsimage='TWHydra_CO3_2line.image.fits')<br />
</source><br />
<br />
Although "FITS format" is supposed to be a standard, in fact most packages expect slightly different things from a FITS image. If you are having difficulty, try setting '''velocity=T''' and/or '''dropstokes=T'''.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf TWHydra_HCOplusline.image.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image',fitsimage='TWHydra_HCOplusline.image.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom0.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image.mom0',<br />
fitsimage='TWHydra_CO3_2line.image.mom0.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_coord.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image.mom.weighted_coord',<br />
fitsimage='TWHydra_CO3_2line.image.mom.weighted_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_dispersion_coord.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image.mom.weighted_dispersion_coord',<br />
fitsimage='TWHydra_CO3_2line.image.mom.weighted_dispersion_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom0.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image.mom0',<br />
fitsimage='TWHydra_HCOplusline.image.mom0.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_coord.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image.mom.weighted_coord',<br />
fitsimage='TWHydra_HCOplusline.image.mom.weighted_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_dispersion_coord.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image.mom.weighted_dispersion_coord',<br />
fitsimage='TWHydra_HCOplusline.image.mom.weighted_dispersion_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_apcal.image.fits')<br />
exportfits(imagename='TWHydra_contall_apcal.image',fitsimage='TWHydra_contall_apcal.image.fits')<br />
</source><br />
<br />
===Display Channel Maps===<br />
<br />
Using the Viewer you can make channel map figures. Start the Viewer and then open the CO(3-2) cube as a raster image and then the continuum as a contour image. Then we use the "wrench" icon and "P wrench" icons to set up the channel images, contour levels etc. (If you need help setting up the viewer for this image, see a screen shot of the viewer setup windows, below.)<br />
<br />
<figure id="TWHya_channel_co3_2.png"><br />
[[Image:TWHya_channel_co3_2.png|center|frame|<caption>Channel maps of the CO(3-2) emission with white continuum contours at 3 and 100 sigma.</caption>]]<br />
</figure><br />
<br />
<figure id="Viewer_setup.png"><br />
[[Image:Viewer_setup.png|center|thumb|500px|<caption>The setup windows looked like this</caption>]]<br />
</figure><br />
<br />
Repeat for HCO+(4-3)<br />
<br />
<figure id="TWHya_channel_HCOp4_3.png"><br />
[[Image:TWHya_channel_HCOp4_3.png|center|thumb|800px|<caption>Channel maps of the HCO+(4-3) emission with white continuum contours at 3 and 100 sigma. The color intensity scale is the same as that used for CO(3-2).</caption>]]<br />
</figure><br />
<br />
<!--<br />
====Examine CO Contours on an HCO+ Raster====<br />
<br />
====Matched Movies====<br />
<br />
===Image Plane and Spectral Fits===<br />
<br />
====Fit a Gaussian to the Continuum====<br />
<br />
=====Fit In the Viewer=====<br />
<br />
=====Fit Using the Command Line=====<br />
<br />
====Fit a Gaussian to the CO Line====<br />
<br />
=====Fit In the Viewer=====<br />
<br />
=====Fit Using the Command Line=====<br />
<br />
===Extract a Sub-Image===<br />
<br />
===Align Image Cubes===<br />
--><br />
<br />
{{Checked 4.3.0}}</div>Sstierwahttps://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_4.3&diff=19485TWHydraBand7 Imaging 4.32016-05-18T04:42:40Z<p>Sstierwa: /* Prepare Continuum Data for Further Processing */</p>
<hr />
<div>[[Category:ALMA]][[Category:Imaging]][[Category:Spectral Line]]<br />
<br />
* '''This tutorial picks up where '''[[TWHydraBand7_Calibration_4.5.2]]''' leaves off, with fully calibrated, split science target MS. If you wish to skip the Calibration guide: obtain the calibrated data from [[TWHydraBand7#Getting_the_Data]]; extract it using <tt>tar -xzvf FILENAME</tt>; and <tt>cd</tt> into the extracted directory.'''<br />
<br />
*'''This guide is designed for CASA 4.3. If you are using an older version of CASA please see [[TWHydraBand7_Imaging_4.3]].<br />
<br />
* '''Details of the ALMA data are provided at [[TWHydraBand7]]'''<br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.5.2. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.3.0'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
== Prepare Continuum Data for Further Processing==<br />
<br />
In order to speed up imaging/self-calibration for the continuum data we will average channels together, and then flag the few spectral features. This method works well in the case of only a few spectral lines, while retaining enough channelization to aid in multi-frequency synthesis and being able to remove spectral features in the averaged data. When generalizing this process to other datasets, the amount of channel averaging will vary. '''Note for wide bandwidth data it is never a good idea to use the continuum estimate generated by uv-continuum subtraction as your continuum data'''. This worked OK in the past with the narrow band systems like the VLA and low dynamic range instruments like the SMA, but is not advised for ALMA wide bandwidth, high dynamic range data. <br />
<br />
<figure id="Cont_spw2.png"><br />
[[Image:Cont_spw2.png|thumb|<caption>CO(3-2) in spw=2 from the "continuum" channel averaged data.</caption>]]<br />
</figure><br />
<figure id="Cont_spw3.png"><br />
[[Image:Cont_spw3.png|thumb|<caption>Notice upswing at high channel numbers in spw=3.</caption>]]<br />
</figure><br />
<br />
One can also flag the spectral features first but in that case make a backup of the file that is analogous to TWHydra_corrected.ms as you will need it later (unflagged) for spectral line imaging. We begin by excluding ~20 channels on each edge, and averaging over 100 channel intervals:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_cont.ms*')<br />
split(vis='TWHydra_corrected.ms',outputvis='TWHydra_cont.ms',<br />
spw='0~3:21~3820',width=100,datacolumn='data')<br />
</source><br />
<br />
Now make a plot of amplitude vs. channel to see what needs to be flagged<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',spw='0~3',xaxis='channel',yaxis='amp',<br />
avgtime='1e8',avgscan=T,coloraxis='spw',iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
The CO(3-2) and HCO+(4-3) lines are obvious. The 4th spw; spw=3 also shows an upswing on the highest channels that is problematic, it was seen on the calibrators too and is likely due to a weak atmospheric feature, we will flag the worst of it.<br />
<br />
<figure id="Cont_uvplot.png"><br />
[[Image:Cont_uvplot.png|thumb|<caption>UV-plot of the continuum emission, colors show spws.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='TWHydra_cont.ms', mode='manual', <br />
spw='0:16~16, 2:21~21, 3:33~37')<br />
</source><br />
<br />
Have a look at the continuum as a function of uv-distance (in the plot to the right, the 4 spw are shown in different colors on top of each other). If the data are flat as a function of uv-distance, the source is completely unresolved. If instead you see structure (in this case decreasing amplitude with uv-distance), the source is resolved. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',spw='',xaxis='uvdist',yaxis='amp',field='',avgchannel='38',<br />
coloraxis='spw',plotfile='cont_uvplot.png')<br />
</source><br />
<br />
Notice that the spw do not have the same amplitude. Unfortunately, the red spw (highest frequency) should be higher than the green one (lowest frequency) because optically thin dust goes as nu^4, and optically thick as nu^2. This inconsistency is due to imperfect amplitude/absolute flux calibration. The self-calibration below will bring them into agreement with each other, but this is the sort of thing that results in considerable absolute flux uncertainty at submillimeter wavelengths. We are working on how to do this better.<br />
<br />
==A priori Noise Estimates==<br />
<br />
<figure id="Corrected_time.png"><br />
[[File:Corrected_time.png|thumb|<caption>Plot for estimating time.</caption>]]<br />
</figure><br />
<figure id="sensitivity_cont.png"><br />
[[File:sensitivity_cont.png|thumb|<caption>Sensitivity calculator setup with observed continuum parameters for these observations.</caption>]]<br />
</figure><br />
<br />
To estimate what the expected noise levels are, we first need to know how much time we had on source. Looking at <br />
a plot of amplitude vs time for the concatenated but pre-split data (see below) there are 9x8min scans + 6x6min scans + 3x1min + 2x2min scans for about 1.9 hours on source. There are 2 polarizations and about 1.75 GHz of total continuum bandwidth taking into account flagging.<br />
<br />
Using this information and https://almascience.nrao.edu/proposing/sensitivity-calculator, we find that the '''expected rms noise for the continuum is about 0.3 mJy/beam'''.<br />
<br />
For the spectral line data, which we will image below, with 0.12 km/s channels (needs to be entered in the field ''bandwidth per polarization''), the '''expected rms noise for the spectral lines is about 32 mJy/beam'''.<br />
<br />
==Image and Self-Calibrate the Continuum==<br />
<br />
====Create Initial Clean Image====<br />
<br />
First we will make an initial image using {{clean}}, this task will both deconvolve and clean. <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
If you are unfamiliar with the basic concepts of deconvolution and clean,<br />
pause here and review for example<br />
http://www.aoc.nrao.edu/events/synthesis/2010/lectures/wilner_synthesis10.pdf<br />
</pre><br />
<br />
In {{clean}}, we use '''mode='mfs'''' to do multifrequency synthesis, in other words grid each uv-channel independently. Since the uv-spacing is a function of frequency, this will actually achieve greater uv-coverage than if all the channels and spws had been averaged in advance. The '''imsize=100''' and '''cellsize=['0.3arcsec']''' were chosen to be appropriate for the Band and antenna configuration. At ALMA Band 7, the Full Width Half Power primary beam is about 20", so we want to make our image at least this big. We've made it a bit larger out to about the 25% power point. For the configuration used to take these data, the resolution is expected to be about 1.5" and it is a good idea to oversample the beam by setting the cell size to be a factor of 4 or 5 smaller than the beam (we have used 5 here). <br />
<br />
For doing self-calibration it is essential that only "real" signal be included in the image model, thus it is important to make a clean mask, and clean the first iteration rather conservatively (shallowly) so that you are sure that you do not have clean components in your model that do not represent real source emission. In the example below we set '''interactive=T''' so you can interactively make the clean mask and stop clean when the signal from the source starts to approach the surrounding "noise" areas in the residual map.<br />
<br />
'''NOTE:''' Real emission will not go away if you do not put a clean box on it. Conversely if you put a clean box on something that is NOT real and clean deeply you can amplify that feature. Thus, its best to be conservative and build up your clean box as you go, you can generally see fainter "real" features in the residuals.<br />
<br />
'''NOTE:''' If you start an interactive clean, and then do not make a mask, clean will stop when you tell it to go on because it has nothing to clean. There is no default mask.<br />
<br />
<figure id="Viewer_clean1.png"><br />
[[Image:Viewer_clean1.png|thumb|<caption>Interactive viewer.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall',<br />
mode='mfs', imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5, <br />
mask='',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
'''NOTE:'''{{clean}} will generate several files automatically with the '''imagename''' prepended:<br />
* <imagename>.image # the final restored image<br />
* <imagename>.flux # the effective primary beam response (e.g. for pbcor)<br />
* <imagename>.flux.pbcoverage # the primary beam coverage (ftmachine=’mosaic’ only)<br />
* <imagename>.model # the model image<br />
* <imagename>.residual # the residual image<br />
* <imagename>.psf # the synthesized (dirty) beam<br />
<br />
Once the Clean Viewer opens, click on the polygon tool with your left mouse button, and draw a polygon around the continuum emission with the left mouse button. Double click inside the region with the left mouse button when you are happy with it. It will turn from green to white when the clean mask is accepted. To continue with clean use the "Next action" buttons in the green area on the Viewer Display GUI. <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
The red X will stop clean where you are, the blue arrow will stop <br />
the interactive part of clean, but continue to clean non-interactively <br />
until reaching the number of iterations requested (niter) or the flux <br />
density threshold (whichever comes first), and the green circle arrow <br />
will clean until it reaches the "iterations" parameter on the left side <br />
of the green area. <br />
</pre><br />
<br />
'''You should chose the green circle arrow'''. It will clean 100 iterations (number under iteration in the green area on the Viewer GUI) and then show the '''residual image''' again. The middle mouse button is automatically assigned to the "plus" icon, which adjusts the colorscale. '''If you cannot easily access multiple mouse buttons, you can always assign your one mouse button the icon you want by clicking on it'''. Adjust the color scale so you can see the structure in the noise better. Also, note that the logger is telling you the amount of clean flux recovered so far, the min/max residuals, and the synthesized beam:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Model 0: max, min residuals = 0.0203454, 0.00267232 clean flux 1.30124<br />
Threshhold not reached yet.<br />
Beam used in restoration: 1.6962 by 1.54549 (arcsec) at pa 28.9043 (deg) <br />
</pre> <br />
<br />
Already with only 100 iterations, the residuals outside the clean mask are larger than that inside. So we will stop here by hitting the Red X symbol.<br />
<br />
====1st Round of Continuum Data Phase Self-calibration====<br />
<br />
Next we can use the clean model to self-calibrate the uv-data. The process of self-calibration tries to adjust the data to better match the model you give it. That is why it is important to make the model as good as you can. {{clean}} places a uv-model of the resulting image in the file <tt>TWHydra_cont.model</tt>. This model can then be used to self-calibrate the data using {{gaincal}}. We use '''gaintype='T'''' to tell it to average the polarizations before deriving solutions (which gains us a sqrt(2) in sensitivity). A critical parameter to play with is '''solint'''; we use '''solint=30s'''. From {{listobs}} the integration time of these data is about 10 seconds, so using '''solint=30s''' then gains us a sqrt(3) in sensitivity. It is often best to start with a larger '''solint''' and then work your way down to the integration time if the S/N of the data permits. For the same reasons as described in the [[TWHydraBand7_Calibration_4.3]] tutorial we want to fix up the phases before tackling amplitude by setting '''calmode='p''''.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='TWHydra_cont.ms',caltable='self_1.pcal',<br />
solint='30s',combine='',gaintype='T',<br />
refant='DV06',spw='',minblperant=4,<br />
calmode='p',minsnr=2)<br />
</source><br />
<br />
<figure id="Self_1_phase.png"><br />
[[Image:Self_1_phase.png|thumb|<caption>Phase solutions from self_1.pcal with solint=30s.</caption>]]<br />
</figure><br />
<br />
Because '''combine=' '''', we are getting independent solutions for each spw. If you are desperate for S/N, you can try combining them with combine='spw'. We have plenty of S/N in these data so we keep them separate. Look at the solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_1.pcal',xaxis='time',yaxis='phase',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,-80,80],figfile='self_1_phase.png')<br />
</source><br />
<br />
The magnitude of corrections gives you a sense of how accurate the phase transfer from the calibrators was. You are checking to see that the phases are being well tracked by the solutions, i.e. smoothly varying functions of time within a given scan. Also the solutions for each spw are lying basically on top of each other which indicates that the spw to spw phase offsets are well calibrated already. Overall, these solutions look quite good. If they didn't you could try increasing the solint and/or combining the spw into a single solution. <br />
<br />
After checking that you are happy with the solutions, apply them with {{applycal}}<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_cont.ms',field='',gaintable=['self_1.pcal'],calwt=F)<br />
</source><br />
<br />
<figure id="Viewer_pcal1.png"><br />
[[Image:Viewer_pcal1.png|thumb|<caption>Clean residuals after 100 iterations and the 1st phase only self-cal. Residuals inside mask are higher than the "noise" outside.</caption>]]<br />
</figure><br />
<br />
Next clean the source again, to save time we can start with the clean mask from the last iteration. If you make interactive adjustments to the clean mask, they will be written to the '''new''' mask TWHydra_contall_1pcal.mask, and not the old one. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_1pcal.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall_1pcal',<br />
mode='mfs',imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5, <br />
mask='TWHydra_contall.mask',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
Now after the first 100 iterations you see that the residuals inside the clean mask are higher than those outside. This is because flux that had been spread out in the map due to poorly correlated phases has been placed where it belongs on the source, thereby increasing its flux. You may also notice that your original clean mask is a little too small. If so, you can make it a bit larger, just by drawing a new polygon around the area you want to include. When you double click, it will incorporate the new mask into the current mask (if your box goes awry you can use the erase toggle [radio button] to erase and redo the mask). The new mask area need not overlap the original mask (though for this source it probably will). You might also want to use the magnifying glass to zoom in. Again, you assign mouse buttons by clicking on the icon you want. Clean another 100 iterations (for a total of 200) and stop by clicking the red X.<br />
<br />
Now open initial and 1st self-cal images to compare them using {{imview}}. This is an alternative version of the {{viewer}} that is somewhat scriptable. <br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(raster=[{'file':'TWHydra_contall.image','range':[-0.01,0.05]},<br />
{'file':'TWHydra_contall_1pcal.image','range':[-0.01,0.05]}])<br />
</source><br />
<br />
Once the Viewer Display panel opens, click on the box next in the "Images" panel and then use the tapedeck buttons in the panel to alternate between the two images. Because the range was explicitly set, they are on the same color scale. It is obvious that the self-calibrated image is better. To quantify, 1st toggle back to "normal" and then draw a region that excludes the central source with the polygon tool and then double click inside (if you stay in the "Images" view, only the statistics for the last image opened will appear on the terminal instead of both). The basic statistics of the polygon region will print to the '''terminal''':<br />
<br />
<pre style="background-color: #fffacd;"><br />
TWHydra_contall.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2357 -9.434800e-01 -2.858690e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-4.002885e-04 7.906752e-03 7.898289e-03 -2.541723e-02 2.172779e-02 <br />
<br />
TWHydra_contall_1pcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2357 6.326584e-01 1.916918e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
2.684168e-04 3.655786e-03 3.646692e-03 -1.215155e-02 1.109403e-02 <br />
</pre><br />
<br />
The self-calibrated image has more than a factor of 2 lower rms noise!<br />
<br />
====2nd Round of Continuum Data Phase Self-calibration====<br />
<br />
Now that we have a better model, we solve for solutions again. This time we will try making the solint smaller -- the integration time is about 10 seconds, so we set '''solint='int'''' to have it use the integration time.<br />
<br />
<figure id="Self_2_phase.png"><br />
[[Image:Self_2_phase.png|thumb|<caption>Phase solutions from self_2.pcal with solint='int'.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='TWHydra_cont.ms',caltable='self_2.pcal',<br />
solint='int',combine='',gaintype='T',<br />
refant='DV06',spw='',minblperant=4,<br />
calmode='p',minsnr=2)<br />
</source><br />
<br />
Now plot the new solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_2.pcal',xaxis='time',yaxis='phase',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,-80,80],figfile='self_2_phase.png')<br />
</source><br />
<br />
The phases on this shorter '''solint''' still seem to be tracking well so we will apply it and make a new image and check to see if there is improvement. <br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_cont.ms',field='',gaintable=['self_2.pcal'],calwt=F)<br />
</source><br />
<br />
<figure id="Viewer_pcal2.png"><br />
[[Image:Viewer_pcal2.png|thumb|<caption>Clean residuals after 2nd phase only self-cal and 250 iterations. The residuals inside the clean mask are lower than those outside, so its time to stop.</caption>]]<br />
</figure><br />
<br />
Now clean again, updating '''mask''' with the most recent mask file.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_2pcal.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall_2pcal',<br />
mode='mfs',imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5,usescratch=False,<br />
mask='TWHydra_contall_1pcal.mask',<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
After 200 iterations<br />
<br />
<pre style="background-color: #fffacd;"><br />
Model 0: max, min residuals = 0.00489776, -0.00464541 clean flux 1.44461<br />
</pre><br />
<br />
It looks like it could use just a little more cleaning, so set '''iterations=50 in the GUI'''.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Clean used 50 iterations to approach a threshhold of 0.0015067<br />
0.0107122 Jy <- cleaned in this cycle for model 0 (Total flux : 1.45532Jy)<br />
Final maximum residual = 0.00326382<br />
Model 0: max, min residuals = 0.00326382, -0.00321361 clean flux 1.45532<br />
</pre><br />
<br />
The small amount of flux cleaned this cycle indicates that clean is converging and it's about time to stop. Also the residuals inside the clean mask are now smaller than the residuals outside (i.e. the noise) also indicating it's time to stop by hitting the red X on the GUI.<br />
<br />
Now repeat the display, blinking, and image statistics steps described above for the 1st and 2nd phase-only self-cal iterations.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(raster=[{'file':'TWHydra_contall_1pcal.image','range':[-0.01,0.05]},<br />
{'file':'TWHydra_contall_2pcal.image','range':[-0.01,0.05]}])<br />
</source><br />
<br />
The difference is small:<br />
<pre style="background-color: #fffacd;"><br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2466 4.611597e-02 1.397287e-03 <br />
Mean Rms Std dev Minimum Maximum <br />
1.870072e-05 3.831524e-03 3.832255e-03 -1.414417e-02 1.109403e-02 <br />
<br />
TWHydra_contall_2pcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2466 1.159416e-01 3.512963e-03 <br />
Mean Rms Std dev Minimum Maximum <br />
4.701606e-05 3.811716e-03 3.812199e-03 -1.383034e-02 1.078456e-02 <br />
</pre><br />
<br />
This small improvement suggests that we have gone as far as we can with phase self-cal.<br />
<br />
===Continuum Data Amplitude Self-Calibration===<br />
<br />
Now we will apply the best phase solution table on-the-fly while solving for the amplitude self-cal solutions. Since amplitude changes more slowly and is less constrained than phase, we use a longer '''solint='inf'''', as long as '''combine=' '''' this means to do one solution per scan. <br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='TWHydra_cont.ms',caltable='self_ap.cal',<br />
solint='inf',combine='',gaintype='T',<br />
refant='DV06',spw='',minblperant=4,<br />
gaintable=['self_2.pcal'],<br />
calmode='ap',minsnr=2)<br />
</source><br />
<br />
It's useful to look at the residual phase in the amplitude calibration table, i.e. since we applied our best phase-only solution while solving for this new amplitude and phase ('''calmode='ap'''') solution, the phase should already be corrected.<br />
<br />
<figure id="Self_ap_phase.png"><br />
[[Image:Self_ap_phase.png|thumb|<caption>Residual phase solutions from self_ap.cal.</caption>]]<br />
</figure><br />
<figure id="Self_ap_amp.png"><br />
[[Image:Self_ap_amp.png|thumb|<caption>Amplitude solutions from self_ap.cal.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_ap.cal',xaxis='time',yaxis='phase',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,-1,1],figfile='self_ap_phase.png')<br />
</source><br />
<br />
The residuals are very small as expected. (If you see large residuals here, it means that the phase-only solution is suspect, and you were mostly just moving noise around.) Now look at the amplitude solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_ap.cal',xaxis='time',yaxis='amp',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,0.6,1.4],figfile='self_ap_amp.png')<br />
</source><br />
<br />
For the most part these look very good except one rather large deviation on DV06. Apply both the final phase and the amplitude calibration tables.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_cont.ms',field='',gaintable=['self_2.pcal','self_ap.cal'],calwt=F)<br />
</source><br />
<br />
Plot the corrected data as a function of both time and uv-distance. It is always a good idea to check these after an amplitude self-calbration to be sure that it worked properly. Occasionally, a few spurious bits of data will get blown up by the amplitude self-cal if it is not well-constrained. <br />
<br />
<figure id="Selfcal_time.png"><br />
[[Image:Selfcal_time.png|thumb|<caption>Post self-calibration amplitude vs. time</caption>]]<br />
</figure><br />
<figure id="Selfcal_uvdist.png"><br />
[[Image:Selfcal_uvdist.png|thumb|<caption>Post self-calibration amplitude vs. uv-distance</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',xaxis='time',yaxis='amp',<br />
avgchannel='38',ydatacolumn='corrected',coloraxis='spw',<br />
plotfile='selfcal_time.png')<br />
</source><br />
<br />
The time where we saw a large amplitude correction on DV06 looks consistent here so the large correction we saw in the solutions corrected a real issue. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',xaxis='uvdist',yaxis='amp',<br />
avgchannel='38',ydatacolumn='corrected',coloraxis='spw',<br />
plotfile='selfcal_uvdist.png')<br />
</source><br />
<br />
You will see that this plot looks much better than before. <br />
<br />
<figure id="Viewer_apcal.png"><br />
[[Image:Viewer_apcal.png|thumb|<caption>Clean residuals after final amplitude and phase self-cal.</caption>]]<br />
</figure><br />
<br />
Now make the final continuum image.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_apcal.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall_apcal',<br />
mode='mfs',imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5,usescratch=False,<br />
mask='TWHydra_contall_2pcal.mask',<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
We know we need to clean at least 300 iterations, so set this in the gui and hit the round green arrow. After this notice how much better the residual looks. Clean another 100 iterations. The "circular pattern", and 4 bright spots at each corner you see now in the residual is likely due to non-closing amplitude errors that cannot be removed with an antenna based self-calibration, so this is as good as it gets with pure self-cal. Hit the Red X to stop clean.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Clean used 100 iterations to approach a threshhold of 0.00105507<br />
0.0061808 Jy <- cleaned in this cycle for model 0<br />
Final maximum residual = 0.00242926<br />
Model 0: max, min residuals = 0.00238278, -0.00242926 clean flux 1.48201<br />
</pre><br />
<br />
Now repeat the display, blinking, and image statistics described above for the 2nd phase only and the new amplitude & phase self-cal'ed images.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(raster=[{'file':'TWHydra_contall_2pcal.image','range':[-0.01,0.05]},<br />
{'file':'TWHydra_contall_apcal.image','range':[-0.01,0.05]}])<br />
</source><br />
<br />
The amplitude and phase self cal'ed image is notably better than phase-only. Quantitatively:<br />
<pre style="background-color: #fffacd;"><br />
<br />
TWHydra_contall_2pcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 3542 2.053068e-01 6.220676e-03 <br />
Mean Rms Std dev Minimum Maximum <br />
5.796351e-05 3.955967e-03 3.956101e-03 -1.383034e-02 1.078456e-02 <br />
<br />
TWHydra_contall_apcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 3542 6.044652e-04 1.831495e-05 <br />
Mean Rms Std dev Minimum Maximum <br />
1.706565e-07 1.270183e-03 1.270362e-03 -4.980673e-03 4.137159e-03 <br />
</pre> <br />
<br />
and indeed, we've gained another factor of 3 in sensitivity. <br />
<br />
'''Overall with this self-calibration we've improved the noise by a factor of 6.7! With a peak flux density of 0.98 Jy, the S/N increased from 115 initially to 770 after. So, well worth the trouble.'''<br />
<br />
<div class="noprint" style="float:none; border:0px solid blue;background-color:#F6CEF5;padding:2px;"><br />
If you have used the '''standard='Butler-JPL-Horizons 2012' ''' model during the calibration process, you should see an increase in peak flux density of about 3%.<br />
</div><br />
<br />
It is notable that we are still a factor of more than 4 from the apriori noise estimate of 0.3 mJy/beam. This is likely due to residual sources of non-closing (not antenna based) errors in the data like baseline errors and baseline-dependent bandpass errors. Additionally, polarization errors (which we did not calibrate at all) can contribute, as well as imperfect uv-coverage with only 8 antennas. A dynamic range of 770 is actually quite good in the submillimeter.<br />
<br />
==Apply self-calibration to Full Dataset and Split Line Data==<br />
<br />
Now apply the self-calibration derived from the continuum emission to the full unchannel-averaged data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_corrected.ms',gaintable=['self_2.pcal','self_ap.cal'],calwt=F)<br />
</source><br />
<br />
Split off the CO(3-2) spectral line data in spw=2 and the HCO+(4-3) data in spw=0 for further processing.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2.ms*')<br />
split(vis='TWHydra_corrected.ms',outputvis='TWHydra_CO3_2.ms',datacolumn='corrected',spw='2')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplus.ms*')<br />
split(vis='TWHydra_corrected.ms',outputvis='TWHydra_HCOplus.ms',datacolumn='corrected',spw='0')<br />
</source><br />
<br />
==Continuum Subtraction== <br />
<br />
Next we need to subtract the continuum emission from the spectral line data. It is best to do this in the uv-plane. The first step is to make a channel plot of the spectral data to get the line-free channel ranges for both spectral lines. Since the line emission is simple (one spectral line per spw) and there are more than enough line-free channels we do not need to be very precise just stay well away from the line and whenever possible it is best to chose line-free channel ranges on either side of the line for the best possible baseline subtraction. <br />
<br />
<figure id="CO3_2_channel.png"><br />
[[Image:CO3_2_channel.png|thumb|<caption>CO(3-2) line in channel space.</caption>]]<br />
</figure><br />
<figure id="HCOp4_3_channel.png"><br />
[[Image:HCOp4_3_channel.png|thumb|<caption>HCO+(4-3) in channel space.</caption>]]<br />
</figure><br />
<br />
'''Note''': after the split above, the original spw ids will be relabeled as 0 in each file because there is only one spectral window in each file.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_CO3_2.ms',spw='0',xaxis='channel',yaxis='amp',<br />
avgtime='1e8',avgscan=T,coloraxis='spw',plotfile='CO3_2_channel.png')<br />
</source><br />
<br />
It is a good idea to stay a little away from the very edges of the baseband which can be noisy. The channel ranges <br />
20~2000 and 2400~3800 look like good choices for CO(3-2).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_HCOplus.ms',spw='0',xaxis='channel',yaxis='amp',<br />
avgtime='1e8',avgscan=T,coloraxis='spw',plotfile='HCOp4_3_channel.png')<br />
</source><br />
<br />
The channel ranges 20~1500 and 1900~3800 look like good choices for HCO+(4-3).<br />
<br />
Next use the identified line-free channel ranges and {{uvcontsub}} to subtract the continuum model from the line emission.<br />
<br />
<source lang="python"><br />
# In CASA<br />
uvcontsub(vis='TWHydra_CO3_2.ms',fitorder=1,fitspw='0:20~2000,0:2400~3800')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
uvcontsub(vis='TWHydra_HCOplus.ms',fitorder=1,fitspw='0:20~1500,0:1900~3800')<br />
</source><br />
<br />
Note: If you do not have line-free channels on both sides of the line emission, it is safer to use '''fitorder=0''', or the fit may diverge.<br />
<br />
==Spectral Line Imaging==<br />
<br />
Now we are ready to make cubes of the line emission. The imaging parameters are similar to the continuum except for <br />
those dealing with the spectral setup: '''mode''', '''start''', '''width''', '''nchan''', '''restfreq''', and '''outframe''' parameters. When making spectral images you have three choices for the '''mode''' parameter: '''channel''', '''velocity''', and '''frequency'''. Data are taken using constant frequency channels. For spectral line analysis it's often more useful to have constant velocity channels, and this is also the best way to make images of multiple lines with the exact same channelization for later comparison. For '''mode='velocity'''', the desired '''start''' and '''width''' also need to be given in velocity units for the desired output frame. <br />
<br />
It is important to note that ALMA does not do on-line Doppler Tracking and the native frame of the data is TOPO. If you do not specify '''outframe''' the output cube will also be in TOPO, which is not very useful for spectral line work. The Doppler Shift is taken out during the regridding to the desired outframe in {{clean}} or alternatively it can be done separately by the {{cvel}} task which would need to be run before {{clean}}. <br />
<br />
<figure id="CO3_2_vel.png"><br />
[[Image:CO3_2_vel.png|thumb|<caption>CO(3-2) spectrum in LSRK velocity space.</caption>]]<br />
</figure><br />
<figure id="HCOp4_3_vel.png"><br />
[[Image:HCOp4_3_vel.png|thumb|<caption>HCO+(4-3) spectrum in LSRK velocity space.</caption>]]<br />
</figure><br />
<br />
To see what velocity parameters you want to set in clean it is useful to make a plot in {{plotms}} in the desired output frame. To make it easier to see, we set a '''plotrange''' since we know the LSRK velocity of TW Hya is about 2.88 km/s. Note these plots take a little longer because of the frame shift.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_CO3_2.ms.contsub',xaxis='velocity',yaxis='amp',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',<br />
restfreq='345.79599GHz',plotrange=[-20,23,0,0],plotfile='CO3_2_vel.png')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_HCOplus.ms.contsub',xaxis='velocity',yaxis='amp',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',<br />
restfreq='356.7342GHz',plotrange=[-20,23,0,0],plotfile='HCOp4_3_vel.png') <br />
</source><br />
<br />
From these plots it looks like imaging the cubes from about -5 to +8 km/s will encompass the line, but still provide several line-free channels on either side so the noise level can be estimated. The channel width is 122 kHz, which at <br />
345.79599 GHz is 0.106 km/s. Recall that the spectral ''resolution'' is a factor of two poorer. We will use a velocity channel width of 0.12 km/s for a little oversampling, but the spectral resolution remains 0.2 km/s.<br />
<br />
As before, it is very important that you make a clean mask. There are many ways to do this ranging from the complicated to simple. For this example we will make a single clean mask that encompasses the line emission in every channel and apply it to all channels. This is much better than no clean mask, though not quite as good as making an individual mask for each channel. For some sources, one can use the continuum mask to clean the line, however TW Hya is a bit curious in that the continuum emission is not as extended as the line emission (Hughes et al. 2008).<br />
<br />
=== CO(3-2) Imaging ===<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.*')<br />
clean(vis='TWHydra_CO3_2.ms.contsub',imagename='TWHydra_CO3_2line',<br />
imagermode='csclean',spw='',<br />
imsize=100,cell=['0.3arcsec'],<br />
mode='velocity',start='-4km/s',width='0.12km/s',nchan=118,<br />
restfreq='345.79599GHz',outframe='LSRK',<br />
weighting='briggs',robust=0.5,<br />
mask='',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=100000)<br />
</source><br />
<br />
<figure id="Viewer_55.png"><br />
[[Image:Viewer_55.png|thumb|<caption>Interactive Viewer window with CO(3-2) clean mask, before cleaning starts.</caption>]]<br />
</figure><br />
<figure id="Viewer_500.png"><br />
[[Image:Viewer_500.png|thumb|<caption>Interactive Viewer window for CO(3-2), after 500 iterations, more cleaning is needed.</caption>]]<br />
</figure><br />
<br />
It will take a little while to grid the cube, when the interactive viewer opens, use the tapedeck to cycle through the channels. You should see a progress of line emission in channels 40 to 70 or so.<br />
*Go to channel 57 (about line center)<br />
*Select the polygon tool with the left mouse button<br />
*Select the "All Channels" toggle in the green area<br />
*Draw a polygon around the channel 57 emission, double click inside to activate.<br />
*Now go to channel 60, this is the channel with the most extent to the SE, draw another polygon that encompasses this emission if necessary,double click inside to activate.<br />
*Now go to channel 55, this is the channel with the most extent to the NW, draw another polygon that encompasses this emission if necessary,double click inside to activate. <br />
*Now double check the mask by cycling through channels with real line emission to be sure that your clean box encompasses the emission, but does not extend far beyond it. Again the "erase" toggle can come in handy if things go awry or if you want to just delete a small portion of an existing mask (just draw a polygon around what you want to erase and double click inside), be sure to switch back to "add" before going on.<br />
<br />
The figure shows what the final clean box should look like. Now clean using the green circle arrow. You can watch the progress in the logger. When 100 iterations are done, the viewer will show the residual map for each channel. Cycle through the channels and see whether you are still happy with the clean box in each signal channel. The "erase button" can help you fix mistakes. If necessary adjust. It is often useful to adjust the colorscale with the "plus" symbol icon. Keep going until the residual emission looks like the surrounding noise. If it seems to be going slowly, increase the iterations to 300 for a round or two. I stopped cleaning (Red x) when the logger showed (about 900 iterations). <br />
<pre style="background-color: #fffacd;"><br />
12.9846 Jy <- cleaned in this cycle for model 0<br />
Final maximum residual = 0.157312<br />
Model 0: max, min residuals = 0.157312, -0.0871295 clean flux 279.304<br />
</pre><br />
<br />
NOTE: The residuals are still a bit high in the strongest emission channels after it is well cleaned in the weaker channels. This is an indication that the sensitivity is "dynamic range" limited. In other words even with more <br />
intrinsic sensitivity per integration (i.e. better system temperature), the dynamic range limit would remain the same unless you get more uv-coverage. The fundamental dynamic range limitations of ALMA will be considerably better with 16 antennas in Early Science and MUCH better with the full 50-antenna array.<br />
<br />
=== HCO+(4-3) Imaging ===<br />
<br />
Now image and clean the HCO+(4-3) line using what you learned above.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.*')<br />
clean(vis='TWHydra_HCOplus.ms.contsub',imagename='TWHydra_HCOplusline',<br />
imagermode='csclean',spw='',<br />
imsize=100,cell=['0.3arcsec'],<br />
mode='velocity',start='-4km/s',nchan=118,width='0.12km/s',<br />
restfreq='356.7342GHz',outframe='LSRK',<br />
weighting='briggs',robust=0.5,<br />
mask='',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=100000)<br />
</source><br />
<br />
I stopped cleaning when: <br />
<pre style="background-color: #fffacd;"><br />
4.79833 Jy <- cleaned in this cycle for model 0<br />
Final maximum residual = 0.0977348<br />
Model 0: max, min residuals = 0.0977348, -0.060484 clean flux 192.066<br />
</pre><br />
<br />
==Image Analysis==<br />
<br />
After all that hard work you now have deconvolved images of the 350 GHz continuum, the CO (3-2) line, and the HCO+ (4-3) line. CASA includes tools to help you understand the contents of these images and make basic scientific measurements. These tools are divided between graphical exploration tools, accessible via the CASA viewer, and command line analysis tasks. To access the viewer, simply type '''viewer()''' and to see the list of analysis tasks available in CASA type '''tasklist''' at the CASA prompt and look under the Analysis sub-heading.<br />
<br />
If you want to do this portion of the guide and have downloaded the (.FITS) reference images, you can import them to be CASA images using '''importfits'''. If you are re-importing the images, use the commented remove command, here, to delete the previous import first.<br />
<br />
<source lang="python"><br />
# In CASA<br />
# os.system("rm -rf TWHydra_CO3_2line.image")<br />
importfits(fitsimage="TWHydra_CO3_2line.image.fits", imagename="TWHydra_CO3_2line.image")<br />
</source><br />
<br />
where '''fitsimage''' refers to the file to imported and '''imagename''' gives the output filename. If you are proceeding directly from the imaging step, your data are already CASA images and you may proceed without any importing.<br />
<br />
You can get the basic properties of any CASA image using the '''imhead''' command. For example, type <br />
<br />
<source lang="python"><br />
# In CASA<br />
imhead("TWHydra_CO3_2line.image")<br />
</source><br />
<br />
and look at the CASA logger. You will see an image summary like the following<br />
<br />
<pre style="background-color: #fffacd;"><br />
INFO imhead ##########################################<br />
INFO imhead ##### Begin Task: imhead #####<br />
INFO imhead imhead(imagename="TWHydra_CO3_2line.image",mode="summary",hdkey="",hdvalue="",<br />
INFO imhead hdtype="",hdcomment="",verbose=False)<br />
INFO ImageAnalysis <br />
INFO ImageAnalysis Image name : TWHydra_CO3_2line.image<br />
INFO ImageAnalysis Object name : TW Hya<br />
INFO ImageAnalysis Image type : PagedImage<br />
INFO ImageAnalysis Image quantity : Intensity<br />
INFO ImageAnalysis Pixel mask(s) : None<br />
INFO ImageAnalysis Region(s) : None<br />
INFO ImageAnalysis Image units : Jy/beam<br />
INFO ImageAnalysis Restoring Beam : 1.68065 arcsec, 1.53193 arcsec, 22.3015 deg<br />
INFO ImageAnalysis <br />
INFO ImageAnalysis Direction reference : J2000<br />
INFO ImageAnalysis Spectral reference : LSRK<br />
INFO ImageAnalysis Velocity type : RADIO<br />
INFO ImageAnalysis Rest frequency : 3.45796e+11 Hz<br />
INFO ImageAnalysis Pointing center : 11:01:51.844983 -34.42.17.160885<br />
INFO ImageAnalysis Telescope : ALMA<br />
INFO ImageAnalysis Observer : Unknown<br />
INFO ImageAnalysis Date observation : 2011/04/22/00:15:42<br />
INFO ImageAnalysis Telescope position: [2.22514e+06m, -5.44031e+06m, -2.48103e+06m] (ITRF)<br />
INFO ImageAnalysis <br />
INFO ImageAnalysis Axis Coord Type Name Proj Shape Tile Coord value at pixel Coord incr Units<br />
INFO ImageAnalysis -------------------------------------------------------------------------------------------------- <br />
INFO ImageAnalysis 0 0 Direction Right Ascension SIN 100 25 11:01:51.845 50.00 -3.000000e-01 arcsec<br />
INFO ImageAnalysis 1 0 Direction Declination SIN 100 25 -34.42.17.161 50.00 3.000000e-01 arcsec<br />
INFO ImageAnalysis 2 2 Spectral Frequency 118 59 3.45801e+11 0.00 -1.38414152e+05 Hz<br />
INFO ImageAnalysis Velocity -4 0.00 1.200000e-01 km/s<br />
INFO ImageAnalysis 3 1 Stokes Stokes 1 1 I<br />
INFO imhead ##### End Task: imhead #####<br />
INFO imhead ##########################################<br />
<br />
</pre><br />
<br />
This report tells you about the target, shape, and coordinates of the image. It also notes the rest frequency and some details of the observation. '''imhead''' may be used more generally to retrieve header keywords as python variables or to manipulate the header of an image. Consult the help for details.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
You may want to pay particular attention to the third and fourth axis of the CASA image. These are <br />
usually frequency (velocity) and Stokes (polarization) in some order. An occasional source of confusion <br />
is that this order is not always the same. Often CLEAN will output images with the Stokes axis third, <br />
while IMPORTFITS usually yields images with the frequency axis third. If you encounter problems with<br />
image analysis tasks, you may want to check whether this results from conflicting axis definitions. You<br />
can adjust the order of the axes using the IMTRANS task.<br />
</pre><br />
<br />
Before proceeding, make sure that you have all three data sets as CASA images: '''TWHydra_CO3_2line.image''', '''TWHydra_HCOPlusline.image''', and '''TWHydra_contall_apcal.image'''. If you do not, then import them from the provided reference images. If you are re-importing the FITS images, run the commented remove commands before running importfits.<br />
<br />
<source lang="python"><br />
# In CASA<br />
# os.system("rm -rf TWHydra_CO3_2line.image")<br />
importfits(fitsimage="TWHydra_CO3_2line.image.fits", imagename="TWHydra_CO3_2line.image")<br />
# os.system("rm -rf TWHydra_HCOplusline.image")<br />
importfits(fitsimage="TWHydra_HCOplusline.image.fits", imagename="TWHydra_HCOplusline.image")<br />
# os.system("rm -rf TWHydra_contall_apcal.image")<br />
importfits(fitsimage="TWHydra_contall_apcal.image.fits", imagename="TWHydra_contall_apcal.image")<br />
</source><br />
<br />
In the rest of this guide we will construct ''moment maps'' showing the integrates, velocity field, and line width of the two lines. We will carry out Gaussian fits to the continuum and line maps. We will also illustrate some of the additional analysis capabilities available in CASA: subcube extraction, retrieval of data into python arrays, cube alignment, smoothing, and overlays of multiple spectral lines.<br />
<br />
===Moment Maps===<br />
<br />
The line "images" of CO(3-2) and HCO+(4-3) are, of course, cubes rather than images. Two dimensional ''moment maps'' are a standard way to present such data. These are maps showing the result of various moments (or similar calculations) carried out along the frequency axis of the cube. For example, the "moment 0" map is the sum of emission along the frequency axis at each pixel. The first moment is the intensity-weighted velocity (or frequency). The second moment is the intensity-weighted velocity (or frequency) dispersion about the mean. These and a number of other calculations (for example the maximum intensity) can be calculated via the '''immoments''' task. Consult the help or the CASA cookbook for more details.<br />
<br />
In this section, we will calculate moments for our two spectral line data cubes. To make the highest quality moment maps, we will first identify the planes of the data cube that contain emission, so that we can carry out the sum only over these channels. Doing otherwise adds noise to the moment map without adding signal and so lowers the signal-to-noise ratio of the final image. For the first and second moments we will identify an intensity threshold above which the data are statistically very likely to correspond to real astronomical emission. We will restrict the calculation to consider only data above this threshold, yielding a cleaner calculation (the second moment, in particular, is not at all robust against the inclusion of outlying noise). Finally, we will inspect the resulting moment maps with the viewer and output them to .FITS files.<br />
<br />
====Estimate the Spectral Extent====<br />
<br />
First, we want to figure out what planes appear to contain real emission. Open the CO data cube with the CASA viewer via:<br />
<br />
<source lang="python"><br />
# In CASA<br />
viewer("TWHydra_CO3_2line.image")<br />
</source><br />
<br />
This will open the CO(3-2) data cube as a raster image. Use the Animator pane to scroll through the cube, noting that the emission is mostly confined to ~40 channels near the center of the cube. There are several ways to make a more rigorous estimate. <br />
<br />
''By-Plane Inspection:'' First, you could increase the stretch of the image to identify by hand the first and last channels with visible emission. To do open the Data Display Options panel in the viewer (the wrench icon) and manually set the data range and/or scaling power cycles to highlight faint emission (note that you can also do this using the mouse and the color stretch - sun - icon). I left the scaling power cycles at 0 and set the data range to [-0.15, 0.15]. Then scroll through the cube and note the first and last channels with obvious emission. If I do this, I find emission from about plane 30 through plane 86.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:DataDisplayPanelStretch.png|The Data Display Panel used to set the color stretch, here from [-0.15, 0.15] with a linear (0) stretch. Setting the stretch to a negative value will highlight lower emission (a more logarithmic stretch). We got to this panel by clicking the wrench icon. You can also get from the dropdown menus (Data->Adjust).<br />
File:TWHydraCOChan33.png|Channel 33 of the CO(3-2) cube on this stretch. This is about the first channel to show clear emission.<br />
File:TWHydraCOChan80.png|Channel 80 of the CO(3-2) cube on this stretch. This is about the last channel to show clear emission.<br />
</gallery><br />
</center><br />
<br />
To make this more rigorous, you can work out a noise estimate before hand (we'll find it to be about 0.025 Jy/beam) and overplot a contour to indicate significant emission. You can do this by hand by using the Data Manager (folder icon) to open TWHydra_CO3_2line.image as a "contour map" and then using the Data Display Options to manipulate the contour levels. To show a 3-sigma contour with sigma=0.025 Jy/beam set the Relative Contour Levels to [3], the Base Contour Level to 0, and the Unit Contour Level to 0.025. You can display a 5-sigma contour or change the RMS analogously. Scrolling through the cube, I see 3-sigma emission from channels 33 through 80.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:DataDisplayPanelContour.png|The Data Display Panel now being used to set the contour levels. We set the contour unit to 0.025 and ask for a single contour at 3 times this value. Notice that we clicked the tab along the top of the window to select the contour map.<br />
File:TWHydraCOChan33Contour.png|Channel 33 of the CO(3-2) cube on this stretch with a 3-sigma contour overlaid.<br />
File:TWHydraCOChan80Contour.png|Channel 80 of the CO(3-2) cube on this stretch with a 3-sigma contour overlaid.<br />
</gallery><br />
</center><br />
<br />
''Look at a Spectrum:'' You can also look at a spectrum of the source. To do this, scroll to a channel with a lot of emission (I went to 57) and then use the mouse to drag out a rectangle. To do this, left click on the rectangle box in the mouse toolbar (this assigns the left mouse button to define rectangle regions). Then drag out a box around the emission using the same button. Now click the spectrum in the toolbar to open the spectral profile tool. You will see the average profile for the selected region. You can set the bottom axis to show channels. You can zoom in within the spectral profile by dragging out a rectangle. When I do this, I find significant emission from channels 40-80.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:TWHydraRectangle.png|Defining a rectangular region around the main emission from TW Hydra. First we clicked the rectangle button on the mouse toolbar, then we held that button and dragged out the purple rectangle. After defining the rectangle, you can drag it around or delete it with <ESC>.<br />
File:TWHydraSpectrum.png|The spectrum of this rectangular region viewed in the spectral profile browser. Note that the bottom axis has been set to show channels. To get this spectrum, we defined the rectangular region and then clicked the spectrum button on the toolbar.<br />
File:TWHydraSpectrumZoom.png|A zoom in on the spectrum. The line extends from channels ~40-80.<br />
</gallery><br />
</center><br />
<br />
''Look at a Declination-Frequency Projection (or an R.A.-Frequency Projection):'' This is probably the least reliable way to do this, but illustrates a neat capability of the viewer. Open the Data Display Options (click the wrench icon) and open the "display axes" and "hidden axes" tabs. Use the dropdown menus to change the display so that the x-axis shows Declination, the y-axis shows Frequency, and the z-axis shows "Right Ascension." Now you are scrolling through planes of intensity as a function of Declination and Frequency. Use the animator to move to R.A. plane ~ 50 (the center of the source) and pull the stretch up (in the wrench tool; I used [-0.15,0.15] again). Mouse over the image and look at the "Position Tracking" pane in the bottom of the image, noting the pixel extent of emission in the frequency axis of this plane. I see traces of emission from channel ~30-90.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:DataDisplayPanelAxes.png|The Data Display Panel, here used to set which axes are displayed. We have adjusted the y-axis to show frequency and the x-axis to show Declination. The z-axis is now Right Ascension, so that we will scroll through planes of Right Ascension.<br />
File:DataDisplayPanelPixels.png|The Data Display Panel, here we are setting coordinates to show "pixels" rather than world coordinates.<br />
File:TWHydraDecFreqPixels.png|A Frequency-Declination plane of the cube near the central R.A. pixel (50). The rough extent of emission may be simply read off the y-coordinate. As above, we could overplot a 3-sigma contour to add more rigor.<br />
</gallery><br />
</center><br />
<br />
<br />
You can repeat this exercise for the HCO+ (4-3) emission. Using the Spectral Profile Browser, I find that the line extends from about channel 40 through channel 75.<br />
<br />
====Make Moment 0 Maps====<br />
<br />
With an estimate of the spectral extent of emission, we are now ready to make moment 0 maps of the CO(3-2) and HCO+(4-3) lines. We do this using the '''immmoments''' command,<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom0')<br />
immoments(imagename='TWHydra_CO3_2line.image',moments=[0],<br />
outfile='TWHydra_CO3_2line.image.mom0',<br />
chans='30~90')<br />
</source><br />
<br />
and<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom0')<br />
immoments(imagename='TWHydra_HCOplusline.image',moments=[0],<br />
outfile='TWHydra_HCOplusline.image.mom0',<br />
chans='40~75')<br />
</source><br />
<br />
immoments will sum across the channels specified by '''chans''' and produce new CASA images with the names specified by '''outfile'''. These can be inspected using the CASA viewer just like any other image. Note that unlike higher-order moments, the moment-0 map is robust to the inclusion of noisy signal-free channels (to within reason, you just decrease your signal-to-noise ratio) and indeed may be biased to miss faint emission by imposing a threshold. For that reason, we will eschew the '''includepix''' keyword as we make the moment 0 maps.<br />
<br />
Let's look at the output using the viewer. We can specify some of the display options in the call to start the viewer by using '''imview''' instead of '''viewer'''.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview( raster=[ {'file':'TWHydra_CO3_2line.image.mom0',<br />
'range':[0.0,10.],<br />
'scaling':-1},<br />
{'file':'TWHydra_HCOplusline.image.mom0',<br />
'range':[0.0,10.],<br />
'scaling':-1}], <br />
contour={'file':'TWHydra_contall_apcal.image', 'base':0, 'unit':0.0025, 'levels':[3,100]} )<br />
</source><br />
<br />
This does several things: It opens the viewer with raster images of the moment 0 maps of CO(3-2) and HCO+(4-3), sets the range of the color stretch from [0, 10] for each image and sets the scaling to be -1, which highlights faint emission compared to the normal (0) stretch. It also opens the continuum image as a contour and defines two contour levels. Once the viewer is open, you can blink between the images by going into the Animator pane, checking the white box next to "Images" to enable animation between images, and then sliding the bar back and forth. See the name of the image being shown change. You can also show two images side by side by going to the Viewer Canvas Manager (wrench+P icon) and opening the "Number of Panels" tab. Set the "Number of panels in x" to 2 and make sure that the Images box is checked in the Animator pane. You will see both images side by side.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:CanvasManagerPanels.png|The Viewer Canvas Manager, accessed via the Wrech+P icon (not to be confused with the plain old wrench). Here we have adjusted the number of x-panels from 1 to 2 so that we show the two moment maps side by side.<br />
File:TWHydraMoment0Maps.png|The moment-0 maps of CO(3-2) and HCO+(4-3) plotted side by side on the same color stretch, both with the continuum contours overlaid. To get the two images side by side, run the imview call above then set the number of panels to 2 and make sure that the Images box in the Animator Pane (here at the bottom of the window) is checked.<br />
File:DataDisplayImview.png|Data Display Panel after our imview call. Imview allowed us to set the stretch, range, and contour levels from the command line.<br />
</gallery><br />
</center><br />
<br />
====Estimate the Noise====<br />
<br />
We have already made a few offhand comparisons to the RMS noise. This quantity is often critical to know when exploring the data. Because the higher-order moments (especially the dispersion) are not at all robust to the inclusion of noise, we will calculate them only from regions of the cube that have intensity several times the RMS noise value or higher and are thus very likely to contain real astronomical emission. To proceed, we need to estimate the RMS noise for our data.<br />
<br />
The easiest way to do this is to calculate the RMS scatter of the data about zero from a part of the data that you suspect to be (mostly) free of astronomical signal. In a data cube the easiest way to do this will often be to identify signal-free planes (channels) of the cube and to simply calculate the RMS in these regions. We can do this straightforwardly using the '''imstat''' command in CASA.<br />
<br />
IMSTAT COMMAND<br />
<br />
IMSTAT OUTPUT<br />
<br />
Alternatively, you can get similar statistics on a region of an image or data cube selected manually inside the viewer. Drag out a region, for example a rectangle, using one of the mouse tools. Then <br />
<br />
IMAGES OF REGION SELECTION, OUTPUT, REGION MANAGER<br />
<br />
Suggested values for CO(3-2), HCO+(4-3), and continuum. Short discussion of dynamic range limited vs. line-free channels.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
A note on primary beam corrections and noise.<br />
</pre><br />
<br />
====Higher Order Moment Maps for CO(3-2)====<br />
<br />
For higher order moments it is very important to set a conservative flux <br />
threshold. Typically something like 6 sigma, using sigma from peak line channel, works well.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom')<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_coord')<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_dispersion_coord')<br />
immoments(imagename='TWHydra_CO3_2line.image',moments=[1,2],<br />
outfile='TWHydra_CO3_2line.image.mom',<br />
chans='40~76',includepix=[0.3,100])<br />
</source><br />
<br />
Display all three moment maps in the viewer, overlaid with continuum contours.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview( raster=[ {'file':'TWHydra_CO3_2line.image.mom0'},<br />
{'file':'TWHydra_CO3_2line.image.mom.weighted_coord'},<br />
{'file':'TWHydra_CO3_2line.image.mom.weighted_dispersion_coord'} ], <br />
contour={'file':'TWHydra_contall_apcal.image', 'base':0, 'unit':0.0025, 'levels':[3,100]} )<br />
</source><br />
<br />
To see all three raster images simultaneously, open the viewer's Panel Display Options (the "P-wrench" icon in the viewer tool bar), click "Number of panels", and change "Number of panels in x" to 3. Then select the "Blink" toggle (radio button) from the Animator panel.<br />
<br />
<figure id="TWHya_CO3_2_moments.png"><br />
[[Image:TWHya_CO3_2_moments.png|center|800px|frame|<caption>ALMA CO(3-2) moment maps, with white continuum contours at 3 and 100 sigma. From left to right: integrated intensity, intensity weighted velocity field, intensity weighted velocity dispersion are shown.</caption>]]<br />
</figure><br />
<br />
Repeat for HCO+(4-3) which has a bit narrower velocity extent than the CO(3-2), but similar rms noise.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom0')<br />
immoments(imagename='TWHydra_HCOplusline.image',moments=[0],<br />
outfile='TWHydra_HCOplusline.image.mom0',<br />
chans='43~74')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom')<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_coord')<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_dispersion_coord')<br />
immoments(imagename='TWHydra_HCOplusline.image',moments=[1,2],<br />
outfile='TWHydra_HCOplusline.image.mom',<br />
chans='43~74',includepix=[0.3,100])<br />
</source><br />
<br />
Display all three moment maps in the viewer using the same method described above for the CO(3-2) maps.<br />
<br />
<figure id="TWHya_HCOp4_3_moments.png"><br />
[[Image:TWHya_HCOp4_3_moments.png|center|800px|frame|<caption>ALMA HCO+(4-3) moment maps, with white continuum contours at 3 and 100 sigma. From left to right: integrated intensity, intensity weighted velocity field, intensity weighted velocity dispersion are shown.</caption>]]<br />
</figure><br />
<br />
=====Exporting Fits Images=====<br />
<br />
If you want to analyze the data using another software package it is easy to convert from CASA format to FITS. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image',fitsimage='TWHydra_CO3_2line.image.fits')<br />
</source><br />
<br />
Although "FITS format" is supposed to be a standard, in fact most packages expect slightly different things from a FITS image. If you are having difficulty, try setting '''velocity=T''' and/or '''dropstokes=T'''.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf TWHydra_HCOplusline.image.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image',fitsimage='TWHydra_HCOplusline.image.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom0.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image.mom0',<br />
fitsimage='TWHydra_CO3_2line.image.mom0.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_coord.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image.mom.weighted_coord',<br />
fitsimage='TWHydra_CO3_2line.image.mom.weighted_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_dispersion_coord.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image.mom.weighted_dispersion_coord',<br />
fitsimage='TWHydra_CO3_2line.image.mom.weighted_dispersion_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom0.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image.mom0',<br />
fitsimage='TWHydra_HCOplusline.image.mom0.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_coord.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image.mom.weighted_coord',<br />
fitsimage='TWHydra_HCOplusline.image.mom.weighted_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_dispersion_coord.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image.mom.weighted_dispersion_coord',<br />
fitsimage='TWHydra_HCOplusline.image.mom.weighted_dispersion_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_apcal.image.fits')<br />
exportfits(imagename='TWHydra_contall_apcal.image',fitsimage='TWHydra_contall_apcal.image.fits')<br />
</source><br />
<br />
===Display Channel Maps===<br />
<br />
Using the Viewer you can make channel map figures. Start the Viewer and then open the CO(3-2) cube as a raster image and then the continuum as a contour image. Then we use the "wrench" icon and "P wrench" icons to set up the channel images, contour levels etc. (If you need help setting up the viewer for this image, see a screen shot of the viewer setup windows, below.)<br />
<br />
<figure id="TWHya_channel_co3_2.png"><br />
[[Image:TWHya_channel_co3_2.png|center|frame|<caption>Channel maps of the CO(3-2) emission with white continuum contours at 3 and 100 sigma.</caption>]]<br />
</figure><br />
<br />
<figure id="Viewer_setup.png"><br />
[[Image:Viewer_setup.png|center|thumb|500px|<caption>The setup windows looked like this</caption>]]<br />
</figure><br />
<br />
Repeat for HCO+(4-3)<br />
<br />
<figure id="TWHya_channel_HCOp4_3.png"><br />
[[Image:TWHya_channel_HCOp4_3.png|center|thumb|800px|<caption>Channel maps of the HCO+(4-3) emission with white continuum contours at 3 and 100 sigma. The color intensity scale is the same as that used for CO(3-2).</caption>]]<br />
</figure><br />
<br />
<!--<br />
====Examine CO Contours on an HCO+ Raster====<br />
<br />
====Matched Movies====<br />
<br />
===Image Plane and Spectral Fits===<br />
<br />
====Fit a Gaussian to the Continuum====<br />
<br />
=====Fit In the Viewer=====<br />
<br />
=====Fit Using the Command Line=====<br />
<br />
====Fit a Gaussian to the CO Line====<br />
<br />
=====Fit In the Viewer=====<br />
<br />
=====Fit Using the Command Line=====<br />
<br />
===Extract a Sub-Image===<br />
<br />
===Align Image Cubes===<br />
--><br />
<br />
{{Checked 4.3.0}}</div>Sstierwahttps://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_4.3&diff=19484TWHydraBand7 Imaging 4.32016-05-18T04:40:38Z<p>Sstierwa: /* Estimate the Spectral Extent */</p>
<hr />
<div>[[Category:ALMA]][[Category:Imaging]][[Category:Spectral Line]]<br />
<br />
* '''This tutorial picks up where '''[[TWHydraBand7_Calibration_4.5.2]]''' leaves off, with fully calibrated, split science target MS. If you wish to skip the Calibration guide: obtain the calibrated data from [[TWHydraBand7#Getting_the_Data]]; extract it using <tt>tar -xzvf FILENAME</tt>; and <tt>cd</tt> into the extracted directory.'''<br />
<br />
*'''This guide is designed for CASA 4.3. If you are using an older version of CASA please see [[TWHydraBand7_Imaging_4.3]].<br />
<br />
* '''Details of the ALMA data are provided at [[TWHydraBand7]]'''<br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.5.2. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.3.0'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
== Prepare Continuum Data for Further Processing==<br />
<br />
In order to speed up imaging/self-calibration for the continuum data we will average channels together, and then flag the few spectral features. This method works well in the case of only a few spectral lines, while retaining enough channelization to aid in multi-frequency synthesis and being able to remove spectral features in the averaged data. The amount of channel averaging should be adjusted to your particular data. '''Note for wide bandwidth data it is never a good idea to use the continuum estimate generated by uv-continuum subtraction as your continuum data'''. This worked OK in the past with the narrow band systems like the VLA and low dynamic range instruments like the SMA, but is not advised for ALMA wide bandwidth, high dynamic range data. <br />
<br />
<figure id="Cont_spw2.png"><br />
[[Image:Cont_spw2.png|thumb|<caption>CO(3-2) in spw=2 from the "continuum" channel averaged data.</caption>]]<br />
</figure><br />
<figure id="Cont_spw3.png"><br />
[[Image:Cont_spw3.png|thumb|<caption>Notice upswing at high channel numbers in spw=3.</caption>]]<br />
</figure><br />
<br />
One can also flag the spectral features first but in that case make a backup of the file that is analogous to TWHydra_corrected.ms as you will need it later (unflagged) for spectral line imaging. We begin by excluding ~20 channels on each edge, and averaging over 100 channel intervals:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_cont.ms*')<br />
split(vis='TWHydra_corrected.ms',outputvis='TWHydra_cont.ms',<br />
spw='0~3:21~3820',width=100,datacolumn='data')<br />
</source><br />
<br />
Now make a plot of amplitude vs. channel to see what needs to be flagged<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',spw='0~3',xaxis='channel',yaxis='amp',<br />
avgtime='1e8',avgscan=T,coloraxis='spw',iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
The CO(3-2) and HCO+(4-3) lines are obvious. The 4th spw; spw=3 also shows an upswing on the highest channels that is problematic, it was seen on the calibrators too and is likely due to a weak atmospheric feature, we will flag the worst of it.<br />
<br />
<figure id="Cont_uvplot.png"><br />
[[Image:Cont_uvplot.png|thumb|<caption>UV-plot of the continuum emission, colors show spws.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='TWHydra_cont.ms', mode='manual', <br />
spw='0:16~16, 2:21~21, 3:33~37')<br />
</source><br />
<br />
Have a look at the continuum as a function of uv-distance (in the plot to the right, the 4 spw are shown in different colors on top of each other). If the data are flat as a function of uv-distance, the source is completely unresolved. If instead you see structure (in this case decreasing amplitude with uv-distance), the source is resolved. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',spw='',xaxis='uvdist',yaxis='amp',field='',avgchannel='38',<br />
coloraxis='spw',plotfile='cont_uvplot.png')<br />
</source><br />
<br />
Notice that the spw do not have the same amplitude. Unfortunately, the red spw (highest frequency) should be higher than the green one (lowest frequency) because optically thin dust goes as nu^4, and optically thick as nu^2. This inconsistency is due to imperfect amplitude/absolute flux calibration. The self-calibration below will bring them into agreement with each other, but this is the sort of thing that results in considerable absolute flux uncertainty at submillimeter wavelengths. We are working on how to do this better.<br />
<br />
==A priori Noise Estimates==<br />
<br />
<figure id="Corrected_time.png"><br />
[[File:Corrected_time.png|thumb|<caption>Plot for estimating time.</caption>]]<br />
</figure><br />
<figure id="sensitivity_cont.png"><br />
[[File:sensitivity_cont.png|thumb|<caption>Sensitivity calculator setup with observed continuum parameters for these observations.</caption>]]<br />
</figure><br />
<br />
To estimate what the expected noise levels are, we first need to know how much time we had on source. Looking at <br />
a plot of amplitude vs time for the concatenated but pre-split data (see below) there are 9x8min scans + 6x6min scans + 3x1min + 2x2min scans for about 1.9 hours on source. There are 2 polarizations and about 1.75 GHz of total continuum bandwidth taking into account flagging.<br />
<br />
Using this information and https://almascience.nrao.edu/proposing/sensitivity-calculator, we find that the '''expected rms noise for the continuum is about 0.3 mJy/beam'''.<br />
<br />
For the spectral line data, which we will image below, with 0.12 km/s channels (needs to be entered in the field ''bandwidth per polarization''), the '''expected rms noise for the spectral lines is about 32 mJy/beam'''.<br />
<br />
==Image and Self-Calibrate the Continuum==<br />
<br />
====Create Initial Clean Image====<br />
<br />
First we will make an initial image using {{clean}}, this task will both deconvolve and clean. <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
If you are unfamiliar with the basic concepts of deconvolution and clean,<br />
pause here and review for example<br />
http://www.aoc.nrao.edu/events/synthesis/2010/lectures/wilner_synthesis10.pdf<br />
</pre><br />
<br />
In {{clean}}, we use '''mode='mfs'''' to do multifrequency synthesis, in other words grid each uv-channel independently. Since the uv-spacing is a function of frequency, this will actually achieve greater uv-coverage than if all the channels and spws had been averaged in advance. The '''imsize=100''' and '''cellsize=['0.3arcsec']''' were chosen to be appropriate for the Band and antenna configuration. At ALMA Band 7, the Full Width Half Power primary beam is about 20", so we want to make our image at least this big. We've made it a bit larger out to about the 25% power point. For the configuration used to take these data, the resolution is expected to be about 1.5" and it is a good idea to oversample the beam by setting the cell size to be a factor of 4 or 5 smaller than the beam (we have used 5 here). <br />
<br />
For doing self-calibration it is essential that only "real" signal be included in the image model, thus it is important to make a clean mask, and clean the first iteration rather conservatively (shallowly) so that you are sure that you do not have clean components in your model that do not represent real source emission. In the example below we set '''interactive=T''' so you can interactively make the clean mask and stop clean when the signal from the source starts to approach the surrounding "noise" areas in the residual map.<br />
<br />
'''NOTE:''' Real emission will not go away if you do not put a clean box on it. Conversely if you put a clean box on something that is NOT real and clean deeply you can amplify that feature. Thus, its best to be conservative and build up your clean box as you go, you can generally see fainter "real" features in the residuals.<br />
<br />
'''NOTE:''' If you start an interactive clean, and then do not make a mask, clean will stop when you tell it to go on because it has nothing to clean. There is no default mask.<br />
<br />
<figure id="Viewer_clean1.png"><br />
[[Image:Viewer_clean1.png|thumb|<caption>Interactive viewer.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall',<br />
mode='mfs', imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5, <br />
mask='',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
'''NOTE:'''{{clean}} will generate several files automatically with the '''imagename''' prepended:<br />
* <imagename>.image # the final restored image<br />
* <imagename>.flux # the effective primary beam response (e.g. for pbcor)<br />
* <imagename>.flux.pbcoverage # the primary beam coverage (ftmachine=’mosaic’ only)<br />
* <imagename>.model # the model image<br />
* <imagename>.residual # the residual image<br />
* <imagename>.psf # the synthesized (dirty) beam<br />
<br />
Once the Clean Viewer opens, click on the polygon tool with your left mouse button, and draw a polygon around the continuum emission with the left mouse button. Double click inside the region with the left mouse button when you are happy with it. It will turn from green to white when the clean mask is accepted. To continue with clean use the "Next action" buttons in the green area on the Viewer Display GUI. <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
The red X will stop clean where you are, the blue arrow will stop <br />
the interactive part of clean, but continue to clean non-interactively <br />
until reaching the number of iterations requested (niter) or the flux <br />
density threshold (whichever comes first), and the green circle arrow <br />
will clean until it reaches the "iterations" parameter on the left side <br />
of the green area. <br />
</pre><br />
<br />
'''You should chose the green circle arrow'''. It will clean 100 iterations (number under iteration in the green area on the Viewer GUI) and then show the '''residual image''' again. The middle mouse button is automatically assigned to the "plus" icon, which adjusts the colorscale. '''If you cannot easily access multiple mouse buttons, you can always assign your one mouse button the icon you want by clicking on it'''. Adjust the color scale so you can see the structure in the noise better. Also, note that the logger is telling you the amount of clean flux recovered so far, the min/max residuals, and the synthesized beam:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Model 0: max, min residuals = 0.0203454, 0.00267232 clean flux 1.30124<br />
Threshhold not reached yet.<br />
Beam used in restoration: 1.6962 by 1.54549 (arcsec) at pa 28.9043 (deg) <br />
</pre> <br />
<br />
Already with only 100 iterations, the residuals outside the clean mask are larger than that inside. So we will stop here by hitting the Red X symbol.<br />
<br />
====1st Round of Continuum Data Phase Self-calibration====<br />
<br />
Next we can use the clean model to self-calibrate the uv-data. The process of self-calibration tries to adjust the data to better match the model you give it. That is why it is important to make the model as good as you can. {{clean}} places a uv-model of the resulting image in the file <tt>TWHydra_cont.model</tt>. This model can then be used to self-calibrate the data using {{gaincal}}. We use '''gaintype='T'''' to tell it to average the polarizations before deriving solutions (which gains us a sqrt(2) in sensitivity). A critical parameter to play with is '''solint'''; we use '''solint=30s'''. From {{listobs}} the integration time of these data is about 10 seconds, so using '''solint=30s''' then gains us a sqrt(3) in sensitivity. It is often best to start with a larger '''solint''' and then work your way down to the integration time if the S/N of the data permits. For the same reasons as described in the [[TWHydraBand7_Calibration_4.3]] tutorial we want to fix up the phases before tackling amplitude by setting '''calmode='p''''.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='TWHydra_cont.ms',caltable='self_1.pcal',<br />
solint='30s',combine='',gaintype='T',<br />
refant='DV06',spw='',minblperant=4,<br />
calmode='p',minsnr=2)<br />
</source><br />
<br />
<figure id="Self_1_phase.png"><br />
[[Image:Self_1_phase.png|thumb|<caption>Phase solutions from self_1.pcal with solint=30s.</caption>]]<br />
</figure><br />
<br />
Because '''combine=' '''', we are getting independent solutions for each spw. If you are desperate for S/N, you can try combining them with combine='spw'. We have plenty of S/N in these data so we keep them separate. Look at the solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_1.pcal',xaxis='time',yaxis='phase',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,-80,80],figfile='self_1_phase.png')<br />
</source><br />
<br />
The magnitude of corrections gives you a sense of how accurate the phase transfer from the calibrators was. You are checking to see that the phases are being well tracked by the solutions, i.e. smoothly varying functions of time within a given scan. Also the solutions for each spw are lying basically on top of each other which indicates that the spw to spw phase offsets are well calibrated already. Overall, these solutions look quite good. If they didn't you could try increasing the solint and/or combining the spw into a single solution. <br />
<br />
After checking that you are happy with the solutions, apply them with {{applycal}}<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_cont.ms',field='',gaintable=['self_1.pcal'],calwt=F)<br />
</source><br />
<br />
<figure id="Viewer_pcal1.png"><br />
[[Image:Viewer_pcal1.png|thumb|<caption>Clean residuals after 100 iterations and the 1st phase only self-cal. Residuals inside mask are higher than the "noise" outside.</caption>]]<br />
</figure><br />
<br />
Next clean the source again, to save time we can start with the clean mask from the last iteration. If you make interactive adjustments to the clean mask, they will be written to the '''new''' mask TWHydra_contall_1pcal.mask, and not the old one. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_1pcal.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall_1pcal',<br />
mode='mfs',imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5, <br />
mask='TWHydra_contall.mask',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
Now after the first 100 iterations you see that the residuals inside the clean mask are higher than those outside. This is because flux that had been spread out in the map due to poorly correlated phases has been placed where it belongs on the source, thereby increasing its flux. You may also notice that your original clean mask is a little too small. If so, you can make it a bit larger, just by drawing a new polygon around the area you want to include. When you double click, it will incorporate the new mask into the current mask (if your box goes awry you can use the erase toggle [radio button] to erase and redo the mask). The new mask area need not overlap the original mask (though for this source it probably will). You might also want to use the magnifying glass to zoom in. Again, you assign mouse buttons by clicking on the icon you want. Clean another 100 iterations (for a total of 200) and stop by clicking the red X.<br />
<br />
Now open initial and 1st self-cal images to compare them using {{imview}}. This is an alternative version of the {{viewer}} that is somewhat scriptable. <br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(raster=[{'file':'TWHydra_contall.image','range':[-0.01,0.05]},<br />
{'file':'TWHydra_contall_1pcal.image','range':[-0.01,0.05]}])<br />
</source><br />
<br />
Once the Viewer Display panel opens, click on the box next in the "Images" panel and then use the tapedeck buttons in the panel to alternate between the two images. Because the range was explicitly set, they are on the same color scale. It is obvious that the self-calibrated image is better. To quantify, 1st toggle back to "normal" and then draw a region that excludes the central source with the polygon tool and then double click inside (if you stay in the "Images" view, only the statistics for the last image opened will appear on the terminal instead of both). The basic statistics of the polygon region will print to the '''terminal''':<br />
<br />
<pre style="background-color: #fffacd;"><br />
TWHydra_contall.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2357 -9.434800e-01 -2.858690e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-4.002885e-04 7.906752e-03 7.898289e-03 -2.541723e-02 2.172779e-02 <br />
<br />
TWHydra_contall_1pcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2357 6.326584e-01 1.916918e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
2.684168e-04 3.655786e-03 3.646692e-03 -1.215155e-02 1.109403e-02 <br />
</pre><br />
<br />
The self-calibrated image has more than a factor of 2 lower rms noise!<br />
<br />
====2nd Round of Continuum Data Phase Self-calibration====<br />
<br />
Now that we have a better model, we solve for solutions again. This time we will try making the solint smaller -- the integration time is about 10 seconds, so we set '''solint='int'''' to have it use the integration time.<br />
<br />
<figure id="Self_2_phase.png"><br />
[[Image:Self_2_phase.png|thumb|<caption>Phase solutions from self_2.pcal with solint='int'.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='TWHydra_cont.ms',caltable='self_2.pcal',<br />
solint='int',combine='',gaintype='T',<br />
refant='DV06',spw='',minblperant=4,<br />
calmode='p',minsnr=2)<br />
</source><br />
<br />
Now plot the new solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_2.pcal',xaxis='time',yaxis='phase',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,-80,80],figfile='self_2_phase.png')<br />
</source><br />
<br />
The phases on this shorter '''solint''' still seem to be tracking well so we will apply it and make a new image and check to see if there is improvement. <br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_cont.ms',field='',gaintable=['self_2.pcal'],calwt=F)<br />
</source><br />
<br />
<figure id="Viewer_pcal2.png"><br />
[[Image:Viewer_pcal2.png|thumb|<caption>Clean residuals after 2nd phase only self-cal and 250 iterations. The residuals inside the clean mask are lower than those outside, so its time to stop.</caption>]]<br />
</figure><br />
<br />
Now clean again, updating '''mask''' with the most recent mask file.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_2pcal.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall_2pcal',<br />
mode='mfs',imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5,usescratch=False,<br />
mask='TWHydra_contall_1pcal.mask',<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
After 200 iterations<br />
<br />
<pre style="background-color: #fffacd;"><br />
Model 0: max, min residuals = 0.00489776, -0.00464541 clean flux 1.44461<br />
</pre><br />
<br />
It looks like it could use just a little more cleaning, so set '''iterations=50 in the GUI'''.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Clean used 50 iterations to approach a threshhold of 0.0015067<br />
0.0107122 Jy <- cleaned in this cycle for model 0 (Total flux : 1.45532Jy)<br />
Final maximum residual = 0.00326382<br />
Model 0: max, min residuals = 0.00326382, -0.00321361 clean flux 1.45532<br />
</pre><br />
<br />
The small amount of flux cleaned this cycle indicates that clean is converging and it's about time to stop. Also the residuals inside the clean mask are now smaller than the residuals outside (i.e. the noise) also indicating it's time to stop by hitting the red X on the GUI.<br />
<br />
Now repeat the display, blinking, and image statistics steps described above for the 1st and 2nd phase-only self-cal iterations.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(raster=[{'file':'TWHydra_contall_1pcal.image','range':[-0.01,0.05]},<br />
{'file':'TWHydra_contall_2pcal.image','range':[-0.01,0.05]}])<br />
</source><br />
<br />
The difference is small:<br />
<pre style="background-color: #fffacd;"><br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2466 4.611597e-02 1.397287e-03 <br />
Mean Rms Std dev Minimum Maximum <br />
1.870072e-05 3.831524e-03 3.832255e-03 -1.414417e-02 1.109403e-02 <br />
<br />
TWHydra_contall_2pcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2466 1.159416e-01 3.512963e-03 <br />
Mean Rms Std dev Minimum Maximum <br />
4.701606e-05 3.811716e-03 3.812199e-03 -1.383034e-02 1.078456e-02 <br />
</pre><br />
<br />
This small improvement suggests that we have gone as far as we can with phase self-cal.<br />
<br />
===Continuum Data Amplitude Self-Calibration===<br />
<br />
Now we will apply the best phase solution table on-the-fly while solving for the amplitude self-cal solutions. Since amplitude changes more slowly and is less constrained than phase, we use a longer '''solint='inf'''', as long as '''combine=' '''' this means to do one solution per scan. <br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='TWHydra_cont.ms',caltable='self_ap.cal',<br />
solint='inf',combine='',gaintype='T',<br />
refant='DV06',spw='',minblperant=4,<br />
gaintable=['self_2.pcal'],<br />
calmode='ap',minsnr=2)<br />
</source><br />
<br />
It's useful to look at the residual phase in the amplitude calibration table, i.e. since we applied our best phase-only solution while solving for this new amplitude and phase ('''calmode='ap'''') solution, the phase should already be corrected.<br />
<br />
<figure id="Self_ap_phase.png"><br />
[[Image:Self_ap_phase.png|thumb|<caption>Residual phase solutions from self_ap.cal.</caption>]]<br />
</figure><br />
<figure id="Self_ap_amp.png"><br />
[[Image:Self_ap_amp.png|thumb|<caption>Amplitude solutions from self_ap.cal.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_ap.cal',xaxis='time',yaxis='phase',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,-1,1],figfile='self_ap_phase.png')<br />
</source><br />
<br />
The residuals are very small as expected. (If you see large residuals here, it means that the phase-only solution is suspect, and you were mostly just moving noise around.) Now look at the amplitude solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_ap.cal',xaxis='time',yaxis='amp',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,0.6,1.4],figfile='self_ap_amp.png')<br />
</source><br />
<br />
For the most part these look very good except one rather large deviation on DV06. Apply both the final phase and the amplitude calibration tables.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_cont.ms',field='',gaintable=['self_2.pcal','self_ap.cal'],calwt=F)<br />
</source><br />
<br />
Plot the corrected data as a function of both time and uv-distance. It is always a good idea to check these after an amplitude self-calbration to be sure that it worked properly. Occasionally, a few spurious bits of data will get blown up by the amplitude self-cal if it is not well-constrained. <br />
<br />
<figure id="Selfcal_time.png"><br />
[[Image:Selfcal_time.png|thumb|<caption>Post self-calibration amplitude vs. time</caption>]]<br />
</figure><br />
<figure id="Selfcal_uvdist.png"><br />
[[Image:Selfcal_uvdist.png|thumb|<caption>Post self-calibration amplitude vs. uv-distance</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',xaxis='time',yaxis='amp',<br />
avgchannel='38',ydatacolumn='corrected',coloraxis='spw',<br />
plotfile='selfcal_time.png')<br />
</source><br />
<br />
The time where we saw a large amplitude correction on DV06 looks consistent here so the large correction we saw in the solutions corrected a real issue. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',xaxis='uvdist',yaxis='amp',<br />
avgchannel='38',ydatacolumn='corrected',coloraxis='spw',<br />
plotfile='selfcal_uvdist.png')<br />
</source><br />
<br />
You will see that this plot looks much better than before. <br />
<br />
<figure id="Viewer_apcal.png"><br />
[[Image:Viewer_apcal.png|thumb|<caption>Clean residuals after final amplitude and phase self-cal.</caption>]]<br />
</figure><br />
<br />
Now make the final continuum image.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_apcal.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall_apcal',<br />
mode='mfs',imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5,usescratch=False,<br />
mask='TWHydra_contall_2pcal.mask',<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
We know we need to clean at least 300 iterations, so set this in the gui and hit the round green arrow. After this notice how much better the residual looks. Clean another 100 iterations. The "circular pattern", and 4 bright spots at each corner you see now in the residual is likely due to non-closing amplitude errors that cannot be removed with an antenna based self-calibration, so this is as good as it gets with pure self-cal. Hit the Red X to stop clean.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Clean used 100 iterations to approach a threshhold of 0.00105507<br />
0.0061808 Jy <- cleaned in this cycle for model 0<br />
Final maximum residual = 0.00242926<br />
Model 0: max, min residuals = 0.00238278, -0.00242926 clean flux 1.48201<br />
</pre><br />
<br />
Now repeat the display, blinking, and image statistics described above for the 2nd phase only and the new amplitude & phase self-cal'ed images.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(raster=[{'file':'TWHydra_contall_2pcal.image','range':[-0.01,0.05]},<br />
{'file':'TWHydra_contall_apcal.image','range':[-0.01,0.05]}])<br />
</source><br />
<br />
The amplitude and phase self cal'ed image is notably better than phase-only. Quantitatively:<br />
<pre style="background-color: #fffacd;"><br />
<br />
TWHydra_contall_2pcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 3542 2.053068e-01 6.220676e-03 <br />
Mean Rms Std dev Minimum Maximum <br />
5.796351e-05 3.955967e-03 3.956101e-03 -1.383034e-02 1.078456e-02 <br />
<br />
TWHydra_contall_apcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 3542 6.044652e-04 1.831495e-05 <br />
Mean Rms Std dev Minimum Maximum <br />
1.706565e-07 1.270183e-03 1.270362e-03 -4.980673e-03 4.137159e-03 <br />
</pre> <br />
<br />
and indeed, we've gained another factor of 3 in sensitivity. <br />
<br />
'''Overall with this self-calibration we've improved the noise by a factor of 6.7! With a peak flux density of 0.98 Jy, the S/N increased from 115 initially to 770 after. So, well worth the trouble.'''<br />
<br />
<div class="noprint" style="float:none; border:0px solid blue;background-color:#F6CEF5;padding:2px;"><br />
If you have used the '''standard='Butler-JPL-Horizons 2012' ''' model during the calibration process, you should see an increase in peak flux density of about 3%.<br />
</div><br />
<br />
It is notable that we are still a factor of more than 4 from the apriori noise estimate of 0.3 mJy/beam. This is likely due to residual sources of non-closing (not antenna based) errors in the data like baseline errors and baseline-dependent bandpass errors. Additionally, polarization errors (which we did not calibrate at all) can contribute, as well as imperfect uv-coverage with only 8 antennas. A dynamic range of 770 is actually quite good in the submillimeter.<br />
<br />
==Apply self-calibration to Full Dataset and Split Line Data==<br />
<br />
Now apply the self-calibration derived from the continuum emission to the full unchannel-averaged data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_corrected.ms',gaintable=['self_2.pcal','self_ap.cal'],calwt=F)<br />
</source><br />
<br />
Split off the CO(3-2) spectral line data in spw=2 and the HCO+(4-3) data in spw=0 for further processing.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2.ms*')<br />
split(vis='TWHydra_corrected.ms',outputvis='TWHydra_CO3_2.ms',datacolumn='corrected',spw='2')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplus.ms*')<br />
split(vis='TWHydra_corrected.ms',outputvis='TWHydra_HCOplus.ms',datacolumn='corrected',spw='0')<br />
</source><br />
<br />
==Continuum Subtraction== <br />
<br />
Next we need to subtract the continuum emission from the spectral line data. It is best to do this in the uv-plane. The first step is to make a channel plot of the spectral data to get the line-free channel ranges for both spectral lines. Since the line emission is simple (one spectral line per spw) and there are more than enough line-free channels we do not need to be very precise just stay well away from the line and whenever possible it is best to chose line-free channel ranges on either side of the line for the best possible baseline subtraction. <br />
<br />
<figure id="CO3_2_channel.png"><br />
[[Image:CO3_2_channel.png|thumb|<caption>CO(3-2) line in channel space.</caption>]]<br />
</figure><br />
<figure id="HCOp4_3_channel.png"><br />
[[Image:HCOp4_3_channel.png|thumb|<caption>HCO+(4-3) in channel space.</caption>]]<br />
</figure><br />
<br />
'''Note''': after the split above, the original spw ids will be relabeled as 0 in each file because there is only one spectral window in each file.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_CO3_2.ms',spw='0',xaxis='channel',yaxis='amp',<br />
avgtime='1e8',avgscan=T,coloraxis='spw',plotfile='CO3_2_channel.png')<br />
</source><br />
<br />
It is a good idea to stay a little away from the very edges of the baseband which can be noisy. The channel ranges <br />
20~2000 and 2400~3800 look like good choices for CO(3-2).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_HCOplus.ms',spw='0',xaxis='channel',yaxis='amp',<br />
avgtime='1e8',avgscan=T,coloraxis='spw',plotfile='HCOp4_3_channel.png')<br />
</source><br />
<br />
The channel ranges 20~1500 and 1900~3800 look like good choices for HCO+(4-3).<br />
<br />
Next use the identified line-free channel ranges and {{uvcontsub}} to subtract the continuum model from the line emission.<br />
<br />
<source lang="python"><br />
# In CASA<br />
uvcontsub(vis='TWHydra_CO3_2.ms',fitorder=1,fitspw='0:20~2000,0:2400~3800')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
uvcontsub(vis='TWHydra_HCOplus.ms',fitorder=1,fitspw='0:20~1500,0:1900~3800')<br />
</source><br />
<br />
Note: If you do not have line-free channels on both sides of the line emission, it is safer to use '''fitorder=0''', or the fit may diverge.<br />
<br />
==Spectral Line Imaging==<br />
<br />
Now we are ready to make cubes of the line emission. The imaging parameters are similar to the continuum except for <br />
those dealing with the spectral setup: '''mode''', '''start''', '''width''', '''nchan''', '''restfreq''', and '''outframe''' parameters. When making spectral images you have three choices for the '''mode''' parameter: '''channel''', '''velocity''', and '''frequency'''. Data are taken using constant frequency channels. For spectral line analysis it's often more useful to have constant velocity channels, and this is also the best way to make images of multiple lines with the exact same channelization for later comparison. For '''mode='velocity'''', the desired '''start''' and '''width''' also need to be given in velocity units for the desired output frame. <br />
<br />
It is important to note that ALMA does not do on-line Doppler Tracking and the native frame of the data is TOPO. If you do not specify '''outframe''' the output cube will also be in TOPO, which is not very useful for spectral line work. The Doppler Shift is taken out during the regridding to the desired outframe in {{clean}} or alternatively it can be done separately by the {{cvel}} task which would need to be run before {{clean}}. <br />
<br />
<figure id="CO3_2_vel.png"><br />
[[Image:CO3_2_vel.png|thumb|<caption>CO(3-2) spectrum in LSRK velocity space.</caption>]]<br />
</figure><br />
<figure id="HCOp4_3_vel.png"><br />
[[Image:HCOp4_3_vel.png|thumb|<caption>HCO+(4-3) spectrum in LSRK velocity space.</caption>]]<br />
</figure><br />
<br />
To see what velocity parameters you want to set in clean it is useful to make a plot in {{plotms}} in the desired output frame. To make it easier to see, we set a '''plotrange''' since we know the LSRK velocity of TW Hya is about 2.88 km/s. Note these plots take a little longer because of the frame shift.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_CO3_2.ms.contsub',xaxis='velocity',yaxis='amp',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',<br />
restfreq='345.79599GHz',plotrange=[-20,23,0,0],plotfile='CO3_2_vel.png')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_HCOplus.ms.contsub',xaxis='velocity',yaxis='amp',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',<br />
restfreq='356.7342GHz',plotrange=[-20,23,0,0],plotfile='HCOp4_3_vel.png') <br />
</source><br />
<br />
From these plots it looks like imaging the cubes from about -5 to +8 km/s will encompass the line, but still provide several line-free channels on either side so the noise level can be estimated. The channel width is 122 kHz, which at <br />
345.79599 GHz is 0.106 km/s. Recall that the spectral ''resolution'' is a factor of two poorer. We will use a velocity channel width of 0.12 km/s for a little oversampling, but the spectral resolution remains 0.2 km/s.<br />
<br />
As before, it is very important that you make a clean mask. There are many ways to do this ranging from the complicated to simple. For this example we will make a single clean mask that encompasses the line emission in every channel and apply it to all channels. This is much better than no clean mask, though not quite as good as making an individual mask for each channel. For some sources, one can use the continuum mask to clean the line, however TW Hya is a bit curious in that the continuum emission is not as extended as the line emission (Hughes et al. 2008).<br />
<br />
=== CO(3-2) Imaging ===<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.*')<br />
clean(vis='TWHydra_CO3_2.ms.contsub',imagename='TWHydra_CO3_2line',<br />
imagermode='csclean',spw='',<br />
imsize=100,cell=['0.3arcsec'],<br />
mode='velocity',start='-4km/s',width='0.12km/s',nchan=118,<br />
restfreq='345.79599GHz',outframe='LSRK',<br />
weighting='briggs',robust=0.5,<br />
mask='',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=100000)<br />
</source><br />
<br />
<figure id="Viewer_55.png"><br />
[[Image:Viewer_55.png|thumb|<caption>Interactive Viewer window with CO(3-2) clean mask, before cleaning starts.</caption>]]<br />
</figure><br />
<figure id="Viewer_500.png"><br />
[[Image:Viewer_500.png|thumb|<caption>Interactive Viewer window for CO(3-2), after 500 iterations, more cleaning is needed.</caption>]]<br />
</figure><br />
<br />
It will take a little while to grid the cube, when the interactive viewer opens, use the tapedeck to cycle through the channels. You should see a progress of line emission in channels 40 to 70 or so.<br />
*Go to channel 57 (about line center)<br />
*Select the polygon tool with the left mouse button<br />
*Select the "All Channels" toggle in the green area<br />
*Draw a polygon around the channel 57 emission, double click inside to activate.<br />
*Now go to channel 60, this is the channel with the most extent to the SE, draw another polygon that encompasses this emission if necessary,double click inside to activate.<br />
*Now go to channel 55, this is the channel with the most extent to the NW, draw another polygon that encompasses this emission if necessary,double click inside to activate. <br />
*Now double check the mask by cycling through channels with real line emission to be sure that your clean box encompasses the emission, but does not extend far beyond it. Again the "erase" toggle can come in handy if things go awry or if you want to just delete a small portion of an existing mask (just draw a polygon around what you want to erase and double click inside), be sure to switch back to "add" before going on.<br />
<br />
The figure shows what the final clean box should look like. Now clean using the green circle arrow. You can watch the progress in the logger. When 100 iterations are done, the viewer will show the residual map for each channel. Cycle through the channels and see whether you are still happy with the clean box in each signal channel. The "erase button" can help you fix mistakes. If necessary adjust. It is often useful to adjust the colorscale with the "plus" symbol icon. Keep going until the residual emission looks like the surrounding noise. If it seems to be going slowly, increase the iterations to 300 for a round or two. I stopped cleaning (Red x) when the logger showed (about 900 iterations). <br />
<pre style="background-color: #fffacd;"><br />
12.9846 Jy <- cleaned in this cycle for model 0<br />
Final maximum residual = 0.157312<br />
Model 0: max, min residuals = 0.157312, -0.0871295 clean flux 279.304<br />
</pre><br />
<br />
NOTE: The residuals are still a bit high in the strongest emission channels after it is well cleaned in the weaker channels. This is an indication that the sensitivity is "dynamic range" limited. In other words even with more <br />
intrinsic sensitivity per integration (i.e. better system temperature), the dynamic range limit would remain the same unless you get more uv-coverage. The fundamental dynamic range limitations of ALMA will be considerably better with 16 antennas in Early Science and MUCH better with the full 50-antenna array.<br />
<br />
=== HCO+(4-3) Imaging ===<br />
<br />
Now image and clean the HCO+(4-3) line using what you learned above.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.*')<br />
clean(vis='TWHydra_HCOplus.ms.contsub',imagename='TWHydra_HCOplusline',<br />
imagermode='csclean',spw='',<br />
imsize=100,cell=['0.3arcsec'],<br />
mode='velocity',start='-4km/s',nchan=118,width='0.12km/s',<br />
restfreq='356.7342GHz',outframe='LSRK',<br />
weighting='briggs',robust=0.5,<br />
mask='',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=100000)<br />
</source><br />
<br />
I stopped cleaning when: <br />
<pre style="background-color: #fffacd;"><br />
4.79833 Jy <- cleaned in this cycle for model 0<br />
Final maximum residual = 0.0977348<br />
Model 0: max, min residuals = 0.0977348, -0.060484 clean flux 192.066<br />
</pre><br />
<br />
==Image Analysis==<br />
<br />
After all that hard work you now have deconvolved images of the 350 GHz continuum, the CO (3-2) line, and the HCO+ (4-3) line. CASA includes tools to help you understand the contents of these images and make basic scientific measurements. These tools are divided between graphical exploration tools, accessible via the CASA viewer, and command line analysis tasks. To access the viewer, simply type '''viewer()''' and to see the list of analysis tasks available in CASA type '''tasklist''' at the CASA prompt and look under the Analysis sub-heading.<br />
<br />
If you want to do this portion of the guide and have downloaded the (.FITS) reference images, you can import them to be CASA images using '''importfits'''. If you are re-importing the images, use the commented remove command, here, to delete the previous import first.<br />
<br />
<source lang="python"><br />
# In CASA<br />
# os.system("rm -rf TWHydra_CO3_2line.image")<br />
importfits(fitsimage="TWHydra_CO3_2line.image.fits", imagename="TWHydra_CO3_2line.image")<br />
</source><br />
<br />
where '''fitsimage''' refers to the file to imported and '''imagename''' gives the output filename. If you are proceeding directly from the imaging step, your data are already CASA images and you may proceed without any importing.<br />
<br />
You can get the basic properties of any CASA image using the '''imhead''' command. For example, type <br />
<br />
<source lang="python"><br />
# In CASA<br />
imhead("TWHydra_CO3_2line.image")<br />
</source><br />
<br />
and look at the CASA logger. You will see an image summary like the following<br />
<br />
<pre style="background-color: #fffacd;"><br />
INFO imhead ##########################################<br />
INFO imhead ##### Begin Task: imhead #####<br />
INFO imhead imhead(imagename="TWHydra_CO3_2line.image",mode="summary",hdkey="",hdvalue="",<br />
INFO imhead hdtype="",hdcomment="",verbose=False)<br />
INFO ImageAnalysis <br />
INFO ImageAnalysis Image name : TWHydra_CO3_2line.image<br />
INFO ImageAnalysis Object name : TW Hya<br />
INFO ImageAnalysis Image type : PagedImage<br />
INFO ImageAnalysis Image quantity : Intensity<br />
INFO ImageAnalysis Pixel mask(s) : None<br />
INFO ImageAnalysis Region(s) : None<br />
INFO ImageAnalysis Image units : Jy/beam<br />
INFO ImageAnalysis Restoring Beam : 1.68065 arcsec, 1.53193 arcsec, 22.3015 deg<br />
INFO ImageAnalysis <br />
INFO ImageAnalysis Direction reference : J2000<br />
INFO ImageAnalysis Spectral reference : LSRK<br />
INFO ImageAnalysis Velocity type : RADIO<br />
INFO ImageAnalysis Rest frequency : 3.45796e+11 Hz<br />
INFO ImageAnalysis Pointing center : 11:01:51.844983 -34.42.17.160885<br />
INFO ImageAnalysis Telescope : ALMA<br />
INFO ImageAnalysis Observer : Unknown<br />
INFO ImageAnalysis Date observation : 2011/04/22/00:15:42<br />
INFO ImageAnalysis Telescope position: [2.22514e+06m, -5.44031e+06m, -2.48103e+06m] (ITRF)<br />
INFO ImageAnalysis <br />
INFO ImageAnalysis Axis Coord Type Name Proj Shape Tile Coord value at pixel Coord incr Units<br />
INFO ImageAnalysis -------------------------------------------------------------------------------------------------- <br />
INFO ImageAnalysis 0 0 Direction Right Ascension SIN 100 25 11:01:51.845 50.00 -3.000000e-01 arcsec<br />
INFO ImageAnalysis 1 0 Direction Declination SIN 100 25 -34.42.17.161 50.00 3.000000e-01 arcsec<br />
INFO ImageAnalysis 2 2 Spectral Frequency 118 59 3.45801e+11 0.00 -1.38414152e+05 Hz<br />
INFO ImageAnalysis Velocity -4 0.00 1.200000e-01 km/s<br />
INFO ImageAnalysis 3 1 Stokes Stokes 1 1 I<br />
INFO imhead ##### End Task: imhead #####<br />
INFO imhead ##########################################<br />
<br />
</pre><br />
<br />
This report tells you about the target, shape, and coordinates of the image. It also notes the rest frequency and some details of the observation. '''imhead''' may be used more generally to retrieve header keywords as python variables or to manipulate the header of an image. Consult the help for details.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
You may want to pay particular attention to the third and fourth axis of the CASA image. These are <br />
usually frequency (velocity) and Stokes (polarization) in some order. An occasional source of confusion <br />
is that this order is not always the same. Often CLEAN will output images with the Stokes axis third, <br />
while IMPORTFITS usually yields images with the frequency axis third. If you encounter problems with<br />
image analysis tasks, you may want to check whether this results from conflicting axis definitions. You<br />
can adjust the order of the axes using the IMTRANS task.<br />
</pre><br />
<br />
Before proceeding, make sure that you have all three data sets as CASA images: '''TWHydra_CO3_2line.image''', '''TWHydra_HCOPlusline.image''', and '''TWHydra_contall_apcal.image'''. If you do not, then import them from the provided reference images. If you are re-importing the FITS images, run the commented remove commands before running importfits.<br />
<br />
<source lang="python"><br />
# In CASA<br />
# os.system("rm -rf TWHydra_CO3_2line.image")<br />
importfits(fitsimage="TWHydra_CO3_2line.image.fits", imagename="TWHydra_CO3_2line.image")<br />
# os.system("rm -rf TWHydra_HCOplusline.image")<br />
importfits(fitsimage="TWHydra_HCOplusline.image.fits", imagename="TWHydra_HCOplusline.image")<br />
# os.system("rm -rf TWHydra_contall_apcal.image")<br />
importfits(fitsimage="TWHydra_contall_apcal.image.fits", imagename="TWHydra_contall_apcal.image")<br />
</source><br />
<br />
In the rest of this guide we will construct ''moment maps'' showing the integrates, velocity field, and line width of the two lines. We will carry out Gaussian fits to the continuum and line maps. We will also illustrate some of the additional analysis capabilities available in CASA: subcube extraction, retrieval of data into python arrays, cube alignment, smoothing, and overlays of multiple spectral lines.<br />
<br />
===Moment Maps===<br />
<br />
The line "images" of CO(3-2) and HCO+(4-3) are, of course, cubes rather than images. Two dimensional ''moment maps'' are a standard way to present such data. These are maps showing the result of various moments (or similar calculations) carried out along the frequency axis of the cube. For example, the "moment 0" map is the sum of emission along the frequency axis at each pixel. The first moment is the intensity-weighted velocity (or frequency). The second moment is the intensity-weighted velocity (or frequency) dispersion about the mean. These and a number of other calculations (for example the maximum intensity) can be calculated via the '''immoments''' task. Consult the help or the CASA cookbook for more details.<br />
<br />
In this section, we will calculate moments for our two spectral line data cubes. To make the highest quality moment maps, we will first identify the planes of the data cube that contain emission, so that we can carry out the sum only over these channels. Doing otherwise adds noise to the moment map without adding signal and so lowers the signal-to-noise ratio of the final image. For the first and second moments we will identify an intensity threshold above which the data are statistically very likely to correspond to real astronomical emission. We will restrict the calculation to consider only data above this threshold, yielding a cleaner calculation (the second moment, in particular, is not at all robust against the inclusion of outlying noise). Finally, we will inspect the resulting moment maps with the viewer and output them to .FITS files.<br />
<br />
====Estimate the Spectral Extent====<br />
<br />
First, we want to figure out what planes appear to contain real emission. Open the CO data cube with the CASA viewer via:<br />
<br />
<source lang="python"><br />
# In CASA<br />
viewer("TWHydra_CO3_2line.image")<br />
</source><br />
<br />
This will open the CO(3-2) data cube as a raster image. Use the Animator pane to scroll through the cube, noting that the emission is mostly confined to ~40 channels near the center of the cube. There are several ways to make a more rigorous estimate. <br />
<br />
''By-Plane Inspection:'' First, you could increase the stretch of the image to identify by hand the first and last channels with visible emission. To do open the Data Display Options panel in the viewer (the wrench icon) and manually set the data range and/or scaling power cycles to highlight faint emission (note that you can also do this using the mouse and the color stretch - sun - icon). I left the scaling power cycles at 0 and set the data range to [-0.15, 0.15]. Then scroll through the cube and note the first and last channels with obvious emission. If I do this, I find emission from about plane 30 through plane 86.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:DataDisplayPanelStretch.png|The Data Display Panel used to set the color stretch, here from [-0.15, 0.15] with a linear (0) stretch. Setting the stretch to a negative value will highlight lower emission (a more logarithmic stretch). We got to this panel by clicking the wrench icon. You can also get from the dropdown menus (Data->Adjust).<br />
File:TWHydraCOChan33.png|Channel 33 of the CO(3-2) cube on this stretch. This is about the first channel to show clear emission.<br />
File:TWHydraCOChan80.png|Channel 80 of the CO(3-2) cube on this stretch. This is about the last channel to show clear emission.<br />
</gallery><br />
</center><br />
<br />
To make this more rigorous, you can work out a noise estimate before hand (we'll find it to be about 0.025 Jy/beam) and overplot a contour to indicate significant emission. You can do this by hand by using the Data Manager (folder icon) to open TWHydra_CO3_2line.image as a "contour map" and then using the Data Display Options to manipulate the contour levels. To show a 3-sigma contour with sigma=0.025 Jy/beam set the Relative Contour Levels to [3], the Base Contour Level to 0, and the Unit Contour Level to 0.025. You can display a 5-sigma contour or change the RMS analogously. Scrolling through the cube, I see 3-sigma emission from channels 33 through 80.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:DataDisplayPanelContour.png|The Data Display Panel now being used to set the contour levels. We set the contour unit to 0.025 and ask for a single contour at 3 times this value. Notice that we clicked the tab along the top of the window to select the contour map.<br />
File:TWHydraCOChan33Contour.png|Channel 33 of the CO(3-2) cube on this stretch with a 3-sigma contour overlaid.<br />
File:TWHydraCOChan80Contour.png|Channel 80 of the CO(3-2) cube on this stretch with a 3-sigma contour overlaid.<br />
</gallery><br />
</center><br />
<br />
''Look at a Spectrum:'' You can also look at a spectrum of the source. To do this, scroll to a channel with a lot of emission (I went to 57) and then use the mouse to drag out a rectangle. To do this, left click on the rectangle box in the mouse toolbar (this assigns the left mouse button to define rectangle regions). Then drag out a box around the emission using the same button. Now click the spectrum in the toolbar to open the spectral profile tool. You will see the average profile for the selected region. You can set the bottom axis to show channels. You can zoom in within the spectral profile by dragging out a rectangle. When I do this, I find significant emission from channels 40-80.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:TWHydraRectangle.png|Defining a rectangular region around the main emission from TW Hydra. First we clicked the rectangle button on the mouse toolbar, then we held that button and dragged out the purple rectangle. After defining the rectangle, you can drag it around or delete it with <ESC>.<br />
File:TWHydraSpectrum.png|The spectrum of this rectangular region viewed in the spectral profile browser. Note that the bottom axis has been set to show channels. To get this spectrum, we defined the rectangular region and then clicked the spectrum button on the toolbar.<br />
File:TWHydraSpectrumZoom.png|A zoom in on the spectrum. The line extends from channels ~40-80.<br />
</gallery><br />
</center><br />
<br />
''Look at a Declination-Frequency Projection (or an R.A.-Frequency Projection):'' This is probably the least reliable way to do this, but illustrates a neat capability of the viewer. Open the Data Display Options (click the wrench icon) and open the "display axes" and "hidden axes" tabs. Use the dropdown menus to change the display so that the x-axis shows Declination, the y-axis shows Frequency, and the z-axis shows "Right Ascension." Now you are scrolling through planes of intensity as a function of Declination and Frequency. Use the animator to move to R.A. plane ~ 50 (the center of the source) and pull the stretch up (in the wrench tool; I used [-0.15,0.15] again). Mouse over the image and look at the "Position Tracking" pane in the bottom of the image, noting the pixel extent of emission in the frequency axis of this plane. I see traces of emission from channel ~30-90.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:DataDisplayPanelAxes.png|The Data Display Panel, here used to set which axes are displayed. We have adjusted the y-axis to show frequency and the x-axis to show Declination. The z-axis is now Right Ascension, so that we will scroll through planes of Right Ascension.<br />
File:DataDisplayPanelPixels.png|The Data Display Panel, here we are setting coordinates to show "pixels" rather than world coordinates.<br />
File:TWHydraDecFreqPixels.png|A Frequency-Declination plane of the cube near the central R.A. pixel (50). The rough extent of emission may be simply read off the y-coordinate. As above, we could overplot a 3-sigma contour to add more rigor.<br />
</gallery><br />
</center><br />
<br />
<br />
You can repeat this exercise for the HCO+ (4-3) emission. Using the Spectral Profile Browser, I find that the line extends from about channel 40 through channel 75.<br />
<br />
====Make Moment 0 Maps====<br />
<br />
With an estimate of the spectral extent of emission, we are now ready to make moment 0 maps of the CO(3-2) and HCO+(4-3) lines. We do this using the '''immmoments''' command,<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom0')<br />
immoments(imagename='TWHydra_CO3_2line.image',moments=[0],<br />
outfile='TWHydra_CO3_2line.image.mom0',<br />
chans='30~90')<br />
</source><br />
<br />
and<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom0')<br />
immoments(imagename='TWHydra_HCOplusline.image',moments=[0],<br />
outfile='TWHydra_HCOplusline.image.mom0',<br />
chans='40~75')<br />
</source><br />
<br />
immoments will sum across the channels specified by '''chans''' and produce new CASA images with the names specified by '''outfile'''. These can be inspected using the CASA viewer just like any other image. Note that unlike higher-order moments, the moment-0 map is robust to the inclusion of noisy signal-free channels (to within reason, you just decrease your signal-to-noise ratio) and indeed may be biased to miss faint emission by imposing a threshold. For that reason, we will eschew the '''includepix''' keyword as we make the moment 0 maps.<br />
<br />
Let's look at the output using the viewer. We can specify some of the display options in the call to start the viewer by using '''imview''' instead of '''viewer'''.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview( raster=[ {'file':'TWHydra_CO3_2line.image.mom0',<br />
'range':[0.0,10.],<br />
'scaling':-1},<br />
{'file':'TWHydra_HCOplusline.image.mom0',<br />
'range':[0.0,10.],<br />
'scaling':-1}], <br />
contour={'file':'TWHydra_contall_apcal.image', 'base':0, 'unit':0.0025, 'levels':[3,100]} )<br />
</source><br />
<br />
This does several things: It opens the viewer with raster images of the moment 0 maps of CO(3-2) and HCO+(4-3), sets the range of the color stretch from [0, 10] for each image and sets the scaling to be -1, which highlights faint emission compared to the normal (0) stretch. It also opens the continuum image as a contour and defines two contour levels. Once the viewer is open, you can blink between the images by going into the Animator pane, checking the white box next to "Images" to enable animation between images, and then sliding the bar back and forth. See the name of the image being shown change. You can also show two images side by side by going to the Viewer Canvas Manager (wrench+P icon) and opening the "Number of Panels" tab. Set the "Number of panels in x" to 2 and make sure that the Images box is checked in the Animator pane. You will see both images side by side.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:CanvasManagerPanels.png|The Viewer Canvas Manager, accessed via the Wrech+P icon (not to be confused with the plain old wrench). Here we have adjusted the number of x-panels from 1 to 2 so that we show the two moment maps side by side.<br />
File:TWHydraMoment0Maps.png|The moment-0 maps of CO(3-2) and HCO+(4-3) plotted side by side on the same color stretch, both with the continuum contours overlaid. To get the two images side by side, run the imview call above then set the number of panels to 2 and make sure that the Images box in the Animator Pane (here at the bottom of the window) is checked.<br />
File:DataDisplayImview.png|Data Display Panel after our imview call. Imview allowed us to set the stretch, range, and contour levels from the command line.<br />
</gallery><br />
</center><br />
<br />
====Estimate the Noise====<br />
<br />
We have already made a few offhand comparisons to the RMS noise. This quantity is often critical to know when exploring the data. Because the higher-order moments (especially the dispersion) are not at all robust to the inclusion of noise, we will calculate them only from regions of the cube that have intensity several times the RMS noise value or higher and are thus very likely to contain real astronomical emission. To proceed, we need to estimate the RMS noise for our data.<br />
<br />
The easiest way to do this is to calculate the RMS scatter of the data about zero from a part of the data that you suspect to be (mostly) free of astronomical signal. In a data cube the easiest way to do this will often be to identify signal-free planes (channels) of the cube and to simply calculate the RMS in these regions. We can do this straightforwardly using the '''imstat''' command in CASA.<br />
<br />
IMSTAT COMMAND<br />
<br />
IMSTAT OUTPUT<br />
<br />
Alternatively, you can get similar statistics on a region of an image or data cube selected manually inside the viewer. Drag out a region, for example a rectangle, using one of the mouse tools. Then <br />
<br />
IMAGES OF REGION SELECTION, OUTPUT, REGION MANAGER<br />
<br />
Suggested values for CO(3-2), HCO+(4-3), and continuum. Short discussion of dynamic range limited vs. line-free channels.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
A note on primary beam corrections and noise.<br />
</pre><br />
<br />
====Higher Order Moment Maps for CO(3-2)====<br />
<br />
For higher order moments it is very important to set a conservative flux <br />
threshold. Typically something like 6 sigma, using sigma from peak line channel, works well.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom')<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_coord')<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_dispersion_coord')<br />
immoments(imagename='TWHydra_CO3_2line.image',moments=[1,2],<br />
outfile='TWHydra_CO3_2line.image.mom',<br />
chans='40~76',includepix=[0.3,100])<br />
</source><br />
<br />
Display all three moment maps in the viewer, overlaid with continuum contours.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview( raster=[ {'file':'TWHydra_CO3_2line.image.mom0'},<br />
{'file':'TWHydra_CO3_2line.image.mom.weighted_coord'},<br />
{'file':'TWHydra_CO3_2line.image.mom.weighted_dispersion_coord'} ], <br />
contour={'file':'TWHydra_contall_apcal.image', 'base':0, 'unit':0.0025, 'levels':[3,100]} )<br />
</source><br />
<br />
To see all three raster images simultaneously, open the viewer's Panel Display Options (the "P-wrench" icon in the viewer tool bar), click "Number of panels", and change "Number of panels in x" to 3. Then select the "Blink" toggle (radio button) from the Animator panel.<br />
<br />
<figure id="TWHya_CO3_2_moments.png"><br />
[[Image:TWHya_CO3_2_moments.png|center|800px|frame|<caption>ALMA CO(3-2) moment maps, with white continuum contours at 3 and 100 sigma. From left to right: integrated intensity, intensity weighted velocity field, intensity weighted velocity dispersion are shown.</caption>]]<br />
</figure><br />
<br />
Repeat for HCO+(4-3) which has a bit narrower velocity extent than the CO(3-2), but similar rms noise.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom0')<br />
immoments(imagename='TWHydra_HCOplusline.image',moments=[0],<br />
outfile='TWHydra_HCOplusline.image.mom0',<br />
chans='43~74')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom')<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_coord')<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_dispersion_coord')<br />
immoments(imagename='TWHydra_HCOplusline.image',moments=[1,2],<br />
outfile='TWHydra_HCOplusline.image.mom',<br />
chans='43~74',includepix=[0.3,100])<br />
</source><br />
<br />
Display all three moment maps in the viewer using the same method described above for the CO(3-2) maps.<br />
<br />
<figure id="TWHya_HCOp4_3_moments.png"><br />
[[Image:TWHya_HCOp4_3_moments.png|center|800px|frame|<caption>ALMA HCO+(4-3) moment maps, with white continuum contours at 3 and 100 sigma. From left to right: integrated intensity, intensity weighted velocity field, intensity weighted velocity dispersion are shown.</caption>]]<br />
</figure><br />
<br />
=====Exporting Fits Images=====<br />
<br />
If you want to analyze the data using another software package it is easy to convert from CASA format to FITS. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image',fitsimage='TWHydra_CO3_2line.image.fits')<br />
</source><br />
<br />
Although "FITS format" is supposed to be a standard, in fact most packages expect slightly different things from a FITS image. If you are having difficulty, try setting '''velocity=T''' and/or '''dropstokes=T'''.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf TWHydra_HCOplusline.image.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image',fitsimage='TWHydra_HCOplusline.image.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom0.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image.mom0',<br />
fitsimage='TWHydra_CO3_2line.image.mom0.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_coord.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image.mom.weighted_coord',<br />
fitsimage='TWHydra_CO3_2line.image.mom.weighted_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_dispersion_coord.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image.mom.weighted_dispersion_coord',<br />
fitsimage='TWHydra_CO3_2line.image.mom.weighted_dispersion_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom0.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image.mom0',<br />
fitsimage='TWHydra_HCOplusline.image.mom0.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_coord.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image.mom.weighted_coord',<br />
fitsimage='TWHydra_HCOplusline.image.mom.weighted_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_dispersion_coord.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image.mom.weighted_dispersion_coord',<br />
fitsimage='TWHydra_HCOplusline.image.mom.weighted_dispersion_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_apcal.image.fits')<br />
exportfits(imagename='TWHydra_contall_apcal.image',fitsimage='TWHydra_contall_apcal.image.fits')<br />
</source><br />
<br />
===Display Channel Maps===<br />
<br />
Using the Viewer you can make channel map figures. Start the Viewer and then open the CO(3-2) cube as a raster image and then the continuum as a contour image. Then we use the "wrench" icon and "P wrench" icons to set up the channel images, contour levels etc. (If you need help setting up the viewer for this image, see a screen shot of the viewer setup windows, below.)<br />
<br />
<figure id="TWHya_channel_co3_2.png"><br />
[[Image:TWHya_channel_co3_2.png|center|frame|<caption>Channel maps of the CO(3-2) emission with white continuum contours at 3 and 100 sigma.</caption>]]<br />
</figure><br />
<br />
<figure id="Viewer_setup.png"><br />
[[Image:Viewer_setup.png|center|thumb|500px|<caption>The setup windows looked like this</caption>]]<br />
</figure><br />
<br />
Repeat for HCO+(4-3)<br />
<br />
<figure id="TWHya_channel_HCOp4_3.png"><br />
[[Image:TWHya_channel_HCOp4_3.png|center|thumb|800px|<caption>Channel maps of the HCO+(4-3) emission with white continuum contours at 3 and 100 sigma. The color intensity scale is the same as that used for CO(3-2).</caption>]]<br />
</figure><br />
<br />
<!--<br />
====Examine CO Contours on an HCO+ Raster====<br />
<br />
====Matched Movies====<br />
<br />
===Image Plane and Spectral Fits===<br />
<br />
====Fit a Gaussian to the Continuum====<br />
<br />
=====Fit In the Viewer=====<br />
<br />
=====Fit Using the Command Line=====<br />
<br />
====Fit a Gaussian to the CO Line====<br />
<br />
=====Fit In the Viewer=====<br />
<br />
=====Fit Using the Command Line=====<br />
<br />
===Extract a Sub-Image===<br />
<br />
===Align Image Cubes===<br />
--><br />
<br />
{{Checked 4.3.0}}</div>Sstierwahttps://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_4.3&diff=19483TWHydraBand7 Imaging 4.32016-05-18T04:39:30Z<p>Sstierwa: </p>
<hr />
<div>[[Category:ALMA]][[Category:Imaging]][[Category:Spectral Line]]<br />
<br />
* '''This tutorial picks up where '''[[TWHydraBand7_Calibration_4.5.2]]''' leaves off, with fully calibrated, split science target MS. If you wish to skip the Calibration guide: obtain the calibrated data from [[TWHydraBand7#Getting_the_Data]]; extract it using <tt>tar -xzvf FILENAME</tt>; and <tt>cd</tt> into the extracted directory.'''<br />
<br />
*'''This guide is designed for CASA 4.3. If you are using an older version of CASA please see [[TWHydraBand7_Imaging_4.3]].<br />
<br />
* '''Details of the ALMA data are provided at [[TWHydraBand7]]'''<br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.5.2. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.3.0'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
== Prepare Continuum Data for Further Processing==<br />
<br />
In order to speed up imaging/self-calibration for the continuum data we will average channels together, and then flag the few spectral features. This method works well in the case of only a few spectral lines, while retaining enough channelization to aid in multi-frequency synthesis and being able to remove spectral features in the averaged data. The amount of channel averaging should be adjusted to your particular data. '''Note for wide bandwidth data it is never a good idea to use the continuum estimate generated by uv-continuum subtraction as your continuum data'''. This worked OK in the past with the narrow band systems like the VLA and low dynamic range instruments like the SMA, but is not advised for ALMA wide bandwidth, high dynamic range data. <br />
<br />
<figure id="Cont_spw2.png"><br />
[[Image:Cont_spw2.png|thumb|<caption>CO(3-2) in spw=2 from the "continuum" channel averaged data.</caption>]]<br />
</figure><br />
<figure id="Cont_spw3.png"><br />
[[Image:Cont_spw3.png|thumb|<caption>Notice upswing at high channel numbers in spw=3.</caption>]]<br />
</figure><br />
<br />
One can also flag the spectral features first but in that case make a backup of the file that is analogous to TWHydra_corrected.ms as you will need it later (unflagged) for spectral line imaging. We begin by excluding ~20 channels on each edge, and averaging over 100 channel intervals:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_cont.ms*')<br />
split(vis='TWHydra_corrected.ms',outputvis='TWHydra_cont.ms',<br />
spw='0~3:21~3820',width=100,datacolumn='data')<br />
</source><br />
<br />
Now make a plot of amplitude vs. channel to see what needs to be flagged<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',spw='0~3',xaxis='channel',yaxis='amp',<br />
avgtime='1e8',avgscan=T,coloraxis='spw',iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
The CO(3-2) and HCO+(4-3) lines are obvious. The 4th spw; spw=3 also shows an upswing on the highest channels that is problematic, it was seen on the calibrators too and is likely due to a weak atmospheric feature, we will flag the worst of it.<br />
<br />
<figure id="Cont_uvplot.png"><br />
[[Image:Cont_uvplot.png|thumb|<caption>UV-plot of the continuum emission, colors show spws.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='TWHydra_cont.ms', mode='manual', <br />
spw='0:16~16, 2:21~21, 3:33~37')<br />
</source><br />
<br />
Have a look at the continuum as a function of uv-distance (in the plot to the right, the 4 spw are shown in different colors on top of each other). If the data are flat as a function of uv-distance, the source is completely unresolved. If instead you see structure (in this case decreasing amplitude with uv-distance), the source is resolved. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',spw='',xaxis='uvdist',yaxis='amp',field='',avgchannel='38',<br />
coloraxis='spw',plotfile='cont_uvplot.png')<br />
</source><br />
<br />
Notice that the spw do not have the same amplitude. Unfortunately, the red spw (highest frequency) should be higher than the green one (lowest frequency) because optically thin dust goes as nu^4, and optically thick as nu^2. This inconsistency is due to imperfect amplitude/absolute flux calibration. The self-calibration below will bring them into agreement with each other, but this is the sort of thing that results in considerable absolute flux uncertainty at submillimeter wavelengths. We are working on how to do this better.<br />
<br />
==A priori Noise Estimates==<br />
<br />
<figure id="Corrected_time.png"><br />
[[File:Corrected_time.png|thumb|<caption>Plot for estimating time.</caption>]]<br />
</figure><br />
<figure id="sensitivity_cont.png"><br />
[[File:sensitivity_cont.png|thumb|<caption>Sensitivity calculator setup with observed continuum parameters for these observations.</caption>]]<br />
</figure><br />
<br />
To estimate what the expected noise levels are, we first need to know how much time we had on source. Looking at <br />
a plot of amplitude vs time for the concatenated but pre-split data (see below) there are 9x8min scans + 6x6min scans + 3x1min + 2x2min scans for about 1.9 hours on source. There are 2 polarizations and about 1.75 GHz of total continuum bandwidth taking into account flagging.<br />
<br />
Using this information and https://almascience.nrao.edu/proposing/sensitivity-calculator, we find that the '''expected rms noise for the continuum is about 0.3 mJy/beam'''.<br />
<br />
For the spectral line data, which we will image below, with 0.12 km/s channels (needs to be entered in the field ''bandwidth per polarization''), the '''expected rms noise for the spectral lines is about 32 mJy/beam'''.<br />
<br />
==Image and Self-Calibrate the Continuum==<br />
<br />
====Create Initial Clean Image====<br />
<br />
First we will make an initial image using {{clean}}, this task will both deconvolve and clean. <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
If you are unfamiliar with the basic concepts of deconvolution and clean,<br />
pause here and review for example<br />
http://www.aoc.nrao.edu/events/synthesis/2010/lectures/wilner_synthesis10.pdf<br />
</pre><br />
<br />
In {{clean}}, we use '''mode='mfs'''' to do multifrequency synthesis, in other words grid each uv-channel independently. Since the uv-spacing is a function of frequency, this will actually achieve greater uv-coverage than if all the channels and spws had been averaged in advance. The '''imsize=100''' and '''cellsize=['0.3arcsec']''' were chosen to be appropriate for the Band and antenna configuration. At ALMA Band 7, the Full Width Half Power primary beam is about 20", so we want to make our image at least this big. We've made it a bit larger out to about the 25% power point. For the configuration used to take these data, the resolution is expected to be about 1.5" and it is a good idea to oversample the beam by setting the cell size to be a factor of 4 or 5 smaller than the beam (we have used 5 here). <br />
<br />
For doing self-calibration it is essential that only "real" signal be included in the image model, thus it is important to make a clean mask, and clean the first iteration rather conservatively (shallowly) so that you are sure that you do not have clean components in your model that do not represent real source emission. In the example below we set '''interactive=T''' so you can interactively make the clean mask and stop clean when the signal from the source starts to approach the surrounding "noise" areas in the residual map.<br />
<br />
'''NOTE:''' Real emission will not go away if you do not put a clean box on it. Conversely if you put a clean box on something that is NOT real and clean deeply you can amplify that feature. Thus, its best to be conservative and build up your clean box as you go, you can generally see fainter "real" features in the residuals.<br />
<br />
'''NOTE:''' If you start an interactive clean, and then do not make a mask, clean will stop when you tell it to go on because it has nothing to clean. There is no default mask.<br />
<br />
<figure id="Viewer_clean1.png"><br />
[[Image:Viewer_clean1.png|thumb|<caption>Interactive viewer.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall',<br />
mode='mfs', imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5, <br />
mask='',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
'''NOTE:'''{{clean}} will generate several files automatically with the '''imagename''' prepended:<br />
* <imagename>.image # the final restored image<br />
* <imagename>.flux # the effective primary beam response (e.g. for pbcor)<br />
* <imagename>.flux.pbcoverage # the primary beam coverage (ftmachine=’mosaic’ only)<br />
* <imagename>.model # the model image<br />
* <imagename>.residual # the residual image<br />
* <imagename>.psf # the synthesized (dirty) beam<br />
<br />
Once the Clean Viewer opens, click on the polygon tool with your left mouse button, and draw a polygon around the continuum emission with the left mouse button. Double click inside the region with the left mouse button when you are happy with it. It will turn from green to white when the clean mask is accepted. To continue with clean use the "Next action" buttons in the green area on the Viewer Display GUI. <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
The red X will stop clean where you are, the blue arrow will stop <br />
the interactive part of clean, but continue to clean non-interactively <br />
until reaching the number of iterations requested (niter) or the flux <br />
density threshold (whichever comes first), and the green circle arrow <br />
will clean until it reaches the "iterations" parameter on the left side <br />
of the green area. <br />
</pre><br />
<br />
'''You should chose the green circle arrow'''. It will clean 100 iterations (number under iteration in the green area on the Viewer GUI) and then show the '''residual image''' again. The middle mouse button is automatically assigned to the "plus" icon, which adjusts the colorscale. '''If you cannot easily access multiple mouse buttons, you can always assign your one mouse button the icon you want by clicking on it'''. Adjust the color scale so you can see the structure in the noise better. Also, note that the logger is telling you the amount of clean flux recovered so far, the min/max residuals, and the synthesized beam:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Model 0: max, min residuals = 0.0203454, 0.00267232 clean flux 1.30124<br />
Threshhold not reached yet.<br />
Beam used in restoration: 1.6962 by 1.54549 (arcsec) at pa 28.9043 (deg) <br />
</pre> <br />
<br />
Already with only 100 iterations, the residuals outside the clean mask are larger than that inside. So we will stop here by hitting the Red X symbol.<br />
<br />
====1st Round of Continuum Data Phase Self-calibration====<br />
<br />
Next we can use the clean model to self-calibrate the uv-data. The process of self-calibration tries to adjust the data to better match the model you give it. That is why it is important to make the model as good as you can. {{clean}} places a uv-model of the resulting image in the file <tt>TWHydra_cont.model</tt>. This model can then be used to self-calibrate the data using {{gaincal}}. We use '''gaintype='T'''' to tell it to average the polarizations before deriving solutions (which gains us a sqrt(2) in sensitivity). A critical parameter to play with is '''solint'''; we use '''solint=30s'''. From {{listobs}} the integration time of these data is about 10 seconds, so using '''solint=30s''' then gains us a sqrt(3) in sensitivity. It is often best to start with a larger '''solint''' and then work your way down to the integration time if the S/N of the data permits. For the same reasons as described in the [[TWHydraBand7_Calibration_4.3]] tutorial we want to fix up the phases before tackling amplitude by setting '''calmode='p''''.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='TWHydra_cont.ms',caltable='self_1.pcal',<br />
solint='30s',combine='',gaintype='T',<br />
refant='DV06',spw='',minblperant=4,<br />
calmode='p',minsnr=2)<br />
</source><br />
<br />
<figure id="Self_1_phase.png"><br />
[[Image:Self_1_phase.png|thumb|<caption>Phase solutions from self_1.pcal with solint=30s.</caption>]]<br />
</figure><br />
<br />
Because '''combine=' '''', we are getting independent solutions for each spw. If you are desperate for S/N, you can try combining them with combine='spw'. We have plenty of S/N in these data so we keep them separate. Look at the solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_1.pcal',xaxis='time',yaxis='phase',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,-80,80],figfile='self_1_phase.png')<br />
</source><br />
<br />
The magnitude of corrections gives you a sense of how accurate the phase transfer from the calibrators was. You are checking to see that the phases are being well tracked by the solutions, i.e. smoothly varying functions of time within a given scan. Also the solutions for each spw are lying basically on top of each other which indicates that the spw to spw phase offsets are well calibrated already. Overall, these solutions look quite good. If they didn't you could try increasing the solint and/or combining the spw into a single solution. <br />
<br />
After checking that you are happy with the solutions, apply them with {{applycal}}<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_cont.ms',field='',gaintable=['self_1.pcal'],calwt=F)<br />
</source><br />
<br />
<figure id="Viewer_pcal1.png"><br />
[[Image:Viewer_pcal1.png|thumb|<caption>Clean residuals after 100 iterations and the 1st phase only self-cal. Residuals inside mask are higher than the "noise" outside.</caption>]]<br />
</figure><br />
<br />
Next clean the source again, to save time we can start with the clean mask from the last iteration. If you make interactive adjustments to the clean mask, they will be written to the '''new''' mask TWHydra_contall_1pcal.mask, and not the old one. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_1pcal.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall_1pcal',<br />
mode='mfs',imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5, <br />
mask='TWHydra_contall.mask',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
Now after the first 100 iterations you see that the residuals inside the clean mask are higher than those outside. This is because flux that had been spread out in the map due to poorly correlated phases has been placed where it belongs on the source, thereby increasing its flux. You may also notice that your original clean mask is a little too small. If so, you can make it a bit larger, just by drawing a new polygon around the area you want to include. When you double click, it will incorporate the new mask into the current mask (if your box goes awry you can use the erase toggle [radio button] to erase and redo the mask). The new mask area need not overlap the original mask (though for this source it probably will). You might also want to use the magnifying glass to zoom in. Again, you assign mouse buttons by clicking on the icon you want. Clean another 100 iterations (for a total of 200) and stop by clicking the red X.<br />
<br />
Now open initial and 1st self-cal images to compare them using {{imview}}. This is an alternative version of the {{viewer}} that is somewhat scriptable. <br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(raster=[{'file':'TWHydra_contall.image','range':[-0.01,0.05]},<br />
{'file':'TWHydra_contall_1pcal.image','range':[-0.01,0.05]}])<br />
</source><br />
<br />
Once the Viewer Display panel opens, click on the box next in the "Images" panel and then use the tapedeck buttons in the panel to alternate between the two images. Because the range was explicitly set, they are on the same color scale. It is obvious that the self-calibrated image is better. To quantify, 1st toggle back to "normal" and then draw a region that excludes the central source with the polygon tool and then double click inside (if you stay in the "Images" view, only the statistics for the last image opened will appear on the terminal instead of both). The basic statistics of the polygon region will print to the '''terminal''':<br />
<br />
<pre style="background-color: #fffacd;"><br />
TWHydra_contall.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2357 -9.434800e-01 -2.858690e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-4.002885e-04 7.906752e-03 7.898289e-03 -2.541723e-02 2.172779e-02 <br />
<br />
TWHydra_contall_1pcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2357 6.326584e-01 1.916918e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
2.684168e-04 3.655786e-03 3.646692e-03 -1.215155e-02 1.109403e-02 <br />
</pre><br />
<br />
The self-calibrated image has more than a factor of 2 lower rms noise!<br />
<br />
====2nd Round of Continuum Data Phase Self-calibration====<br />
<br />
Now that we have a better model, we solve for solutions again. This time we will try making the solint smaller -- the integration time is about 10 seconds, so we set '''solint='int'''' to have it use the integration time.<br />
<br />
<figure id="Self_2_phase.png"><br />
[[Image:Self_2_phase.png|thumb|<caption>Phase solutions from self_2.pcal with solint='int'.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='TWHydra_cont.ms',caltable='self_2.pcal',<br />
solint='int',combine='',gaintype='T',<br />
refant='DV06',spw='',minblperant=4,<br />
calmode='p',minsnr=2)<br />
</source><br />
<br />
Now plot the new solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_2.pcal',xaxis='time',yaxis='phase',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,-80,80],figfile='self_2_phase.png')<br />
</source><br />
<br />
The phases on this shorter '''solint''' still seem to be tracking well so we will apply it and make a new image and check to see if there is improvement. <br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_cont.ms',field='',gaintable=['self_2.pcal'],calwt=F)<br />
</source><br />
<br />
<figure id="Viewer_pcal2.png"><br />
[[Image:Viewer_pcal2.png|thumb|<caption>Clean residuals after 2nd phase only self-cal and 250 iterations. The residuals inside the clean mask are lower than those outside, so its time to stop.</caption>]]<br />
</figure><br />
<br />
Now clean again, updating '''mask''' with the most recent mask file.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_2pcal.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall_2pcal',<br />
mode='mfs',imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5,usescratch=False,<br />
mask='TWHydra_contall_1pcal.mask',<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
After 200 iterations<br />
<br />
<pre style="background-color: #fffacd;"><br />
Model 0: max, min residuals = 0.00489776, -0.00464541 clean flux 1.44461<br />
</pre><br />
<br />
It looks like it could use just a little more cleaning, so set '''iterations=50 in the GUI'''.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Clean used 50 iterations to approach a threshhold of 0.0015067<br />
0.0107122 Jy <- cleaned in this cycle for model 0 (Total flux : 1.45532Jy)<br />
Final maximum residual = 0.00326382<br />
Model 0: max, min residuals = 0.00326382, -0.00321361 clean flux 1.45532<br />
</pre><br />
<br />
The small amount of flux cleaned this cycle indicates that clean is converging and it's about time to stop. Also the residuals inside the clean mask are now smaller than the residuals outside (i.e. the noise) also indicating it's time to stop by hitting the red X on the GUI.<br />
<br />
Now repeat the display, blinking, and image statistics steps described above for the 1st and 2nd phase-only self-cal iterations.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(raster=[{'file':'TWHydra_contall_1pcal.image','range':[-0.01,0.05]},<br />
{'file':'TWHydra_contall_2pcal.image','range':[-0.01,0.05]}])<br />
</source><br />
<br />
The difference is small:<br />
<pre style="background-color: #fffacd;"><br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2466 4.611597e-02 1.397287e-03 <br />
Mean Rms Std dev Minimum Maximum <br />
1.870072e-05 3.831524e-03 3.832255e-03 -1.414417e-02 1.109403e-02 <br />
<br />
TWHydra_contall_2pcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2466 1.159416e-01 3.512963e-03 <br />
Mean Rms Std dev Minimum Maximum <br />
4.701606e-05 3.811716e-03 3.812199e-03 -1.383034e-02 1.078456e-02 <br />
</pre><br />
<br />
This small improvement suggests that we have gone as far as we can with phase self-cal.<br />
<br />
===Continuum Data Amplitude Self-Calibration===<br />
<br />
Now we will apply the best phase solution table on-the-fly while solving for the amplitude self-cal solutions. Since amplitude changes more slowly and is less constrained than phase, we use a longer '''solint='inf'''', as long as '''combine=' '''' this means to do one solution per scan. <br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='TWHydra_cont.ms',caltable='self_ap.cal',<br />
solint='inf',combine='',gaintype='T',<br />
refant='DV06',spw='',minblperant=4,<br />
gaintable=['self_2.pcal'],<br />
calmode='ap',minsnr=2)<br />
</source><br />
<br />
It's useful to look at the residual phase in the amplitude calibration table, i.e. since we applied our best phase-only solution while solving for this new amplitude and phase ('''calmode='ap'''') solution, the phase should already be corrected.<br />
<br />
<figure id="Self_ap_phase.png"><br />
[[Image:Self_ap_phase.png|thumb|<caption>Residual phase solutions from self_ap.cal.</caption>]]<br />
</figure><br />
<figure id="Self_ap_amp.png"><br />
[[Image:Self_ap_amp.png|thumb|<caption>Amplitude solutions from self_ap.cal.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_ap.cal',xaxis='time',yaxis='phase',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,-1,1],figfile='self_ap_phase.png')<br />
</source><br />
<br />
The residuals are very small as expected. (If you see large residuals here, it means that the phase-only solution is suspect, and you were mostly just moving noise around.) Now look at the amplitude solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_ap.cal',xaxis='time',yaxis='amp',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,0.6,1.4],figfile='self_ap_amp.png')<br />
</source><br />
<br />
For the most part these look very good except one rather large deviation on DV06. Apply both the final phase and the amplitude calibration tables.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_cont.ms',field='',gaintable=['self_2.pcal','self_ap.cal'],calwt=F)<br />
</source><br />
<br />
Plot the corrected data as a function of both time and uv-distance. It is always a good idea to check these after an amplitude self-calbration to be sure that it worked properly. Occasionally, a few spurious bits of data will get blown up by the amplitude self-cal if it is not well-constrained. <br />
<br />
<figure id="Selfcal_time.png"><br />
[[Image:Selfcal_time.png|thumb|<caption>Post self-calibration amplitude vs. time</caption>]]<br />
</figure><br />
<figure id="Selfcal_uvdist.png"><br />
[[Image:Selfcal_uvdist.png|thumb|<caption>Post self-calibration amplitude vs. uv-distance</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',xaxis='time',yaxis='amp',<br />
avgchannel='38',ydatacolumn='corrected',coloraxis='spw',<br />
plotfile='selfcal_time.png')<br />
</source><br />
<br />
The time where we saw a large amplitude correction on DV06 looks consistent here so the large correction we saw in the solutions corrected a real issue. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',xaxis='uvdist',yaxis='amp',<br />
avgchannel='38',ydatacolumn='corrected',coloraxis='spw',<br />
plotfile='selfcal_uvdist.png')<br />
</source><br />
<br />
You will see that this plot looks much better than before. <br />
<br />
<figure id="Viewer_apcal.png"><br />
[[Image:Viewer_apcal.png|thumb|<caption>Clean residuals after final amplitude and phase self-cal.</caption>]]<br />
</figure><br />
<br />
Now make the final continuum image.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_apcal.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall_apcal',<br />
mode='mfs',imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5,usescratch=False,<br />
mask='TWHydra_contall_2pcal.mask',<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
We know we need to clean at least 300 iterations, so set this in the gui and hit the round green arrow. After this notice how much better the residual looks. Clean another 100 iterations. The "circular pattern", and 4 bright spots at each corner you see now in the residual is likely due to non-closing amplitude errors that cannot be removed with an antenna based self-calibration, so this is as good as it gets with pure self-cal. Hit the Red X to stop clean.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Clean used 100 iterations to approach a threshhold of 0.00105507<br />
0.0061808 Jy <- cleaned in this cycle for model 0<br />
Final maximum residual = 0.00242926<br />
Model 0: max, min residuals = 0.00238278, -0.00242926 clean flux 1.48201<br />
</pre><br />
<br />
Now repeat the display, blinking, and image statistics described above for the 2nd phase only and the new amplitude & phase self-cal'ed images.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(raster=[{'file':'TWHydra_contall_2pcal.image','range':[-0.01,0.05]},<br />
{'file':'TWHydra_contall_apcal.image','range':[-0.01,0.05]}])<br />
</source><br />
<br />
The amplitude and phase self cal'ed image is notably better than phase-only. Quantitatively:<br />
<pre style="background-color: #fffacd;"><br />
<br />
TWHydra_contall_2pcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 3542 2.053068e-01 6.220676e-03 <br />
Mean Rms Std dev Minimum Maximum <br />
5.796351e-05 3.955967e-03 3.956101e-03 -1.383034e-02 1.078456e-02 <br />
<br />
TWHydra_contall_apcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 3542 6.044652e-04 1.831495e-05 <br />
Mean Rms Std dev Minimum Maximum <br />
1.706565e-07 1.270183e-03 1.270362e-03 -4.980673e-03 4.137159e-03 <br />
</pre> <br />
<br />
and indeed, we've gained another factor of 3 in sensitivity. <br />
<br />
'''Overall with this self-calibration we've improved the noise by a factor of 6.7! With a peak flux density of 0.98 Jy, the S/N increased from 115 initially to 770 after. So, well worth the trouble.'''<br />
<br />
<div class="noprint" style="float:none; border:0px solid blue;background-color:#F6CEF5;padding:2px;"><br />
If you have used the '''standard='Butler-JPL-Horizons 2012' ''' model during the calibration process, you should see an increase in peak flux density of about 3%.<br />
</div><br />
<br />
It is notable that we are still a factor of more than 4 from the apriori noise estimate of 0.3 mJy/beam. This is likely due to residual sources of non-closing (not antenna based) errors in the data like baseline errors and baseline-dependent bandpass errors. Additionally, polarization errors (which we did not calibrate at all) can contribute, as well as imperfect uv-coverage with only 8 antennas. A dynamic range of 770 is actually quite good in the submillimeter.<br />
<br />
==Apply self-calibration to Full Dataset and Split Line Data==<br />
<br />
Now apply the self-calibration derived from the continuum emission to the full unchannel-averaged data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_corrected.ms',gaintable=['self_2.pcal','self_ap.cal'],calwt=F)<br />
</source><br />
<br />
Split off the CO(3-2) spectral line data in spw=2 and the HCO+(4-3) data in spw=0 for further processing.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2.ms*')<br />
split(vis='TWHydra_corrected.ms',outputvis='TWHydra_CO3_2.ms',datacolumn='corrected',spw='2')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplus.ms*')<br />
split(vis='TWHydra_corrected.ms',outputvis='TWHydra_HCOplus.ms',datacolumn='corrected',spw='0')<br />
</source><br />
<br />
==Continuum Subtraction== <br />
<br />
Next we need to subtract the continuum emission from the spectral line data. It is best to do this in the uv-plane. The first step is to make a channel plot of the spectral data to get the line-free channel ranges for both spectral lines. Since the line emission is simple (one spectral line per spw) and there are more than enough line-free channels we do not need to be very precise just stay well away from the line and whenever possible it is best to chose line-free channel ranges on either side of the line for the best possible baseline subtraction. <br />
<br />
<figure id="CO3_2_channel.png"><br />
[[Image:CO3_2_channel.png|thumb|<caption>CO(3-2) line in channel space.</caption>]]<br />
</figure><br />
<figure id="HCOp4_3_channel.png"><br />
[[Image:HCOp4_3_channel.png|thumb|<caption>HCO+(4-3) in channel space.</caption>]]<br />
</figure><br />
<br />
'''Note''': after the split above, the original spw ids will be relabeled as 0 in each file because there is only one spectral window in each file.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_CO3_2.ms',spw='0',xaxis='channel',yaxis='amp',<br />
avgtime='1e8',avgscan=T,coloraxis='spw',plotfile='CO3_2_channel.png')<br />
</source><br />
<br />
It is a good idea to stay a little away from the very edges of the baseband which can be noisy. The channel ranges <br />
20~2000 and 2400~3800 look like good choices for CO(3-2).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_HCOplus.ms',spw='0',xaxis='channel',yaxis='amp',<br />
avgtime='1e8',avgscan=T,coloraxis='spw',plotfile='HCOp4_3_channel.png')<br />
</source><br />
<br />
The channel ranges 20~1500 and 1900~3800 look like good choices for HCO+(4-3).<br />
<br />
Next use the identified line-free channel ranges and {{uvcontsub}} to subtract the continuum model from the line emission.<br />
<br />
<source lang="python"><br />
# In CASA<br />
uvcontsub(vis='TWHydra_CO3_2.ms',fitorder=1,fitspw='0:20~2000,0:2400~3800')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
uvcontsub(vis='TWHydra_HCOplus.ms',fitorder=1,fitspw='0:20~1500,0:1900~3800')<br />
</source><br />
<br />
Note: If you do not have line-free channels on both sides of the line emission, it is safer to use '''fitorder=0''', or the fit may diverge.<br />
<br />
==Spectral Line Imaging==<br />
<br />
Now we are ready to make cubes of the line emission. The imaging parameters are similar to the continuum except for <br />
those dealing with the spectral setup: '''mode''', '''start''', '''width''', '''nchan''', '''restfreq''', and '''outframe''' parameters. When making spectral images you have three choices for the '''mode''' parameter: '''channel''', '''velocity''', and '''frequency'''. Data are taken using constant frequency channels. For spectral line analysis it's often more useful to have constant velocity channels, and this is also the best way to make images of multiple lines with the exact same channelization for later comparison. For '''mode='velocity'''', the desired '''start''' and '''width''' also need to be given in velocity units for the desired output frame. <br />
<br />
It is important to note that ALMA does not do on-line Doppler Tracking and the native frame of the data is TOPO. If you do not specify '''outframe''' the output cube will also be in TOPO, which is not very useful for spectral line work. The Doppler Shift is taken out during the regridding to the desired outframe in {{clean}} or alternatively it can be done separately by the {{cvel}} task which would need to be run before {{clean}}. <br />
<br />
<figure id="CO3_2_vel.png"><br />
[[Image:CO3_2_vel.png|thumb|<caption>CO(3-2) spectrum in LSRK velocity space.</caption>]]<br />
</figure><br />
<figure id="HCOp4_3_vel.png"><br />
[[Image:HCOp4_3_vel.png|thumb|<caption>HCO+(4-3) spectrum in LSRK velocity space.</caption>]]<br />
</figure><br />
<br />
To see what velocity parameters you want to set in clean it is useful to make a plot in {{plotms}} in the desired output frame. To make it easier to see, we set a '''plotrange''' since we know the LSRK velocity of TW Hya is about 2.88 km/s. Note these plots take a little longer because of the frame shift.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_CO3_2.ms.contsub',xaxis='velocity',yaxis='amp',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',<br />
restfreq='345.79599GHz',plotrange=[-20,23,0,0],plotfile='CO3_2_vel.png')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_HCOplus.ms.contsub',xaxis='velocity',yaxis='amp',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',<br />
restfreq='356.7342GHz',plotrange=[-20,23,0,0],plotfile='HCOp4_3_vel.png') <br />
</source><br />
<br />
From these plots it looks like imaging the cubes from about -5 to +8 km/s will encompass the line, but still provide several line-free channels on either side so the noise level can be estimated. The channel width is 122 kHz, which at <br />
345.79599 GHz is 0.106 km/s. Recall that the spectral ''resolution'' is a factor of two poorer. We will use a velocity channel width of 0.12 km/s for a little oversampling, but the spectral resolution remains 0.2 km/s.<br />
<br />
As before, it is very important that you make a clean mask. There are many ways to do this ranging from the complicated to simple. For this example we will make a single clean mask that encompasses the line emission in every channel and apply it to all channels. This is much better than no clean mask, though not quite as good as making an individual mask for each channel. For some sources, one can use the continuum mask to clean the line, however TW Hya is a bit curious in that the continuum emission is not as extended as the line emission (Hughes et al. 2008).<br />
<br />
=== CO(3-2) Imaging ===<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.*')<br />
clean(vis='TWHydra_CO3_2.ms.contsub',imagename='TWHydra_CO3_2line',<br />
imagermode='csclean',spw='',<br />
imsize=100,cell=['0.3arcsec'],<br />
mode='velocity',start='-4km/s',width='0.12km/s',nchan=118,<br />
restfreq='345.79599GHz',outframe='LSRK',<br />
weighting='briggs',robust=0.5,<br />
mask='',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=100000)<br />
</source><br />
<br />
<figure id="Viewer_55.png"><br />
[[Image:Viewer_55.png|thumb|<caption>Interactive Viewer window with CO(3-2) clean mask, before cleaning starts.</caption>]]<br />
</figure><br />
<figure id="Viewer_500.png"><br />
[[Image:Viewer_500.png|thumb|<caption>Interactive Viewer window for CO(3-2), after 500 iterations, more cleaning is needed.</caption>]]<br />
</figure><br />
<br />
It will take a little while to grid the cube, when the interactive viewer opens, use the tapedeck to cycle through the channels. You should see a progress of line emission in channels 40 to 70 or so.<br />
*Go to channel 57 (about line center)<br />
*Select the polygon tool with the left mouse button<br />
*Select the "All Channels" toggle in the green area<br />
*Draw a polygon around the channel 57 emission, double click inside to activate.<br />
*Now go to channel 60, this is the channel with the most extent to the SE, draw another polygon that encompasses this emission if necessary,double click inside to activate.<br />
*Now go to channel 55, this is the channel with the most extent to the NW, draw another polygon that encompasses this emission if necessary,double click inside to activate. <br />
*Now double check the mask by cycling through channels with real line emission to be sure that your clean box encompasses the emission, but does not extend far beyond it. Again the "erase" toggle can come in handy if things go awry or if you want to just delete a small portion of an existing mask (just draw a polygon around what you want to erase and double click inside), be sure to switch back to "add" before going on.<br />
<br />
The figure shows what the final clean box should look like. Now clean using the green circle arrow. You can watch the progress in the logger. When 100 iterations are done, the viewer will show the residual map for each channel. Cycle through the channels and see whether you are still happy with the clean box in each signal channel. The "erase button" can help you fix mistakes. If necessary adjust. It is often useful to adjust the colorscale with the "plus" symbol icon. Keep going until the residual emission looks like the surrounding noise. If it seems to be going slowly, increase the iterations to 300 for a round or two. I stopped cleaning (Red x) when the logger showed (about 900 iterations). <br />
<pre style="background-color: #fffacd;"><br />
12.9846 Jy <- cleaned in this cycle for model 0<br />
Final maximum residual = 0.157312<br />
Model 0: max, min residuals = 0.157312, -0.0871295 clean flux 279.304<br />
</pre><br />
<br />
NOTE: The residuals are still a bit high in the strongest emission channels after it is well cleaned in the weaker channels. This is an indication that the sensitivity is "dynamic range" limited. In other words even with more <br />
intrinsic sensitivity per integration (i.e. better system temperature), the dynamic range limit would remain the same unless you get more uv-coverage. The fundamental dynamic range limitations of ALMA will be considerably better with 16 antennas in Early Science and MUCH better with the full 50-antenna array.<br />
<br />
=== HCO+(4-3) Imaging ===<br />
<br />
Now image and clean the HCO+(4-3) line using what you learned above.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.*')<br />
clean(vis='TWHydra_HCOplus.ms.contsub',imagename='TWHydra_HCOplusline',<br />
imagermode='csclean',spw='',<br />
imsize=100,cell=['0.3arcsec'],<br />
mode='velocity',start='-4km/s',nchan=118,width='0.12km/s',<br />
restfreq='356.7342GHz',outframe='LSRK',<br />
weighting='briggs',robust=0.5,<br />
mask='',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=100000)<br />
</source><br />
<br />
I stopped cleaning when: <br />
<pre style="background-color: #fffacd;"><br />
4.79833 Jy <- cleaned in this cycle for model 0<br />
Final maximum residual = 0.0977348<br />
Model 0: max, min residuals = 0.0977348, -0.060484 clean flux 192.066<br />
</pre><br />
<br />
==Image Analysis==<br />
<br />
After all that hard work you now have deconvolved images of the 350 GHz continuum, the CO (3-2) line, and the HCO+ (4-3) line. CASA includes tools to help you understand the contents of these images and make basic scientific measurements. These tools are divided between graphical exploration tools, accessible via the CASA viewer, and command line analysis tasks. To access the viewer, simply type '''viewer()''' and to see the list of analysis tasks available in CASA type '''tasklist''' at the CASA prompt and look under the Analysis sub-heading.<br />
<br />
If you want to do this portion of the guide and have downloaded the (.FITS) reference images, you can import them to be CASA images using '''importfits'''. If you are re-importing the images, use the commented remove command, here, to delete the previous import first.<br />
<br />
<source lang="python"><br />
# In CASA<br />
# os.system("rm -rf TWHydra_CO3_2line.image")<br />
importfits(fitsimage="TWHydra_CO3_2line.image.fits", imagename="TWHydra_CO3_2line.image")<br />
</source><br />
<br />
where '''fitsimage''' refers to the file to imported and '''imagename''' gives the output filename. If you are proceeding directly from the imaging step, your data are already CASA images and you may proceed without any importing.<br />
<br />
You can get the basic properties of any CASA image using the '''imhead''' command. For example, type <br />
<br />
<source lang="python"><br />
# In CASA<br />
imhead("TWHydra_CO3_2line.image")<br />
</source><br />
<br />
and look at the CASA logger. You will see an image summary like the following<br />
<br />
<pre style="background-color: #fffacd;"><br />
INFO imhead ##########################################<br />
INFO imhead ##### Begin Task: imhead #####<br />
INFO imhead imhead(imagename="TWHydra_CO3_2line.image",mode="summary",hdkey="",hdvalue="",<br />
INFO imhead hdtype="",hdcomment="",verbose=False)<br />
INFO ImageAnalysis <br />
INFO ImageAnalysis Image name : TWHydra_CO3_2line.image<br />
INFO ImageAnalysis Object name : TW Hya<br />
INFO ImageAnalysis Image type : PagedImage<br />
INFO ImageAnalysis Image quantity : Intensity<br />
INFO ImageAnalysis Pixel mask(s) : None<br />
INFO ImageAnalysis Region(s) : None<br />
INFO ImageAnalysis Image units : Jy/beam<br />
INFO ImageAnalysis Restoring Beam : 1.68065 arcsec, 1.53193 arcsec, 22.3015 deg<br />
INFO ImageAnalysis <br />
INFO ImageAnalysis Direction reference : J2000<br />
INFO ImageAnalysis Spectral reference : LSRK<br />
INFO ImageAnalysis Velocity type : RADIO<br />
INFO ImageAnalysis Rest frequency : 3.45796e+11 Hz<br />
INFO ImageAnalysis Pointing center : 11:01:51.844983 -34.42.17.160885<br />
INFO ImageAnalysis Telescope : ALMA<br />
INFO ImageAnalysis Observer : Unknown<br />
INFO ImageAnalysis Date observation : 2011/04/22/00:15:42<br />
INFO ImageAnalysis Telescope position: [2.22514e+06m, -5.44031e+06m, -2.48103e+06m] (ITRF)<br />
INFO ImageAnalysis <br />
INFO ImageAnalysis Axis Coord Type Name Proj Shape Tile Coord value at pixel Coord incr Units<br />
INFO ImageAnalysis -------------------------------------------------------------------------------------------------- <br />
INFO ImageAnalysis 0 0 Direction Right Ascension SIN 100 25 11:01:51.845 50.00 -3.000000e-01 arcsec<br />
INFO ImageAnalysis 1 0 Direction Declination SIN 100 25 -34.42.17.161 50.00 3.000000e-01 arcsec<br />
INFO ImageAnalysis 2 2 Spectral Frequency 118 59 3.45801e+11 0.00 -1.38414152e+05 Hz<br />
INFO ImageAnalysis Velocity -4 0.00 1.200000e-01 km/s<br />
INFO ImageAnalysis 3 1 Stokes Stokes 1 1 I<br />
INFO imhead ##### End Task: imhead #####<br />
INFO imhead ##########################################<br />
<br />
</pre><br />
<br />
This report tells you about the target, shape, and coordinates of the image. It also notes the rest frequency and some details of the observation. '''imhead''' may be used more generally to retrieve header keywords as python variables or to manipulate the header of an image. Consult the help for details.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
You may want to pay particular attention to the third and fourth axis of the CASA image. These are <br />
usually frequency (velocity) and Stokes (polarization) in some order. An occasional source of confusion <br />
is that this order is not always the same. Often CLEAN will output images with the Stokes axis third, <br />
while IMPORTFITS usually yields images with the frequency axis third. If you encounter problems with<br />
image analysis tasks, you may want to check whether this results from conflicting axis definitions. You<br />
can adjust the order of the axes using the IMTRANS task.<br />
</pre><br />
<br />
Before proceeding, make sure that you have all three data sets as CASA images: '''TWHydra_CO3_2line.image''', '''TWHydra_HCOPlusline.image''', and '''TWHydra_contall_apcal.image'''. If you do not, then import them from the provided reference images. If you are re-importing the FITS images, run the commented remove commands before running importfits.<br />
<br />
<source lang="python"><br />
# In CASA<br />
# os.system("rm -rf TWHydra_CO3_2line.image")<br />
importfits(fitsimage="TWHydra_CO3_2line.image.fits", imagename="TWHydra_CO3_2line.image")<br />
# os.system("rm -rf TWHydra_HCOplusline.image")<br />
importfits(fitsimage="TWHydra_HCOplusline.image.fits", imagename="TWHydra_HCOplusline.image")<br />
# os.system("rm -rf TWHydra_contall_apcal.image")<br />
importfits(fitsimage="TWHydra_contall_apcal.image.fits", imagename="TWHydra_contall_apcal.image")<br />
</source><br />
<br />
In the rest of this guide we will construct ''moment maps'' showing the integrates, velocity field, and line width of the two lines. We will carry out Gaussian fits to the continuum and line maps. We will also illustrate some of the additional analysis capabilities available in CASA: subcube extraction, retrieval of data into python arrays, cube alignment, smoothing, and overlays of multiple spectral lines.<br />
<br />
===Moment Maps===<br />
<br />
The line "images" of CO(3-2) and HCO+(4-3) are, of course, cubes rather than images. Two dimensional ''moment maps'' are a standard way to present such data. These are maps showing the result of various moments (or similar calculations) carried out along the frequency axis of the cube. For example, the "moment 0" map is the sum of emission along the frequency axis at each pixel. The first moment is the intensity-weighted velocity (or frequency). The second moment is the intensity-weighted velocity (or frequency) dispersion about the mean. These and a number of other calculations (for example the maximum intensity) can be calculated via the '''immoments''' task. Consult the help or the CASA cookbook for more details.<br />
<br />
In this section, we will calculate moments for our two spectral line data cubes. To make the highest quality moment maps, we will first identify the planes of the data cube that contain emission, so that we can carry out the sum only over these channels. Doing otherwise adds noise to the moment map without adding signal and so lowers the signal-to-noise ratio of the final image. For the first and second moments we will identify an intensity threshold above which the data are statistically very likely to correspond to real astronomical emission. We will restrict the calculation to consider only data above this threshold, yielding a cleaner calculation (the second moment, in particular, is not at all robust against the inclusion of outlying noise). Finally, we will inspect the resulting moment maps with the viewer and output them to .FITS files.<br />
<br />
====Estimate the Spectral Extent====<br />
<br />
First, we want to figure out what planes appear to contain real emission. Open the CO data cube with the CASA viewer via:<br />
<br />
<source lang="python"><br />
# In CASA<br />
viewer("TWHydra_CO3_2line.image")<br />
</source><br />
<br />
This will open the CO(3-2) data cube as a raster image. Use the Animator pane to scroll through the cube, noting that the emission is mostly confined to ~40 channels near the center of the cube. There are several ways to make a more rigorous estimate. <br />
<br />
''By-Plane Inspection:'' First, you could increase the stretch of the image to identify by hand the first and last channels with visible emission. To do open the Data Display Options panel in the viewer (the wrench icon) and manually set the data range and/or scaling power cycles to highlight faint emission (note that you can also do this using the mouse and the color stretch - sun - icon). I left the scaling power cycles at 0 and set the data range to [-0.5, 0.5]. Then scroll through the cube and note the first and last channels with obvious emission. If I do this, I find emission from about plane 30 through plane 86.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:DataDisplayPanelStretch.png|The Data Display Panel used to set the color stretch, here from [-0.15, 0.15] with a linear (0) stretch. Setting the stretch to a negative value will highlight lower emission (a more logarithmic stretch). We got to this panel by clicking the wrench icon. You can also get from the dropdown menus (Data->Adjust).<br />
File:TWHydraCOChan33.png|Channel 33 of the CO(3-2) cube on this stretch. This is about the first channel to show clear emission.<br />
File:TWHydraCOChan80.png|Channel 80 of the CO(3-2) cube on this stretch. This is about the last channel to show clear emission.<br />
</gallery><br />
</center><br />
<br />
To make this more rigorous, you can work out a noise estimate before hand (we'll find it to be about 0.025 Jy/beam) and overplot a contour to indicate significant emission. You can do this by hand by using the Data Manager (folder icon) to open TWHydra_CO3_2line.image as a "contour map" and then using the Data Display Options to manipulate the contour levels. To show a 3-sigma contour with sigma=0.025 Jy/beam set the Relative Contour Levels to [3], the Base Contour Level to 0, and the Unit Contour Level to 0.025. You can display a 5-sigma contour or change the RMS analogously. Scrolling through the cube, I see 3-sigma emission from channels 33 through 80.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:DataDisplayPanelContour.png|The Data Display Panel now being used to set the contour levels. We set the contour unit to 0.025 and ask for a single contour at 3 times this value. Notice that we clicked the tab along the top of the window to select the contour map.<br />
File:TWHydraCOChan33Contour.png|Channel 33 of the CO(3-2) cube on this stretch with a 3-sigma contour overlaid.<br />
File:TWHydraCOChan80Contour.png|Channel 80 of the CO(3-2) cube on this stretch with a 3-sigma contour overlaid.<br />
</gallery><br />
</center><br />
<br />
''Look at a Spectrum:'' You can also look at a spectrum of the source. To do this, scroll to a channel with a lot of emission (I went to 57) and then use the mouse to drag out a rectangle. To do this, left click on the rectangle box in the mouse toolbar (this assigns the left mouse button to define rectangle regions). Then drag out a box around the emission using the same button. Now click the spectrum in the toolbar to open the spectral profile tool. You will see the average profile for the selected region. You can set the bottom axis to show channels. You can zoom in within the spectral profile by dragging out a rectangle. When I do this, I find significant emission from channels 40-80.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:TWHydraRectangle.png|Defining a rectangular region around the main emission from TW Hydra. First we clicked the rectangle button on the mouse toolbar, then we held that button and dragged out the purple rectangle. After defining the rectangle, you can drag it around or delete it with <ESC>.<br />
File:TWHydraSpectrum.png|The spectrum of this rectangular region viewed in the spectral profile browser. Note that the bottom axis has been set to show channels. To get this spectrum, we defined the rectangular region and then clicked the spectrum button on the toolbar.<br />
File:TWHydraSpectrumZoom.png|A zoom in on the spectrum. The line extends from channels ~40-80.<br />
</gallery><br />
</center><br />
<br />
''Look at a Declination-Frequency Projection (or an R.A.-Frequency Projection):'' This is probably the least reliable way to do this, but illustrates a neat capability of the viewer. Open the Data Display Options (click the wrench icon) and open the "display axes" and "hidden axes" tabs. Use the dropdown menus to change the display so that the x-axis shows Declination, the y-axis shows Frequency, and the z-axis shows "Right Ascension." Now you are scrolling through planes of intensity as a function of Declination and Frequency. Use the animator to move to R.A. plane ~ 50 (the center of the source) and pull the stretch up (in the wrench tool; I used [-0.15,0.15] again). Mouse over the image and look at the "Position Tracking" pane in the bottom of the image, noting the pixel extent of emission in the frequency axis of this plane. I see traces of emission from channel ~30-90.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:DataDisplayPanelAxes.png|The Data Display Panel, here used to set which axes are displayed. We have adjusted the y-axis to show frequency and the x-axis to show Declination. The z-axis is now Right Ascension, so that we will scroll through planes of Right Ascension.<br />
File:DataDisplayPanelPixels.png|The Data Display Panel, here we are setting coordinates to show "pixels" rather than world coordinates.<br />
File:TWHydraDecFreqPixels.png|A Frequency-Declination plane of the cube near the central R.A. pixel (50). The rough extent of emission may be simply read off the y-coordinate. As above, we could overplot a 3-sigma contour to add more rigor.<br />
</gallery><br />
</center><br />
<br />
<br />
You can repeat this exercise for the HCO+ (4-3) emission. Using the Spectral Profile Browser, I find that the line extends from about channel 40 through channel 75.<br />
<br />
====Make Moment 0 Maps====<br />
<br />
With an estimate of the spectral extent of emission, we are now ready to make moment 0 maps of the CO(3-2) and HCO+(4-3) lines. We do this using the '''immmoments''' command,<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom0')<br />
immoments(imagename='TWHydra_CO3_2line.image',moments=[0],<br />
outfile='TWHydra_CO3_2line.image.mom0',<br />
chans='30~90')<br />
</source><br />
<br />
and<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom0')<br />
immoments(imagename='TWHydra_HCOplusline.image',moments=[0],<br />
outfile='TWHydra_HCOplusline.image.mom0',<br />
chans='40~75')<br />
</source><br />
<br />
immoments will sum across the channels specified by '''chans''' and produce new CASA images with the names specified by '''outfile'''. These can be inspected using the CASA viewer just like any other image. Note that unlike higher-order moments, the moment-0 map is robust to the inclusion of noisy signal-free channels (to within reason, you just decrease your signal-to-noise ratio) and indeed may be biased to miss faint emission by imposing a threshold. For that reason, we will eschew the '''includepix''' keyword as we make the moment 0 maps.<br />
<br />
Let's look at the output using the viewer. We can specify some of the display options in the call to start the viewer by using '''imview''' instead of '''viewer'''.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview( raster=[ {'file':'TWHydra_CO3_2line.image.mom0',<br />
'range':[0.0,10.],<br />
'scaling':-1},<br />
{'file':'TWHydra_HCOplusline.image.mom0',<br />
'range':[0.0,10.],<br />
'scaling':-1}], <br />
contour={'file':'TWHydra_contall_apcal.image', 'base':0, 'unit':0.0025, 'levels':[3,100]} )<br />
</source><br />
<br />
This does several things: It opens the viewer with raster images of the moment 0 maps of CO(3-2) and HCO+(4-3), sets the range of the color stretch from [0, 10] for each image and sets the scaling to be -1, which highlights faint emission compared to the normal (0) stretch. It also opens the continuum image as a contour and defines two contour levels. Once the viewer is open, you can blink between the images by going into the Animator pane, checking the white box next to "Images" to enable animation between images, and then sliding the bar back and forth. See the name of the image being shown change. You can also show two images side by side by going to the Viewer Canvas Manager (wrench+P icon) and opening the "Number of Panels" tab. Set the "Number of panels in x" to 2 and make sure that the Images box is checked in the Animator pane. You will see both images side by side.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:CanvasManagerPanels.png|The Viewer Canvas Manager, accessed via the Wrech+P icon (not to be confused with the plain old wrench). Here we have adjusted the number of x-panels from 1 to 2 so that we show the two moment maps side by side.<br />
File:TWHydraMoment0Maps.png|The moment-0 maps of CO(3-2) and HCO+(4-3) plotted side by side on the same color stretch, both with the continuum contours overlaid. To get the two images side by side, run the imview call above then set the number of panels to 2 and make sure that the Images box in the Animator Pane (here at the bottom of the window) is checked.<br />
File:DataDisplayImview.png|Data Display Panel after our imview call. Imview allowed us to set the stretch, range, and contour levels from the command line.<br />
</gallery><br />
</center><br />
<br />
====Estimate the Noise====<br />
<br />
We have already made a few offhand comparisons to the RMS noise. This quantity is often critical to know when exploring the data. Because the higher-order moments (especially the dispersion) are not at all robust to the inclusion of noise, we will calculate them only from regions of the cube that have intensity several times the RMS noise value or higher and are thus very likely to contain real astronomical emission. To proceed, we need to estimate the RMS noise for our data.<br />
<br />
The easiest way to do this is to calculate the RMS scatter of the data about zero from a part of the data that you suspect to be (mostly) free of astronomical signal. In a data cube the easiest way to do this will often be to identify signal-free planes (channels) of the cube and to simply calculate the RMS in these regions. We can do this straightforwardly using the '''imstat''' command in CASA.<br />
<br />
IMSTAT COMMAND<br />
<br />
IMSTAT OUTPUT<br />
<br />
Alternatively, you can get similar statistics on a region of an image or data cube selected manually inside the viewer. Drag out a region, for example a rectangle, using one of the mouse tools. Then <br />
<br />
IMAGES OF REGION SELECTION, OUTPUT, REGION MANAGER<br />
<br />
Suggested values for CO(3-2), HCO+(4-3), and continuum. Short discussion of dynamic range limited vs. line-free channels.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
A note on primary beam corrections and noise.<br />
</pre><br />
<br />
====Higher Order Moment Maps for CO(3-2)====<br />
<br />
For higher order moments it is very important to set a conservative flux <br />
threshold. Typically something like 6 sigma, using sigma from peak line channel, works well.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom')<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_coord')<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_dispersion_coord')<br />
immoments(imagename='TWHydra_CO3_2line.image',moments=[1,2],<br />
outfile='TWHydra_CO3_2line.image.mom',<br />
chans='40~76',includepix=[0.3,100])<br />
</source><br />
<br />
Display all three moment maps in the viewer, overlaid with continuum contours.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview( raster=[ {'file':'TWHydra_CO3_2line.image.mom0'},<br />
{'file':'TWHydra_CO3_2line.image.mom.weighted_coord'},<br />
{'file':'TWHydra_CO3_2line.image.mom.weighted_dispersion_coord'} ], <br />
contour={'file':'TWHydra_contall_apcal.image', 'base':0, 'unit':0.0025, 'levels':[3,100]} )<br />
</source><br />
<br />
To see all three raster images simultaneously, open the viewer's Panel Display Options (the "P-wrench" icon in the viewer tool bar), click "Number of panels", and change "Number of panels in x" to 3. Then select the "Blink" toggle (radio button) from the Animator panel.<br />
<br />
<figure id="TWHya_CO3_2_moments.png"><br />
[[Image:TWHya_CO3_2_moments.png|center|800px|frame|<caption>ALMA CO(3-2) moment maps, with white continuum contours at 3 and 100 sigma. From left to right: integrated intensity, intensity weighted velocity field, intensity weighted velocity dispersion are shown.</caption>]]<br />
</figure><br />
<br />
Repeat for HCO+(4-3) which has a bit narrower velocity extent than the CO(3-2), but similar rms noise.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom0')<br />
immoments(imagename='TWHydra_HCOplusline.image',moments=[0],<br />
outfile='TWHydra_HCOplusline.image.mom0',<br />
chans='43~74')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom')<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_coord')<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_dispersion_coord')<br />
immoments(imagename='TWHydra_HCOplusline.image',moments=[1,2],<br />
outfile='TWHydra_HCOplusline.image.mom',<br />
chans='43~74',includepix=[0.3,100])<br />
</source><br />
<br />
Display all three moment maps in the viewer using the same method described above for the CO(3-2) maps.<br />
<br />
<figure id="TWHya_HCOp4_3_moments.png"><br />
[[Image:TWHya_HCOp4_3_moments.png|center|800px|frame|<caption>ALMA HCO+(4-3) moment maps, with white continuum contours at 3 and 100 sigma. From left to right: integrated intensity, intensity weighted velocity field, intensity weighted velocity dispersion are shown.</caption>]]<br />
</figure><br />
<br />
=====Exporting Fits Images=====<br />
<br />
If you want to analyze the data using another software package it is easy to convert from CASA format to FITS. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image',fitsimage='TWHydra_CO3_2line.image.fits')<br />
</source><br />
<br />
Although "FITS format" is supposed to be a standard, in fact most packages expect slightly different things from a FITS image. If you are having difficulty, try setting '''velocity=T''' and/or '''dropstokes=T'''.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf TWHydra_HCOplusline.image.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image',fitsimage='TWHydra_HCOplusline.image.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom0.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image.mom0',<br />
fitsimage='TWHydra_CO3_2line.image.mom0.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_coord.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image.mom.weighted_coord',<br />
fitsimage='TWHydra_CO3_2line.image.mom.weighted_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_dispersion_coord.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image.mom.weighted_dispersion_coord',<br />
fitsimage='TWHydra_CO3_2line.image.mom.weighted_dispersion_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom0.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image.mom0',<br />
fitsimage='TWHydra_HCOplusline.image.mom0.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_coord.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image.mom.weighted_coord',<br />
fitsimage='TWHydra_HCOplusline.image.mom.weighted_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_dispersion_coord.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image.mom.weighted_dispersion_coord',<br />
fitsimage='TWHydra_HCOplusline.image.mom.weighted_dispersion_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_apcal.image.fits')<br />
exportfits(imagename='TWHydra_contall_apcal.image',fitsimage='TWHydra_contall_apcal.image.fits')<br />
</source><br />
<br />
===Display Channel Maps===<br />
<br />
Using the Viewer you can make channel map figures. Start the Viewer and then open the CO(3-2) cube as a raster image and then the continuum as a contour image. Then we use the "wrench" icon and "P wrench" icons to set up the channel images, contour levels etc. (If you need help setting up the viewer for this image, see a screen shot of the viewer setup windows, below.)<br />
<br />
<figure id="TWHya_channel_co3_2.png"><br />
[[Image:TWHya_channel_co3_2.png|center|frame|<caption>Channel maps of the CO(3-2) emission with white continuum contours at 3 and 100 sigma.</caption>]]<br />
</figure><br />
<br />
<figure id="Viewer_setup.png"><br />
[[Image:Viewer_setup.png|center|thumb|500px|<caption>The setup windows looked like this</caption>]]<br />
</figure><br />
<br />
Repeat for HCO+(4-3)<br />
<br />
<figure id="TWHya_channel_HCOp4_3.png"><br />
[[Image:TWHya_channel_HCOp4_3.png|center|thumb|800px|<caption>Channel maps of the HCO+(4-3) emission with white continuum contours at 3 and 100 sigma. The color intensity scale is the same as that used for CO(3-2).</caption>]]<br />
</figure><br />
<br />
<!--<br />
====Examine CO Contours on an HCO+ Raster====<br />
<br />
====Matched Movies====<br />
<br />
===Image Plane and Spectral Fits===<br />
<br />
====Fit a Gaussian to the Continuum====<br />
<br />
=====Fit In the Viewer=====<br />
<br />
=====Fit Using the Command Line=====<br />
<br />
====Fit a Gaussian to the CO Line====<br />
<br />
=====Fit In the Viewer=====<br />
<br />
=====Fit Using the Command Line=====<br />
<br />
===Extract a Sub-Image===<br />
<br />
===Align Image Cubes===<br />
--><br />
<br />
{{Checked 4.3.0}}</div>Sstierwahttps://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_4.3&diff=19482TWHydraBand7 Imaging 4.32016-05-18T04:38:31Z<p>Sstierwa: </p>
<hr />
<div>[[Category:ALMA]][[Category:Imaging]][[Category:Spectral Line]]<br />
<br />
* '''This tutorial picks up where '''[[TWHydraBand7_Calibration_4.5.2]]''' leaves off, with fully calibrated, split science target MS. If you wish to skip the Calibration guide: obtain the calibrated data from [[TWHydraBand7#Getting_the_Data]]; extract it using <tt>tar -xzvf FILENAME</tt>; and <tt>cd</tt> into the extracted directory.'''<br />
<br />
*'''This guide is designed for CASA 4.3. If you are using an older version of CASA please see [[TWHydraBand7_Imaging_4.2]].<br />
<br />
* '''Details of the ALMA data are provided at [[TWHydraBand7]]'''<br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.5.2. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.3.0'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
== Prepare Continuum Data for Further Processing==<br />
<br />
In order to speed up imaging/self-calibration for the continuum data we will average channels together, and then flag the few spectral features. This method works well in the case of only a few spectral lines, while retaining enough channelization to aid in multi-frequency synthesis and being able to remove spectral features in the averaged data. The amount of channel averaging should be adjusted to your particular data. '''Note for wide bandwidth data it is never a good idea to use the continuum estimate generated by uv-continuum subtraction as your continuum data'''. This worked OK in the past with the narrow band systems like the VLA and low dynamic range instruments like the SMA, but is not advised for ALMA wide bandwidth, high dynamic range data. <br />
<br />
<figure id="Cont_spw2.png"><br />
[[Image:Cont_spw2.png|thumb|<caption>CO(3-2) in spw=2 from the "continuum" channel averaged data.</caption>]]<br />
</figure><br />
<figure id="Cont_spw3.png"><br />
[[Image:Cont_spw3.png|thumb|<caption>Notice upswing at high channel numbers in spw=3.</caption>]]<br />
</figure><br />
<br />
One can also flag the spectral features first but in that case make a backup of the file that is analogous to TWHydra_corrected.ms as you will need it later (unflagged) for spectral line imaging. We begin by excluding ~20 channels on each edge, and averaging over 100 channel intervals:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_cont.ms*')<br />
split(vis='TWHydra_corrected.ms',outputvis='TWHydra_cont.ms',<br />
spw='0~3:21~3820',width=100,datacolumn='data')<br />
</source><br />
<br />
Now make a plot of amplitude vs. channel to see what needs to be flagged<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',spw='0~3',xaxis='channel',yaxis='amp',<br />
avgtime='1e8',avgscan=T,coloraxis='spw',iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
The CO(3-2) and HCO+(4-3) lines are obvious. The 4th spw; spw=3 also shows an upswing on the highest channels that is problematic, it was seen on the calibrators too and is likely due to a weak atmospheric feature, we will flag the worst of it.<br />
<br />
<figure id="Cont_uvplot.png"><br />
[[Image:Cont_uvplot.png|thumb|<caption>UV-plot of the continuum emission, colors show spws.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='TWHydra_cont.ms', mode='manual', <br />
spw='0:16~16, 2:21~21, 3:33~37')<br />
</source><br />
<br />
Have a look at the continuum as a function of uv-distance (in the plot to the right, the 4 spw are shown in different colors on top of each other). If the data are flat as a function of uv-distance, the source is completely unresolved. If instead you see structure (in this case decreasing amplitude with uv-distance), the source is resolved. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',spw='',xaxis='uvdist',yaxis='amp',field='',avgchannel='38',<br />
coloraxis='spw',plotfile='cont_uvplot.png')<br />
</source><br />
<br />
Notice that the spw do not have the same amplitude. Unfortunately, the red spw (highest frequency) should be higher than the green one (lowest frequency) because optically thin dust goes as nu^4, and optically thick as nu^2. This inconsistency is due to imperfect amplitude/absolute flux calibration. The self-calibration below will bring them into agreement with each other, but this is the sort of thing that results in considerable absolute flux uncertainty at submillimeter wavelengths. We are working on how to do this better.<br />
<br />
==A priori Noise Estimates==<br />
<br />
<figure id="Corrected_time.png"><br />
[[File:Corrected_time.png|thumb|<caption>Plot for estimating time.</caption>]]<br />
</figure><br />
<figure id="sensitivity_cont.png"><br />
[[File:sensitivity_cont.png|thumb|<caption>Sensitivity calculator setup with observed continuum parameters for these observations.</caption>]]<br />
</figure><br />
<br />
To estimate what the expected noise levels are, we first need to know how much time we had on source. Looking at <br />
a plot of amplitude vs time for the concatenated but pre-split data (see below) there are 9x8min scans + 6x6min scans + 3x1min + 2x2min scans for about 1.9 hours on source. There are 2 polarizations and about 1.75 GHz of total continuum bandwidth taking into account flagging.<br />
<br />
Using this information and https://almascience.nrao.edu/proposing/sensitivity-calculator, we find that the '''expected rms noise for the continuum is about 0.3 mJy/beam'''.<br />
<br />
For the spectral line data, which we will image below, with 0.12 km/s channels (needs to be entered in the field ''bandwidth per polarization''), the '''expected rms noise for the spectral lines is about 32 mJy/beam'''.<br />
<br />
==Image and Self-Calibrate the Continuum==<br />
<br />
====Create Initial Clean Image====<br />
<br />
First we will make an initial image using {{clean}}, this task will both deconvolve and clean. <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
If you are unfamiliar with the basic concepts of deconvolution and clean,<br />
pause here and review for example<br />
http://www.aoc.nrao.edu/events/synthesis/2010/lectures/wilner_synthesis10.pdf<br />
</pre><br />
<br />
In {{clean}}, we use '''mode='mfs'''' to do multifrequency synthesis, in other words grid each uv-channel independently. Since the uv-spacing is a function of frequency, this will actually achieve greater uv-coverage than if all the channels and spws had been averaged in advance. The '''imsize=100''' and '''cellsize=['0.3arcsec']''' were chosen to be appropriate for the Band and antenna configuration. At ALMA Band 7, the Full Width Half Power primary beam is about 20", so we want to make our image at least this big. We've made it a bit larger out to about the 25% power point. For the configuration used to take these data, the resolution is expected to be about 1.5" and it is a good idea to oversample the beam by setting the cell size to be a factor of 4 or 5 smaller than the beam (we have used 5 here). <br />
<br />
For doing self-calibration it is essential that only "real" signal be included in the image model, thus it is important to make a clean mask, and clean the first iteration rather conservatively (shallowly) so that you are sure that you do not have clean components in your model that do not represent real source emission. In the example below we set '''interactive=T''' so you can interactively make the clean mask and stop clean when the signal from the source starts to approach the surrounding "noise" areas in the residual map.<br />
<br />
'''NOTE:''' Real emission will not go away if you do not put a clean box on it. Conversely if you put a clean box on something that is NOT real and clean deeply you can amplify that feature. Thus, its best to be conservative and build up your clean box as you go, you can generally see fainter "real" features in the residuals.<br />
<br />
'''NOTE:''' If you start an interactive clean, and then do not make a mask, clean will stop when you tell it to go on because it has nothing to clean. There is no default mask.<br />
<br />
<figure id="Viewer_clean1.png"><br />
[[Image:Viewer_clean1.png|thumb|<caption>Interactive viewer.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall',<br />
mode='mfs', imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5, <br />
mask='',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
'''NOTE:'''{{clean}} will generate several files automatically with the '''imagename''' prepended:<br />
* <imagename>.image # the final restored image<br />
* <imagename>.flux # the effective primary beam response (e.g. for pbcor)<br />
* <imagename>.flux.pbcoverage # the primary beam coverage (ftmachine=’mosaic’ only)<br />
* <imagename>.model # the model image<br />
* <imagename>.residual # the residual image<br />
* <imagename>.psf # the synthesized (dirty) beam<br />
<br />
Once the Clean Viewer opens, click on the polygon tool with your left mouse button, and draw a polygon around the continuum emission with the left mouse button. Double click inside the region with the left mouse button when you are happy with it. It will turn from green to white when the clean mask is accepted. To continue with clean use the "Next action" buttons in the green area on the Viewer Display GUI. <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
The red X will stop clean where you are, the blue arrow will stop <br />
the interactive part of clean, but continue to clean non-interactively <br />
until reaching the number of iterations requested (niter) or the flux <br />
density threshold (whichever comes first), and the green circle arrow <br />
will clean until it reaches the "iterations" parameter on the left side <br />
of the green area. <br />
</pre><br />
<br />
'''You should chose the green circle arrow'''. It will clean 100 iterations (number under iteration in the green area on the Viewer GUI) and then show the '''residual image''' again. The middle mouse button is automatically assigned to the "plus" icon, which adjusts the colorscale. '''If you cannot easily access multiple mouse buttons, you can always assign your one mouse button the icon you want by clicking on it'''. Adjust the color scale so you can see the structure in the noise better. Also, note that the logger is telling you the amount of clean flux recovered so far, the min/max residuals, and the synthesized beam:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Model 0: max, min residuals = 0.0203454, 0.00267232 clean flux 1.30124<br />
Threshhold not reached yet.<br />
Beam used in restoration: 1.6962 by 1.54549 (arcsec) at pa 28.9043 (deg) <br />
</pre> <br />
<br />
Already with only 100 iterations, the residuals outside the clean mask are larger than that inside. So we will stop here by hitting the Red X symbol.<br />
<br />
====1st Round of Continuum Data Phase Self-calibration====<br />
<br />
Next we can use the clean model to self-calibrate the uv-data. The process of self-calibration tries to adjust the data to better match the model you give it. That is why it is important to make the model as good as you can. {{clean}} places a uv-model of the resulting image in the file <tt>TWHydra_cont.model</tt>. This model can then be used to self-calibrate the data using {{gaincal}}. We use '''gaintype='T'''' to tell it to average the polarizations before deriving solutions (which gains us a sqrt(2) in sensitivity). A critical parameter to play with is '''solint'''; we use '''solint=30s'''. From {{listobs}} the integration time of these data is about 10 seconds, so using '''solint=30s''' then gains us a sqrt(3) in sensitivity. It is often best to start with a larger '''solint''' and then work your way down to the integration time if the S/N of the data permits. For the same reasons as described in the [[TWHydraBand7_Calibration_4.3]] tutorial we want to fix up the phases before tackling amplitude by setting '''calmode='p''''.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='TWHydra_cont.ms',caltable='self_1.pcal',<br />
solint='30s',combine='',gaintype='T',<br />
refant='DV06',spw='',minblperant=4,<br />
calmode='p',minsnr=2)<br />
</source><br />
<br />
<figure id="Self_1_phase.png"><br />
[[Image:Self_1_phase.png|thumb|<caption>Phase solutions from self_1.pcal with solint=30s.</caption>]]<br />
</figure><br />
<br />
Because '''combine=' '''', we are getting independent solutions for each spw. If you are desperate for S/N, you can try combining them with combine='spw'. We have plenty of S/N in these data so we keep them separate. Look at the solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_1.pcal',xaxis='time',yaxis='phase',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,-80,80],figfile='self_1_phase.png')<br />
</source><br />
<br />
The magnitude of corrections gives you a sense of how accurate the phase transfer from the calibrators was. You are checking to see that the phases are being well tracked by the solutions, i.e. smoothly varying functions of time within a given scan. Also the solutions for each spw are lying basically on top of each other which indicates that the spw to spw phase offsets are well calibrated already. Overall, these solutions look quite good. If they didn't you could try increasing the solint and/or combining the spw into a single solution. <br />
<br />
After checking that you are happy with the solutions, apply them with {{applycal}}<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_cont.ms',field='',gaintable=['self_1.pcal'],calwt=F)<br />
</source><br />
<br />
<figure id="Viewer_pcal1.png"><br />
[[Image:Viewer_pcal1.png|thumb|<caption>Clean residuals after 100 iterations and the 1st phase only self-cal. Residuals inside mask are higher than the "noise" outside.</caption>]]<br />
</figure><br />
<br />
Next clean the source again, to save time we can start with the clean mask from the last iteration. If you make interactive adjustments to the clean mask, they will be written to the '''new''' mask TWHydra_contall_1pcal.mask, and not the old one. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_1pcal.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall_1pcal',<br />
mode='mfs',imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5, <br />
mask='TWHydra_contall.mask',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
Now after the first 100 iterations you see that the residuals inside the clean mask are higher than those outside. This is because flux that had been spread out in the map due to poorly correlated phases has been placed where it belongs on the source, thereby increasing its flux. You may also notice that your original clean mask is a little too small. If so, you can make it a bit larger, just by drawing a new polygon around the area you want to include. When you double click, it will incorporate the new mask into the current mask (if your box goes awry you can use the erase toggle [radio button] to erase and redo the mask). The new mask area need not overlap the original mask (though for this source it probably will). You might also want to use the magnifying glass to zoom in. Again, you assign mouse buttons by clicking on the icon you want. Clean another 100 iterations (for a total of 200) and stop by clicking the red X.<br />
<br />
Now open initial and 1st self-cal images to compare them using {{imview}}. This is an alternative version of the {{viewer}} that is somewhat scriptable. <br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(raster=[{'file':'TWHydra_contall.image','range':[-0.01,0.05]},<br />
{'file':'TWHydra_contall_1pcal.image','range':[-0.01,0.05]}])<br />
</source><br />
<br />
Once the Viewer Display panel opens, click on the box next in the "Images" panel and then use the tapedeck buttons in the panel to alternate between the two images. Because the range was explicitly set, they are on the same color scale. It is obvious that the self-calibrated image is better. To quantify, 1st toggle back to "normal" and then draw a region that excludes the central source with the polygon tool and then double click inside (if you stay in the "Images" view, only the statistics for the last image opened will appear on the terminal instead of both). The basic statistics of the polygon region will print to the '''terminal''':<br />
<br />
<pre style="background-color: #fffacd;"><br />
TWHydra_contall.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2357 -9.434800e-01 -2.858690e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-4.002885e-04 7.906752e-03 7.898289e-03 -2.541723e-02 2.172779e-02 <br />
<br />
TWHydra_contall_1pcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2357 6.326584e-01 1.916918e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
2.684168e-04 3.655786e-03 3.646692e-03 -1.215155e-02 1.109403e-02 <br />
</pre><br />
<br />
The self-calibrated image has more than a factor of 2 lower rms noise!<br />
<br />
====2nd Round of Continuum Data Phase Self-calibration====<br />
<br />
Now that we have a better model, we solve for solutions again. This time we will try making the solint smaller -- the integration time is about 10 seconds, so we set '''solint='int'''' to have it use the integration time.<br />
<br />
<figure id="Self_2_phase.png"><br />
[[Image:Self_2_phase.png|thumb|<caption>Phase solutions from self_2.pcal with solint='int'.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='TWHydra_cont.ms',caltable='self_2.pcal',<br />
solint='int',combine='',gaintype='T',<br />
refant='DV06',spw='',minblperant=4,<br />
calmode='p',minsnr=2)<br />
</source><br />
<br />
Now plot the new solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_2.pcal',xaxis='time',yaxis='phase',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,-80,80],figfile='self_2_phase.png')<br />
</source><br />
<br />
The phases on this shorter '''solint''' still seem to be tracking well so we will apply it and make a new image and check to see if there is improvement. <br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_cont.ms',field='',gaintable=['self_2.pcal'],calwt=F)<br />
</source><br />
<br />
<figure id="Viewer_pcal2.png"><br />
[[Image:Viewer_pcal2.png|thumb|<caption>Clean residuals after 2nd phase only self-cal and 250 iterations. The residuals inside the clean mask are lower than those outside, so its time to stop.</caption>]]<br />
</figure><br />
<br />
Now clean again, updating '''mask''' with the most recent mask file.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_2pcal.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall_2pcal',<br />
mode='mfs',imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5,usescratch=False,<br />
mask='TWHydra_contall_1pcal.mask',<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
After 200 iterations<br />
<br />
<pre style="background-color: #fffacd;"><br />
Model 0: max, min residuals = 0.00489776, -0.00464541 clean flux 1.44461<br />
</pre><br />
<br />
It looks like it could use just a little more cleaning, so set '''iterations=50 in the GUI'''.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Clean used 50 iterations to approach a threshhold of 0.0015067<br />
0.0107122 Jy <- cleaned in this cycle for model 0 (Total flux : 1.45532Jy)<br />
Final maximum residual = 0.00326382<br />
Model 0: max, min residuals = 0.00326382, -0.00321361 clean flux 1.45532<br />
</pre><br />
<br />
The small amount of flux cleaned this cycle indicates that clean is converging and it's about time to stop. Also the residuals inside the clean mask are now smaller than the residuals outside (i.e. the noise) also indicating it's time to stop by hitting the red X on the GUI.<br />
<br />
Now repeat the display, blinking, and image statistics steps described above for the 1st and 2nd phase-only self-cal iterations.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(raster=[{'file':'TWHydra_contall_1pcal.image','range':[-0.01,0.05]},<br />
{'file':'TWHydra_contall_2pcal.image','range':[-0.01,0.05]}])<br />
</source><br />
<br />
The difference is small:<br />
<pre style="background-color: #fffacd;"><br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2466 4.611597e-02 1.397287e-03 <br />
Mean Rms Std dev Minimum Maximum <br />
1.870072e-05 3.831524e-03 3.832255e-03 -1.414417e-02 1.109403e-02 <br />
<br />
TWHydra_contall_2pcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 2466 1.159416e-01 3.512963e-03 <br />
Mean Rms Std dev Minimum Maximum <br />
4.701606e-05 3.811716e-03 3.812199e-03 -1.383034e-02 1.078456e-02 <br />
</pre><br />
<br />
This small improvement suggests that we have gone as far as we can with phase self-cal.<br />
<br />
===Continuum Data Amplitude Self-Calibration===<br />
<br />
Now we will apply the best phase solution table on-the-fly while solving for the amplitude self-cal solutions. Since amplitude changes more slowly and is less constrained than phase, we use a longer '''solint='inf'''', as long as '''combine=' '''' this means to do one solution per scan. <br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='TWHydra_cont.ms',caltable='self_ap.cal',<br />
solint='inf',combine='',gaintype='T',<br />
refant='DV06',spw='',minblperant=4,<br />
gaintable=['self_2.pcal'],<br />
calmode='ap',minsnr=2)<br />
</source><br />
<br />
It's useful to look at the residual phase in the amplitude calibration table, i.e. since we applied our best phase-only solution while solving for this new amplitude and phase ('''calmode='ap'''') solution, the phase should already be corrected.<br />
<br />
<figure id="Self_ap_phase.png"><br />
[[Image:Self_ap_phase.png|thumb|<caption>Residual phase solutions from self_ap.cal.</caption>]]<br />
</figure><br />
<figure id="Self_ap_amp.png"><br />
[[Image:Self_ap_amp.png|thumb|<caption>Amplitude solutions from self_ap.cal.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_ap.cal',xaxis='time',yaxis='phase',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,-1,1],figfile='self_ap_phase.png')<br />
</source><br />
<br />
The residuals are very small as expected. (If you see large residuals here, it means that the phase-only solution is suspect, and you were mostly just moving noise around.) Now look at the amplitude solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='self_ap.cal',xaxis='time',yaxis='amp',<br />
spw='',field='',antenna='1~8',iteration='antenna',<br />
subplot=421,plotrange=[0,0,0.6,1.4],figfile='self_ap_amp.png')<br />
</source><br />
<br />
For the most part these look very good except one rather large deviation on DV06. Apply both the final phase and the amplitude calibration tables.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_cont.ms',field='',gaintable=['self_2.pcal','self_ap.cal'],calwt=F)<br />
</source><br />
<br />
Plot the corrected data as a function of both time and uv-distance. It is always a good idea to check these after an amplitude self-calbration to be sure that it worked properly. Occasionally, a few spurious bits of data will get blown up by the amplitude self-cal if it is not well-constrained. <br />
<br />
<figure id="Selfcal_time.png"><br />
[[Image:Selfcal_time.png|thumb|<caption>Post self-calibration amplitude vs. time</caption>]]<br />
</figure><br />
<figure id="Selfcal_uvdist.png"><br />
[[Image:Selfcal_uvdist.png|thumb|<caption>Post self-calibration amplitude vs. uv-distance</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',xaxis='time',yaxis='amp',<br />
avgchannel='38',ydatacolumn='corrected',coloraxis='spw',<br />
plotfile='selfcal_time.png')<br />
</source><br />
<br />
The time where we saw a large amplitude correction on DV06 looks consistent here so the large correction we saw in the solutions corrected a real issue. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_cont.ms',xaxis='uvdist',yaxis='amp',<br />
avgchannel='38',ydatacolumn='corrected',coloraxis='spw',<br />
plotfile='selfcal_uvdist.png')<br />
</source><br />
<br />
You will see that this plot looks much better than before. <br />
<br />
<figure id="Viewer_apcal.png"><br />
[[Image:Viewer_apcal.png|thumb|<caption>Clean residuals after final amplitude and phase self-cal.</caption>]]<br />
</figure><br />
<br />
Now make the final continuum image.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_apcal.*')<br />
clean(vis='TWHydra_cont.ms',imagename='TWHydra_contall_apcal',<br />
mode='mfs',imagermode='csclean',<br />
imsize=100,cell=['0.3arcsec'],spw='',<br />
weighting='briggs',robust=0.5,usescratch=False,<br />
mask='TWHydra_contall_2pcal.mask',<br />
interactive=T,threshold='1mJy',niter=10000)<br />
</source><br />
<br />
We know we need to clean at least 300 iterations, so set this in the gui and hit the round green arrow. After this notice how much better the residual looks. Clean another 100 iterations. The "circular pattern", and 4 bright spots at each corner you see now in the residual is likely due to non-closing amplitude errors that cannot be removed with an antenna based self-calibration, so this is as good as it gets with pure self-cal. Hit the Red X to stop clean.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Clean used 100 iterations to approach a threshhold of 0.00105507<br />
0.0061808 Jy <- cleaned in this cycle for model 0<br />
Final maximum residual = 0.00242926<br />
Model 0: max, min residuals = 0.00238278, -0.00242926 clean flux 1.48201<br />
</pre><br />
<br />
Now repeat the display, blinking, and image statistics described above for the 2nd phase only and the new amplitude & phase self-cal'ed images.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(raster=[{'file':'TWHydra_contall_2pcal.image','range':[-0.01,0.05]},<br />
{'file':'TWHydra_contall_apcal.image','range':[-0.01,0.05]}])<br />
</source><br />
<br />
The amplitude and phase self cal'ed image is notably better than phase-only. Quantitatively:<br />
<pre style="background-color: #fffacd;"><br />
<br />
TWHydra_contall_2pcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 3542 2.053068e-01 6.220676e-03 <br />
Mean Rms Std dev Minimum Maximum <br />
5.796351e-05 3.955967e-03 3.956101e-03 -1.383034e-02 1.078456e-02 <br />
<br />
TWHydra_contall_apcal.image<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s TOPO RADIO 3.50845e+11 <br />
BrightnessUnit BeamArea Npts Sum Flux <br />
Jy/beam 33.0039 3542 6.044652e-04 1.831495e-05 <br />
Mean Rms Std dev Minimum Maximum <br />
1.706565e-07 1.270183e-03 1.270362e-03 -4.980673e-03 4.137159e-03 <br />
</pre> <br />
<br />
and indeed, we've gained another factor of 3 in sensitivity. <br />
<br />
'''Overall with this self-calibration we've improved the noise by a factor of 6.7! With a peak flux density of 0.98 Jy, the S/N increased from 115 initially to 770 after. So, well worth the trouble.'''<br />
<br />
<div class="noprint" style="float:none; border:0px solid blue;background-color:#F6CEF5;padding:2px;"><br />
If you have used the '''standard='Butler-JPL-Horizons 2012' ''' model during the calibration process, you should see an increase in peak flux density of about 3%.<br />
</div><br />
<br />
It is notable that we are still a factor of more than 4 from the apriori noise estimate of 0.3 mJy/beam. This is likely due to residual sources of non-closing (not antenna based) errors in the data like baseline errors and baseline-dependent bandpass errors. Additionally, polarization errors (which we did not calibrate at all) can contribute, as well as imperfect uv-coverage with only 8 antennas. A dynamic range of 770 is actually quite good in the submillimeter.<br />
<br />
==Apply self-calibration to Full Dataset and Split Line Data==<br />
<br />
Now apply the self-calibration derived from the continuum emission to the full unchannel-averaged data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='TWHydra_corrected.ms',gaintable=['self_2.pcal','self_ap.cal'],calwt=F)<br />
</source><br />
<br />
Split off the CO(3-2) spectral line data in spw=2 and the HCO+(4-3) data in spw=0 for further processing.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2.ms*')<br />
split(vis='TWHydra_corrected.ms',outputvis='TWHydra_CO3_2.ms',datacolumn='corrected',spw='2')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplus.ms*')<br />
split(vis='TWHydra_corrected.ms',outputvis='TWHydra_HCOplus.ms',datacolumn='corrected',spw='0')<br />
</source><br />
<br />
==Continuum Subtraction== <br />
<br />
Next we need to subtract the continuum emission from the spectral line data. It is best to do this in the uv-plane. The first step is to make a channel plot of the spectral data to get the line-free channel ranges for both spectral lines. Since the line emission is simple (one spectral line per spw) and there are more than enough line-free channels we do not need to be very precise just stay well away from the line and whenever possible it is best to chose line-free channel ranges on either side of the line for the best possible baseline subtraction. <br />
<br />
<figure id="CO3_2_channel.png"><br />
[[Image:CO3_2_channel.png|thumb|<caption>CO(3-2) line in channel space.</caption>]]<br />
</figure><br />
<figure id="HCOp4_3_channel.png"><br />
[[Image:HCOp4_3_channel.png|thumb|<caption>HCO+(4-3) in channel space.</caption>]]<br />
</figure><br />
<br />
'''Note''': after the split above, the original spw ids will be relabeled as 0 in each file because there is only one spectral window in each file.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_CO3_2.ms',spw='0',xaxis='channel',yaxis='amp',<br />
avgtime='1e8',avgscan=T,coloraxis='spw',plotfile='CO3_2_channel.png')<br />
</source><br />
<br />
It is a good idea to stay a little away from the very edges of the baseband which can be noisy. The channel ranges <br />
20~2000 and 2400~3800 look like good choices for CO(3-2).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_HCOplus.ms',spw='0',xaxis='channel',yaxis='amp',<br />
avgtime='1e8',avgscan=T,coloraxis='spw',plotfile='HCOp4_3_channel.png')<br />
</source><br />
<br />
The channel ranges 20~1500 and 1900~3800 look like good choices for HCO+(4-3).<br />
<br />
Next use the identified line-free channel ranges and {{uvcontsub}} to subtract the continuum model from the line emission.<br />
<br />
<source lang="python"><br />
# In CASA<br />
uvcontsub(vis='TWHydra_CO3_2.ms',fitorder=1,fitspw='0:20~2000,0:2400~3800')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
uvcontsub(vis='TWHydra_HCOplus.ms',fitorder=1,fitspw='0:20~1500,0:1900~3800')<br />
</source><br />
<br />
Note: If you do not have line-free channels on both sides of the line emission, it is safer to use '''fitorder=0''', or the fit may diverge.<br />
<br />
==Spectral Line Imaging==<br />
<br />
Now we are ready to make cubes of the line emission. The imaging parameters are similar to the continuum except for <br />
those dealing with the spectral setup: '''mode''', '''start''', '''width''', '''nchan''', '''restfreq''', and '''outframe''' parameters. When making spectral images you have three choices for the '''mode''' parameter: '''channel''', '''velocity''', and '''frequency'''. Data are taken using constant frequency channels. For spectral line analysis it's often more useful to have constant velocity channels, and this is also the best way to make images of multiple lines with the exact same channelization for later comparison. For '''mode='velocity'''', the desired '''start''' and '''width''' also need to be given in velocity units for the desired output frame. <br />
<br />
It is important to note that ALMA does not do on-line Doppler Tracking and the native frame of the data is TOPO. If you do not specify '''outframe''' the output cube will also be in TOPO, which is not very useful for spectral line work. The Doppler Shift is taken out during the regridding to the desired outframe in {{clean}} or alternatively it can be done separately by the {{cvel}} task which would need to be run before {{clean}}. <br />
<br />
<figure id="CO3_2_vel.png"><br />
[[Image:CO3_2_vel.png|thumb|<caption>CO(3-2) spectrum in LSRK velocity space.</caption>]]<br />
</figure><br />
<figure id="HCOp4_3_vel.png"><br />
[[Image:HCOp4_3_vel.png|thumb|<caption>HCO+(4-3) spectrum in LSRK velocity space.</caption>]]<br />
</figure><br />
<br />
To see what velocity parameters you want to set in clean it is useful to make a plot in {{plotms}} in the desired output frame. To make it easier to see, we set a '''plotrange''' since we know the LSRK velocity of TW Hya is about 2.88 km/s. Note these plots take a little longer because of the frame shift.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_CO3_2.ms.contsub',xaxis='velocity',yaxis='amp',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',<br />
restfreq='345.79599GHz',plotrange=[-20,23,0,0],plotfile='CO3_2_vel.png')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TWHydra_HCOplus.ms.contsub',xaxis='velocity',yaxis='amp',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',<br />
restfreq='356.7342GHz',plotrange=[-20,23,0,0],plotfile='HCOp4_3_vel.png') <br />
</source><br />
<br />
From these plots it looks like imaging the cubes from about -5 to +8 km/s will encompass the line, but still provide several line-free channels on either side so the noise level can be estimated. The channel width is 122 kHz, which at <br />
345.79599 GHz is 0.106 km/s. Recall that the spectral ''resolution'' is a factor of two poorer. We will use a velocity channel width of 0.12 km/s for a little oversampling, but the spectral resolution remains 0.2 km/s.<br />
<br />
As before, it is very important that you make a clean mask. There are many ways to do this ranging from the complicated to simple. For this example we will make a single clean mask that encompasses the line emission in every channel and apply it to all channels. This is much better than no clean mask, though not quite as good as making an individual mask for each channel. For some sources, one can use the continuum mask to clean the line, however TW Hya is a bit curious in that the continuum emission is not as extended as the line emission (Hughes et al. 2008).<br />
<br />
=== CO(3-2) Imaging ===<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.*')<br />
clean(vis='TWHydra_CO3_2.ms.contsub',imagename='TWHydra_CO3_2line',<br />
imagermode='csclean',spw='',<br />
imsize=100,cell=['0.3arcsec'],<br />
mode='velocity',start='-4km/s',width='0.12km/s',nchan=118,<br />
restfreq='345.79599GHz',outframe='LSRK',<br />
weighting='briggs',robust=0.5,<br />
mask='',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=100000)<br />
</source><br />
<br />
<figure id="Viewer_55.png"><br />
[[Image:Viewer_55.png|thumb|<caption>Interactive Viewer window with CO(3-2) clean mask, before cleaning starts.</caption>]]<br />
</figure><br />
<figure id="Viewer_500.png"><br />
[[Image:Viewer_500.png|thumb|<caption>Interactive Viewer window for CO(3-2), after 500 iterations, more cleaning is needed.</caption>]]<br />
</figure><br />
<br />
It will take a little while to grid the cube, when the interactive viewer opens, use the tapedeck to cycle through the channels. You should see a progress of line emission in channels 40 to 70 or so.<br />
*Go to channel 57 (about line center)<br />
*Select the polygon tool with the left mouse button<br />
*Select the "All Channels" toggle in the green area<br />
*Draw a polygon around the channel 57 emission, double click inside to activate.<br />
*Now go to channel 60, this is the channel with the most extent to the SE, draw another polygon that encompasses this emission if necessary,double click inside to activate.<br />
*Now go to channel 55, this is the channel with the most extent to the NW, draw another polygon that encompasses this emission if necessary,double click inside to activate. <br />
*Now double check the mask by cycling through channels with real line emission to be sure that your clean box encompasses the emission, but does not extend far beyond it. Again the "erase" toggle can come in handy if things go awry or if you want to just delete a small portion of an existing mask (just draw a polygon around what you want to erase and double click inside), be sure to switch back to "add" before going on.<br />
<br />
The figure shows what the final clean box should look like. Now clean using the green circle arrow. You can watch the progress in the logger. When 100 iterations are done, the viewer will show the residual map for each channel. Cycle through the channels and see whether you are still happy with the clean box in each signal channel. The "erase button" can help you fix mistakes. If necessary adjust. It is often useful to adjust the colorscale with the "plus" symbol icon. Keep going until the residual emission looks like the surrounding noise. If it seems to be going slowly, increase the iterations to 300 for a round or two. I stopped cleaning (Red x) when the logger showed (about 900 iterations). <br />
<pre style="background-color: #fffacd;"><br />
12.9846 Jy <- cleaned in this cycle for model 0<br />
Final maximum residual = 0.157312<br />
Model 0: max, min residuals = 0.157312, -0.0871295 clean flux 279.304<br />
</pre><br />
<br />
NOTE: The residuals are still a bit high in the strongest emission channels after it is well cleaned in the weaker channels. This is an indication that the sensitivity is "dynamic range" limited. In other words even with more <br />
intrinsic sensitivity per integration (i.e. better system temperature), the dynamic range limit would remain the same unless you get more uv-coverage. The fundamental dynamic range limitations of ALMA will be considerably better with 16 antennas in Early Science and MUCH better with the full 50-antenna array.<br />
<br />
=== HCO+(4-3) Imaging ===<br />
<br />
Now image and clean the HCO+(4-3) line using what you learned above.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.*')<br />
clean(vis='TWHydra_HCOplus.ms.contsub',imagename='TWHydra_HCOplusline',<br />
imagermode='csclean',spw='',<br />
imsize=100,cell=['0.3arcsec'],<br />
mode='velocity',start='-4km/s',nchan=118,width='0.12km/s',<br />
restfreq='356.7342GHz',outframe='LSRK',<br />
weighting='briggs',robust=0.5,<br />
mask='',usescratch=False,<br />
interactive=T,threshold='1mJy',niter=100000)<br />
</source><br />
<br />
I stopped cleaning when: <br />
<pre style="background-color: #fffacd;"><br />
4.79833 Jy <- cleaned in this cycle for model 0<br />
Final maximum residual = 0.0977348<br />
Model 0: max, min residuals = 0.0977348, -0.060484 clean flux 192.066<br />
</pre><br />
<br />
==Image Analysis==<br />
<br />
After all that hard work you now have deconvolved images of the 350 GHz continuum, the CO (3-2) line, and the HCO+ (4-3) line. CASA includes tools to help you understand the contents of these images and make basic scientific measurements. These tools are divided between graphical exploration tools, accessible via the CASA viewer, and command line analysis tasks. To access the viewer, simply type '''viewer()''' and to see the list of analysis tasks available in CASA type '''tasklist''' at the CASA prompt and look under the Analysis sub-heading.<br />
<br />
If you want to do this portion of the guide and have downloaded the (.FITS) reference images, you can import them to be CASA images using '''importfits'''. If you are re-importing the images, use the commented remove command, here, to delete the previous import first.<br />
<br />
<source lang="python"><br />
# In CASA<br />
# os.system("rm -rf TWHydra_CO3_2line.image")<br />
importfits(fitsimage="TWHydra_CO3_2line.image.fits", imagename="TWHydra_CO3_2line.image")<br />
</source><br />
<br />
where '''fitsimage''' refers to the file to imported and '''imagename''' gives the output filename. If you are proceeding directly from the imaging step, your data are already CASA images and you may proceed without any importing.<br />
<br />
You can get the basic properties of any CASA image using the '''imhead''' command. For example, type <br />
<br />
<source lang="python"><br />
# In CASA<br />
imhead("TWHydra_CO3_2line.image")<br />
</source><br />
<br />
and look at the CASA logger. You will see an image summary like the following<br />
<br />
<pre style="background-color: #fffacd;"><br />
INFO imhead ##########################################<br />
INFO imhead ##### Begin Task: imhead #####<br />
INFO imhead imhead(imagename="TWHydra_CO3_2line.image",mode="summary",hdkey="",hdvalue="",<br />
INFO imhead hdtype="",hdcomment="",verbose=False)<br />
INFO ImageAnalysis <br />
INFO ImageAnalysis Image name : TWHydra_CO3_2line.image<br />
INFO ImageAnalysis Object name : TW Hya<br />
INFO ImageAnalysis Image type : PagedImage<br />
INFO ImageAnalysis Image quantity : Intensity<br />
INFO ImageAnalysis Pixel mask(s) : None<br />
INFO ImageAnalysis Region(s) : None<br />
INFO ImageAnalysis Image units : Jy/beam<br />
INFO ImageAnalysis Restoring Beam : 1.68065 arcsec, 1.53193 arcsec, 22.3015 deg<br />
INFO ImageAnalysis <br />
INFO ImageAnalysis Direction reference : J2000<br />
INFO ImageAnalysis Spectral reference : LSRK<br />
INFO ImageAnalysis Velocity type : RADIO<br />
INFO ImageAnalysis Rest frequency : 3.45796e+11 Hz<br />
INFO ImageAnalysis Pointing center : 11:01:51.844983 -34.42.17.160885<br />
INFO ImageAnalysis Telescope : ALMA<br />
INFO ImageAnalysis Observer : Unknown<br />
INFO ImageAnalysis Date observation : 2011/04/22/00:15:42<br />
INFO ImageAnalysis Telescope position: [2.22514e+06m, -5.44031e+06m, -2.48103e+06m] (ITRF)<br />
INFO ImageAnalysis <br />
INFO ImageAnalysis Axis Coord Type Name Proj Shape Tile Coord value at pixel Coord incr Units<br />
INFO ImageAnalysis -------------------------------------------------------------------------------------------------- <br />
INFO ImageAnalysis 0 0 Direction Right Ascension SIN 100 25 11:01:51.845 50.00 -3.000000e-01 arcsec<br />
INFO ImageAnalysis 1 0 Direction Declination SIN 100 25 -34.42.17.161 50.00 3.000000e-01 arcsec<br />
INFO ImageAnalysis 2 2 Spectral Frequency 118 59 3.45801e+11 0.00 -1.38414152e+05 Hz<br />
INFO ImageAnalysis Velocity -4 0.00 1.200000e-01 km/s<br />
INFO ImageAnalysis 3 1 Stokes Stokes 1 1 I<br />
INFO imhead ##### End Task: imhead #####<br />
INFO imhead ##########################################<br />
<br />
</pre><br />
<br />
This report tells you about the target, shape, and coordinates of the image. It also notes the rest frequency and some details of the observation. '''imhead''' may be used more generally to retrieve header keywords as python variables or to manipulate the header of an image. Consult the help for details.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
You may want to pay particular attention to the third and fourth axis of the CASA image. These are <br />
usually frequency (velocity) and Stokes (polarization) in some order. An occasional source of confusion <br />
is that this order is not always the same. Often CLEAN will output images with the Stokes axis third, <br />
while IMPORTFITS usually yields images with the frequency axis third. If you encounter problems with<br />
image analysis tasks, you may want to check whether this results from conflicting axis definitions. You<br />
can adjust the order of the axes using the IMTRANS task.<br />
</pre><br />
<br />
Before proceeding, make sure that you have all three data sets as CASA images: '''TWHydra_CO3_2line.image''', '''TWHydra_HCOPlusline.image''', and '''TWHydra_contall_apcal.image'''. If you do not, then import them from the provided reference images. If you are re-importing the FITS images, run the commented remove commands before running importfits.<br />
<br />
<source lang="python"><br />
# In CASA<br />
# os.system("rm -rf TWHydra_CO3_2line.image")<br />
importfits(fitsimage="TWHydra_CO3_2line.image.fits", imagename="TWHydra_CO3_2line.image")<br />
# os.system("rm -rf TWHydra_HCOplusline.image")<br />
importfits(fitsimage="TWHydra_HCOplusline.image.fits", imagename="TWHydra_HCOplusline.image")<br />
# os.system("rm -rf TWHydra_contall_apcal.image")<br />
importfits(fitsimage="TWHydra_contall_apcal.image.fits", imagename="TWHydra_contall_apcal.image")<br />
</source><br />
<br />
In the rest of this guide we will construct ''moment maps'' showing the integrates, velocity field, and line width of the two lines. We will carry out Gaussian fits to the continuum and line maps. We will also illustrate some of the additional analysis capabilities available in CASA: subcube extraction, retrieval of data into python arrays, cube alignment, smoothing, and overlays of multiple spectral lines.<br />
<br />
===Moment Maps===<br />
<br />
The line "images" of CO(3-2) and HCO+(4-3) are, of course, cubes rather than images. Two dimensional ''moment maps'' are a standard way to present such data. These are maps showing the result of various moments (or similar calculations) carried out along the frequency axis of the cube. For example, the "moment 0" map is the sum of emission along the frequency axis at each pixel. The first moment is the intensity-weighted velocity (or frequency). The second moment is the intensity-weighted velocity (or frequency) dispersion about the mean. These and a number of other calculations (for example the maximum intensity) can be calculated via the '''immoments''' task. Consult the help or the CASA cookbook for more details.<br />
<br />
In this section, we will calculate moments for our two spectral line data cubes. To make the highest quality moment maps, we will first identify the planes of the data cube that contain emission, so that we can carry out the sum only over these channels. Doing otherwise adds noise to the moment map without adding signal and so lowers the signal-to-noise ratio of the final image. For the first and second moments we will identify an intensity threshold above which the data are statistically very likely to correspond to real astronomical emission. We will restrict the calculation to consider only data above this threshold, yielding a cleaner calculation (the second moment, in particular, is not at all robust against the inclusion of outlying noise). Finally, we will inspect the resulting moment maps with the viewer and output them to .FITS files.<br />
<br />
====Estimate the Spectral Extent====<br />
<br />
First, we want to figure out what planes appear to contain real emission. Open the CO data cube with the CASA viewer via:<br />
<br />
<source lang="python"><br />
# In CASA<br />
viewer("TWHydra_CO3_2line.image")<br />
</source><br />
<br />
This will open the CO(3-2) data cube as a raster image. Use the Animator pane to scroll through the cube, noting that the emission is mostly confined to ~40 channels near the center of the cube. There are several ways to make a more rigorous estimate. <br />
<br />
''By-Plane Inspection:'' First, you could increase the stretch of the image to identify by hand the first and last channels with visible emission. To do open the Data Display Options panel in the viewer (the wrench icon) and manually set the data range and/or scaling power cycles to highlight faint emission (note that you can also do this using the mouse and the color stretch - sun - icon). I left the scaling power cycles at 0 and set the data range to [-0.5, 0.5]. Then scroll through the cube and note the first and last channels with obvious emission. If I do this, I find emission from about plane 30 through plane 86.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:DataDisplayPanelStretch.png|The Data Display Panel used to set the color stretch, here from [-0.15, 0.15] with a linear (0) stretch. Setting the stretch to a negative value will highlight lower emission (a more logarithmic stretch). We got to this panel by clicking the wrench icon. You can also get from the dropdown menus (Data->Adjust).<br />
File:TWHydraCOChan33.png|Channel 33 of the CO(3-2) cube on this stretch. This is about the first channel to show clear emission.<br />
File:TWHydraCOChan80.png|Channel 80 of the CO(3-2) cube on this stretch. This is about the last channel to show clear emission.<br />
</gallery><br />
</center><br />
<br />
To make this more rigorous, you can work out a noise estimate before hand (we'll find it to be about 0.025 Jy/beam) and overplot a contour to indicate significant emission. You can do this by hand by using the Data Manager (folder icon) to open TWHydra_CO3_2line.image as a "contour map" and then using the Data Display Options to manipulate the contour levels. To show a 3-sigma contour with sigma=0.025 Jy/beam set the Relative Contour Levels to [3], the Base Contour Level to 0, and the Unit Contour Level to 0.025. You can display a 5-sigma contour or change the RMS analogously. Scrolling through the cube, I see 3-sigma emission from channels 33 through 80.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:DataDisplayPanelContour.png|The Data Display Panel now being used to set the contour levels. We set the contour unit to 0.025 and ask for a single contour at 3 times this value. Notice that we clicked the tab along the top of the window to select the contour map.<br />
File:TWHydraCOChan33Contour.png|Channel 33 of the CO(3-2) cube on this stretch with a 3-sigma contour overlaid.<br />
File:TWHydraCOChan80Contour.png|Channel 80 of the CO(3-2) cube on this stretch with a 3-sigma contour overlaid.<br />
</gallery><br />
</center><br />
<br />
''Look at a Spectrum:'' You can also look at a spectrum of the source. To do this, scroll to a channel with a lot of emission (I went to 57) and then use the mouse to drag out a rectangle. To do this, left click on the rectangle box in the mouse toolbar (this assigns the left mouse button to define rectangle regions). Then drag out a box around the emission using the same button. Now click the spectrum in the toolbar to open the spectral profile tool. You will see the average profile for the selected region. You can set the bottom axis to show channels. You can zoom in within the spectral profile by dragging out a rectangle. When I do this, I find significant emission from channels 40-80.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:TWHydraRectangle.png|Defining a rectangular region around the main emission from TW Hydra. First we clicked the rectangle button on the mouse toolbar, then we held that button and dragged out the purple rectangle. After defining the rectangle, you can drag it around or delete it with <ESC>.<br />
File:TWHydraSpectrum.png|The spectrum of this rectangular region viewed in the spectral profile browser. Note that the bottom axis has been set to show channels. To get this spectrum, we defined the rectangular region and then clicked the spectrum button on the toolbar.<br />
File:TWHydraSpectrumZoom.png|A zoom in on the spectrum. The line extends from channels ~40-80.<br />
</gallery><br />
</center><br />
<br />
''Look at a Declination-Frequency Projection (or an R.A.-Frequency Projection):'' This is probably the least reliable way to do this, but illustrates a neat capability of the viewer. Open the Data Display Options (click the wrench icon) and open the "display axes" and "hidden axes" tabs. Use the dropdown menus to change the display so that the x-axis shows Declination, the y-axis shows Frequency, and the z-axis shows "Right Ascension." Now you are scrolling through planes of intensity as a function of Declination and Frequency. Use the animator to move to R.A. plane ~ 50 (the center of the source) and pull the stretch up (in the wrench tool; I used [-0.15,0.15] again). Mouse over the image and look at the "Position Tracking" pane in the bottom of the image, noting the pixel extent of emission in the frequency axis of this plane. I see traces of emission from channel ~30-90.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:DataDisplayPanelAxes.png|The Data Display Panel, here used to set which axes are displayed. We have adjusted the y-axis to show frequency and the x-axis to show Declination. The z-axis is now Right Ascension, so that we will scroll through planes of Right Ascension.<br />
File:DataDisplayPanelPixels.png|The Data Display Panel, here we are setting coordinates to show "pixels" rather than world coordinates.<br />
File:TWHydraDecFreqPixels.png|A Frequency-Declination plane of the cube near the central R.A. pixel (50). The rough extent of emission may be simply read off the y-coordinate. As above, we could overplot a 3-sigma contour to add more rigor.<br />
</gallery><br />
</center><br />
<br />
<br />
You can repeat this exercise for the HCO+ (4-3) emission. Using the Spectral Profile Browser, I find that the line extends from about channel 40 through channel 75.<br />
<br />
====Make Moment 0 Maps====<br />
<br />
With an estimate of the spectral extent of emission, we are now ready to make moment 0 maps of the CO(3-2) and HCO+(4-3) lines. We do this using the '''immmoments''' command,<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom0')<br />
immoments(imagename='TWHydra_CO3_2line.image',moments=[0],<br />
outfile='TWHydra_CO3_2line.image.mom0',<br />
chans='30~90')<br />
</source><br />
<br />
and<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom0')<br />
immoments(imagename='TWHydra_HCOplusline.image',moments=[0],<br />
outfile='TWHydra_HCOplusline.image.mom0',<br />
chans='40~75')<br />
</source><br />
<br />
immoments will sum across the channels specified by '''chans''' and produce new CASA images with the names specified by '''outfile'''. These can be inspected using the CASA viewer just like any other image. Note that unlike higher-order moments, the moment-0 map is robust to the inclusion of noisy signal-free channels (to within reason, you just decrease your signal-to-noise ratio) and indeed may be biased to miss faint emission by imposing a threshold. For that reason, we will eschew the '''includepix''' keyword as we make the moment 0 maps.<br />
<br />
Let's look at the output using the viewer. We can specify some of the display options in the call to start the viewer by using '''imview''' instead of '''viewer'''.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview( raster=[ {'file':'TWHydra_CO3_2line.image.mom0',<br />
'range':[0.0,10.],<br />
'scaling':-1},<br />
{'file':'TWHydra_HCOplusline.image.mom0',<br />
'range':[0.0,10.],<br />
'scaling':-1}], <br />
contour={'file':'TWHydra_contall_apcal.image', 'base':0, 'unit':0.0025, 'levels':[3,100]} )<br />
</source><br />
<br />
This does several things: It opens the viewer with raster images of the moment 0 maps of CO(3-2) and HCO+(4-3), sets the range of the color stretch from [0, 10] for each image and sets the scaling to be -1, which highlights faint emission compared to the normal (0) stretch. It also opens the continuum image as a contour and defines two contour levels. Once the viewer is open, you can blink between the images by going into the Animator pane, checking the white box next to "Images" to enable animation between images, and then sliding the bar back and forth. See the name of the image being shown change. You can also show two images side by side by going to the Viewer Canvas Manager (wrench+P icon) and opening the "Number of Panels" tab. Set the "Number of panels in x" to 2 and make sure that the Images box is checked in the Animator pane. You will see both images side by side.<br />
<br />
<center><br />
<gallery widths=250px heights=250px><br />
File:CanvasManagerPanels.png|The Viewer Canvas Manager, accessed via the Wrech+P icon (not to be confused with the plain old wrench). Here we have adjusted the number of x-panels from 1 to 2 so that we show the two moment maps side by side.<br />
File:TWHydraMoment0Maps.png|The moment-0 maps of CO(3-2) and HCO+(4-3) plotted side by side on the same color stretch, both with the continuum contours overlaid. To get the two images side by side, run the imview call above then set the number of panels to 2 and make sure that the Images box in the Animator Pane (here at the bottom of the window) is checked.<br />
File:DataDisplayImview.png|Data Display Panel after our imview call. Imview allowed us to set the stretch, range, and contour levels from the command line.<br />
</gallery><br />
</center><br />
<br />
====Estimate the Noise====<br />
<br />
We have already made a few offhand comparisons to the RMS noise. This quantity is often critical to know when exploring the data. Because the higher-order moments (especially the dispersion) are not at all robust to the inclusion of noise, we will calculate them only from regions of the cube that have intensity several times the RMS noise value or higher and are thus very likely to contain real astronomical emission. To proceed, we need to estimate the RMS noise for our data.<br />
<br />
The easiest way to do this is to calculate the RMS scatter of the data about zero from a part of the data that you suspect to be (mostly) free of astronomical signal. In a data cube the easiest way to do this will often be to identify signal-free planes (channels) of the cube and to simply calculate the RMS in these regions. We can do this straightforwardly using the '''imstat''' command in CASA.<br />
<br />
IMSTAT COMMAND<br />
<br />
IMSTAT OUTPUT<br />
<br />
Alternatively, you can get similar statistics on a region of an image or data cube selected manually inside the viewer. Drag out a region, for example a rectangle, using one of the mouse tools. Then <br />
<br />
IMAGES OF REGION SELECTION, OUTPUT, REGION MANAGER<br />
<br />
Suggested values for CO(3-2), HCO+(4-3), and continuum. Short discussion of dynamic range limited vs. line-free channels.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
A note on primary beam corrections and noise.<br />
</pre><br />
<br />
====Higher Order Moment Maps for CO(3-2)====<br />
<br />
For higher order moments it is very important to set a conservative flux <br />
threshold. Typically something like 6 sigma, using sigma from peak line channel, works well.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom')<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_coord')<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_dispersion_coord')<br />
immoments(imagename='TWHydra_CO3_2line.image',moments=[1,2],<br />
outfile='TWHydra_CO3_2line.image.mom',<br />
chans='40~76',includepix=[0.3,100])<br />
</source><br />
<br />
Display all three moment maps in the viewer, overlaid with continuum contours.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview( raster=[ {'file':'TWHydra_CO3_2line.image.mom0'},<br />
{'file':'TWHydra_CO3_2line.image.mom.weighted_coord'},<br />
{'file':'TWHydra_CO3_2line.image.mom.weighted_dispersion_coord'} ], <br />
contour={'file':'TWHydra_contall_apcal.image', 'base':0, 'unit':0.0025, 'levels':[3,100]} )<br />
</source><br />
<br />
To see all three raster images simultaneously, open the viewer's Panel Display Options (the "P-wrench" icon in the viewer tool bar), click "Number of panels", and change "Number of panels in x" to 3. Then select the "Blink" toggle (radio button) from the Animator panel.<br />
<br />
<figure id="TWHya_CO3_2_moments.png"><br />
[[Image:TWHya_CO3_2_moments.png|center|800px|frame|<caption>ALMA CO(3-2) moment maps, with white continuum contours at 3 and 100 sigma. From left to right: integrated intensity, intensity weighted velocity field, intensity weighted velocity dispersion are shown.</caption>]]<br />
</figure><br />
<br />
Repeat for HCO+(4-3) which has a bit narrower velocity extent than the CO(3-2), but similar rms noise.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom0')<br />
immoments(imagename='TWHydra_HCOplusline.image',moments=[0],<br />
outfile='TWHydra_HCOplusline.image.mom0',<br />
chans='43~74')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom')<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_coord')<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_dispersion_coord')<br />
immoments(imagename='TWHydra_HCOplusline.image',moments=[1,2],<br />
outfile='TWHydra_HCOplusline.image.mom',<br />
chans='43~74',includepix=[0.3,100])<br />
</source><br />
<br />
Display all three moment maps in the viewer using the same method described above for the CO(3-2) maps.<br />
<br />
<figure id="TWHya_HCOp4_3_moments.png"><br />
[[Image:TWHya_HCOp4_3_moments.png|center|800px|frame|<caption>ALMA HCO+(4-3) moment maps, with white continuum contours at 3 and 100 sigma. From left to right: integrated intensity, intensity weighted velocity field, intensity weighted velocity dispersion are shown.</caption>]]<br />
</figure><br />
<br />
=====Exporting Fits Images=====<br />
<br />
If you want to analyze the data using another software package it is easy to convert from CASA format to FITS. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image',fitsimage='TWHydra_CO3_2line.image.fits')<br />
</source><br />
<br />
Although "FITS format" is supposed to be a standard, in fact most packages expect slightly different things from a FITS image. If you are having difficulty, try setting '''velocity=T''' and/or '''dropstokes=T'''.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf TWHydra_HCOplusline.image.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image',fitsimage='TWHydra_HCOplusline.image.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom0.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image.mom0',<br />
fitsimage='TWHydra_CO3_2line.image.mom0.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_coord.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image.mom.weighted_coord',<br />
fitsimage='TWHydra_CO3_2line.image.mom.weighted_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_CO3_2line.image.mom.weighted_dispersion_coord.fits')<br />
exportfits(imagename='TWHydra_CO3_2line.image.mom.weighted_dispersion_coord',<br />
fitsimage='TWHydra_CO3_2line.image.mom.weighted_dispersion_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom0.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image.mom0',<br />
fitsimage='TWHydra_HCOplusline.image.mom0.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_coord.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image.mom.weighted_coord',<br />
fitsimage='TWHydra_HCOplusline.image.mom.weighted_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_HCOplusline.image.mom.weighted_dispersion_coord.fits')<br />
exportfits(imagename='TWHydra_HCOplusline.image.mom.weighted_dispersion_coord',<br />
fitsimage='TWHydra_HCOplusline.image.mom.weighted_dispersion_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_contall_apcal.image.fits')<br />
exportfits(imagename='TWHydra_contall_apcal.image',fitsimage='TWHydra_contall_apcal.image.fits')<br />
</source><br />
<br />
===Display Channel Maps===<br />
<br />
Using the Viewer you can make channel map figures. Start the Viewer and then open the CO(3-2) cube as a raster image and then the continuum as a contour image. Then we use the "wrench" icon and "P wrench" icons to set up the channel images, contour levels etc. (If you need help setting up the viewer for this image, see a screen shot of the viewer setup windows, below.)<br />
<br />
<figure id="TWHya_channel_co3_2.png"><br />
[[Image:TWHya_channel_co3_2.png|center|frame|<caption>Channel maps of the CO(3-2) emission with white continuum contours at 3 and 100 sigma.</caption>]]<br />
</figure><br />
<br />
<figure id="Viewer_setup.png"><br />
[[Image:Viewer_setup.png|center|thumb|500px|<caption>The setup windows looked like this</caption>]]<br />
</figure><br />
<br />
Repeat for HCO+(4-3)<br />
<br />
<figure id="TWHya_channel_HCOp4_3.png"><br />
[[Image:TWHya_channel_HCOp4_3.png|center|thumb|800px|<caption>Channel maps of the HCO+(4-3) emission with white continuum contours at 3 and 100 sigma. The color intensity scale is the same as that used for CO(3-2).</caption>]]<br />
</figure><br />
<br />
<!--<br />
====Examine CO Contours on an HCO+ Raster====<br />
<br />
====Matched Movies====<br />
<br />
===Image Plane and Spectral Fits===<br />
<br />
====Fit a Gaussian to the Continuum====<br />
<br />
=====Fit In the Viewer=====<br />
<br />
=====Fit Using the Command Line=====<br />
<br />
====Fit a Gaussian to the CO Line====<br />
<br />
=====Fit In the Viewer=====<br />
<br />
=====Fit Using the Command Line=====<br />
<br />
===Extract a Sub-Image===<br />
<br />
===Align Image Cubes===<br />
--><br />
<br />
{{Checked 4.3.0}}</div>Sstierwahttps://casaguides.nrao.edu/index.php?title=TWHydraBand7&diff=19481TWHydraBand72016-05-18T04:35:56Z<p>Sstierwa: /* How to Use A casaguide */</p>
<hr />
<div>[[Category:ALMA]][[Category:Calibration]][[Category:Spectral Line]]<br />
<br />
== Science Target Overview ==<br />
<br />
[[Image:Roberge STIS.jpg|thumb|HST STIS image of TW Hya ([http://adsabs.harvard.edu/abs/2005ApJ...622.1171R Roberge et al. 2005]; Figure 7). The solid green line is the direction of maximum disk brightness at optical wavelengths.]]<br />
<br />
TW Hya is a pre-main sequence classical T Tauri star at a distance of about 52+/-1 pc (Mamajek 2005,2010). It is the most studied member of the TW Hydra association (TWA) of low mass stars. From a wide variety of previous observations from the infrared to submillimeter, TW Hya is known to have a hot inner disk extending to radii < 4 AU, which is optically thin in the IR, and a larger cold dust disk out to about 200 AU (see for example the introduction by Vacca & Sandell 2011, and references therein). Recent optical interferometry finds that TW Hya also contains a hot optically thick disk on even smaller size scales of ~0.5 AU, and suggests that the optically thin disk could be due to gas clearing by a planet (Akeson et al. 2011). TW Hya is apparently still accreting from its disk at a rate of about (4-20) x 10<sup>-10</sup> Msun/year and the most recent estimates of its spectral type, mass, and age are M2.5V, 0.4 Msun, and 3 Myr (Vacca & Sandell 2011). <br />
<br />
Millimeter and submillimeter observations of the continuum and spectral lines are particularly useful for tracing in the outer cold disk. Previous observations by the VLA at 7 mm (Wilner et al. 2000), ATCA at 3 mm (Wilner et al. 2003), and the SMA at 1.3, 0.87, and 0.45 mm (Qi et al. 2004, 2006, 2008 and Hughes et al. 2011) reveal Keplerian rotation in the disk and an inclination angle of about 7 degrees (i.e. almost face-on). Detailed studies of the dust continuum properties from the SMA work suggest that there are centimeter sized particles within the cold proto-planetary disk.<br />
<br />
== ALMA Data Overview ==<br />
[[Image:Hughes_band7.jpg|thumb|SMA CO(3-2) emission from TW Hya (Hughes et al. 2011; Figure 2).]]<br />
<br />
[[Image:Qi_HCOp3_2.gif|thumb|SMA HCO+(3-2) emission from TW Hya (Qi et al. 2008; Figure 2).]]<br />
<br />
ALMA Science Verification data at Band 7 (~345 GHz) was taken for TW Hya on April 22, 2011. A scheduling block about 1.5 hours long was run three times in a row for a total of about 4.5 hours of observing time. The names of the three ASDMs were: uid://A002/X1d9d21/X3c1, uid://A002/X1d9d21/X5d8 and uid://A002/X1d9d21/X7ef. Nine antennas were available during these runs, but one has to be flagged. All four available basebands were used, resulting in four spectral windows (spws) containing data. Two basebands were placed in the Lower Sideband (LSB) and two basebands in the Upper Sideband (USB). In the LSB the CO(3-2) line at a rest frequency of 345.79599 GHz is located in spw=2. In the USB the HCO+(4-3) line at a rest frequency of 356.7342 GHz is located in spw=0. The other two spectral windows do not contain strong spectral lines and are used for measuring the continuum. Each spectral window is 0.5 GHz wide and the channel width is 122 kHz. Because the ALMA correlator was configured to apply Hanning smoothing of the signal, the effective spectral resolution is about twice the channel width, which in this case is about 0.2 km/s. For the antenna configuration in use at the time, the angular resolution is expected to be about 1.5". The median value of precipitable water vapor (PWV) for this period was 1.16 mm, as measured by the water vapor radiometers. This PWV corresponds to an opacity of 0.20 at the CO(3-2) line. The mean wind speed was 6.2 m/s.<br />
<br />
The ALMA CO(3-2) data presented here is similar to the Submillimeter Array data presented in Hughes et al. 2011 (ApJ, 727, 85), though the SMA data have ~3 times smaller channel width at 50 kHz. <br />
<br />
HCO+(4-3) data has not previously been published, but SMA HCO+(3-2) data (at 267.55762 GHz) is presented in Qi et al. 2008 (ApJ, 681, 1396). These SMA data have comparable angular resolution but a wider 203 kHz channel width.<br />
<br />
'''Using the data for publication''': Please use the acknowledgement given at the bottom of the [https://almascience.nrao.edu/alma-data/science-verification Science Verification Data page].<br />
<br />
[[Image:TWHya_HCOp4_3_moments.png|center|frame|700px]] ''ALMA HCO+(4-3) moment maps from TW Hya, with white continuum contours at 3 and 100 sigma. From left to right: integrated intensity, intensity weighted velocity field, intensity weighted velocity dispersion are shown.''<br />
<br />
==Obtaining the Data==<br />
<br />
'''To download the data, click on the region below that is closest to your location:'''<br />
*[http://almascience.nrao.edu/almadata/sciver/TWHya North America] <br />
*[http://almascience.eso.org/almadata/sciver/TWHya Europe] <br />
*[http://almascience.nao.ac.jp/almadata/sciver/TWHya East Asia] <br />
<br />
This will take you to a webpage with the following files:<br />
<br />
* '''TWHYA_BAND7_UnCalibratedMSAndTablesForReduction.tgz''' - This contains the uncalibrated data, already converted from raw data in ALMA Science Data Model (ASDM) format to CASA Measurement Sets (MS). We did this using the {{importasdm}} task in CASA. Along with the uncalibrated data, we also provide some tables that you will need for the calibration which cannot currently be generated inside of CASA (for Early Science, these tables will either be pre-applied or supplied with the data). <br />
<br />
* '''TWHYA_BAND7_CalibratedData.tgz''' - Contains only the calibrated uv-data for TWHya ready for imaging and self-calibration.<br />
<br />
* '''TWHYA_BAND7_ReferenceImages.tgz''' - The final spectral line and continuum images.<br />
<br />
'''***Before***''' you begin to download, read the details of [[TWHydraBand7#Data_Reduction_Tutorial]] below to see which files you want, these files are quite large and you may not want to download everything.<br />
<br />
==TWHya Data Reduction Tutorial==<br />
<br />
The tutorial (called a casaguide) for reducing these data '''using CASA version 4.3.0''' has been split into calibration and imaging pages:<br />
<br />
# '''[[TWHydraBand7_Calibration_4.3]]''' this page requires that you download the TWHYA_BAND7_UnCalibratedMSAndTablesForReduction directory<br />
# '''[[TWHydraBand7_Imaging_4.3]]''' this page requires that you have either used [[TWHydraBand7_Calibration_4.3]] to obtain the TWHYA_BAND7_CalibratedData or that you have downloaded this directory.<br />
<br />
Alternatively you can just download the final images (TWHYA_BAND7_ReferenceImages directory) if you only want to see the final results.<br />
<br />
'''NOTE: CASA 4.3 is required to process the data using the guides above''' see http://casa.nrao.edu/casa_obtaining.shtml. The data products have not changed. <br />
* The older CASA 4.2 casaguide versions are still available at: [[TWHydraBand7_Calibration_4.2]] and [[TWHydraBand7_Imaging_4.2]].<br />
* The older CASA 4.1 casaguide versions are still available at: [[TWHydraBand7_Calibration_4.1]] and [[TWHydraBand7_Imaging_4.1]].<br />
* The older CASA 4.0 casaguide versions are still available at: [[TWHydraBand7_Calibration_4.0]] and [[TWHydraBand7_Imaging_4.0]].<br />
* The older CASA 3.4 casaguide versions are still available at: [[TWHydraBand7_Calibration_3.4]] and [[TWHydraBand7_Imaging_3.4]].<br />
* The older CASA 3.3 casaguide versions are still available at: [[TWHydraBand7_Calibration_for_CASA_3.3]] and [[TWHydraBand7_Imaging_for_CASA_3.3]].<br />
<br />
NOTE: These guides are dynamic and will evolve as our understanding of how best to reduce ALMA data improves. Check back for updates periodically.<br />
<br />
==How to Use A casaguide==<br />
<br />
For tips on using CASA and ways CASA can be run, see [[EVLA_Spectral_Line_Calibration_IRC%2B10216#How_to_Use_This_casaguide]] page.<br />
<br />
'''To learn how to extract executable Python scripts from the tutorial, see [[Extracting_scripts_from_these_tutorials]].'''<br />
<br />
In the guides<br />
<br />
<source lang="python"><br />
# In CASA<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. Use the CASA command 'cpaste' <br />
to enter block commands and preserve whitespace.<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>Sstierwahttps://casaguides.nrao.edu/index.php?title=TWHydraBand7&diff=19480TWHydraBand72016-05-18T04:35:05Z<p>Sstierwa: /* How to Use A casaguide */</p>
<hr />
<div>[[Category:ALMA]][[Category:Calibration]][[Category:Spectral Line]]<br />
<br />
== Science Target Overview ==<br />
<br />
[[Image:Roberge STIS.jpg|thumb|HST STIS image of TW Hya ([http://adsabs.harvard.edu/abs/2005ApJ...622.1171R Roberge et al. 2005]; Figure 7). The solid green line is the direction of maximum disk brightness at optical wavelengths.]]<br />
<br />
TW Hya is a pre-main sequence classical T Tauri star at a distance of about 52+/-1 pc (Mamajek 2005,2010). It is the most studied member of the TW Hydra association (TWA) of low mass stars. From a wide variety of previous observations from the infrared to submillimeter, TW Hya is known to have a hot inner disk extending to radii < 4 AU, which is optically thin in the IR, and a larger cold dust disk out to about 200 AU (see for example the introduction by Vacca & Sandell 2011, and references therein). Recent optical interferometry finds that TW Hya also contains a hot optically thick disk on even smaller size scales of ~0.5 AU, and suggests that the optically thin disk could be due to gas clearing by a planet (Akeson et al. 2011). TW Hya is apparently still accreting from its disk at a rate of about (4-20) x 10<sup>-10</sup> Msun/year and the most recent estimates of its spectral type, mass, and age are M2.5V, 0.4 Msun, and 3 Myr (Vacca & Sandell 2011). <br />
<br />
Millimeter and submillimeter observations of the continuum and spectral lines are particularly useful for tracing in the outer cold disk. Previous observations by the VLA at 7 mm (Wilner et al. 2000), ATCA at 3 mm (Wilner et al. 2003), and the SMA at 1.3, 0.87, and 0.45 mm (Qi et al. 2004, 2006, 2008 and Hughes et al. 2011) reveal Keplerian rotation in the disk and an inclination angle of about 7 degrees (i.e. almost face-on). Detailed studies of the dust continuum properties from the SMA work suggest that there are centimeter sized particles within the cold proto-planetary disk.<br />
<br />
== ALMA Data Overview ==<br />
[[Image:Hughes_band7.jpg|thumb|SMA CO(3-2) emission from TW Hya (Hughes et al. 2011; Figure 2).]]<br />
<br />
[[Image:Qi_HCOp3_2.gif|thumb|SMA HCO+(3-2) emission from TW Hya (Qi et al. 2008; Figure 2).]]<br />
<br />
ALMA Science Verification data at Band 7 (~345 GHz) was taken for TW Hya on April 22, 2011. A scheduling block about 1.5 hours long was run three times in a row for a total of about 4.5 hours of observing time. The names of the three ASDMs were: uid://A002/X1d9d21/X3c1, uid://A002/X1d9d21/X5d8 and uid://A002/X1d9d21/X7ef. Nine antennas were available during these runs, but one has to be flagged. All four available basebands were used, resulting in four spectral windows (spws) containing data. Two basebands were placed in the Lower Sideband (LSB) and two basebands in the Upper Sideband (USB). In the LSB the CO(3-2) line at a rest frequency of 345.79599 GHz is located in spw=2. In the USB the HCO+(4-3) line at a rest frequency of 356.7342 GHz is located in spw=0. The other two spectral windows do not contain strong spectral lines and are used for measuring the continuum. Each spectral window is 0.5 GHz wide and the channel width is 122 kHz. Because the ALMA correlator was configured to apply Hanning smoothing of the signal, the effective spectral resolution is about twice the channel width, which in this case is about 0.2 km/s. For the antenna configuration in use at the time, the angular resolution is expected to be about 1.5". The median value of precipitable water vapor (PWV) for this period was 1.16 mm, as measured by the water vapor radiometers. This PWV corresponds to an opacity of 0.20 at the CO(3-2) line. The mean wind speed was 6.2 m/s.<br />
<br />
The ALMA CO(3-2) data presented here is similar to the Submillimeter Array data presented in Hughes et al. 2011 (ApJ, 727, 85), though the SMA data have ~3 times smaller channel width at 50 kHz. <br />
<br />
HCO+(4-3) data has not previously been published, but SMA HCO+(3-2) data (at 267.55762 GHz) is presented in Qi et al. 2008 (ApJ, 681, 1396). These SMA data have comparable angular resolution but a wider 203 kHz channel width.<br />
<br />
'''Using the data for publication''': Please use the acknowledgement given at the bottom of the [https://almascience.nrao.edu/alma-data/science-verification Science Verification Data page].<br />
<br />
[[Image:TWHya_HCOp4_3_moments.png|center|frame|700px]] ''ALMA HCO+(4-3) moment maps from TW Hya, with white continuum contours at 3 and 100 sigma. From left to right: integrated intensity, intensity weighted velocity field, intensity weighted velocity dispersion are shown.''<br />
<br />
==Obtaining the Data==<br />
<br />
'''To download the data, click on the region below that is closest to your location:'''<br />
*[http://almascience.nrao.edu/almadata/sciver/TWHya North America] <br />
*[http://almascience.eso.org/almadata/sciver/TWHya Europe] <br />
*[http://almascience.nao.ac.jp/almadata/sciver/TWHya East Asia] <br />
<br />
This will take you to a webpage with the following files:<br />
<br />
* '''TWHYA_BAND7_UnCalibratedMSAndTablesForReduction.tgz''' - This contains the uncalibrated data, already converted from raw data in ALMA Science Data Model (ASDM) format to CASA Measurement Sets (MS). We did this using the {{importasdm}} task in CASA. Along with the uncalibrated data, we also provide some tables that you will need for the calibration which cannot currently be generated inside of CASA (for Early Science, these tables will either be pre-applied or supplied with the data). <br />
<br />
* '''TWHYA_BAND7_CalibratedData.tgz''' - Contains only the calibrated uv-data for TWHya ready for imaging and self-calibration.<br />
<br />
* '''TWHYA_BAND7_ReferenceImages.tgz''' - The final spectral line and continuum images.<br />
<br />
'''***Before***''' you begin to download, read the details of [[TWHydraBand7#Data_Reduction_Tutorial]] below to see which files you want, these files are quite large and you may not want to download everything.<br />
<br />
==TWHya Data Reduction Tutorial==<br />
<br />
The tutorial (called a casaguide) for reducing these data '''using CASA version 4.3.0''' has been split into calibration and imaging pages:<br />
<br />
# '''[[TWHydraBand7_Calibration_4.3]]''' this page requires that you download the TWHYA_BAND7_UnCalibratedMSAndTablesForReduction directory<br />
# '''[[TWHydraBand7_Imaging_4.3]]''' this page requires that you have either used [[TWHydraBand7_Calibration_4.3]] to obtain the TWHYA_BAND7_CalibratedData or that you have downloaded this directory.<br />
<br />
Alternatively you can just download the final images (TWHYA_BAND7_ReferenceImages directory) if you only want to see the final results.<br />
<br />
'''NOTE: CASA 4.3 is required to process the data using the guides above''' see http://casa.nrao.edu/casa_obtaining.shtml. The data products have not changed. <br />
* The older CASA 4.2 casaguide versions are still available at: [[TWHydraBand7_Calibration_4.2]] and [[TWHydraBand7_Imaging_4.2]].<br />
* The older CASA 4.1 casaguide versions are still available at: [[TWHydraBand7_Calibration_4.1]] and [[TWHydraBand7_Imaging_4.1]].<br />
* The older CASA 4.0 casaguide versions are still available at: [[TWHydraBand7_Calibration_4.0]] and [[TWHydraBand7_Imaging_4.0]].<br />
* The older CASA 3.4 casaguide versions are still available at: [[TWHydraBand7_Calibration_3.4]] and [[TWHydraBand7_Imaging_3.4]].<br />
* The older CASA 3.3 casaguide versions are still available at: [[TWHydraBand7_Calibration_for_CASA_3.3]] and [[TWHydraBand7_Imaging_for_CASA_3.3]].<br />
<br />
NOTE: These guides are dynamic and will evolve as our understanding of how best to reduce ALMA data improves. Check back for updates periodically.<br />
<br />
==How to Use A casaguide==<br />
<br />
For tips on using CASA and ways CASA can be run, see [[EVLA_Spectral_Line_Calibration_IRC%2B10216#How_to_Use_This_casaguide]] page.<br />
<br />
'''To learn how to extract executable Python scripts from the tutorial, see [[Extracting_scripts_from_these_tutorials]].'''<br />
<br />
In the guides<br />
<br />
<source lang="python"><br />
# In CASA<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. Use the CASA command 'paste' <br />
to enter block commands and preserve whitespace.<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>Sstierwahttps://casaguides.nrao.edu/index.php?title=TWHydraBand7&diff=19479TWHydraBand72016-05-18T04:34:46Z<p>Sstierwa: /* How to Use A casaguide */</p>
<hr />
<div>[[Category:ALMA]][[Category:Calibration]][[Category:Spectral Line]]<br />
<br />
== Science Target Overview ==<br />
<br />
[[Image:Roberge STIS.jpg|thumb|HST STIS image of TW Hya ([http://adsabs.harvard.edu/abs/2005ApJ...622.1171R Roberge et al. 2005]; Figure 7). The solid green line is the direction of maximum disk brightness at optical wavelengths.]]<br />
<br />
TW Hya is a pre-main sequence classical T Tauri star at a distance of about 52+/-1 pc (Mamajek 2005,2010). It is the most studied member of the TW Hydra association (TWA) of low mass stars. From a wide variety of previous observations from the infrared to submillimeter, TW Hya is known to have a hot inner disk extending to radii < 4 AU, which is optically thin in the IR, and a larger cold dust disk out to about 200 AU (see for example the introduction by Vacca & Sandell 2011, and references therein). Recent optical interferometry finds that TW Hya also contains a hot optically thick disk on even smaller size scales of ~0.5 AU, and suggests that the optically thin disk could be due to gas clearing by a planet (Akeson et al. 2011). TW Hya is apparently still accreting from its disk at a rate of about (4-20) x 10<sup>-10</sup> Msun/year and the most recent estimates of its spectral type, mass, and age are M2.5V, 0.4 Msun, and 3 Myr (Vacca & Sandell 2011). <br />
<br />
Millimeter and submillimeter observations of the continuum and spectral lines are particularly useful for tracing in the outer cold disk. Previous observations by the VLA at 7 mm (Wilner et al. 2000), ATCA at 3 mm (Wilner et al. 2003), and the SMA at 1.3, 0.87, and 0.45 mm (Qi et al. 2004, 2006, 2008 and Hughes et al. 2011) reveal Keplerian rotation in the disk and an inclination angle of about 7 degrees (i.e. almost face-on). Detailed studies of the dust continuum properties from the SMA work suggest that there are centimeter sized particles within the cold proto-planetary disk.<br />
<br />
== ALMA Data Overview ==<br />
[[Image:Hughes_band7.jpg|thumb|SMA CO(3-2) emission from TW Hya (Hughes et al. 2011; Figure 2).]]<br />
<br />
[[Image:Qi_HCOp3_2.gif|thumb|SMA HCO+(3-2) emission from TW Hya (Qi et al. 2008; Figure 2).]]<br />
<br />
ALMA Science Verification data at Band 7 (~345 GHz) was taken for TW Hya on April 22, 2011. A scheduling block about 1.5 hours long was run three times in a row for a total of about 4.5 hours of observing time. The names of the three ASDMs were: uid://A002/X1d9d21/X3c1, uid://A002/X1d9d21/X5d8 and uid://A002/X1d9d21/X7ef. Nine antennas were available during these runs, but one has to be flagged. All four available basebands were used, resulting in four spectral windows (spws) containing data. Two basebands were placed in the Lower Sideband (LSB) and two basebands in the Upper Sideband (USB). In the LSB the CO(3-2) line at a rest frequency of 345.79599 GHz is located in spw=2. In the USB the HCO+(4-3) line at a rest frequency of 356.7342 GHz is located in spw=0. The other two spectral windows do not contain strong spectral lines and are used for measuring the continuum. Each spectral window is 0.5 GHz wide and the channel width is 122 kHz. Because the ALMA correlator was configured to apply Hanning smoothing of the signal, the effective spectral resolution is about twice the channel width, which in this case is about 0.2 km/s. For the antenna configuration in use at the time, the angular resolution is expected to be about 1.5". The median value of precipitable water vapor (PWV) for this period was 1.16 mm, as measured by the water vapor radiometers. This PWV corresponds to an opacity of 0.20 at the CO(3-2) line. The mean wind speed was 6.2 m/s.<br />
<br />
The ALMA CO(3-2) data presented here is similar to the Submillimeter Array data presented in Hughes et al. 2011 (ApJ, 727, 85), though the SMA data have ~3 times smaller channel width at 50 kHz. <br />
<br />
HCO+(4-3) data has not previously been published, but SMA HCO+(3-2) data (at 267.55762 GHz) is presented in Qi et al. 2008 (ApJ, 681, 1396). These SMA data have comparable angular resolution but a wider 203 kHz channel width.<br />
<br />
'''Using the data for publication''': Please use the acknowledgement given at the bottom of the [https://almascience.nrao.edu/alma-data/science-verification Science Verification Data page].<br />
<br />
[[Image:TWHya_HCOp4_3_moments.png|center|frame|700px]] ''ALMA HCO+(4-3) moment maps from TW Hya, with white continuum contours at 3 and 100 sigma. From left to right: integrated intensity, intensity weighted velocity field, intensity weighted velocity dispersion are shown.''<br />
<br />
==Obtaining the Data==<br />
<br />
'''To download the data, click on the region below that is closest to your location:'''<br />
*[http://almascience.nrao.edu/almadata/sciver/TWHya North America] <br />
*[http://almascience.eso.org/almadata/sciver/TWHya Europe] <br />
*[http://almascience.nao.ac.jp/almadata/sciver/TWHya East Asia] <br />
<br />
This will take you to a webpage with the following files:<br />
<br />
* '''TWHYA_BAND7_UnCalibratedMSAndTablesForReduction.tgz''' - This contains the uncalibrated data, already converted from raw data in ALMA Science Data Model (ASDM) format to CASA Measurement Sets (MS). We did this using the {{importasdm}} task in CASA. Along with the uncalibrated data, we also provide some tables that you will need for the calibration which cannot currently be generated inside of CASA (for Early Science, these tables will either be pre-applied or supplied with the data). <br />
<br />
* '''TWHYA_BAND7_CalibratedData.tgz''' - Contains only the calibrated uv-data for TWHya ready for imaging and self-calibration.<br />
<br />
* '''TWHYA_BAND7_ReferenceImages.tgz''' - The final spectral line and continuum images.<br />
<br />
'''***Before***''' you begin to download, read the details of [[TWHydraBand7#Data_Reduction_Tutorial]] below to see which files you want, these files are quite large and you may not want to download everything.<br />
<br />
==TWHya Data Reduction Tutorial==<br />
<br />
The tutorial (called a casaguide) for reducing these data '''using CASA version 4.3.0''' has been split into calibration and imaging pages:<br />
<br />
# '''[[TWHydraBand7_Calibration_4.3]]''' this page requires that you download the TWHYA_BAND7_UnCalibratedMSAndTablesForReduction directory<br />
# '''[[TWHydraBand7_Imaging_4.3]]''' this page requires that you have either used [[TWHydraBand7_Calibration_4.3]] to obtain the TWHYA_BAND7_CalibratedData or that you have downloaded this directory.<br />
<br />
Alternatively you can just download the final images (TWHYA_BAND7_ReferenceImages directory) if you only want to see the final results.<br />
<br />
'''NOTE: CASA 4.3 is required to process the data using the guides above''' see http://casa.nrao.edu/casa_obtaining.shtml. The data products have not changed. <br />
* The older CASA 4.2 casaguide versions are still available at: [[TWHydraBand7_Calibration_4.2]] and [[TWHydraBand7_Imaging_4.2]].<br />
* The older CASA 4.1 casaguide versions are still available at: [[TWHydraBand7_Calibration_4.1]] and [[TWHydraBand7_Imaging_4.1]].<br />
* The older CASA 4.0 casaguide versions are still available at: [[TWHydraBand7_Calibration_4.0]] and [[TWHydraBand7_Imaging_4.0]].<br />
* The older CASA 3.4 casaguide versions are still available at: [[TWHydraBand7_Calibration_3.4]] and [[TWHydraBand7_Imaging_3.4]].<br />
* The older CASA 3.3 casaguide versions are still available at: [[TWHydraBand7_Calibration_for_CASA_3.3]] and [[TWHydraBand7_Imaging_for_CASA_3.3]].<br />
<br />
NOTE: These guides are dynamic and will evolve as our understanding of how best to reduce ALMA data improves. Check back for updates periodically.<br />
<br />
==How to Use A casaguide==<br />
<br />
For tips on using CASA and ways CASA can be run, see [[EVLA_Spectral_Line_Calibration_IRC%2B10216#How_to_Use_This_casaguide]] page.<br />
<br />
'''To learn how to extract executable Python scripts from the tutorial, see [[Extracting_scripts_from_these_tutorials]].'''<br />
<br />
In the guides<br />
<br />
<source lang="python"><br />
# In CASA<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. Use the CASA command 'paste' to enter block commands and preserve whitespace.<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>Sstierwahttps://casaguides.nrao.edu/index.php?title=TWHydraBand7&diff=19478TWHydraBand72016-05-18T04:32:14Z<p>Sstierwa: /* ALMA Data Overview */</p>
<hr />
<div>[[Category:ALMA]][[Category:Calibration]][[Category:Spectral Line]]<br />
<br />
== Science Target Overview ==<br />
<br />
[[Image:Roberge STIS.jpg|thumb|HST STIS image of TW Hya ([http://adsabs.harvard.edu/abs/2005ApJ...622.1171R Roberge et al. 2005]; Figure 7). The solid green line is the direction of maximum disk brightness at optical wavelengths.]]<br />
<br />
TW Hya is a pre-main sequence classical T Tauri star at a distance of about 52+/-1 pc (Mamajek 2005,2010). It is the most studied member of the TW Hydra association (TWA) of low mass stars. From a wide variety of previous observations from the infrared to submillimeter, TW Hya is known to have a hot inner disk extending to radii < 4 AU, which is optically thin in the IR, and a larger cold dust disk out to about 200 AU (see for example the introduction by Vacca & Sandell 2011, and references therein). Recent optical interferometry finds that TW Hya also contains a hot optically thick disk on even smaller size scales of ~0.5 AU, and suggests that the optically thin disk could be due to gas clearing by a planet (Akeson et al. 2011). TW Hya is apparently still accreting from its disk at a rate of about (4-20) x 10<sup>-10</sup> Msun/year and the most recent estimates of its spectral type, mass, and age are M2.5V, 0.4 Msun, and 3 Myr (Vacca & Sandell 2011). <br />
<br />
Millimeter and submillimeter observations of the continuum and spectral lines are particularly useful for tracing in the outer cold disk. Previous observations by the VLA at 7 mm (Wilner et al. 2000), ATCA at 3 mm (Wilner et al. 2003), and the SMA at 1.3, 0.87, and 0.45 mm (Qi et al. 2004, 2006, 2008 and Hughes et al. 2011) reveal Keplerian rotation in the disk and an inclination angle of about 7 degrees (i.e. almost face-on). Detailed studies of the dust continuum properties from the SMA work suggest that there are centimeter sized particles within the cold proto-planetary disk.<br />
<br />
== ALMA Data Overview ==<br />
[[Image:Hughes_band7.jpg|thumb|SMA CO(3-2) emission from TW Hya (Hughes et al. 2011; Figure 2).]]<br />
<br />
[[Image:Qi_HCOp3_2.gif|thumb|SMA HCO+(3-2) emission from TW Hya (Qi et al. 2008; Figure 2).]]<br />
<br />
ALMA Science Verification data at Band 7 (~345 GHz) was taken for TW Hya on April 22, 2011. A scheduling block about 1.5 hours long was run three times in a row for a total of about 4.5 hours of observing time. The names of the three ASDMs were: uid://A002/X1d9d21/X3c1, uid://A002/X1d9d21/X5d8 and uid://A002/X1d9d21/X7ef. Nine antennas were available during these runs, but one has to be flagged. All four available basebands were used, resulting in four spectral windows (spws) containing data. Two basebands were placed in the Lower Sideband (LSB) and two basebands in the Upper Sideband (USB). In the LSB the CO(3-2) line at a rest frequency of 345.79599 GHz is located in spw=2. In the USB the HCO+(4-3) line at a rest frequency of 356.7342 GHz is located in spw=0. The other two spectral windows do not contain strong spectral lines and are used for measuring the continuum. Each spectral window is 0.5 GHz wide and the channel width is 122 kHz. Because the ALMA correlator was configured to apply Hanning smoothing of the signal, the effective spectral resolution is about twice the channel width, which in this case is about 0.2 km/s. For the antenna configuration in use at the time, the angular resolution is expected to be about 1.5". The median value of precipitable water vapor (PWV) for this period was 1.16 mm, as measured by the water vapor radiometers. This PWV corresponds to an opacity of 0.20 at the CO(3-2) line. The mean wind speed was 6.2 m/s.<br />
<br />
The ALMA CO(3-2) data presented here is similar to the Submillimeter Array data presented in Hughes et al. 2011 (ApJ, 727, 85), though the SMA data have ~3 times smaller channel width at 50 kHz. <br />
<br />
HCO+(4-3) data has not previously been published, but SMA HCO+(3-2) data (at 267.55762 GHz) is presented in Qi et al. 2008 (ApJ, 681, 1396). These SMA data have comparable angular resolution but a wider 203 kHz channel width.<br />
<br />
'''Using the data for publication''': Please use the acknowledgement given at the bottom of the [https://almascience.nrao.edu/alma-data/science-verification Science Verification Data page].<br />
<br />
[[Image:TWHya_HCOp4_3_moments.png|center|frame|700px]] ''ALMA HCO+(4-3) moment maps from TW Hya, with white continuum contours at 3 and 100 sigma. From left to right: integrated intensity, intensity weighted velocity field, intensity weighted velocity dispersion are shown.''<br />
<br />
==Obtaining the Data==<br />
<br />
'''To download the data, click on the region below that is closest to your location:'''<br />
*[http://almascience.nrao.edu/almadata/sciver/TWHya North America] <br />
*[http://almascience.eso.org/almadata/sciver/TWHya Europe] <br />
*[http://almascience.nao.ac.jp/almadata/sciver/TWHya East Asia] <br />
<br />
This will take you to a webpage with the following files:<br />
<br />
* '''TWHYA_BAND7_UnCalibratedMSAndTablesForReduction.tgz''' - This contains the uncalibrated data, already converted from raw data in ALMA Science Data Model (ASDM) format to CASA Measurement Sets (MS). We did this using the {{importasdm}} task in CASA. Along with the uncalibrated data, we also provide some tables that you will need for the calibration which cannot currently be generated inside of CASA (for Early Science, these tables will either be pre-applied or supplied with the data). <br />
<br />
* '''TWHYA_BAND7_CalibratedData.tgz''' - Contains only the calibrated uv-data for TWHya ready for imaging and self-calibration.<br />
<br />
* '''TWHYA_BAND7_ReferenceImages.tgz''' - The final spectral line and continuum images.<br />
<br />
'''***Before***''' you begin to download, read the details of [[TWHydraBand7#Data_Reduction_Tutorial]] below to see which files you want, these files are quite large and you may not want to download everything.<br />
<br />
==TWHya Data Reduction Tutorial==<br />
<br />
The tutorial (called a casaguide) for reducing these data '''using CASA version 4.3.0''' has been split into calibration and imaging pages:<br />
<br />
# '''[[TWHydraBand7_Calibration_4.3]]''' this page requires that you download the TWHYA_BAND7_UnCalibratedMSAndTablesForReduction directory<br />
# '''[[TWHydraBand7_Imaging_4.3]]''' this page requires that you have either used [[TWHydraBand7_Calibration_4.3]] to obtain the TWHYA_BAND7_CalibratedData or that you have downloaded this directory.<br />
<br />
Alternatively you can just download the final images (TWHYA_BAND7_ReferenceImages directory) if you only want to see the final results.<br />
<br />
'''NOTE: CASA 4.3 is required to process the data using the guides above''' see http://casa.nrao.edu/casa_obtaining.shtml. The data products have not changed. <br />
* The older CASA 4.2 casaguide versions are still available at: [[TWHydraBand7_Calibration_4.2]] and [[TWHydraBand7_Imaging_4.2]].<br />
* The older CASA 4.1 casaguide versions are still available at: [[TWHydraBand7_Calibration_4.1]] and [[TWHydraBand7_Imaging_4.1]].<br />
* The older CASA 4.0 casaguide versions are still available at: [[TWHydraBand7_Calibration_4.0]] and [[TWHydraBand7_Imaging_4.0]].<br />
* The older CASA 3.4 casaguide versions are still available at: [[TWHydraBand7_Calibration_3.4]] and [[TWHydraBand7_Imaging_3.4]].<br />
* The older CASA 3.3 casaguide versions are still available at: [[TWHydraBand7_Calibration_for_CASA_3.3]] and [[TWHydraBand7_Imaging_for_CASA_3.3]].<br />
<br />
NOTE: These guides are dynamic and will evolve as our understanding of how best to reduce ALMA data improves. Check back for updates periodically.<br />
<br />
==How to Use A casaguide==<br />
<br />
For tips on using CASA and ways CASA can be run, see [[EVLA_Spectral_Line_Calibration_IRC%2B10216#How_to_Use_This_casaguide]] page.<br />
<br />
'''To learn how to extract executable Python scripts from the tutorial, see [[Extracting_scripts_from_these_tutorials]].'''<br />
<br />
In the guides<br />
<br />
<source lang="python"><br />
# In CASA<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>Sstierwahttps://casaguides.nrao.edu/index.php?title=TWHydraBand7_Calibration_4.5&diff=19477TWHydraBand7 Calibration 4.52016-05-18T04:28:35Z<p>Sstierwa: /* Apply Calibration and Inspect */</p>
<hr />
<div>[[Category:ALMA]][[Category:Calibration]][[Category:Spectral Line]]<br />
*'''This script assumes that you have downloaded TWHYA_BAND7_UnCalibratedMSAndTablesForReduction.tgz from [[TWHydraBand7#Getting_the_Data]]'''<br />
<br />
*'''An introduction to this data set is available at [[TWHydraBand7]].<br />
<br />
*'''This guide is designed for CASA 4.5.2 If you are using an older version of CASA please see [[TWHydraBand7_Calibration_4.3]].<br />
<br />
==Preparation==<br />
<br />
Once you have downloaded TWHYA_BAND7_UnCalibratedMSAndTablesForReduction.tgz, in a terminal unpack it with<br />
<br />
<source lang="bash"><br />
tar -zxvf TWHYA_BAND7_UnCalibratedMSAndTablesForReduction.tgz<br />
</source><br />
<br />
Please be aware that you will need about 100 GB of free space to do the data reduction. It is a good idea to check that now before you begin. Some of the plots described here require 9 GB of RAM; as little as 4 GB may be sufficient if additional data averaging is used when the plots are generated. When you are satisfied with the available drive space and memory on your machine:<br />
<br />
<source lang="bash"><br />
cd TWHYA_BAND7_UnCalibratedMSAndTablesForReduction<br />
</source><br />
<br />
'''NOTE: the calibration tables included in TWHYA_BAND7_UnCalibratedMSAndTablesForReduction CANNOT be used with CASA 4.5, they should be discarded, or moved out of the working directory.'''<br />
<br />
Then start CASA by typing 'casa' at a shell prompt. <br />
<br />
<source lang="bash"><br />
casa<br />
</source><br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.5.2. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.5.2'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
==Install Analysis Utilities==<br />
<br />
Analysis Utilities (or analysisUtils for short) is a small set of Python scripts that provide a number of analysis and plotting utilities for ALMA data reduction. This guide uses a few of these utilities. They are very easy to install (just download and untar). See <br />
<br />
http://casaguides.nrao.edu/index.php?title=Analysis_Utilities<br />
<br />
for a full description and download instructions. If you do not wish to do this, see the [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Calibration_for_CASA_3.3 CASA 3.3 version of the guide] for alternative (but slow) plotting options. Analysis Utilities are updated frequently so if its been a while since you installed it, its probably worth doing it again. If you are at an ALMA site or ARC, the analysis utilities are probably already installed and up to date.<br />
<br />
==Fix Titan's coordinates==<br />
<br />
'''Note that in the near future this step will be unnecessary.''' <br />
<br />
It is temporarily necessary to correct the positions of ephemeris objects observed during ALMA Cycle 0, because the control software revisions earlier than 9.0 erroneously write the data with coordinates of 00:00:00.0000 +00.00.00.0000 (J2000). For this dataset, we need to correct the position of the absolute flux calibrator Titan, as we can<br />
see from the first {{listobs}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -f X3c1.ms.listobs')<br />
listobs('X3c1.ms', verbose=T, listfile='X3c1.ms.listobs') <br />
</source><br />
<br />
You can view the listobs output files using command "less" from the CASA prompt.<br />
<br />
<pre style="background-color: #fffacd;"><br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 23625<br />
1 none Titan 00:00:00.00000 +00.00.00.0000 J2000 1 4842<br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 175176<br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 14832<br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 59877<br />
</pre><br />
<br />
To correct Titan's position, we will use the task [http://casa.nrao.edu/stable/docs/TaskRef/fixplanets-task.html fixplanets], which writes the actual coordinates at the instant of the first observation. This step takes a while because we are recalculating the uvw's accordingly.<br />
<source lang="python"><br />
# In CASA<br />
fixplanets(vis='X3c1.ms', field='Titan', fixuvw=True)<br />
</source><br />
<br />
Check the header information again with {{listobs}} to confirm that the information for Titan has changed:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -f X3c1.ms.listobs')<br />
listobs('X3c1.ms', verbose=T, listfile='X3c1.ms.listobs') <br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 23625<br />
1 none Titan 12:49:25.93349 -02.22.41.5638 J2000 1 4842<br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 175176<br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 14832<br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 59877<br />
</pre><br />
<br />
Now fix the other two measurement sets similarly:<br />
<source lang="python"><br />
# In CASA<br />
fixplanets(vis='X5d8.ms', field='Titan', fixuvw=True)<br />
fixplanets(vis='X7ef.ms', field='Titan', fixuvw=True)<br />
</source><br />
<br />
==Observing Log and Priors==<br />
<br />
Below is some information that may not be obvious from the data<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Like at most telescopes, the ALMA operators and astronomers at the site log any significant issues <br />
that were noticed from the online system during the observation. For these Band 7 observations of <br />
TW Hya on April 22, 2011, the only issue of note was that antenna DV04 could not observe at Band 7 <br />
and will need to be flagged. <br />
</pre><br />
<br />
First let's examine the basic properties of the data using {{listobs}}. Among other information we <br />
will be able to deduce what the source ids are and what each source was used for:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
3c279 is the bandpass calibrator (field id=0)<br />
Titan is the absolute flux calibrator (field id=1)<br />
J1147-382 is the secondary phase calibrator (field id=3)<br />
J1037-295 is the primary phase calibrator (field id=4)<br />
</pre><br />
<br />
<source lang="python"><br />
# In CASA<br />
data=['X3c1.ms','X5d8.ms','X7ef.ms']<br />
for vis in data:<br />
os.system('rm '+vis+'.listobs')<br />
listobs(vis, verbose=T, listfile=vis+'.listobs') <br />
</source><br />
<br />
You can view the {{listobs}} output files using command '''less''' from the CASA prompt. <br />
Below we copy select parts of the {{listobs}} output files for reference. <br />
<br />
<pre style="background-color: #fffacd;"><br />
X3c1.ms:<br />
Data records: 278352 Total integration time = 6109.06 seconds<br />
Observed from 22-Apr-2011/00:01:52.9 to 22-Apr-2011/01:43:42.0 (UTC)<br />
<br />
X5d8.ms:<br />
Data records: 278406 Total integration time = 5995.01 seconds<br />
Observed from 22-Apr-2011/01:48:05.8 to 22-Apr-2011/03:28:00.8 (UTC)<br />
<br />
X7ef.ms:<br />
Data records: 255717 Total integration time = 5407.49 seconds<br />
Observed from 22-Apr-2011/03:30:39.7 to 22-Apr-2011/05:00:47.2 (UTC)<br />
<br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 23625<br />
1 none Titan 12:49:25.97588 -02.22.41.3024 J2000 1 4842<br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 175176<br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 14832<br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 59877 <br />
<br />
SpwID #Chans Frame Ch1(MHz) ChanWid(kHz) TotBW(kHz) Corrs<br />
0 4 TOPO 184550 1500000 7500000 I<br />
1 128 TOPO 355740.062 15625 2000000 XX YY<br />
2 1 TOPO 356716.625 1796875 1796875 XX YY<br />
3 128 TOPO 356507.813 15625 2000000 XX YY<br />
4 1 TOPO 357484.375 1796875 1796875 XX YY<br />
5 128 TOPO 346792.187 15625 2000000 XX YY<br />
6 1 TOPO 345784.375 1796875 1796875 XX YY<br />
7 128 TOPO 345182.438 15625 2000000 XX YY<br />
8 1 TOPO 344174.625 1796875 1796875 XX YY<br />
9 128 TOPO 344386.763 15625 2000000 XX YY<br />
10 1 TOPO 343378.95 1796875 1796875 XX YY<br />
11 128 TOPO 346324.263 15625 2000000 XX YY<br />
12 1 TOPO 345316.45 1796875 1796875 XX YY<br />
13 128 TOPO 354402.388 15625 2000000 XX YY<br />
14 1 TOPO 355378.95 1796875 1796875 XX YY<br />
15 128 TOPO 356402.388 15625 2000000 XX YY<br />
16 1 TOPO 357378.95 1796875 1796875 XX YY<br />
17 3840 TOPO 356497.936 122.070312 468750 XX YY<br />
18 1 TOPO 356732.189 468750 468750 XX YY<br />
19 3840 TOPO 357734.314 122.070312 468750 XX YY<br />
20 1 TOPO 357499.939 468750 468750 XX YY<br />
21 3840 TOPO 346034.314 122.070312 468750 XX YY<br />
22 1 TOPO 345799.939 468750 468750 XX YY<br />
23 3840 TOPO 343955.936 122.070312 468750 XX YY<br />
24 1 TOPO 344190.189 468750 468750 XX YY<br />
<br />
Antennas: 9:<br />
Name Station Diam. Long. Lat.<br />
0 DV04 J505 12.0 m -067.45.18.0 -22.53.22.8<br />
1 DV06 T704 12.0 m -067.45.16.2 -22.53.22.1<br />
2 DV07 J510 12.0 m -067.45.17.8 -22.53.23.5<br />
3 DV08 T703 12.0 m -067.45.16.2 -22.53.23.9<br />
4 DV09 N602 12.0 m -067.45.17.4 -22.53.22.3<br />
5 DV10 N606 12.0 m -067.45.17.1 -22.53.23.6<br />
6 PM01 T702 12.0 m -067.45.18.6 -22.53.24.1<br />
7 PM02 T701 12.0 m -067.45.18.8 -22.53.22.2<br />
8 PM03 J504 12.0 m -067.45.17.0 -22.53.23.0<br />
</pre><br />
<br />
Things to Notice from above: <br />
*There are three different data sets acquired close together in time. We will calibrate each dataset independently and then combine the calibrated data prior to imaging. <br />
*Titan appears to have slightly different positions in each dataset because it is a moving body. In fact, at the time of observation, due to temporary data capture issue in the ALMA system, the position was written has (0,0). We have pre-corrected this error using fixplanets. Later in the tutorial, we will run fixplanets again to force all three datasets to have the same fixed position for Titan.<br />
*There are a lot of spectral windows! Don't be alarmed. In ALMA data, <br />
**spw=0 is always reserved for the water vapor radiometry data.<br />
**spw=9, 11, 13, 15 are the wideband (TDM) correlator mode with 128 channels per spw default settings for doing pointing and this is all they are used for in these data.<br />
**Currently Tsys data can only be taken in the wide (TDM) correlator mode with 128 channels per spw, these correspond to spws=1, 3, 5, 7 above. The frequencies of these TDM spws were carefully chosen so the the narrowband FDM spws fall within them.<br />
** The 0.5 GHz, high spectral resolution spws that contain all the real source data (science target and calibrators) are 17, 19, 21, and 23<br />
**For quicklook purposes, the ALMA online system produces a channel averaged spw for each channelized spw, these correspond to spw=2,4,6,8,10,12,14,16,18,20,22,24 and shouldn't be used for anything in post-processing as bandpass calibration etc has not been applied.<br />
<br />
In the portion of the {{listobs}} output that shows the timerange, the final column gives the scan intent. It is important to have a look at this because you can flag and do other operations in CASA using the scan intent as a selection option. Also, these intents will be used in the future for pipeline processing. You will usually want to use them to flag the CALIBRATE_POINTING* and CALIBRATE_ATMOS* (the latter correspond to the hot and cold load measurements used to calculate Tsys) data. This is essential for science or calibration data taken only in TDM (wide bandwidth) mode, i.e. the same mode that the pointing and Tsys data are taken in. For the current data however, that calibration data is recorded in different spws from the useful FDM (narrow bandwidth) data, so we'll be able to separate them by splitting them off at the final step prior to imaging.<br />
<br />
<figure id="Ant_pos.png"><br />
[[Image:Ant_pos.png|thumb|<caption>Antenna locations for the first dataset.</caption>]]<br />
</figure><br />
<br />
Before we move on, its also nice to get an idea where the antennas are with respect to each other. We can use {{plotants}} to plot their positions. It is a good idea to check each file since an antenna may have entered or exited the array between observations.<br />
<source lang="python"><br />
# In CASA<br />
for vis in data:<br />
plotants(vis=vis,figfile=vis+'.plotants.png')<br />
</source><br />
<br />
You can view the output images using any standard image viewer.<br />
<br />
==Create the Tsys and WVR Tables, and Examine ==<br />
<br />
Each ms include tables that contain the Tsys and WVR measurements associated with the visibility data.<br />
We must create calibration tables from these measurements. First we create the WVR calibration tables <br />
by running the task [http://casa.nrao.edu/stable/docs/TaskRef/wvrgcal-task.html wvrgcal]. This task <br />
examines the data for each ms as a whole and creates a calibration<br />
table containing only phase corrections for each antenna and spw. <br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
os.system('rm -rf '+asdm+'.wvr')<br />
wvrgcal(vis=asdm+'.ms', caltable=asdm+'.wvr', segsource=True, toffset=-1)<br />
</source><br />
<br />
Next we create the Tsys tables by running {{gencal}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
os.system('rm -rf '+asdm+'.tsys')<br />
gencal(vis=asdm+'.ms', caltable=asdm+'.tsys', caltype='tsys')<br />
</source><br />
<br />
It is very important that Tsys measurements taken as close in time and elevation as possible to a particular source are applied. To save telescope time, Tsys measurements are sometimes intentionally skipped in the scheduling block for specific sources. So the first step is to establish which sources have their own Tsys measurements and which do not. To do this, you may use the intent parameter of {{listobs}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
listobs(vis=asdm+'.ms', verbose=F, selectdata=True, intent='CALIBRATE_ATMOS*')<br />
</source><br />
<br />
<figure id="X3c1.tsys_vs_time_3.4.png"><br />
[[File:X3c1.tsys_vs_time_3.4.png|thumb|<caption>Tsys vs. time for spw 1 of the X3c1.ms data.</caption>]]<br />
</figure><br />
<figure id="X5d8.tsys_vs_time_3.4.png"><br />
[[File:X5d8.tsys_vs_time_3.4.png|thumb|<caption>Tsys vs. time for spw 1 of the X5d8.ms data.</caption>]]<br />
</figure><br />
<figure id="X7ef.tsys_vs_time_3.4.png"><br />
[[File:X7ef.tsys_vs_time_3.4.png|thumb|<caption>Tsys vs. time for spw 1 of the X7ef.ms data.</caption>]]<br />
</figure><br />
<br />
<pre style="background-color: #fffacd;"><br />
Fields: 4<br />
ID Code Name RA Decl Epoch SrcId nRows <br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 1116 <br />
1 none Titan 12:49:25.97588 -02.22.41.3024 J2000 1 1125 <br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 6795 <br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 6777 <br />
Spectral Windows: (9 unique spectral windows and 2 unique polarization setups)<br />
SpwID #Chans Frame Ch1(MHz) ChanWid(kHz) TotBW(kHz) Corrs <br />
0 4 TOPO 184550 1500000 7500000 I <br />
1 128 TOPO 355740.062 15625 2000000 XX YY <br />
2 1 TOPO 356716.625 1796875 1796875 XX YY <br />
3 128 TOPO 356507.813 15625 2000000 XX YY <br />
4 1 TOPO 357484.375 1796875 1796875 XX YY <br />
5 128 TOPO 346792.187 15625 2000000 XX YY <br />
6 1 TOPO 345784.375 1796875 1796875 XX YY <br />
7 128 TOPO 345182.438 15625 2000000 XX YY <br />
8 1 TOPO 344174.625 1796875 1796875 XX YY <br />
</pre><br />
<br />
Because field '3' (the secondary phase calibrator) does not appear in the list, it has no tsys. Since the secondary phase calibrator is close on the sky to the primary phase calibrator and observed near in time, we will transfer the Tsys from the primary to the secondary phase calibrator. <br />
Also notice that spws 1,3,5,7 are the only multi-channel spws that contain Tsys data. At present, Tsys measurements can only be obtained with TDM spectral setups (128 channels/dual pol). Because our science target is observed in FDM (3840 channels/dual pol), we will need to interpolate the measurements from TDM to FDM. But first, to inspect the Tsys vs. time, we use {{plotcal}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all = ['X3c1','X5d8','X7ef']<br />
tsysfields=['0','1','2','4']<br />
os.system('mkdir cal_plots; mkdir cal_plots/Tsys_plots') <br />
for asdm in basename_all:<br />
print "Plotting Tsys vs. time for "+asdm<br />
plotcal(caltable=asdm+'.tsys', xaxis='time',yaxis='tsys',<br />
antenna='1~8',plotrange=[0,0,100,500],<br />
iteration='antenna',subplot=421,poln='',spw='1:50~50',<br />
figfile='cal_plots/Tsys_plots/'+asdm+'.tsys_vs_time.png')<br />
if (asdm != basename_all[-1]):<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
To inspect Tsys vs. frequency, we use [[plotbandpass]]. There are many different options for plotbandpass, and we demonstrate some of the most useful ones. The option '''showtsky=T''' will overlay the effective temperature curve from the atmospheric model. This shows us the location of any atmospheric lines which will appear as emission lines in the autocorrelation data (from which the Tsys spectra are derived) from all antennas. In the<br />
example below, we set '''interactive=False''', which will produce many pages of plots as<br />
individual pngs but will only show the final page in the graphics window. To view all the pages we use the image viewer '''eog''' (Eye of GNOME) available on Linux. The alternative is to set '''interactive=True''' and examine the plots in the casa graphics window as they are produced.<br />
<br />
<figure id="X3c1.tsys.field0.DV04.spw1.t1.png"><br />
[[File:X3c1.tsys.field0.DV04.spw1.t1.png|thumb|<caption>Tsys vs. frequency on 3C279 for the X3c1.ms data, spw=1.</caption>]]<br />
</figure><br />
<figure id="X3c1.tsys.field0.DV04.spw3.t1.png"><br />
[[File:X3c1.tsys.field0.DV04.spw3.t1.png|thumb|<caption>Tsys vs. frequency on 3C279 for the X3c1.ms data, spw=3.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
print "Plotting Tsys vs. frequency for "+asdm<br />
for spw in [1,3,5,7]:<br />
for field in ['0','1']:<br />
plotbandpass(caltable=asdm+'.tsys', xaxis='freq',yaxis='amp',<br />
showtsky=T,subplot=42,field=field,<br />
spw=spw, interactive=False, plotrange=[0,0,0,0],<br />
figfile='cal_plots/Tsys_plots/'+asdm+'.tsys.field%s.png'%field,<br />
buildpdf=False)<br />
</source><br />
<br />
In <xr id="X3c1.tsys.field0.DV04.spw1.t1.png"/> and <xr id="X3c1.tsys.field0.DV04.spw3.t1.png"/> we see the effect of atmospheric ozone lines on the Tsys measurements associated with 3C279 in spw 1 and 3.<br />
<br />
For sources that have multiple Tsys measurements (typically the primary phase calibrator and/or the science target) one can use '''overlay="time"''' to overlay all the measurements for that source. This can help to identify any anomalous Tsys scans. As a fraction of the plots produced by this loop, here we show the Tsys recorded on spw=1 for TW Hya from the first dataset.<br />
<br />
<figure id="X3c1.tsys.field2.DV04.spw1.png"><br />
[[File:X3c1.tsys.field2.DV04.spw1.png|thumb|<caption>Tsys vs. freq for field 2, spw 1 of the X3c1.ms data (antennas 0..3).</caption>]]<br />
</figure><br />
<figure id="X3c1.tsys.field2.DV04.spw1.png"><br />
[[File:X3c1.tsys.field2.DV09.spw1.png|thumb|<caption>Tsys vs. freq for field 2, spw 1 of the X3c1.ms data (antennas 4..7).</caption>]]<br />
</figure><br />
<figure id="X3c1.tsys.field2.PM03.spw1.png"><br />
[[File:X3c1.tsys.field2.PM03.spw1.png|thumb|<caption>Tsys vs. freq for field 2, spw 1 of the X3c1.ms data (antenna 8).</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
print "Plotting Tsys vs. frequency for "+asdm<br />
for spw in [1,3,5,7]:<br />
for field in ['2','4']:<br />
plotbandpass(caltable=asdm+'.tsys', xaxis='freq',yaxis='amp',<br />
showtsky=T,subplot=22,field=field,<br />
overlay='time',spw=spw, interactive=False, plotrange=[0,0,0,0],<br />
figfile='cal_plots/Tsys_plots/'+asdm+'.tsys.field%s.png'%field,<br />
buildpdf = False)<br />
</source><br />
<br />
Alternatively, the '''overlay="antenna"''' option will quickly reveal any Antennas with discrepant Tsys values, as they<br />
will be obvious outliers. For FDM projects like this one, using the '''showfdm=True''' option can be helpful, as it<br />
will show where in the TDM bandpass each FDM spw was located. <br />
<figure id="X3c1.tsys.field0.spw1.t1.png"><br />
[[Image:X3c1.tsys.field0.spw1.t1.png|thumb|<caption>Tsys vs Freq for field 0, spw 1 of the X3c1.ms data with all antennas overlaid.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
tsysfields=['0','1','2','4'] <br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
print "Plotting Tsys vs. frequency for "+asdm<br />
for spw in [1,3,5,7]:<br />
for field in tsysfields:<br />
plotbandpass(caltable=asdm+'.tsys', xaxis='freq',yaxis='amp',<br />
showtsky=T,subplot=11,field=field,<br />
overlay='antenna',spw=spw, interactive=False,<br />
figfile='cal_plots/Tsys_plots/'+asdm+'.tsys.field%s.png'%field,<br />
buildpdf=False,showfdm=True)<br />
</source><br />
<br />
<br />
Note that DV04 consistently has a significantly higher Tsys than the rest of the antennas. We already know from the Observation log that<br />
we need to flag that antenna, but had we not had that information, examining this plot would have demonstrated the situation.<br />
<br />
==Apply the Tsys and WVR Tables, and Split ==<br />
<br />
Next we apply the calibrations. For the (4) sources with Tsys measurements, we use the '''field''' and '''gainfield''' parameters of {{applycal}} to apply solutions only to themselves. {{applycal}} has the ability to interpolate gain tables from one spw onto another spw. In this case, we want to interpolate the TDM Tsys values in spws 1,3,5,7 onto the FDM spws 17,19,21,23. We use the '''interp''' parameter to request linear interpolation in the time dimension and spline interpolation in the channel/frequency dimension. To map the solutions for each spw, we use the '''spwmap''' parameter, which requires a list of all spws for each gain table to be applied, or a blank list ([]) which is a shorthand notation to apply the solution for each spw to itself. While applying Tsys, we will also apply the wvr calibration tables; wvr data is usually always present for all sources. Below we first set some definitions so we can loop over the correct parameters:<br />
<br />
<source lang="python"><br />
# In CASA<br />
fdm='17,19,21,23'<br />
nocal='3' # This source had no Tsys measurements associated with it <br />
tsysfields=['0','1','2','4'] <br />
tsysmap = range(25)<br />
tsysmap[17] = 1<br />
tsysmap[19] = 3<br />
tsysmap[21] = 5<br />
tsysmap[23] = 7<br />
for asdm in basename_all:<br />
for field in tsysfields:<br />
applycal(vis=asdm+'.ms', spw=fdm, field=field, gainfield=field,<br />
gaintable=[asdm+'.tsys', asdm+'.wvr'], spwmap=[tsysmap,[]],<br />
interp=['linear,spline','nearest'], flagbackup=F, calwt=T)<br />
</source><br />
<br />
For the sources without Tsys (i.e. field=3), couple them with the best available source with Tsys (i.e. field=4).<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename_all:<br />
applycal(vis=asdm+'.ms', spw=fdm, field=nocal,<br />
gaintable=[asdm+'.tsys', asdm+'.wvr'], spwmap=[tsysmap,[]],<br />
gainfield=['4',nocal], interp=['linear,spline','nearest'],flagbackup=F,<br />
calwt=T)<br />
</source><br />
<br />
Check Tsys application with plotms. First we make plots with '''ydatacolumn='data'''' to look at the raw data. For <br />
simplicity we'll just look at the two strongest sources 3C279 and Titan.<br />
<br />
<figure id="X5d8_wvrtsys_corrected_spw19.png"><br />
[[Image:X5d8_wvrtsys_corrected_spw19.png|thumb|<caption>Spectral plots of 3C279 (black) and Titan (magenta) for spw=19 after Tsys and wvr correction.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X5d8.ms',spw='17,19,21,23',xaxis='frequency',yaxis='amp',field='0,1',<br />
antenna='*&*',avgtime='1e8',avgscan=T,coloraxis='field',iteraxis='spw',<br />
xselfscale=T,ydatacolumn='data')<br />
</source><br />
<br />
<figure id="X5d8_wvrtsys_corrected_spw21.png"><br />
[[Image:X5d8_wvrtsys_corrected_spw21.png|thumb|<caption>Spectral plots of 3C279 (black) and Titan (magenta) for spw=21 after Tsys and wvr correction.</caption>]]<br />
</figure><br />
<br />
'''Note''': the antenna='*&*' is specifying that we only want to see the cross-correlation data (i.e. not the autocorrelations).<br />
<br />
Use the '''green arrows''' on the {{plotms}} display to cycle through the 4 FDM spws. <br />
<br />
Now change '''Data Column''' to '''corrected''' on the "Axes" tab (this is the same as ydatacolumn in the task) and hit '''Plot''' button on the GUI. Flip through again.<br />
<br />
'''Things to notice:'''<br />
* The amplitude scale has changed due to application of Tsys<br />
* spw=17 is clean and flat<br />
* spw=19 shows a strong dip around channel 3000 (channels can be plotted by going to the Axes tab, and changing X Axis to Channel, then hit the Plot button)-- this is an atmospheric ozone absorption feature at 357.6 GHz. In the future, high spectral resolution Tsys measurements may help to remove the shape of the absorption, but until then we will need to flag this part of the spectrum.<br />
* spw=21 Titan shows both a narrow and a broad spectral feature. The broad feature is CO(3-2) and it completely fills the 0.5 GHz band so there are no line-free channels! Titan must be handled carefully when it is used as a calibrator because it contains strong line emission. Indeed, we will not be able to use the absolute flux transfer from this spw for other targets. When possible Titan should be avoided for absolute flux calibration. For these observations, no other suitable absolute flux calibrator was available.<br />
* spw=23 shows another strong line from Titan.<br />
<br />
Beyond these things to notice, the application of Tsys and wvr seem to have gone well. We can now split off only the narrow band FDM spectral windows for further processing.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename_all:<br />
newvis = asdm + '_wvrtsys.ms'<br />
os.system('rm -rf ' + newvis)<br />
split(vis=asdm+'.ms',outputvis=newvis,datacolumn='corrected',spw=fdm)<br />
</source><br />
<br />
'''Note''': After {{split}}, the spectral windows will be renumbered to 0, 1, 2, 3 corresponding to the old spw=17, 19, 21, 23, see {{listobs}} excerpt below.<br />
<br />
<pre style="background-color: #fffacd;"><br />
SpwID #Chans Frame Ch1(MHz) ChanWid(kHz) TotBW(kHz) Corrs <br />
0 3840 TOPO 356497.936 122.070312 468750 XX YY <br />
1 3840 TOPO 357734.314 122.070312 468750 XX YY <br />
2 3840 TOPO 346034.314 122.070312 468750 XX YY <br />
3 3840 TOPO 343955.936 122.070312 468750 XX YY <br />
</pre><br />
<br />
==Initial Inspection and Flagging==<br />
<br />
From here we begin to operate on the *wvrtsys.ms files. <br />
<br />
Before we begin flagging data, we unflag all data in the measurement sets. If this is your first pass through this section of the guide, no data in the measurement sets will have previously been flagged, and so you can skip the next splitdata step with mode set to 'unflag'. If you are rerunning the flagging commands below, running splitdata in 'unflag' mode will reset your flag columns to their original state.<br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
for vis in splitdata:<br />
flagdata(vis=vis, mode='unflag', action='apply', flagbackup=F)<br />
</source><br />
<br />
ALMA data contains both the cross correlation and autocorrelation data. Presently nothing more can be done with the autocorrelation data so we flag it. Additionally, for smaller configurations of the array, and northerly sources one antenna can ''shadow'' another, blocking its view. This data also needs to be flagged. Finally, the observing log told us DV04 was not behaving properly at Band 7 and shouldn't be used so we flag that as well.<br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
for vis in splitdata:<br />
flagdata(vis=vis, mode='manual', autocorr=True, action = 'apply', flagbackup=T)<br />
flagdata(vis=vis, mode='shadow',tolerance=12.0, action='apply', flagbackup=F)<br />
flagdata(vis=vis, mode='manual', antenna='DV04', action='apply', flagbackup=F)<br />
</source><br />
<br />
Next we inspect the data with {{plotms}} for additional issues that need flagging, first looking at amplitude vs. time for each of the three datasets. Use the '''green''' arrows on the plotms gui to cycle through spws. <br />
<br />
<figure id="Tsyswvr_time_spw0_X3x1.png"><br />
[[Image:Tsyswvr_time_spw0_X3x1.png|thumb|<caption>Amplitude as a function of time for X3c1_wvrtsys.ms, spw=0</caption>]]<br />
</figure><br />
<br />
'''Note''': when '''iteraxis''' is invoked in {{plotms}}, unzoom does not always work properly. If you have trouble with this, flip to next page and then back to current one. This usually fixes the problem.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X5d8_wvrtsys.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X7ef_wvrtsys.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw')<br />
</source><br />
<br />
<figure id="Tsyswvr_time_spw2corr_X3x1.png"><br />
[[Image:Tsyswvr_time_spw2corr_X3x1.png|thumb|<caption>Amplitude as a function of time for X3x1_wvrtsys.ms, spw=2 with colorize='corr'.</caption>]]<br />
</figure><br />
<br />
'''Things to Notice:'''<br />
* In spw=2 there are some low points in all three data files. Use the "Mark Regions" box (left of center on bottom row of icons) to draw small box on low points. Then click the magnifying glass icon to the right of center. The output will be sent to the logger window. '''Note''': keep the marked region small or you can overwhelm the buffer. Locate suggests correlation YY on PM03 is the culprit. <br />
<br />
To see this more clearly you can rerun {{plotms}} with '''coloraxis='field'''' switched to '''coloraxis='corr''''<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='2',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='corr')<br />
</source><br />
<br />
To further check, you can exclude PM03 from the plot using '''antenna='!PM03'.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='2',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='corr',antenna='!PM03')<br />
</source><br />
<br />
Having confirmed the problem antenna, we flag it below. <br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
for vis in splitdata:<br />
flagdata(vis=vis, mode='manual', action= 'apply', flagbackup=T,<br />
spw='2',<br />
antenna='PM03')<br />
</source><br />
<br />
'''Next we need to inspect the spectral properties of the data to look for issues.'''<br />
<br />
First we look at phase as a function of frequency for an antenna like DV06 for which we have not yet identified any problems. <br />
'''coloraxis='baselines'''' (note this parameter is called '''Colorize''' in the GUI "Display" tab) will show each baseline as a different color. Significant delay errors or baseline errors will show up as phase slopes in these plots. Again you will want to page through the spectral windows.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='',xaxis='frequency',yaxis='phase',field='0',antenna='DV06',<br />
avgtime='1e8',avgscan=T,coloraxis='baseline',iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X5d8_wvrtsys.ms',spw='',xaxis='frequency',yaxis='phase',field='0',antenna='DV06',<br />
avgtime='1e8',avgscan=T,coloraxis='baseline',iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X7ef_wvrtsys.ms',spw='',xaxis='frequency',yaxis='phase',field='0',antenna='DV06',<br />
avgtime='1e8',avgscan=T,coloraxis='baseline',iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
Overall these plots look good: they show the phases varying slowly in a correlated way (i.e. without rapid or unpredictable scatter).<br />
<br />
<figure id="Birdies_spw2_X3x1.png"><br />
[[Image:Birdies_spw2_X3x1.png|thumb|<caption>Phase calibrators (brown and green) and TW Hya (orange) showing both real CO(3-2) emission in TW Hya and weak ''birdie'' spectral features in all three sources for spw=2.</caption>]]<br />
</figure><br />
<br />
With such high spectral resolution data, one often sees occasional "birdies" in the data. These are typically very narrow spectral features that are internally generated in the system. As ALMA development continues across observation cycles, the number of birdies should decrease. They are easiest to check for by looking at amplitude vs. frequency for sources observed over a long time range (for sensitivity). It is helpful to look at more than one source to verify the nature of the emission. Below we look at both calibrators (brown and green) and TW Hya (orange). If you have enough sensitivity birdies should be seen on all sources, however, be careful not to mistake real line emission for a birdie even on a calibrator - they can be present as we've seen for Titan. Most often birdies will only appear on a subset of antennas and so can often be identified and eliminated that way.<br />
<br />
<figure id="Birdies_spw3_X3x1.png"><br />
[[Image:Birdies_spw3_X3x1.png|thumb|<caption>Phase calibrators (brown and green) and TW Hya (orange) showing only weak birdie spectral features in spw=3.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='',xaxis='channel',yaxis='amp',field='2,3,4',<br />
avgtime='1e8',avgscan=T,coloraxis='field',iteraxis='spw',xselfscale=T,yselfscale=T)<br />
</source><br />
<br />
Do a quick check that other two datasets are the same (they are usually similar if the source of internal resonance hasn't changed in the meantime).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X5d8_wvrtsys.ms',spw='',xaxis='channel',yaxis='amp',field='2,3,4',<br />
avgtime='1e8',avgscan=T,coloraxis='field',iteraxis='spw',xselfscale=T,yselfscale=T)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X7ef_wvrtsys.ms',spw='',xaxis='channel',yaxis='amp',field='2,3,4',<br />
avgtime='1e8',avgscan=T,coloraxis='field',iteraxis='spw',xselfscale=T,yselfscale=T)<br />
</source><br />
<br />
Now you can zoom in on each region to get channels for flagging, or to save time just go ahead and run the flagging command below where this has been done for you.<br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
for vis in splitdata:<br />
flagdata(vis=vis, mode='manual', action='apply', flagbackup=T,<br />
spw='0:1067~1068;1279~1280;2367~2368;3775~3776, 1:1279~1280;2367~2368;3775~3776, 2:1279~1280;3775~3776, 3:831~832;1535~1536;2367~2368;3775~3776;3839~3839')<br />
</source><br />
<br />
Replete in {{plotms}} using the plotms commands directly above to check that flagging has been done as anticipated.<br />
<br />
==Flag Calibrator Spectral Features==<br />
<br />
In this section, we will flag spectral features in the calibrators so they do not skew the calibration solutions. First make plots of 3C279 and Titan in channel space to get channels for flagging. <br />
<br />
<figure id="3C279_Titan_spw1.png"><br />
[[Image:3C279_Titan_spw1.png|thumb|<caption>Spectral plots of 3C279 (black) and Titan (magenta) for spw=1 after Tsys and wvr correction.</caption>]]<br />
</figure><br />
<figure id="3c279_meso_freq.png"><br />
[[Image:3c279_meso_freq.png|thumb|<caption>Zoomed spectral plot of 3C279 showing mesospheric absorption of CO(3-2) in frequency space.</caption>]]<br />
</figure><br />
<figure id="3c279_meso_chann.png"><br />
[[Image:3c279_meso_chann.png|thumb|<caption>Zoomed spectral plot of 3C279 showing mesospheric absorption of CO(3-2) in channel space.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='channel',yaxis='amp',field='0,1',<br />
avgtime='1e8',coloraxis='field',iteraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
The figure to the right shows a broad absorption line in spw 1 at channel 3000. This is the ozone absorption line at 357.62982 GHz. However, there is another narrow absorption feature in the spectra (spw 2) that is most easily seen on 3C279 (because it is the strongest calibrator). Let's look at it first in frequency space.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='2:1600~2300',xaxis='frequency',yaxis='amp',<br />
field='0',avgtime='1e8',coloraxis='field')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
The absorption feature lies exactly at the rest frequency for CO 3-2 (345.79599 GHz). Because it is so narrow (< 1 MHz), it must originate from a very low pressure region (i.e. high altitude) in the Earth's atmosphere, otherwise it would be more pressure broadened. Indeed, the first detection of CO in the mesosphere was made over 35 years ago (see, e.g. [http://adsabs.harvard.edu/abs/1976Sci...191.1174W Waters et al. 1976] or [http://adsabs.harvard.edu/abs/1979JGR....84..416G Goldsmith et al. 1979]). Be aware that the line is stronger as you go up the CO ladder (strength ~ J^3 for low J) because the temperature at that altitude (~50km) is about 250 K. In April 2011, the apparent depth of the feature was about 10% in the 2-1 line and 35% in the 3-2 line. However, the depth of the absorption feature is exaggerated due to the way ALMA normalizes the cross-correlation spectra by the autocorrelation spectra prior to storage. While this technique generally leads to a flat bandpass shape, it will accentuate telluric features because they are emission lines in the single dish spectrum (e.g. JCMT observations of mesospheric CO 3-2 can be found in [http://adsabs.harvard.edu/abs/1993MNRAS.264..673P Preston et al. 1993]). Finally, note that large seasonal variations in the line strength have been reported from observations at [http://adsabs.harvard.edu/abs/2003GeoRL..30j..39F Onsala]. <br />
<br />
Now, let's re-plot the line with channel number as the x-axis in order to get the channel range for flagging. <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='2:1600~2300',xaxis='channel',yaxis='amp',<br />
field='0',avgtime='1e8',coloraxis='field')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Now lets look at Titan in more detail.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='channel',yaxis='amp',field='1',<br />
avgtime='1e8',coloraxis='field',iteraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Explicitly back up the flag tables so that flagged regions can be restored later.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
flagmanager(vis=asdm+'.ms',mode='save',versionname=asdm+'.before_calspectralflags')<br />
</source><br />
<br />
<figure id="Titan_spw2.png"><br />
[[Image:Titan_spw2.png|thumb|<caption>Spectral plot of Titan (magenta) for spw=2.</caption>]]<br />
</figure><br />
<br />
Flag absorption features for all sources.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
print "Flagging absorption features in all sources for "+asdm<br />
flagdata(vis=asdm+'.ms', mode='manual', spw='1:2000~3839, 2:1945~1960')<br />
</source><br />
<br />
<figure id="Titan_spw3.png"><br />
[[Image:Titan_spw3.png|thumb|<caption>Spectral plot of Titan (magenta) for spw=3.</caption>]]<br />
</figure><br />
<br />
Now we need to flag emission. The very broad CO(3-2) in spw=2 of Titan will prevent us from using it as a calibrator for this spectral window since there are no line-free channels (we will transfer, phase, amplitude, and absolute flux from another Titan spw below). We do want to flag the narrower Titan line in spw=3.<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
flagmanager(vis=asdm+'.ms',mode='save',versionname=asdm+'.before_emissionflags')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
print "Flagging emission for "+asdm<br />
flagdata(vis=asdm+'.ms', mode='manual', <br />
field='1',<br />
spw='3:1000~3000')<br />
</source><br />
<br />
If you like, check that the right things have been flagged.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='channel',yaxis='amp',field='0,1',<br />
avgtime='1e8',coloraxis='field',iteraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
==Set Up the Flux Calibrator Model==<br />
<br />
Fill the model data column for Titan with a model for the flux density as a function of baseline. The model is a uniformly illuminated disk with the size obtained from the JPL Horizons ephemeris.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
setjy(vis=asdm+'.ms',field='1',usescratch=F,<br />
standard='Butler-JPL-Horizons 2010',scalebychan=F)<br />
</source><br />
<br />
<figure id="Titan amp vs uvdist.png"><br />
[[Image:Titan amp vs uvdist.png|thumb|<caption>Plot of Titan model for each of the 4 spws. We used the Butler-JPL-Horizons 2010 standard to compute this model.</caption>]]<br />
</figure><br />
<br />
After running setjy, it is a good idea to plot the model in order to confirm that it makes sense. In this case, Titan is partially resolved, so we expect the flux density to drop with uv distance, but not so much as to pass through a null. We also expect it to be brighter at higher frequencies since it has a thermal blackbody spectrum.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',field='1',xaxis='uvdist',yaxis='amp',coloraxis='spw',<br />
ydatacolumn='model')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<figure id="twhydra_X3c1_wvrtsys_2012_titan_model.png">[[File:twhydra_X3c1_wvrtsys_2012_titan_model.png|thumb|right|<caption>Titan model produced by 'Butler-JPL-Horizons 2012'.</caption>]]</figure><br />
<br />
<br/><br />
<div class="noprint" style="float:none; border:0px solid blue;background-color:#F6CEF5;padding:2px;"><br />
The setjy invocation, above, uses the flux density standard '''standard='Butler-JPL-Horizons 2010' '''. A more updated standard is also available: '''standard='Butler-JPL-Horizons 2012' '''. <xr id="twhydra_X3c1_wvrtsys_2012_titan_model.png"/> shows the Titan model produced using the updated standard. The motivated reader may wish to rerun {{setjy}} using the updated model. We will highlight later in this tutorial, and in the imaging tutorial that follows, the effects of using the updated model.<br />
</div><br />
<br />
==Bandpass Calibration==<br />
<br />
First we need to check how the amplitude and phase of 3C279 behave as a function of time. In order to set<br />
a fixed scale on the y-axis, we first make a plot of all the data, excluding antenna DV04. (We must specify '''ydatacolumn='data' ''' explicitly here because the default value of '''ydatacolumn''' equals the value used in the previous execution of {{plotms}}. In the previous execution '''ydatacolumn''' was set to '''model'''. See the online help, <tt>help plotms</tt>, for details.)<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',xaxis='time',yaxis='amp',coloraxis='corr',<br />
field='0',avgchannel='3840',ydatacolumn='data')<br />
</source><br />
<br />
<figure id="ThreeScansAmp.png"><br />
[[Image:ThreeScansAmp.png|thumb|<caption>Amplitude variation for three 3C279 scans, spw 0 (for one representative baseline).</caption>]]<br />
</figure><br />
<br />
We see that the uncalibrated amplitudes range between 0.2-0.4, so let's set this as our<br />
scale and examine a representative baseline (DV06-DV07) to see how the amplitude changes with time. <br />
<br />
<source lang="python"><br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for spw in ['0','1','2','3']:<br />
for asdm in basename:<br />
print "Now showing spw %s from %s" % (spw, asdm+'.ms')<br />
plotms(vis=asdm+'.ms',spw=spw,xaxis='time',yaxis='amp',coloraxis='corr',iteraxis='spw',<br />
field='0',avgchannel='3840',antenna='DV06&DV07',plotrange=[0,0,0.2,0.4])<br />
user_check=raw_input('press enter to go to the next plot\n')<br />
</source><br />
<br />
<figure id="ThreeScansPhase.png"><br />
[[Image:ThreeScansPhase.png|thumb|<caption>Phase variation for three 3C279 scans, spw 0 (for one representative baseline).</caption>]]<br />
</figure><br />
<br />
Page through the measurement sets for each spw. This shows significant variations in the amplitude across the three measurement sets.<br />
Now do the same with phase.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for spw in ['0','1','2','3']:<br />
for asdm in basename:<br />
print "Now showing spw %s from %s" % (spw, asdm+'.ms')<br />
plotms(vis=asdm+'.ms',spw=spw,xaxis='time',yaxis='phase',coloraxis='corr',iteraxis='spw',<br />
field='0',avgchannel='3840',antenna='DV06&DV07',plotrange=[0,0,-180,180])<br />
user_check=raw_input('press enter to go to the next plot\n')<br />
</source><br />
<br />
This examination reveals two findings: (1) significant variation in the phase across the three scans, as well as (2) smaller but significant variations within a scan. The first finding suggests that we do not want to combine the scans for bandpass calibration, but instead derive an independent bandpass for each scan. Actually what is more important than a DC offset is if the '''shape''' of the amplitude or phase changes from scan to scan. There isn't enough S/N to tell for sure so we will keep them separate. This situation is often the case, which is why we did not concatenate the three datasets prior to calibration. The second finding suggests that we need to correct the phase vs. time behavior of the bandpass calibrator (3C279; field=0) within each scan, before doing the bandpass. We want to chose a relatively narrow range of channels near the center of the spws so that the bandpass phase slopes (to be corrected with the bandpass calibration itself) do not decorrelate the signal. You need to avoid spectral regions that were completely flagged above.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.bpphase.gcal')<br />
gaincal(vis=asdm+'.ms',caltable=asdm+'.bpphase.gcal',<br />
field='0',spw='0~3:900~1100',refant='DV06',<br />
calmode='p',solint='int',minsnr=2.0,minblperant=4)<br />
</source><br />
<br />
<figure id="X7ef_wvrtsys.bpphase.X.png"><br />
[[Image:X7ef_wvrtsys.bpphase.X.png|thumb|<caption>Phase only solutions for correlation X on the third scan of the bandpass calibrator 3C279.</caption>]]<br />
</figure><br />
<br />
Inspect the phase-only calibration solutions for the bandpass calibrator. Look for any noisy solutions. We do XX and YY separately to reduce confusion in the plot. It will help if you make your plotcal window wide.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.bpphase.gcal',xaxis='time',yaxis='phase',spw='',antenna='1~8', <br />
iteration='antenna',subplot=421,plotrange=[0,0,-180,180],<br />
figfile=asdm+'.bpphase.X.png',poln='X')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
In the plotcal gui you can use the magnifying glass symbol to zoom in on one of the scans to see the phase variations. The colors are the 4 different spws.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.bpphase.gcal',xaxis='time',yaxis='phase',spw='',antenna='1~8', <br />
iteration='antenna',subplot=421,plotrange=[0,0,-180,180],<br />
figfile=asdm+'.bpphase.Y.png',poln='Y')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Next we apply this phase-only correction on the fly while calculating the bandpass solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.bandpass.bcal')<br />
bandpass(vis=asdm+'.ms',caltable=asdm+'.bandpass.bcal',<br />
field='0',spw='',combine='',refant='DV06',<br />
solint='inf',solnorm=T,minblperant=4, bandtype='B', fillgaps=17,<br />
gaintable=asdm+'.bpphase.gcal')<br />
</source><br />
<br />
You will see some error messages in the terminal, these are just related to the flagged channels. We set fillgaps=17 to interpolate across the smaller regions of flagged channels (mesospheric features and birdies).<br />
<br />
<figure id="Bandpass.ampspw0.png"><br />
[[Image:Bandpass.ampspw0.png|thumb|<caption>Bandpass amplitude solution plots.</caption>]]<br />
</figure><br />
<figure id="Bandpass.phasespw0.png"><br />
[[Image:Bandpass.phasespw0.png|thumb|<caption>Bandpass phase solution plots.</caption>]]<br />
</figure><br />
<br />
'''A few words about solint and combine:'''<br />
<br />
In {{bandpass}}, the use of '''solint='inf'''' (as in "infinite") will derive a bandpass<br />
solution for each 3C279 scan, '''unless''' '''combine='scan'''' (which is the default). Here we set combine=' ' explicitly so that it does not combine the scans into one bandpass. Likewise, field boundaries are only crossed if combine='field', and spw boundaries are only crossed if combine='spw'. In some cases it can be helpful to combine fields if you suffer from lack of S/N, but it is never a good idea to combine spws. <br />
<br />
Now inspect the phase and amplitude solutions. You are looking for excursions from smooth fits, or particularly noisy solutions compared to the others. <br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
for spw in [0,1,2,3]:<br />
plotbandpass(asdm+'.bandpass.bcal',xaxis='freq',yaxis='amp', spw=spw,<br />
antenna='1~8', subplot=42, figfile=asdm+'.bandpass.amp', showatm=T,<br />
interactive=True)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
for spw in [0,1,2,3]:<br />
plotbandpass(asdm+'.bandpass.bcal',xaxis='freq',yaxis='phase',spw=spw,<br />
antenna='1~8',subplot=42,figfile=asdm+'.bandpass.phs', showatm=T,<br />
interactive=True)<br />
</source><br />
<br />
The values of phase on DV06 are very close to zero because it was used as the reference antenna.<br />
<br />
==Gain Calibration==<br />
<br />
Now that we have a bandpass solution to apply we can solve for the antenna-based phase and amplitude gain calibration. Since the phase changes on a much shorter timescale than the amplitude, we will solve for them separately. In particular, if the phase changes significantly over a scan time, the amplitude would be decorrelated, if the un-corrected phase were averaged over this timescale. Note that we re-solve for the gain solutions of the bandpass calibrator, so we can derive new solutions that are corrected for the bandpass shape. Since the bandpass calibrator will not be used again, this is not strictly necessary, but is useful to check its calibrated flux density for example. <br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.intphase.gcal')<br />
gaincal(vis=asdm+'.ms',caltable=asdm+'.intphase.gcal',<br />
field='0,1,3,4',spw='0~3:40~3800',refant='DV06',<br />
calmode='p',solint='int',minsnr=2.0,minblperant=4,<br />
gaintable=[asdm+'.bandpass.bcal'])<br />
</source><br />
<br />
Here '''solint='int' ''' coupled with '''calmode='p' ''' will derive a single phase solution for each 10 second integration. Note that the bandpass table is applied on-the-fly before solving for the phase solutions, however the bandpass is NOT applied to the data permanently until applycal is run later on. <br />
<br />
Although '''solint='int' ''' (i.e. the integration time of 10 seconds) is the best choice to apply before solving for the amplitude solutions, it is not a good idea to use this to apply to the target. This is because the phase-scatter within a scan can dominate the interpolation between calibrator scans. Instead, we also solve for the phase on the scan time, '''solint='inf' ''' (but '''combine=' ' ''', since we want one solution per scan) for application to the target later on. Unlike the bandpass task, for {{gaincal}}, the default of the combine parameter is '''combine=' ' '''. <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.scanphase.gcal')<br />
gaincal(vis=asdm+'.ms',caltable=asdm+'.scanphase.gcal',<br />
field='0,1,3,4',spw='0~3:40~3800',refant='DV06',<br />
calmode='p',solint='inf',minsnr=2.0,minblperant=4,<br />
gaintable=[asdm+'.bandpass.bcal'])<br />
</source><br />
<br />
Alternatively, instead of making a separate phase solution for application to the target, one can also run {{smoothcal}} to smooth the solutions derived on the integration time. <br />
<br />
Next we apply the bandpass and '''solint='int' ''' phase-only calibration solutions on-the-fly to derive amplitude solutions. Here the use of '''solint='inf' ''', but '''combine=' ' ''' will result in one solution per scan interval. <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.amp.gcal')<br />
gaincal(vis=asdm+'.ms',caltable=asdm+'.amp.gcal',<br />
field='0,1,3,4',spw='0~3:40~3800',refant='DV06',<br />
calmode='ap',solint='inf',minsnr=2.0,minblperant=4,<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal'])<br />
</source><br />
<br />
Now carefully inspect all these solutions looking for discrepant solutions. If you see any, you will need to flag them and rerun the calibration tasks above. <br />
<br />
We make plots in X and Y separately for clarity. The colors are showing the spectral windows.<br />
<figure id="X3c1_wvrtsys.intphase_X.png"><br />
[[Image:X3c1_wvrtsys.intphase_X.png|thumb|<caption>Phase solutions for the X polarization for every integration time of the first dataset.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.intphase.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',iteration='antenna',subplot=421,<br />
plotrange=[0,0,-180,180],poln='X',figfile=asdm+'.intphase_X.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.intphase.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',iteration='antenna',subplot=421,<br />
plotrange=[0,0,-180,180],poln='Y',figfile=asdm+'.intphase_Y.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<figure id="X3c1_wvrtsys.scanphase_X.png"><br />
[[Image:X3c1_wvrtsys.scanphase_X.png|thumb|<caption>Phase solutions for the X polarization for each scan of the first dataset.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.scanphase.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',iteration='antenna',subplot=421,<br />
plotrange=[0,0,-180,180],poln='X',figfile=asdm+'.scanphase_X.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.scanphase.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',iteration='antenna',subplot=421,<br />
plotrange=[0,0,-180,180],poln='Y',figfile=asdm+'.scanphase_Y.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Since we have taken out the phase as best we can by applying the '''solint='int' ''' phase-only solution, this plot will give a good idea of the residual phase error. If you see scatter of more than a few degrees here, you should consider going back and looking for more data to flag, particularly bad timeranges etc. <br />
<br />
<figure id="X3c1_wvrtsys.amp_phase.png"><br />
[[Image:X3c1_wvrtsys.amp_phase.png|thumb|<caption>Residual phase after applying intphase.gcal for both correlations in the first dataset.</caption>]]<br />
</figure><br />
<figure id="X3c1_wvrtsys.amp_X.png"><br />
[[Image:X3c1_wvrtsys.amp_X.png|thumb|<caption>Amplitude solutions on a scan interval for correlation X in the first dataset.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.amp.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',plotrange=[0,0,-1,1],<br />
iteration='antenna',subplot=421,figfile=asdm+'.amp_phase.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
These are very small, as they should be. Now look at the amplitude solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.amp.gcal',xaxis='time',yaxis='amp',antenna='1~8', <br />
iteration='antenna',subplot=421,spw='',poln='X',<br />
plotrange=[0,0,0.0,0.3],figfile=asdm+'.amp_X.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.amp.gcal',xaxis='time',yaxis='amp',antenna='1~8', <br />
iteration='antenna',subplot=421,spw='',poln='Y',<br />
plotrange=[0,0,0.0,0.3],figfile=asdm+'.amp_Y.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
==Flux Calibration==<br />
<br />
Next we use the flux calibrator (whose flux density was set in {{setjy}} above) to derive the flux density of the other calibrators. Note that the flux table REPLACES the amp.gcal in terms of future application of the calibration to the data, i.e. the flux table contains both the amp.gcal and flux scaling. Unlike the gain calibration steps, this is not an incremental table.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.flux.cal')<br />
fluxscale(vis=asdm+'.ms',caltable=asdm+'.amp.gcal',<br />
fluxtable=asdm+'.flux.cal',reference='1',refspwmap=[0,1,3,3],<br />
listfile=asdm+'.fluxscale.txt')<br />
</source><br />
<br />
Its a good idea to record the derived fluxscale values using the listfile option. The values can also be viewed in the Log Messages window.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Found reference field(s): Titan<br />
Found transfer field(s): 3c279 J1147-382=QSO J1037-295=QSO<br />
Spw=2 will be referenced to spw=3<br />
Flux density for 3c279 in SpW=0 (freq=3.56498e+11 Hz) is: 10.537 +/- 0.0183518 (SNR = 574.169, N = 16)<br />
Flux density for 3c279 in SpW=1 (freq=3.57734e+11 Hz) is: 10.6933 +/- 0.0264134 (SNR = 404.842, N = 16)<br />
Flux density for 3c279 in SpW=2 (freq=3.46034e+11 Hz) (ref SpW=3) is: 10.251 +/- 0.0477949 (SNR = 214.479, N = 14)<br />
Flux density for 3c279 in SpW=3 (freq=3.43956e+11 Hz) is: 9.91798 +/- 0.020167 (SNR = 491.791, N = 16)<br />
Flux density for J1147-382=QSO in SpW=0 (freq=3.56498e+11 Hz) is: 1.03399 +/- 0.0167344 (SNR = 61.7887, N = 16)<br />
Flux density for J1147-382=QSO in SpW=1 (freq=3.57734e+11 Hz) is: 0.844817 +/- 0.0191013 (SNR = 44.2283, N = 16)<br />
Flux density for J1147-382=QSO in SpW=2 (freq=3.46034e+11 Hz) (ref SpW=3) is: 0.987193 +/- 0.024391 (SNR = 40.4737, N = 14)<br />
Flux density for J1147-382=QSO in SpW=3 (freq=3.43956e+11 Hz) is: 1.28859 +/- 0.0194364 (SNR = 66.298, N = 16)<br />
Flux density for J1037-295=QSO in SpW=0 (freq=3.56498e+11 Hz) is: 0.968281 +/- 0.00895224 (SNR = 108.161, N = 16)<br />
Flux density for J1037-295=QSO in SpW=1 (freq=3.57734e+11 Hz) is: 0.75916 +/- 0.015366 (SNR = 49.4053, N = 16)<br />
Flux density for J1037-295=QSO in SpW=2 (freq=3.46034e+11 Hz) (ref SpW=3) is: 0.948551 +/- 0.0165421 (SNR = 57.3416, N = 14)<br />
Flux density for J1037-295=QSO in SpW=3 (freq=3.43956e+11 Hz) is: 1.21905 +/- 0.0139967 (SNR = 87.0956, N = 16)<br />
Fitted spectrum for 3c279 with fitorder=1: Flux density = 10.2962 +/- 0.0450319 (freq=351.002 GHz) spidx=1.70757 +/- 0.245737<br />
Fitted spectrum for J1147-382=QSO with fitorder=1: Flux density = 1.06853 +/- 0.0709817 (freq=351.002 GHz) spidx=-6.77353 +/- 3.71867<br />
Fitted spectrum for J1037-295=QSO with fitorder=1: Flux density = 1.01822 +/- 0.0654586 (freq=351.002 GHz) spidx=-6.28977 +/- 3.71453<br />
Storing result in X7ef_wvrtsys.flux.cal<br />
Writing solutions to table: X7ef_wvrtsys.flux.cal<br />
</pre><br />
<br />
<figure id="x3c1_wvrtsys.flux_X.png"><br />
[[Image:x3c1_wvrtsys.flux_X.png|thumb|<caption>Absolute flux calibration solutions for correlation X for the first dataset.</caption>]]<br />
</figure><br />
<br />
<div class="noprint" style="float:none; border:0px solid blue;background-color:#F6CEF5;padding:2px;"><br />
If you used the updated (Butler-JPL-Horizons 2012) flux density standard when you ran {{setjy}} earlier in this tutorial, the derived flux values for the calibrators will be slightly different. For example, when averaged over the 3 measurement sets, 3c279 in spectral window 0 has a flux of 10.77 Jy using the 2010 standard and 10.63 Jy using the 2012 standard; as a second example, J1147-382 in SPW 3 has an average flux of 1.13 Jy (2010 standard) and 1.15 Jy (2012 standard). <br />
</div><br />
<br />
Now look at the flux solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.flux.cal',xaxis='time',yaxis='amp',antenna='1~8', <br />
iteration='antenna',subplot=421,spw='',poln='X',<br />
plotrange=[0,0,0.0,0.3],figfile=asdm+'.flux_X.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.flux.cal',xaxis='time',yaxis='amp',antenna='1~8', <br />
iteration='antenna',subplot=421,spw='',poln='Y',<br />
plotrange=[0,0,0.0,0.3],figfile=asdm+'.flux_Y.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
==Apply Calibration and Inspect==<br />
<br />
Now we can use the {{flagmanager}} if we want to restore any of the spectral flagging we did prior to bandpass calibration. <br />
In this case, we choose to restore the flags of the emission lines on Titan, because we are interested in seeing how<br />
strong they are compared to the continuum. However, we leave the strong ozone line and mesospheric CO line flagged on all <br />
sources, because we want to get the most accurate continuum flux density for the science target. <br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
flagmanager(vis=asdm+'.ms',mode='restore',versionname=asdm+'.before_emissionflags')<br />
</source><br />
<br />
Next we apply the calibration solutions to each source individually, using the '''gainfield''' parameter to specify which calibrator's solutions should be applied from each of the '''gaintable''' calibration tables. <br />
<br />
First, we do 3C279 (the bandpass calibrator), applying all 3 of its solutions to itself (that's why gainfield contains three zeros):<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='0',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['0','0','0'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
Next, we do Titan (the absolute flux calibrator) using the bandpass solution from 3C279:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='1',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['0','1','1'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
For the secondary phase calibrator, we apply the phase and flux solutions from the primary phase calibrator. This will allow us to check how well the phase transfer to the science target (TW Hya) has worked:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='3',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.scanphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','linear','linear'],<br />
gainfield=['0','4','4'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
Next is the Primary phase calibrator:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='4',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['0','4','4'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
Finally, for the Science Target TW Hya, we apply the phase solutions from both the primary and secondary phase calibrators:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='2',<br />
interp=['nearest','linear','linear'],<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.scanphase.gcal',asdm+'.flux.cal'],<br />
gainfield=['0','3,4','3,4'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
Now we can check the results of applying the calibration solutions.<br />
<br />
<figure id="Corrected_vs_time_1.png"><br />
[[Image:Corrected_vs_time_1.png|thumb|<caption>The calibrated data for the first dataset (amplitude vs. time).</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw',ydatacolumn='corrected')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
In amplitude, it looks good but there are some noisy points toward the end of the first scheduling block, but it mostly only affects the secondary phase calibrator (green). In phase, we expect all the points to cluster about zero. The large scatter in phase on the secondary phase calibrator is readily apparent: <br />
<br />
<figure id="Corrected_phase_vs_time_1.png"><br />
[[Image:Corrected_phase_vs_time_1.png|thumb|<caption>The calibrated data on the calibrators for the first dataset (phase vs. time).</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='time',yaxis='phase',field='0,1,3,4',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw',ydatacolumn='corrected')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Let's check whether the situation improves when we apply this calibrator's solutions to itself rather than transferring the solutions from the primary phase calibrator (which is 17 degrees away, and observed at a different time). <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='3',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['0','3','3'],flagbackup=T, calwt=T)<br />
</source><br />
<br />
<figure id="Corrected_vs_time_1_field3.png"><br />
[[Image:Corrected_vs_time_1_field3.png|thumb|<caption>The calibrated data for the first dataset (amplitude vs. time), but now with field 3, the secondary phase calibrator, calibrated with itself.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw',ydatacolumn='corrected')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<figure id="Corrected_phase_vs_time_1_field3.png"><br />
[[Image:Corrected_phase_vs_time_1_field3.png|thumb|<caption>The calibrated data from the first dataset (phase vs. time), but now with field 3, the secondary phase calibrator, calibrated with itself.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='time',yaxis='phase',field='0,1,3,4',<br />
avgchannel='3840', coloraxis='field',iteraxis='spw',<br />
ydatacolumn='corrected')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Indeed, the secondary calibrator looks better now in amplitude and phase. This is an indication that the calibration transfer is not working well in this timerange. Because the effect is not catastrophic and we know we can self-calibrate on TW Hya later, we will let this go for now. Or, if you want you can delve deeper into the data and try to solve the mystery... <br />
<br />
In any case, we will re-issue the original {{applycal}} so that it is this calibration that our subsequent {{split}} will use. This will allow us to check the effect of correcting the secondary phase calibrator with the primary phase calibrator later. <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='3',<br />
gaintable=[asdm+'.bandpass.bcal', asdm+'.scanphase.gcal', asdm+'.flux.cal'],<br />
interp=['nearest','linear','linear'],<br />
gainfield=['0','4','4'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
<br />
Let's check the spectral calibration now. First 3C279 and Titan:<br />
<br />
<figure id="X3c1_spw2_corrected_3.4.png"><br />
[[Image:X3c1_spw2_corrected_3.4.png|thumb|<caption>Spectral UV-plots of 3C279 and Titan of spw=2 for the first dataset.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='frequency',yaxis='amp',field='0,1',<br />
avgtime='1e8',avgscan=T,coloraxis='field',ydatacolumn='corrected',<br />
iteraxis='spw',xselfscale=T)<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Flip through the spws. These look good. Next the two phase calibrators:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='frequency',yaxis='amp',field='3,4',<br />
avgtime='1e8',avgscan=T,coloraxis='field',ydatacolumn='corrected',<br />
iteraxis='spw',xselfscale=T)<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Flip through the spws. This also looks good, the secondary phase calibrator is a bit noisier but this is normal. The upswing at the lower frequency end of spw=3 will probably need to be flagged on the science target as well. It corresponds to the edge of an atmospheric feature.<br />
<br />
Now for the exciting part, what does the science target look like...<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='frequency',yaxis='amp',field='2',<br />
avgtime='1e8',avgscan=T,coloraxis='field',ydatacolumn='corrected',<br />
iteraxis='spw',xselfscale=T)<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
We see HCO+(4-3) in spw=0 and CO(3-2) in spw=2 as expected. Because the shape of the <br />
line profiles varies with baseline, you can already tell that the line emission is resolved.<br />
<br />
<figure id="X3c1_CO3_2_uvplot_3.4.png"><br />
[[Image:X3c1_CO3_2_uvplot_3.4.png|thumb|<caption>Visibility Plot of the TW Hya CO(3-2) emission from the first dataset.</caption>]]<br />
</figure><br />
<figure id="X3c1_HCOp4_3_uvplot_3.4.png"><br />
[[Image:X3c1_HCOp4_3_uvplot_3.4.png|thumb|<caption>Visibility Plot of the TW Hya HCO+(4-3) emission from the first dataset.</caption>]]<br />
</figure><br />
<br />
Now check that the velocity of TWHydra is correct in the LSRK frame, it should be around 2.88 km/s.<br />
* CO 3-2 rest freq 345.79599 GHz<br />
* HCO+ 4-3 rest freq 356.7342 GHz<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='2',xaxis='velocity',yaxis='amp',field='2',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',<br />
restfreq='345.79599GHz', plotrange=[-10,15,0,0],coloraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='0',xaxis='velocity',yaxis='amp',field='2',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',<br />
restfreq='356.7342GHz',plotrange=[-10,15,0,0],coloraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Both lines show up at the expected velocity.<br />
<br />
==Concatenate the Data==<br />
<br />
Here we will concatenate the three datasets prior to imaging.<br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
os.system('rm -rf Band7multi_april22.ms')<br />
concat(vis=splitdata,concatvis='Band7multi_april22.ms')<br />
</source><br />
<br />
If you like you can run listobs on new combined dataset<br />
<br />
<source lang="python"><br />
# In CASA<br />
listfile = 'Band7multi_april22.listobs.txt'<br />
os.system('rm ' + listfile)<br />
listobs(vis='Band7multi_april22.ms',verbose=F, listfile=listfile)<br />
</source><br />
<br />
<figure id="All_spw2_corrected_3.4.png"><br />
[[Image:All_spw2_corrected_3.4.png|thumb|<caption>Spectral UV-plots of 3C279 and Titan of spw=2 for the combined datasets.</caption>]]<br />
</figure><br />
<br />
You can also examine the spectral uv plots for the combined dataset to see the improvement in S/N: <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='Band7multi_april22.ms',spw='',xaxis='frequency',yaxis='amp',field='0,1',<br />
avgtime='1e8',avgscan=T,coloraxis='field',ydatacolumn='corrected',<br />
iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
<figure id="All_CO3_2_uvplot_3.4.png"><br />
[[Image:All_CO3_2_uvplot_3.4.png|thumb|<caption>UV-Plot of the TW Hya CO(3-2) emission from the combined datasets.</caption>]]<br />
</figure><br />
<br />
...and the CO line profile for the combined dataset: <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='Band7multi_april22.ms',spw='2',xaxis='velocity',yaxis='amp',field='2',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',restfreq='345.79599GHz',<br />
plotrange=[-10,15,0,0],coloraxis='spw')<br />
</source><br />
<br />
==Split Calibrated Data==<br />
<br />
Now we split off the calibrated data for the Science Target as well as the interesting parts of the calibrators for imaging.<br />
<br />
When we {{split}} off the Titan data, a few dozen warnings like the following are written to the log:<br />
<pre><br />
2012-05-15 22:00:35 WARN split::SubMS::copySource() Invalid SOURCE ID in SOURCE table row 20 <br />
</pre><br />
These can be ignored, because they do not indicate any problem that will prevent you from imaging Titan correctly at a single position using all the data in the output ms.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_corrected.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='TWHydra_corrected.ms',<br />
datacolumn='corrected',spw='',field='2')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf J1037_corrected.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='J1037_corrected.ms',<br />
datacolumn='corrected',spw='',field='4')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf J1147_corrected.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='J1147_corrected.ms',<br />
datacolumn='corrected',spw='',field='3')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3C279_CO3_2.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='3C279_CO3_2.ms',<br />
datacolumn='corrected',spw='2:1900~2000',field='0')<br />
</source><br />
<br />
==Optional: Reconcile Titan's Coordinates==<br />
<br />
If you do not care to image Titan, then you can skip this step and simply continue on to the [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_4.5 imaging guide].<br />
<br />
Our earlier treatment of Titan's coordinates using [http://casa.nrao.edu/stable/docs/TaskRef/fixplanets-task.html fixplanets] replaced the zeros written by the ALMA control system with the correct position of the body at the instant of the first observation of that SB. As a result, it has slightly different positions in all three datasets, as seen by listobs:<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='Band7multi_april22.ms',verbose=F)<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
ID Code Name RA Decl Epoch SrcId nRows <br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 70866 <br />
1 none Titan 12:49:25.97588 -02.22.41.3024 J2000 1 4842 <br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 515151 <br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 40797 <br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 171153 <br />
5 none Titan 12:49:26.53729 -02.22.27.1521 J2000 0 4833 <br />
6 none Titan 12:49:26.53059 -02.22.18.7878 J2000 0 4833 <br />
</pre><br />
<br />
If we want to image such moving objects observed across multiple SBs, we need to bring the positions into agreement, otherwise {{clean}} will try to make a mosaic. Task [http://casa.nrao.edu/stable/docs/TaskRef/fixplanets-task.html fixplanets] can be used to do this. Here, we set the direction to the direction of the first dataset as reported by listobs. Note that the RA/Dec format is slightly different from the {{listobs}} output format. Also, we do not<br />
fix the uvw coordinates because they are already more correct now than they would be if we "fixed" them.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fixplanets(vis='Band7multi_april22.ms', field='Titan', direction='J2000 12h49m25.97588 -02d22m41.3024', fixuvw=False)<br />
</source><br />
<br />
Check the header information again to see that the information for Titan has changed for the second<br />
and third datasets. They will appear as fields 5 and 6.<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='Band7multi_april22.ms',verbose=F)<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
ID Code Name RA Decl Epoch SrcId <br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 70866 <br />
1 none Titan 12:49:25.97588 -02.22.41.3024 J2000 1 4842 <br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 515151 <br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 40797 <br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 171153 <br />
5 none Titan 12:49:25.97588 -02.22.41.3024 J2000 0 4833 <br />
6 none Titan 12:49:25.97588 -02.22.41.3024 J2000 0 4833 <br />
</pre><br />
<br />
==Optional: Split Calibrated Titan Data==<br />
<br />
When we {{split}} off the Titan data, a few dozen warnings like the following are written to the log:<br />
<pre><br />
2012-05-15 22:00:35 WARN split::SubMS::copySource() Invalid SOURCE ID in SOURCE table row 20 <br />
</pre><br />
These can be ignored, because they do not indicate any problem that will prevent you from imaging Titan correctly at a single position using all the data in the output ms.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Titan_cont.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='Titan_cont.ms',<br />
datacolumn='corrected',spw='0',field='1')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Titan_CO3_2.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='Titan_CO3_2.ms',<br />
datacolumn='corrected',spw='2',field='1')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Titan_unknown.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='Titan_unknown.ms',<br />
datacolumn='corrected',spw='3',field='1')<br />
</source><br />
<br />
==Continue on to Imaging of the Science Target==<br />
<br />
Now you can continue on to the [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_4.5 imaging guide].<br />
<br />
{{Checked 4.5.2}}</div>Sstierwahttps://casaguides.nrao.edu/index.php?title=TWHydraBand7_Calibration_4.5&diff=19476TWHydraBand7 Calibration 4.52016-05-18T04:22:53Z<p>Sstierwa: /* Apply Calibration and Inspect */</p>
<hr />
<div>[[Category:ALMA]][[Category:Calibration]][[Category:Spectral Line]]<br />
*'''This script assumes that you have downloaded TWHYA_BAND7_UnCalibratedMSAndTablesForReduction.tgz from [[TWHydraBand7#Getting_the_Data]]'''<br />
<br />
*'''An introduction to this data set is available at [[TWHydraBand7]].<br />
<br />
*'''This guide is designed for CASA 4.5.2 If you are using an older version of CASA please see [[TWHydraBand7_Calibration_4.3]].<br />
<br />
==Preparation==<br />
<br />
Once you have downloaded TWHYA_BAND7_UnCalibratedMSAndTablesForReduction.tgz, in a terminal unpack it with<br />
<br />
<source lang="bash"><br />
tar -zxvf TWHYA_BAND7_UnCalibratedMSAndTablesForReduction.tgz<br />
</source><br />
<br />
Please be aware that you will need about 100 GB of free space to do the data reduction. It is a good idea to check that now before you begin. Some of the plots described here require 9 GB of RAM; as little as 4 GB may be sufficient if additional data averaging is used when the plots are generated. When you are satisfied with the available drive space and memory on your machine:<br />
<br />
<source lang="bash"><br />
cd TWHYA_BAND7_UnCalibratedMSAndTablesForReduction<br />
</source><br />
<br />
'''NOTE: the calibration tables included in TWHYA_BAND7_UnCalibratedMSAndTablesForReduction CANNOT be used with CASA 4.5, they should be discarded, or moved out of the working directory.'''<br />
<br />
Then start CASA by typing 'casa' at a shell prompt. <br />
<br />
<source lang="bash"><br />
casa<br />
</source><br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.5.2. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.5.2'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
==Install Analysis Utilities==<br />
<br />
Analysis Utilities (or analysisUtils for short) is a small set of Python scripts that provide a number of analysis and plotting utilities for ALMA data reduction. This guide uses a few of these utilities. They are very easy to install (just download and untar). See <br />
<br />
http://casaguides.nrao.edu/index.php?title=Analysis_Utilities<br />
<br />
for a full description and download instructions. If you do not wish to do this, see the [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Calibration_for_CASA_3.3 CASA 3.3 version of the guide] for alternative (but slow) plotting options. Analysis Utilities are updated frequently so if its been a while since you installed it, its probably worth doing it again. If you are at an ALMA site or ARC, the analysis utilities are probably already installed and up to date.<br />
<br />
==Fix Titan's coordinates==<br />
<br />
'''Note that in the near future this step will be unnecessary.''' <br />
<br />
It is temporarily necessary to correct the positions of ephemeris objects observed during ALMA Cycle 0, because the control software revisions earlier than 9.0 erroneously write the data with coordinates of 00:00:00.0000 +00.00.00.0000 (J2000). For this dataset, we need to correct the position of the absolute flux calibrator Titan, as we can<br />
see from the first {{listobs}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -f X3c1.ms.listobs')<br />
listobs('X3c1.ms', verbose=T, listfile='X3c1.ms.listobs') <br />
</source><br />
<br />
You can view the listobs output files using command "less" from the CASA prompt.<br />
<br />
<pre style="background-color: #fffacd;"><br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 23625<br />
1 none Titan 00:00:00.00000 +00.00.00.0000 J2000 1 4842<br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 175176<br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 14832<br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 59877<br />
</pre><br />
<br />
To correct Titan's position, we will use the task [http://casa.nrao.edu/stable/docs/TaskRef/fixplanets-task.html fixplanets], which writes the actual coordinates at the instant of the first observation. This step takes a while because we are recalculating the uvw's accordingly.<br />
<source lang="python"><br />
# In CASA<br />
fixplanets(vis='X3c1.ms', field='Titan', fixuvw=True)<br />
</source><br />
<br />
Check the header information again with {{listobs}} to confirm that the information for Titan has changed:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -f X3c1.ms.listobs')<br />
listobs('X3c1.ms', verbose=T, listfile='X3c1.ms.listobs') <br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 23625<br />
1 none Titan 12:49:25.93349 -02.22.41.5638 J2000 1 4842<br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 175176<br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 14832<br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 59877<br />
</pre><br />
<br />
Now fix the other two measurement sets similarly:<br />
<source lang="python"><br />
# In CASA<br />
fixplanets(vis='X5d8.ms', field='Titan', fixuvw=True)<br />
fixplanets(vis='X7ef.ms', field='Titan', fixuvw=True)<br />
</source><br />
<br />
==Observing Log and Priors==<br />
<br />
Below is some information that may not be obvious from the data<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Like at most telescopes, the ALMA operators and astronomers at the site log any significant issues <br />
that were noticed from the online system during the observation. For these Band 7 observations of <br />
TW Hya on April 22, 2011, the only issue of note was that antenna DV04 could not observe at Band 7 <br />
and will need to be flagged. <br />
</pre><br />
<br />
First let's examine the basic properties of the data using {{listobs}}. Among other information we <br />
will be able to deduce what the source ids are and what each source was used for:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
3c279 is the bandpass calibrator (field id=0)<br />
Titan is the absolute flux calibrator (field id=1)<br />
J1147-382 is the secondary phase calibrator (field id=3)<br />
J1037-295 is the primary phase calibrator (field id=4)<br />
</pre><br />
<br />
<source lang="python"><br />
# In CASA<br />
data=['X3c1.ms','X5d8.ms','X7ef.ms']<br />
for vis in data:<br />
os.system('rm '+vis+'.listobs')<br />
listobs(vis, verbose=T, listfile=vis+'.listobs') <br />
</source><br />
<br />
You can view the {{listobs}} output files using command '''less''' from the CASA prompt. <br />
Below we copy select parts of the {{listobs}} output files for reference. <br />
<br />
<pre style="background-color: #fffacd;"><br />
X3c1.ms:<br />
Data records: 278352 Total integration time = 6109.06 seconds<br />
Observed from 22-Apr-2011/00:01:52.9 to 22-Apr-2011/01:43:42.0 (UTC)<br />
<br />
X5d8.ms:<br />
Data records: 278406 Total integration time = 5995.01 seconds<br />
Observed from 22-Apr-2011/01:48:05.8 to 22-Apr-2011/03:28:00.8 (UTC)<br />
<br />
X7ef.ms:<br />
Data records: 255717 Total integration time = 5407.49 seconds<br />
Observed from 22-Apr-2011/03:30:39.7 to 22-Apr-2011/05:00:47.2 (UTC)<br />
<br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 23625<br />
1 none Titan 12:49:25.97588 -02.22.41.3024 J2000 1 4842<br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 175176<br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 14832<br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 59877 <br />
<br />
SpwID #Chans Frame Ch1(MHz) ChanWid(kHz) TotBW(kHz) Corrs<br />
0 4 TOPO 184550 1500000 7500000 I<br />
1 128 TOPO 355740.062 15625 2000000 XX YY<br />
2 1 TOPO 356716.625 1796875 1796875 XX YY<br />
3 128 TOPO 356507.813 15625 2000000 XX YY<br />
4 1 TOPO 357484.375 1796875 1796875 XX YY<br />
5 128 TOPO 346792.187 15625 2000000 XX YY<br />
6 1 TOPO 345784.375 1796875 1796875 XX YY<br />
7 128 TOPO 345182.438 15625 2000000 XX YY<br />
8 1 TOPO 344174.625 1796875 1796875 XX YY<br />
9 128 TOPO 344386.763 15625 2000000 XX YY<br />
10 1 TOPO 343378.95 1796875 1796875 XX YY<br />
11 128 TOPO 346324.263 15625 2000000 XX YY<br />
12 1 TOPO 345316.45 1796875 1796875 XX YY<br />
13 128 TOPO 354402.388 15625 2000000 XX YY<br />
14 1 TOPO 355378.95 1796875 1796875 XX YY<br />
15 128 TOPO 356402.388 15625 2000000 XX YY<br />
16 1 TOPO 357378.95 1796875 1796875 XX YY<br />
17 3840 TOPO 356497.936 122.070312 468750 XX YY<br />
18 1 TOPO 356732.189 468750 468750 XX YY<br />
19 3840 TOPO 357734.314 122.070312 468750 XX YY<br />
20 1 TOPO 357499.939 468750 468750 XX YY<br />
21 3840 TOPO 346034.314 122.070312 468750 XX YY<br />
22 1 TOPO 345799.939 468750 468750 XX YY<br />
23 3840 TOPO 343955.936 122.070312 468750 XX YY<br />
24 1 TOPO 344190.189 468750 468750 XX YY<br />
<br />
Antennas: 9:<br />
Name Station Diam. Long. Lat.<br />
0 DV04 J505 12.0 m -067.45.18.0 -22.53.22.8<br />
1 DV06 T704 12.0 m -067.45.16.2 -22.53.22.1<br />
2 DV07 J510 12.0 m -067.45.17.8 -22.53.23.5<br />
3 DV08 T703 12.0 m -067.45.16.2 -22.53.23.9<br />
4 DV09 N602 12.0 m -067.45.17.4 -22.53.22.3<br />
5 DV10 N606 12.0 m -067.45.17.1 -22.53.23.6<br />
6 PM01 T702 12.0 m -067.45.18.6 -22.53.24.1<br />
7 PM02 T701 12.0 m -067.45.18.8 -22.53.22.2<br />
8 PM03 J504 12.0 m -067.45.17.0 -22.53.23.0<br />
</pre><br />
<br />
Things to Notice from above: <br />
*There are three different data sets acquired close together in time. We will calibrate each dataset independently and then combine the calibrated data prior to imaging. <br />
*Titan appears to have slightly different positions in each dataset because it is a moving body. In fact, at the time of observation, due to temporary data capture issue in the ALMA system, the position was written has (0,0). We have pre-corrected this error using fixplanets. Later in the tutorial, we will run fixplanets again to force all three datasets to have the same fixed position for Titan.<br />
*There are a lot of spectral windows! Don't be alarmed. In ALMA data, <br />
**spw=0 is always reserved for the water vapor radiometry data.<br />
**spw=9, 11, 13, 15 are the wideband (TDM) correlator mode with 128 channels per spw default settings for doing pointing and this is all they are used for in these data.<br />
**Currently Tsys data can only be taken in the wide (TDM) correlator mode with 128 channels per spw, these correspond to spws=1, 3, 5, 7 above. The frequencies of these TDM spws were carefully chosen so the the narrowband FDM spws fall within them.<br />
** The 0.5 GHz, high spectral resolution spws that contain all the real source data (science target and calibrators) are 17, 19, 21, and 23<br />
**For quicklook purposes, the ALMA online system produces a channel averaged spw for each channelized spw, these correspond to spw=2,4,6,8,10,12,14,16,18,20,22,24 and shouldn't be used for anything in post-processing as bandpass calibration etc has not been applied.<br />
<br />
In the portion of the {{listobs}} output that shows the timerange, the final column gives the scan intent. It is important to have a look at this because you can flag and do other operations in CASA using the scan intent as a selection option. Also, these intents will be used in the future for pipeline processing. You will usually want to use them to flag the CALIBRATE_POINTING* and CALIBRATE_ATMOS* (the latter correspond to the hot and cold load measurements used to calculate Tsys) data. This is essential for science or calibration data taken only in TDM (wide bandwidth) mode, i.e. the same mode that the pointing and Tsys data are taken in. For the current data however, that calibration data is recorded in different spws from the useful FDM (narrow bandwidth) data, so we'll be able to separate them by splitting them off at the final step prior to imaging.<br />
<br />
<figure id="Ant_pos.png"><br />
[[Image:Ant_pos.png|thumb|<caption>Antenna locations for the first dataset.</caption>]]<br />
</figure><br />
<br />
Before we move on, its also nice to get an idea where the antennas are with respect to each other. We can use {{plotants}} to plot their positions. It is a good idea to check each file since an antenna may have entered or exited the array between observations.<br />
<source lang="python"><br />
# In CASA<br />
for vis in data:<br />
plotants(vis=vis,figfile=vis+'.plotants.png')<br />
</source><br />
<br />
You can view the output images using any standard image viewer.<br />
<br />
==Create the Tsys and WVR Tables, and Examine ==<br />
<br />
Each ms include tables that contain the Tsys and WVR measurements associated with the visibility data.<br />
We must create calibration tables from these measurements. First we create the WVR calibration tables <br />
by running the task [http://casa.nrao.edu/stable/docs/TaskRef/wvrgcal-task.html wvrgcal]. This task <br />
examines the data for each ms as a whole and creates a calibration<br />
table containing only phase corrections for each antenna and spw. <br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
os.system('rm -rf '+asdm+'.wvr')<br />
wvrgcal(vis=asdm+'.ms', caltable=asdm+'.wvr', segsource=True, toffset=-1)<br />
</source><br />
<br />
Next we create the Tsys tables by running {{gencal}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
os.system('rm -rf '+asdm+'.tsys')<br />
gencal(vis=asdm+'.ms', caltable=asdm+'.tsys', caltype='tsys')<br />
</source><br />
<br />
It is very important that Tsys measurements taken as close in time and elevation as possible to a particular source are applied. To save telescope time, Tsys measurements are sometimes intentionally skipped in the scheduling block for specific sources. So the first step is to establish which sources have their own Tsys measurements and which do not. To do this, you may use the intent parameter of {{listobs}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
listobs(vis=asdm+'.ms', verbose=F, selectdata=True, intent='CALIBRATE_ATMOS*')<br />
</source><br />
<br />
<figure id="X3c1.tsys_vs_time_3.4.png"><br />
[[File:X3c1.tsys_vs_time_3.4.png|thumb|<caption>Tsys vs. time for spw 1 of the X3c1.ms data.</caption>]]<br />
</figure><br />
<figure id="X5d8.tsys_vs_time_3.4.png"><br />
[[File:X5d8.tsys_vs_time_3.4.png|thumb|<caption>Tsys vs. time for spw 1 of the X5d8.ms data.</caption>]]<br />
</figure><br />
<figure id="X7ef.tsys_vs_time_3.4.png"><br />
[[File:X7ef.tsys_vs_time_3.4.png|thumb|<caption>Tsys vs. time for spw 1 of the X7ef.ms data.</caption>]]<br />
</figure><br />
<br />
<pre style="background-color: #fffacd;"><br />
Fields: 4<br />
ID Code Name RA Decl Epoch SrcId nRows <br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 1116 <br />
1 none Titan 12:49:25.97588 -02.22.41.3024 J2000 1 1125 <br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 6795 <br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 6777 <br />
Spectral Windows: (9 unique spectral windows and 2 unique polarization setups)<br />
SpwID #Chans Frame Ch1(MHz) ChanWid(kHz) TotBW(kHz) Corrs <br />
0 4 TOPO 184550 1500000 7500000 I <br />
1 128 TOPO 355740.062 15625 2000000 XX YY <br />
2 1 TOPO 356716.625 1796875 1796875 XX YY <br />
3 128 TOPO 356507.813 15625 2000000 XX YY <br />
4 1 TOPO 357484.375 1796875 1796875 XX YY <br />
5 128 TOPO 346792.187 15625 2000000 XX YY <br />
6 1 TOPO 345784.375 1796875 1796875 XX YY <br />
7 128 TOPO 345182.438 15625 2000000 XX YY <br />
8 1 TOPO 344174.625 1796875 1796875 XX YY <br />
</pre><br />
<br />
Because field '3' (the secondary phase calibrator) does not appear in the list, it has no tsys. Since the secondary phase calibrator is close on the sky to the primary phase calibrator and observed near in time, we will transfer the Tsys from the primary to the secondary phase calibrator. <br />
Also notice that spws 1,3,5,7 are the only multi-channel spws that contain Tsys data. At present, Tsys measurements can only be obtained with TDM spectral setups (128 channels/dual pol). Because our science target is observed in FDM (3840 channels/dual pol), we will need to interpolate the measurements from TDM to FDM. But first, to inspect the Tsys vs. time, we use {{plotcal}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all = ['X3c1','X5d8','X7ef']<br />
tsysfields=['0','1','2','4']<br />
os.system('mkdir cal_plots; mkdir cal_plots/Tsys_plots') <br />
for asdm in basename_all:<br />
print "Plotting Tsys vs. time for "+asdm<br />
plotcal(caltable=asdm+'.tsys', xaxis='time',yaxis='tsys',<br />
antenna='1~8',plotrange=[0,0,100,500],<br />
iteration='antenna',subplot=421,poln='',spw='1:50~50',<br />
figfile='cal_plots/Tsys_plots/'+asdm+'.tsys_vs_time.png')<br />
if (asdm != basename_all[-1]):<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
To inspect Tsys vs. frequency, we use [[plotbandpass]]. There are many different options for plotbandpass, and we demonstrate some of the most useful ones. The option '''showtsky=T''' will overlay the effective temperature curve from the atmospheric model. This shows us the location of any atmospheric lines which will appear as emission lines in the autocorrelation data (from which the Tsys spectra are derived) from all antennas. In the<br />
example below, we set '''interactive=False''', which will produce many pages of plots as<br />
individual pngs but will only show the final page in the graphics window. To view all the pages we use the image viewer '''eog''' (Eye of GNOME) available on Linux. The alternative is to set '''interactive=True''' and examine the plots in the casa graphics window as they are produced.<br />
<br />
<figure id="X3c1.tsys.field0.DV04.spw1.t1.png"><br />
[[File:X3c1.tsys.field0.DV04.spw1.t1.png|thumb|<caption>Tsys vs. frequency on 3C279 for the X3c1.ms data, spw=1.</caption>]]<br />
</figure><br />
<figure id="X3c1.tsys.field0.DV04.spw3.t1.png"><br />
[[File:X3c1.tsys.field0.DV04.spw3.t1.png|thumb|<caption>Tsys vs. frequency on 3C279 for the X3c1.ms data, spw=3.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
print "Plotting Tsys vs. frequency for "+asdm<br />
for spw in [1,3,5,7]:<br />
for field in ['0','1']:<br />
plotbandpass(caltable=asdm+'.tsys', xaxis='freq',yaxis='amp',<br />
showtsky=T,subplot=42,field=field,<br />
spw=spw, interactive=False, plotrange=[0,0,0,0],<br />
figfile='cal_plots/Tsys_plots/'+asdm+'.tsys.field%s.png'%field,<br />
buildpdf=False)<br />
</source><br />
<br />
In <xr id="X3c1.tsys.field0.DV04.spw1.t1.png"/> and <xr id="X3c1.tsys.field0.DV04.spw3.t1.png"/> we see the effect of atmospheric ozone lines on the Tsys measurements associated with 3C279 in spw 1 and 3.<br />
<br />
For sources that have multiple Tsys measurements (typically the primary phase calibrator and/or the science target) one can use '''overlay="time"''' to overlay all the measurements for that source. This can help to identify any anomalous Tsys scans. As a fraction of the plots produced by this loop, here we show the Tsys recorded on spw=1 for TW Hya from the first dataset.<br />
<br />
<figure id="X3c1.tsys.field2.DV04.spw1.png"><br />
[[File:X3c1.tsys.field2.DV04.spw1.png|thumb|<caption>Tsys vs. freq for field 2, spw 1 of the X3c1.ms data (antennas 0..3).</caption>]]<br />
</figure><br />
<figure id="X3c1.tsys.field2.DV04.spw1.png"><br />
[[File:X3c1.tsys.field2.DV09.spw1.png|thumb|<caption>Tsys vs. freq for field 2, spw 1 of the X3c1.ms data (antennas 4..7).</caption>]]<br />
</figure><br />
<figure id="X3c1.tsys.field2.PM03.spw1.png"><br />
[[File:X3c1.tsys.field2.PM03.spw1.png|thumb|<caption>Tsys vs. freq for field 2, spw 1 of the X3c1.ms data (antenna 8).</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
print "Plotting Tsys vs. frequency for "+asdm<br />
for spw in [1,3,5,7]:<br />
for field in ['2','4']:<br />
plotbandpass(caltable=asdm+'.tsys', xaxis='freq',yaxis='amp',<br />
showtsky=T,subplot=22,field=field,<br />
overlay='time',spw=spw, interactive=False, plotrange=[0,0,0,0],<br />
figfile='cal_plots/Tsys_plots/'+asdm+'.tsys.field%s.png'%field,<br />
buildpdf = False)<br />
</source><br />
<br />
Alternatively, the '''overlay="antenna"''' option will quickly reveal any Antennas with discrepant Tsys values, as they<br />
will be obvious outliers. For FDM projects like this one, using the '''showfdm=True''' option can be helpful, as it<br />
will show where in the TDM bandpass each FDM spw was located. <br />
<figure id="X3c1.tsys.field0.spw1.t1.png"><br />
[[Image:X3c1.tsys.field0.spw1.t1.png|thumb|<caption>Tsys vs Freq for field 0, spw 1 of the X3c1.ms data with all antennas overlaid.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
tsysfields=['0','1','2','4'] <br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
print "Plotting Tsys vs. frequency for "+asdm<br />
for spw in [1,3,5,7]:<br />
for field in tsysfields:<br />
plotbandpass(caltable=asdm+'.tsys', xaxis='freq',yaxis='amp',<br />
showtsky=T,subplot=11,field=field,<br />
overlay='antenna',spw=spw, interactive=False,<br />
figfile='cal_plots/Tsys_plots/'+asdm+'.tsys.field%s.png'%field,<br />
buildpdf=False,showfdm=True)<br />
</source><br />
<br />
<br />
Note that DV04 consistently has a significantly higher Tsys than the rest of the antennas. We already know from the Observation log that<br />
we need to flag that antenna, but had we not had that information, examining this plot would have demonstrated the situation.<br />
<br />
==Apply the Tsys and WVR Tables, and Split ==<br />
<br />
Next we apply the calibrations. For the (4) sources with Tsys measurements, we use the '''field''' and '''gainfield''' parameters of {{applycal}} to apply solutions only to themselves. {{applycal}} has the ability to interpolate gain tables from one spw onto another spw. In this case, we want to interpolate the TDM Tsys values in spws 1,3,5,7 onto the FDM spws 17,19,21,23. We use the '''interp''' parameter to request linear interpolation in the time dimension and spline interpolation in the channel/frequency dimension. To map the solutions for each spw, we use the '''spwmap''' parameter, which requires a list of all spws for each gain table to be applied, or a blank list ([]) which is a shorthand notation to apply the solution for each spw to itself. While applying Tsys, we will also apply the wvr calibration tables; wvr data is usually always present for all sources. Below we first set some definitions so we can loop over the correct parameters:<br />
<br />
<source lang="python"><br />
# In CASA<br />
fdm='17,19,21,23'<br />
nocal='3' # This source had no Tsys measurements associated with it <br />
tsysfields=['0','1','2','4'] <br />
tsysmap = range(25)<br />
tsysmap[17] = 1<br />
tsysmap[19] = 3<br />
tsysmap[21] = 5<br />
tsysmap[23] = 7<br />
for asdm in basename_all:<br />
for field in tsysfields:<br />
applycal(vis=asdm+'.ms', spw=fdm, field=field, gainfield=field,<br />
gaintable=[asdm+'.tsys', asdm+'.wvr'], spwmap=[tsysmap,[]],<br />
interp=['linear,spline','nearest'], flagbackup=F, calwt=T)<br />
</source><br />
<br />
For the sources without Tsys (i.e. field=3), couple them with the best available source with Tsys (i.e. field=4).<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename_all:<br />
applycal(vis=asdm+'.ms', spw=fdm, field=nocal,<br />
gaintable=[asdm+'.tsys', asdm+'.wvr'], spwmap=[tsysmap,[]],<br />
gainfield=['4',nocal], interp=['linear,spline','nearest'],flagbackup=F,<br />
calwt=T)<br />
</source><br />
<br />
Check Tsys application with plotms. First we make plots with '''ydatacolumn='data'''' to look at the raw data. For <br />
simplicity we'll just look at the two strongest sources 3C279 and Titan.<br />
<br />
<figure id="X5d8_wvrtsys_corrected_spw19.png"><br />
[[Image:X5d8_wvrtsys_corrected_spw19.png|thumb|<caption>Spectral plots of 3C279 (black) and Titan (magenta) for spw=19 after Tsys and wvr correction.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X5d8.ms',spw='17,19,21,23',xaxis='frequency',yaxis='amp',field='0,1',<br />
antenna='*&*',avgtime='1e8',avgscan=T,coloraxis='field',iteraxis='spw',<br />
xselfscale=T,ydatacolumn='data')<br />
</source><br />
<br />
<figure id="X5d8_wvrtsys_corrected_spw21.png"><br />
[[Image:X5d8_wvrtsys_corrected_spw21.png|thumb|<caption>Spectral plots of 3C279 (black) and Titan (magenta) for spw=21 after Tsys and wvr correction.</caption>]]<br />
</figure><br />
<br />
'''Note''': the antenna='*&*' is specifying that we only want to see the cross-correlation data (i.e. not the autocorrelations).<br />
<br />
Use the '''green arrows''' on the {{plotms}} display to cycle through the 4 FDM spws. <br />
<br />
Now change '''Data Column''' to '''corrected''' on the "Axes" tab (this is the same as ydatacolumn in the task) and hit '''Plot''' button on the GUI. Flip through again.<br />
<br />
'''Things to notice:'''<br />
* The amplitude scale has changed due to application of Tsys<br />
* spw=17 is clean and flat<br />
* spw=19 shows a strong dip around channel 3000 (channels can be plotted by going to the Axes tab, and changing X Axis to Channel, then hit the Plot button)-- this is an atmospheric ozone absorption feature at 357.6 GHz. In the future, high spectral resolution Tsys measurements may help to remove the shape of the absorption, but until then we will need to flag this part of the spectrum.<br />
* spw=21 Titan shows both a narrow and a broad spectral feature. The broad feature is CO(3-2) and it completely fills the 0.5 GHz band so there are no line-free channels! Titan must be handled carefully when it is used as a calibrator because it contains strong line emission. Indeed, we will not be able to use the absolute flux transfer from this spw for other targets. When possible Titan should be avoided for absolute flux calibration. For these observations, no other suitable absolute flux calibrator was available.<br />
* spw=23 shows another strong line from Titan.<br />
<br />
Beyond these things to notice, the application of Tsys and wvr seem to have gone well. We can now split off only the narrow band FDM spectral windows for further processing.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename_all:<br />
newvis = asdm + '_wvrtsys.ms'<br />
os.system('rm -rf ' + newvis)<br />
split(vis=asdm+'.ms',outputvis=newvis,datacolumn='corrected',spw=fdm)<br />
</source><br />
<br />
'''Note''': After {{split}}, the spectral windows will be renumbered to 0, 1, 2, 3 corresponding to the old spw=17, 19, 21, 23, see {{listobs}} excerpt below.<br />
<br />
<pre style="background-color: #fffacd;"><br />
SpwID #Chans Frame Ch1(MHz) ChanWid(kHz) TotBW(kHz) Corrs <br />
0 3840 TOPO 356497.936 122.070312 468750 XX YY <br />
1 3840 TOPO 357734.314 122.070312 468750 XX YY <br />
2 3840 TOPO 346034.314 122.070312 468750 XX YY <br />
3 3840 TOPO 343955.936 122.070312 468750 XX YY <br />
</pre><br />
<br />
==Initial Inspection and Flagging==<br />
<br />
From here we begin to operate on the *wvrtsys.ms files. <br />
<br />
Before we begin flagging data, we unflag all data in the measurement sets. If this is your first pass through this section of the guide, no data in the measurement sets will have previously been flagged, and so you can skip the next splitdata step with mode set to 'unflag'. If you are rerunning the flagging commands below, running splitdata in 'unflag' mode will reset your flag columns to their original state.<br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
for vis in splitdata:<br />
flagdata(vis=vis, mode='unflag', action='apply', flagbackup=F)<br />
</source><br />
<br />
ALMA data contains both the cross correlation and autocorrelation data. Presently nothing more can be done with the autocorrelation data so we flag it. Additionally, for smaller configurations of the array, and northerly sources one antenna can ''shadow'' another, blocking its view. This data also needs to be flagged. Finally, the observing log told us DV04 was not behaving properly at Band 7 and shouldn't be used so we flag that as well.<br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
for vis in splitdata:<br />
flagdata(vis=vis, mode='manual', autocorr=True, action = 'apply', flagbackup=T)<br />
flagdata(vis=vis, mode='shadow',tolerance=12.0, action='apply', flagbackup=F)<br />
flagdata(vis=vis, mode='manual', antenna='DV04', action='apply', flagbackup=F)<br />
</source><br />
<br />
Next we inspect the data with {{plotms}} for additional issues that need flagging, first looking at amplitude vs. time for each of the three datasets. Use the '''green''' arrows on the plotms gui to cycle through spws. <br />
<br />
<figure id="Tsyswvr_time_spw0_X3x1.png"><br />
[[Image:Tsyswvr_time_spw0_X3x1.png|thumb|<caption>Amplitude as a function of time for X3c1_wvrtsys.ms, spw=0</caption>]]<br />
</figure><br />
<br />
'''Note''': when '''iteraxis''' is invoked in {{plotms}}, unzoom does not always work properly. If you have trouble with this, flip to next page and then back to current one. This usually fixes the problem.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X5d8_wvrtsys.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X7ef_wvrtsys.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw')<br />
</source><br />
<br />
<figure id="Tsyswvr_time_spw2corr_X3x1.png"><br />
[[Image:Tsyswvr_time_spw2corr_X3x1.png|thumb|<caption>Amplitude as a function of time for X3x1_wvrtsys.ms, spw=2 with colorize='corr'.</caption>]]<br />
</figure><br />
<br />
'''Things to Notice:'''<br />
* In spw=2 there are some low points in all three data files. Use the "Mark Regions" box (left of center on bottom row of icons) to draw small box on low points. Then click the magnifying glass icon to the right of center. The output will be sent to the logger window. '''Note''': keep the marked region small or you can overwhelm the buffer. Locate suggests correlation YY on PM03 is the culprit. <br />
<br />
To see this more clearly you can rerun {{plotms}} with '''coloraxis='field'''' switched to '''coloraxis='corr''''<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='2',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='corr')<br />
</source><br />
<br />
To further check, you can exclude PM03 from the plot using '''antenna='!PM03'.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='2',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='corr',antenna='!PM03')<br />
</source><br />
<br />
Having confirmed the problem antenna, we flag it below. <br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
for vis in splitdata:<br />
flagdata(vis=vis, mode='manual', action= 'apply', flagbackup=T,<br />
spw='2',<br />
antenna='PM03')<br />
</source><br />
<br />
'''Next we need to inspect the spectral properties of the data to look for issues.'''<br />
<br />
First we look at phase as a function of frequency for an antenna like DV06 for which we have not yet identified any problems. <br />
'''coloraxis='baselines'''' (note this parameter is called '''Colorize''' in the GUI "Display" tab) will show each baseline as a different color. Significant delay errors or baseline errors will show up as phase slopes in these plots. Again you will want to page through the spectral windows.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='',xaxis='frequency',yaxis='phase',field='0',antenna='DV06',<br />
avgtime='1e8',avgscan=T,coloraxis='baseline',iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X5d8_wvrtsys.ms',spw='',xaxis='frequency',yaxis='phase',field='0',antenna='DV06',<br />
avgtime='1e8',avgscan=T,coloraxis='baseline',iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X7ef_wvrtsys.ms',spw='',xaxis='frequency',yaxis='phase',field='0',antenna='DV06',<br />
avgtime='1e8',avgscan=T,coloraxis='baseline',iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
Overall these plots look good: they show the phases varying slowly in a correlated way (i.e. without rapid or unpredictable scatter).<br />
<br />
<figure id="Birdies_spw2_X3x1.png"><br />
[[Image:Birdies_spw2_X3x1.png|thumb|<caption>Phase calibrators (brown and green) and TW Hya (orange) showing both real CO(3-2) emission in TW Hya and weak ''birdie'' spectral features in all three sources for spw=2.</caption>]]<br />
</figure><br />
<br />
With such high spectral resolution data, one often sees occasional "birdies" in the data. These are typically very narrow spectral features that are internally generated in the system. As ALMA development continues across observation cycles, the number of birdies should decrease. They are easiest to check for by looking at amplitude vs. frequency for sources observed over a long time range (for sensitivity). It is helpful to look at more than one source to verify the nature of the emission. Below we look at both calibrators (brown and green) and TW Hya (orange). If you have enough sensitivity birdies should be seen on all sources, however, be careful not to mistake real line emission for a birdie even on a calibrator - they can be present as we've seen for Titan. Most often birdies will only appear on a subset of antennas and so can often be identified and eliminated that way.<br />
<br />
<figure id="Birdies_spw3_X3x1.png"><br />
[[Image:Birdies_spw3_X3x1.png|thumb|<caption>Phase calibrators (brown and green) and TW Hya (orange) showing only weak birdie spectral features in spw=3.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='',xaxis='channel',yaxis='amp',field='2,3,4',<br />
avgtime='1e8',avgscan=T,coloraxis='field',iteraxis='spw',xselfscale=T,yselfscale=T)<br />
</source><br />
<br />
Do a quick check that other two datasets are the same (they are usually similar if the source of internal resonance hasn't changed in the meantime).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X5d8_wvrtsys.ms',spw='',xaxis='channel',yaxis='amp',field='2,3,4',<br />
avgtime='1e8',avgscan=T,coloraxis='field',iteraxis='spw',xselfscale=T,yselfscale=T)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X7ef_wvrtsys.ms',spw='',xaxis='channel',yaxis='amp',field='2,3,4',<br />
avgtime='1e8',avgscan=T,coloraxis='field',iteraxis='spw',xselfscale=T,yselfscale=T)<br />
</source><br />
<br />
Now you can zoom in on each region to get channels for flagging, or to save time just go ahead and run the flagging command below where this has been done for you.<br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
for vis in splitdata:<br />
flagdata(vis=vis, mode='manual', action='apply', flagbackup=T,<br />
spw='0:1067~1068;1279~1280;2367~2368;3775~3776, 1:1279~1280;2367~2368;3775~3776, 2:1279~1280;3775~3776, 3:831~832;1535~1536;2367~2368;3775~3776;3839~3839')<br />
</source><br />
<br />
Replete in {{plotms}} using the plotms commands directly above to check that flagging has been done as anticipated.<br />
<br />
==Flag Calibrator Spectral Features==<br />
<br />
In this section, we will flag spectral features in the calibrators so they do not skew the calibration solutions. First make plots of 3C279 and Titan in channel space to get channels for flagging. <br />
<br />
<figure id="3C279_Titan_spw1.png"><br />
[[Image:3C279_Titan_spw1.png|thumb|<caption>Spectral plots of 3C279 (black) and Titan (magenta) for spw=1 after Tsys and wvr correction.</caption>]]<br />
</figure><br />
<figure id="3c279_meso_freq.png"><br />
[[Image:3c279_meso_freq.png|thumb|<caption>Zoomed spectral plot of 3C279 showing mesospheric absorption of CO(3-2) in frequency space.</caption>]]<br />
</figure><br />
<figure id="3c279_meso_chann.png"><br />
[[Image:3c279_meso_chann.png|thumb|<caption>Zoomed spectral plot of 3C279 showing mesospheric absorption of CO(3-2) in channel space.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='channel',yaxis='amp',field='0,1',<br />
avgtime='1e8',coloraxis='field',iteraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
The figure to the right shows a broad absorption line in spw 1 at channel 3000. This is the ozone absorption line at 357.62982 GHz. However, there is another narrow absorption feature in the spectra (spw 2) that is most easily seen on 3C279 (because it is the strongest calibrator). Let's look at it first in frequency space.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='2:1600~2300',xaxis='frequency',yaxis='amp',<br />
field='0',avgtime='1e8',coloraxis='field')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
The absorption feature lies exactly at the rest frequency for CO 3-2 (345.79599 GHz). Because it is so narrow (< 1 MHz), it must originate from a very low pressure region (i.e. high altitude) in the Earth's atmosphere, otherwise it would be more pressure broadened. Indeed, the first detection of CO in the mesosphere was made over 35 years ago (see, e.g. [http://adsabs.harvard.edu/abs/1976Sci...191.1174W Waters et al. 1976] or [http://adsabs.harvard.edu/abs/1979JGR....84..416G Goldsmith et al. 1979]). Be aware that the line is stronger as you go up the CO ladder (strength ~ J^3 for low J) because the temperature at that altitude (~50km) is about 250 K. In April 2011, the apparent depth of the feature was about 10% in the 2-1 line and 35% in the 3-2 line. However, the depth of the absorption feature is exaggerated due to the way ALMA normalizes the cross-correlation spectra by the autocorrelation spectra prior to storage. While this technique generally leads to a flat bandpass shape, it will accentuate telluric features because they are emission lines in the single dish spectrum (e.g. JCMT observations of mesospheric CO 3-2 can be found in [http://adsabs.harvard.edu/abs/1993MNRAS.264..673P Preston et al. 1993]). Finally, note that large seasonal variations in the line strength have been reported from observations at [http://adsabs.harvard.edu/abs/2003GeoRL..30j..39F Onsala]. <br />
<br />
Now, let's re-plot the line with channel number as the x-axis in order to get the channel range for flagging. <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='2:1600~2300',xaxis='channel',yaxis='amp',<br />
field='0',avgtime='1e8',coloraxis='field')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Now lets look at Titan in more detail.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='channel',yaxis='amp',field='1',<br />
avgtime='1e8',coloraxis='field',iteraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Explicitly back up the flag tables so that flagged regions can be restored later.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
flagmanager(vis=asdm+'.ms',mode='save',versionname=asdm+'.before_calspectralflags')<br />
</source><br />
<br />
<figure id="Titan_spw2.png"><br />
[[Image:Titan_spw2.png|thumb|<caption>Spectral plot of Titan (magenta) for spw=2.</caption>]]<br />
</figure><br />
<br />
Flag absorption features for all sources.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
print "Flagging absorption features in all sources for "+asdm<br />
flagdata(vis=asdm+'.ms', mode='manual', spw='1:2000~3839, 2:1945~1960')<br />
</source><br />
<br />
<figure id="Titan_spw3.png"><br />
[[Image:Titan_spw3.png|thumb|<caption>Spectral plot of Titan (magenta) for spw=3.</caption>]]<br />
</figure><br />
<br />
Now we need to flag emission. The very broad CO(3-2) in spw=2 of Titan will prevent us from using it as a calibrator for this spectral window since there are no line-free channels (we will transfer, phase, amplitude, and absolute flux from another Titan spw below). We do want to flag the narrower Titan line in spw=3.<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
flagmanager(vis=asdm+'.ms',mode='save',versionname=asdm+'.before_emissionflags')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
print "Flagging emission for "+asdm<br />
flagdata(vis=asdm+'.ms', mode='manual', <br />
field='1',<br />
spw='3:1000~3000')<br />
</source><br />
<br />
If you like, check that the right things have been flagged.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='channel',yaxis='amp',field='0,1',<br />
avgtime='1e8',coloraxis='field',iteraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
==Set Up the Flux Calibrator Model==<br />
<br />
Fill the model data column for Titan with a model for the flux density as a function of baseline. The model is a uniformly illuminated disk with the size obtained from the JPL Horizons ephemeris.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
setjy(vis=asdm+'.ms',field='1',usescratch=F,<br />
standard='Butler-JPL-Horizons 2010',scalebychan=F)<br />
</source><br />
<br />
<figure id="Titan amp vs uvdist.png"><br />
[[Image:Titan amp vs uvdist.png|thumb|<caption>Plot of Titan model for each of the 4 spws. We used the Butler-JPL-Horizons 2010 standard to compute this model.</caption>]]<br />
</figure><br />
<br />
After running setjy, it is a good idea to plot the model in order to confirm that it makes sense. In this case, Titan is partially resolved, so we expect the flux density to drop with uv distance, but not so much as to pass through a null. We also expect it to be brighter at higher frequencies since it has a thermal blackbody spectrum.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',field='1',xaxis='uvdist',yaxis='amp',coloraxis='spw',<br />
ydatacolumn='model')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<figure id="twhydra_X3c1_wvrtsys_2012_titan_model.png">[[File:twhydra_X3c1_wvrtsys_2012_titan_model.png|thumb|right|<caption>Titan model produced by 'Butler-JPL-Horizons 2012'.</caption>]]</figure><br />
<br />
<br/><br />
<div class="noprint" style="float:none; border:0px solid blue;background-color:#F6CEF5;padding:2px;"><br />
The setjy invocation, above, uses the flux density standard '''standard='Butler-JPL-Horizons 2010' '''. A more updated standard is also available: '''standard='Butler-JPL-Horizons 2012' '''. <xr id="twhydra_X3c1_wvrtsys_2012_titan_model.png"/> shows the Titan model produced using the updated standard. The motivated reader may wish to rerun {{setjy}} using the updated model. We will highlight later in this tutorial, and in the imaging tutorial that follows, the effects of using the updated model.<br />
</div><br />
<br />
==Bandpass Calibration==<br />
<br />
First we need to check how the amplitude and phase of 3C279 behave as a function of time. In order to set<br />
a fixed scale on the y-axis, we first make a plot of all the data, excluding antenna DV04. (We must specify '''ydatacolumn='data' ''' explicitly here because the default value of '''ydatacolumn''' equals the value used in the previous execution of {{plotms}}. In the previous execution '''ydatacolumn''' was set to '''model'''. See the online help, <tt>help plotms</tt>, for details.)<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',xaxis='time',yaxis='amp',coloraxis='corr',<br />
field='0',avgchannel='3840',ydatacolumn='data')<br />
</source><br />
<br />
<figure id="ThreeScansAmp.png"><br />
[[Image:ThreeScansAmp.png|thumb|<caption>Amplitude variation for three 3C279 scans, spw 0 (for one representative baseline).</caption>]]<br />
</figure><br />
<br />
We see that the uncalibrated amplitudes range between 0.2-0.4, so let's set this as our<br />
scale and examine a representative baseline (DV06-DV07) to see how the amplitude changes with time. <br />
<br />
<source lang="python"><br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for spw in ['0','1','2','3']:<br />
for asdm in basename:<br />
print "Now showing spw %s from %s" % (spw, asdm+'.ms')<br />
plotms(vis=asdm+'.ms',spw=spw,xaxis='time',yaxis='amp',coloraxis='corr',iteraxis='spw',<br />
field='0',avgchannel='3840',antenna='DV06&DV07',plotrange=[0,0,0.2,0.4])<br />
user_check=raw_input('press enter to go to the next plot\n')<br />
</source><br />
<br />
<figure id="ThreeScansPhase.png"><br />
[[Image:ThreeScansPhase.png|thumb|<caption>Phase variation for three 3C279 scans, spw 0 (for one representative baseline).</caption>]]<br />
</figure><br />
<br />
Page through the measurement sets for each spw. This shows significant variations in the amplitude across the three measurement sets.<br />
Now do the same with phase.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for spw in ['0','1','2','3']:<br />
for asdm in basename:<br />
print "Now showing spw %s from %s" % (spw, asdm+'.ms')<br />
plotms(vis=asdm+'.ms',spw=spw,xaxis='time',yaxis='phase',coloraxis='corr',iteraxis='spw',<br />
field='0',avgchannel='3840',antenna='DV06&DV07',plotrange=[0,0,-180,180])<br />
user_check=raw_input('press enter to go to the next plot\n')<br />
</source><br />
<br />
This examination reveals two findings: (1) significant variation in the phase across the three scans, as well as (2) smaller but significant variations within a scan. The first finding suggests that we do not want to combine the scans for bandpass calibration, but instead derive an independent bandpass for each scan. Actually what is more important than a DC offset is if the '''shape''' of the amplitude or phase changes from scan to scan. There isn't enough S/N to tell for sure so we will keep them separate. This situation is often the case, which is why we did not concatenate the three datasets prior to calibration. The second finding suggests that we need to correct the phase vs. time behavior of the bandpass calibrator (3C279; field=0) within each scan, before doing the bandpass. We want to chose a relatively narrow range of channels near the center of the spws so that the bandpass phase slopes (to be corrected with the bandpass calibration itself) do not decorrelate the signal. You need to avoid spectral regions that were completely flagged above.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.bpphase.gcal')<br />
gaincal(vis=asdm+'.ms',caltable=asdm+'.bpphase.gcal',<br />
field='0',spw='0~3:900~1100',refant='DV06',<br />
calmode='p',solint='int',minsnr=2.0,minblperant=4)<br />
</source><br />
<br />
<figure id="X7ef_wvrtsys.bpphase.X.png"><br />
[[Image:X7ef_wvrtsys.bpphase.X.png|thumb|<caption>Phase only solutions for correlation X on the third scan of the bandpass calibrator 3C279.</caption>]]<br />
</figure><br />
<br />
Inspect the phase-only calibration solutions for the bandpass calibrator. Look for any noisy solutions. We do XX and YY separately to reduce confusion in the plot. It will help if you make your plotcal window wide.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.bpphase.gcal',xaxis='time',yaxis='phase',spw='',antenna='1~8', <br />
iteration='antenna',subplot=421,plotrange=[0,0,-180,180],<br />
figfile=asdm+'.bpphase.X.png',poln='X')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
In the plotcal gui you can use the magnifying glass symbol to zoom in on one of the scans to see the phase variations. The colors are the 4 different spws.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.bpphase.gcal',xaxis='time',yaxis='phase',spw='',antenna='1~8', <br />
iteration='antenna',subplot=421,plotrange=[0,0,-180,180],<br />
figfile=asdm+'.bpphase.Y.png',poln='Y')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Next we apply this phase-only correction on the fly while calculating the bandpass solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.bandpass.bcal')<br />
bandpass(vis=asdm+'.ms',caltable=asdm+'.bandpass.bcal',<br />
field='0',spw='',combine='',refant='DV06',<br />
solint='inf',solnorm=T,minblperant=4, bandtype='B', fillgaps=17,<br />
gaintable=asdm+'.bpphase.gcal')<br />
</source><br />
<br />
You will see some error messages in the terminal, these are just related to the flagged channels. We set fillgaps=17 to interpolate across the smaller regions of flagged channels (mesospheric features and birdies).<br />
<br />
<figure id="Bandpass.ampspw0.png"><br />
[[Image:Bandpass.ampspw0.png|thumb|<caption>Bandpass amplitude solution plots.</caption>]]<br />
</figure><br />
<figure id="Bandpass.phasespw0.png"><br />
[[Image:Bandpass.phasespw0.png|thumb|<caption>Bandpass phase solution plots.</caption>]]<br />
</figure><br />
<br />
'''A few words about solint and combine:'''<br />
<br />
In {{bandpass}}, the use of '''solint='inf'''' (as in "infinite") will derive a bandpass<br />
solution for each 3C279 scan, '''unless''' '''combine='scan'''' (which is the default). Here we set combine=' ' explicitly so that it does not combine the scans into one bandpass. Likewise, field boundaries are only crossed if combine='field', and spw boundaries are only crossed if combine='spw'. In some cases it can be helpful to combine fields if you suffer from lack of S/N, but it is never a good idea to combine spws. <br />
<br />
Now inspect the phase and amplitude solutions. You are looking for excursions from smooth fits, or particularly noisy solutions compared to the others. <br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
for spw in [0,1,2,3]:<br />
plotbandpass(asdm+'.bandpass.bcal',xaxis='freq',yaxis='amp', spw=spw,<br />
antenna='1~8', subplot=42, figfile=asdm+'.bandpass.amp', showatm=T,<br />
interactive=True)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
for spw in [0,1,2,3]:<br />
plotbandpass(asdm+'.bandpass.bcal',xaxis='freq',yaxis='phase',spw=spw,<br />
antenna='1~8',subplot=42,figfile=asdm+'.bandpass.phs', showatm=T,<br />
interactive=True)<br />
</source><br />
<br />
The values of phase on DV06 are very close to zero because it was used as the reference antenna.<br />
<br />
==Gain Calibration==<br />
<br />
Now that we have a bandpass solution to apply we can solve for the antenna-based phase and amplitude gain calibration. Since the phase changes on a much shorter timescale than the amplitude, we will solve for them separately. In particular, if the phase changes significantly over a scan time, the amplitude would be decorrelated, if the un-corrected phase were averaged over this timescale. Note that we re-solve for the gain solutions of the bandpass calibrator, so we can derive new solutions that are corrected for the bandpass shape. Since the bandpass calibrator will not be used again, this is not strictly necessary, but is useful to check its calibrated flux density for example. <br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.intphase.gcal')<br />
gaincal(vis=asdm+'.ms',caltable=asdm+'.intphase.gcal',<br />
field='0,1,3,4',spw='0~3:40~3800',refant='DV06',<br />
calmode='p',solint='int',minsnr=2.0,minblperant=4,<br />
gaintable=[asdm+'.bandpass.bcal'])<br />
</source><br />
<br />
Here '''solint='int' ''' coupled with '''calmode='p' ''' will derive a single phase solution for each 10 second integration. Note that the bandpass table is applied on-the-fly before solving for the phase solutions, however the bandpass is NOT applied to the data permanently until applycal is run later on. <br />
<br />
Although '''solint='int' ''' (i.e. the integration time of 10 seconds) is the best choice to apply before solving for the amplitude solutions, it is not a good idea to use this to apply to the target. This is because the phase-scatter within a scan can dominate the interpolation between calibrator scans. Instead, we also solve for the phase on the scan time, '''solint='inf' ''' (but '''combine=' ' ''', since we want one solution per scan) for application to the target later on. Unlike the bandpass task, for {{gaincal}}, the default of the combine parameter is '''combine=' ' '''. <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.scanphase.gcal')<br />
gaincal(vis=asdm+'.ms',caltable=asdm+'.scanphase.gcal',<br />
field='0,1,3,4',spw='0~3:40~3800',refant='DV06',<br />
calmode='p',solint='inf',minsnr=2.0,minblperant=4,<br />
gaintable=[asdm+'.bandpass.bcal'])<br />
</source><br />
<br />
Alternatively, instead of making a separate phase solution for application to the target, one can also run {{smoothcal}} to smooth the solutions derived on the integration time. <br />
<br />
Next we apply the bandpass and '''solint='int' ''' phase-only calibration solutions on-the-fly to derive amplitude solutions. Here the use of '''solint='inf' ''', but '''combine=' ' ''' will result in one solution per scan interval. <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.amp.gcal')<br />
gaincal(vis=asdm+'.ms',caltable=asdm+'.amp.gcal',<br />
field='0,1,3,4',spw='0~3:40~3800',refant='DV06',<br />
calmode='ap',solint='inf',minsnr=2.0,minblperant=4,<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal'])<br />
</source><br />
<br />
Now carefully inspect all these solutions looking for discrepant solutions. If you see any, you will need to flag them and rerun the calibration tasks above. <br />
<br />
We make plots in X and Y separately for clarity. The colors are showing the spectral windows.<br />
<figure id="X3c1_wvrtsys.intphase_X.png"><br />
[[Image:X3c1_wvrtsys.intphase_X.png|thumb|<caption>Phase solutions for the X polarization for every integration time of the first dataset.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.intphase.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',iteration='antenna',subplot=421,<br />
plotrange=[0,0,-180,180],poln='X',figfile=asdm+'.intphase_X.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.intphase.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',iteration='antenna',subplot=421,<br />
plotrange=[0,0,-180,180],poln='Y',figfile=asdm+'.intphase_Y.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<figure id="X3c1_wvrtsys.scanphase_X.png"><br />
[[Image:X3c1_wvrtsys.scanphase_X.png|thumb|<caption>Phase solutions for the X polarization for each scan of the first dataset.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.scanphase.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',iteration='antenna',subplot=421,<br />
plotrange=[0,0,-180,180],poln='X',figfile=asdm+'.scanphase_X.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.scanphase.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',iteration='antenna',subplot=421,<br />
plotrange=[0,0,-180,180],poln='Y',figfile=asdm+'.scanphase_Y.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Since we have taken out the phase as best we can by applying the '''solint='int' ''' phase-only solution, this plot will give a good idea of the residual phase error. If you see scatter of more than a few degrees here, you should consider going back and looking for more data to flag, particularly bad timeranges etc. <br />
<br />
<figure id="X3c1_wvrtsys.amp_phase.png"><br />
[[Image:X3c1_wvrtsys.amp_phase.png|thumb|<caption>Residual phase after applying intphase.gcal for both correlations in the first dataset.</caption>]]<br />
</figure><br />
<figure id="X3c1_wvrtsys.amp_X.png"><br />
[[Image:X3c1_wvrtsys.amp_X.png|thumb|<caption>Amplitude solutions on a scan interval for correlation X in the first dataset.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.amp.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',plotrange=[0,0,-1,1],<br />
iteration='antenna',subplot=421,figfile=asdm+'.amp_phase.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
These are very small, as they should be. Now look at the amplitude solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.amp.gcal',xaxis='time',yaxis='amp',antenna='1~8', <br />
iteration='antenna',subplot=421,spw='',poln='X',<br />
plotrange=[0,0,0.0,0.3],figfile=asdm+'.amp_X.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.amp.gcal',xaxis='time',yaxis='amp',antenna='1~8', <br />
iteration='antenna',subplot=421,spw='',poln='Y',<br />
plotrange=[0,0,0.0,0.3],figfile=asdm+'.amp_Y.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
==Flux Calibration==<br />
<br />
Next we use the flux calibrator (whose flux density was set in {{setjy}} above) to derive the flux density of the other calibrators. Note that the flux table REPLACES the amp.gcal in terms of future application of the calibration to the data, i.e. the flux table contains both the amp.gcal and flux scaling. Unlike the gain calibration steps, this is not an incremental table.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.flux.cal')<br />
fluxscale(vis=asdm+'.ms',caltable=asdm+'.amp.gcal',<br />
fluxtable=asdm+'.flux.cal',reference='1',refspwmap=[0,1,3,3],<br />
listfile=asdm+'.fluxscale.txt')<br />
</source><br />
<br />
Its a good idea to record the derived fluxscale values using the listfile option. The values can also be viewed in the Log Messages window.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Found reference field(s): Titan<br />
Found transfer field(s): 3c279 J1147-382=QSO J1037-295=QSO<br />
Spw=2 will be referenced to spw=3<br />
Flux density for 3c279 in SpW=0 (freq=3.56498e+11 Hz) is: 10.537 +/- 0.0183518 (SNR = 574.169, N = 16)<br />
Flux density for 3c279 in SpW=1 (freq=3.57734e+11 Hz) is: 10.6933 +/- 0.0264134 (SNR = 404.842, N = 16)<br />
Flux density for 3c279 in SpW=2 (freq=3.46034e+11 Hz) (ref SpW=3) is: 10.251 +/- 0.0477949 (SNR = 214.479, N = 14)<br />
Flux density for 3c279 in SpW=3 (freq=3.43956e+11 Hz) is: 9.91798 +/- 0.020167 (SNR = 491.791, N = 16)<br />
Flux density for J1147-382=QSO in SpW=0 (freq=3.56498e+11 Hz) is: 1.03399 +/- 0.0167344 (SNR = 61.7887, N = 16)<br />
Flux density for J1147-382=QSO in SpW=1 (freq=3.57734e+11 Hz) is: 0.844817 +/- 0.0191013 (SNR = 44.2283, N = 16)<br />
Flux density for J1147-382=QSO in SpW=2 (freq=3.46034e+11 Hz) (ref SpW=3) is: 0.987193 +/- 0.024391 (SNR = 40.4737, N = 14)<br />
Flux density for J1147-382=QSO in SpW=3 (freq=3.43956e+11 Hz) is: 1.28859 +/- 0.0194364 (SNR = 66.298, N = 16)<br />
Flux density for J1037-295=QSO in SpW=0 (freq=3.56498e+11 Hz) is: 0.968281 +/- 0.00895224 (SNR = 108.161, N = 16)<br />
Flux density for J1037-295=QSO in SpW=1 (freq=3.57734e+11 Hz) is: 0.75916 +/- 0.015366 (SNR = 49.4053, N = 16)<br />
Flux density for J1037-295=QSO in SpW=2 (freq=3.46034e+11 Hz) (ref SpW=3) is: 0.948551 +/- 0.0165421 (SNR = 57.3416, N = 14)<br />
Flux density for J1037-295=QSO in SpW=3 (freq=3.43956e+11 Hz) is: 1.21905 +/- 0.0139967 (SNR = 87.0956, N = 16)<br />
Fitted spectrum for 3c279 with fitorder=1: Flux density = 10.2962 +/- 0.0450319 (freq=351.002 GHz) spidx=1.70757 +/- 0.245737<br />
Fitted spectrum for J1147-382=QSO with fitorder=1: Flux density = 1.06853 +/- 0.0709817 (freq=351.002 GHz) spidx=-6.77353 +/- 3.71867<br />
Fitted spectrum for J1037-295=QSO with fitorder=1: Flux density = 1.01822 +/- 0.0654586 (freq=351.002 GHz) spidx=-6.28977 +/- 3.71453<br />
Storing result in X7ef_wvrtsys.flux.cal<br />
Writing solutions to table: X7ef_wvrtsys.flux.cal<br />
</pre><br />
<br />
<figure id="x3c1_wvrtsys.flux_X.png"><br />
[[Image:x3c1_wvrtsys.flux_X.png|thumb|<caption>Absolute flux calibration solutions for correlation X for the first dataset.</caption>]]<br />
</figure><br />
<br />
<div class="noprint" style="float:none; border:0px solid blue;background-color:#F6CEF5;padding:2px;"><br />
If you used the updated (Butler-JPL-Horizons 2012) flux density standard when you ran {{setjy}} earlier in this tutorial, the derived flux values for the calibrators will be slightly different. For example, when averaged over the 3 measurement sets, 3c279 in spectral window 0 has a flux of 10.77 Jy using the 2010 standard and 10.63 Jy using the 2012 standard; as a second example, J1147-382 in SPW 3 has an average flux of 1.13 Jy (2010 standard) and 1.15 Jy (2012 standard). <br />
</div><br />
<br />
Now look at the flux solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.flux.cal',xaxis='time',yaxis='amp',antenna='1~8', <br />
iteration='antenna',subplot=421,spw='',poln='X',<br />
plotrange=[0,0,0.0,0.3],figfile=asdm+'.flux_X.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.flux.cal',xaxis='time',yaxis='amp',antenna='1~8', <br />
iteration='antenna',subplot=421,spw='',poln='Y',<br />
plotrange=[0,0,0.0,0.3],figfile=asdm+'.flux_Y.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
==Apply Calibration and Inspect==<br />
<br />
Now we can use the {{flagmanager}} if we want to restore any of the spectral flagging we did prior to bandpass calibration. <br />
In this case, we choose to restore the flags of the emission lines on Titan, because we are interested in seeing how<br />
strong they are compared to the continuum. However, we leave the strong ozone line and mesospheric CO line flagged on all <br />
sources, because we want to get the most accurate continuum flux density for the science target. <br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
flagmanager(vis=asdm+'.ms',mode='restore',versionname=asdm+'.before_emissionflags')<br />
</source><br />
<br />
Next we apply the calibration solutions to each source individually, using the '''gainfield''' parameter to specify which calibrator's solutions should be applied from each of the '''gaintable''' calibration tables. <br />
<br />
First, we do 3C279 (the bandpass calibrator), applying all 3 of its solutions to itself (that's why gainfield contains three zeros):<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='0',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['0','0','0'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
Next, we do Titan (the absolute flux calibrator) using the bandpass solution from 3C279:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='1',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['0','1','1'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
For the secondary phase calibrator, we apply the phase and flux solutions from the primary phase calibrator. This will allow us to check how well the phase transfer to the science target (TW Hya) has worked:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='3',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.scanphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','linear','linear'],<br />
gainfield=['0','4','4'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
Next is the Primary phase calibrator:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='4',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['0','4','4'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
Finally, for the Science Target TW Hya, we apply the phase solutions from both the primary and secondary phase calibrators:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='2',<br />
interp=['nearest','linear','linear'],<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.scanphase.gcal',asdm+'.flux.cal'],<br />
gainfield=['0','3,4','3,4'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
Now we can check the results of applying the calibration solutions.<br />
<br />
<figure id="Corrected_vs_time_1.png"><br />
[[Image:Corrected_vs_time_1.png|thumb|<caption>The calibrated data for the first dataset (amplitude vs. time).</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw',ydatacolumn='corrected')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
In amplitude, it looks good but there are some noisy points toward the end of the first scheduling block, but it mostly only affects the secondary phase calibrator (green). In phase, we expect all the points to cluster about zero. The large scatter in phase on the secondary phase calibrator is readily apparent: <br />
<br />
<figure id="Corrected_phase_vs_time_1.png"><br />
[[Image:Corrected_phase_vs_time_1.png|thumb|<caption>The calibrated data on the calibrators for the first dataset (phase vs. time).</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='time',yaxis='phase',field='0,1,3,4',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw',ydatacolumn='corrected')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Let's check whether the situation improves when we apply this calibrator's solutions to itself rather than transferring the solutions from the primary phase calibrator (which is 17 degrees away, and observed at a different time). <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='3',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['0','3','3'],flagbackup=T, calwt=T)<br />
</source><br />
<br />
<figure id="Corrected_vs_time_1_field3.png"><br />
[[Image:Corrected_vs_time_1_field3.png|thumb|<caption>The calibrated data for the first dataset (amplitude vs. time), but now with field 3, the secondary phase calibrator, calibrated with itself.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw',ydatacolumn='corrected')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<figure id="Corrected_phase_vs_time_1_field3.png"><br />
[[Image:Corrected_phase_vs_time_1_field3.png|thumb|<caption>The calibrated data from the first dataset (phase vs. time), but now with field 3, the secondary phase calibrator, calibrated with itself.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='time',yaxis='phase',field='0,1,3,4',<br />
avgchannel='3840', coloraxis='field',iteraxis='spw',<br />
ydatacolumn='corrected')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Indeed, the secondary calibrator looks better now in amplitude and phase. This is an indication that the calibration transfer is not working well in this timerange. Because the effect is not catastrophic and we know we can self-calibrate on TW Hya later, we will let this go for now. Or, if you want you can delve deeper into the data and try to solve the mystery... <br />
<br />
In any case, we will re-issue the original {{applycal}} so that it is this calibration that our subsequent {{split}} will use. This will allow us to check the effect of correcting the secondary phase calibrator with the primary phase calibrator later. <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='3',<br />
gaintable=[asdm+'.bandpass.bcal', asdm+'.scanphase.gcal', asdm+'.flux.cal'],<br />
interp=['nearest','linear','linear'],<br />
gainfield=['0','4','4'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
<br />
Let's check the spectral calibration now. First 3C279 and Titan:<br />
<br />
<figure id="X3c1_spw2_corrected_3.4.png"><br />
[[Image:X3c1_spw2_corrected_3.4.png|thumb|<caption>Spectral UV-plots of 3C279 and Titan of spw=2 for the first dataset.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='frequency',yaxis='amp',field='0,1',<br />
avgtime='1e8',avgscan=T,coloraxis='field',ydatacolumn='corrected',<br />
iteraxis='spw',xselfscale=T)<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Flip through the spws. These look good. Next the two phase calibrators:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='frequency',yaxis='amp',field='3,4',<br />
avgtime='1e8',avgscan=T,coloraxis='field',ydatacolumn='corrected',<br />
iteraxis='spw',xselfscale=T)<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Flip through the spws. This also looks good, the secondary phase calibrator is a bit noisier but this is normal. The upswing at the lower frequency end of spw=3 will probably need to be flagged on the science target as well. It corresponds to the edge of an atmospheric feature.<br />
<br />
Now for the exciting part, what does the science target look like...<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='frequency',yaxis='amp',field='2',<br />
avgtime='1e8',avgscan=T,coloraxis='field',ydatacolumn='corrected',<br />
iteraxis='spw',xselfscale=T)<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
We see HCO+(4-3) in spw=0 and CO(3-2) in spw=2 as expected. Because the shape of the <br />
line profiles varies with baseline, you can already tell that the line emission is resolved.<br />
<br />
<figure id="X3c1_CO3_2_uvplot_3.4.png"><br />
[[Image:X3c1_CO3_2_uvplot_3.4.png|thumb|<caption>UV-Plot of the TW Hya CO(3-2) emission from the first dataset.</caption>]]<br />
</figure><br />
<figure id="X3c1_HCOp4_3_uvplot_3.4.png"><br />
[[Image:X3c1_HCOp4_3_uvplot_3.4.png|thumb|<caption>UV-Plot of the TW Hya HCO+(4-3) emission from the first dataset.</caption>]]<br />
</figure><br />
<br />
Now check that the velocity of TWHydra is correct in the LSRK frame, it should be around 2.88 km/s.<br />
* CO 3-2 rest freq 345.79599 GHz<br />
* HCO+ 4-3 rest freq 356.7342 GHz<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='2',xaxis='velocity',yaxis='amp',field='2',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',<br />
restfreq='345.79599GHz', plotrange=[-10,15,0,0],coloraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='0',xaxis='velocity',yaxis='amp',field='2',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',<br />
restfreq='356.7342GHz',plotrange=[-10,15,0,0],coloraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Both lines show up at the expected velocity.<br />
<br />
==Concatenate the Data==<br />
<br />
Here we will concatenate the three datasets prior to imaging.<br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
os.system('rm -rf Band7multi_april22.ms')<br />
concat(vis=splitdata,concatvis='Band7multi_april22.ms')<br />
</source><br />
<br />
If you like you can run listobs on new combined dataset<br />
<br />
<source lang="python"><br />
# In CASA<br />
listfile = 'Band7multi_april22.listobs.txt'<br />
os.system('rm ' + listfile)<br />
listobs(vis='Band7multi_april22.ms',verbose=F, listfile=listfile)<br />
</source><br />
<br />
<figure id="All_spw2_corrected_3.4.png"><br />
[[Image:All_spw2_corrected_3.4.png|thumb|<caption>Spectral UV-plots of 3C279 and Titan of spw=2 for the combined datasets.</caption>]]<br />
</figure><br />
<br />
You can also examine the spectral uv plots for the combined dataset to see the improvement in S/N: <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='Band7multi_april22.ms',spw='',xaxis='frequency',yaxis='amp',field='0,1',<br />
avgtime='1e8',avgscan=T,coloraxis='field',ydatacolumn='corrected',<br />
iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
<figure id="All_CO3_2_uvplot_3.4.png"><br />
[[Image:All_CO3_2_uvplot_3.4.png|thumb|<caption>UV-Plot of the TW Hya CO(3-2) emission from the combined datasets.</caption>]]<br />
</figure><br />
<br />
...and the CO line profile for the combined dataset: <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='Band7multi_april22.ms',spw='2',xaxis='velocity',yaxis='amp',field='2',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',restfreq='345.79599GHz',<br />
plotrange=[-10,15,0,0],coloraxis='spw')<br />
</source><br />
<br />
==Split Calibrated Data==<br />
<br />
Now we split off the calibrated data for the Science Target as well as the interesting parts of the calibrators for imaging.<br />
<br />
When we {{split}} off the Titan data, a few dozen warnings like the following are written to the log:<br />
<pre><br />
2012-05-15 22:00:35 WARN split::SubMS::copySource() Invalid SOURCE ID in SOURCE table row 20 <br />
</pre><br />
These can be ignored, because they do not indicate any problem that will prevent you from imaging Titan correctly at a single position using all the data in the output ms.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_corrected.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='TWHydra_corrected.ms',<br />
datacolumn='corrected',spw='',field='2')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf J1037_corrected.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='J1037_corrected.ms',<br />
datacolumn='corrected',spw='',field='4')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf J1147_corrected.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='J1147_corrected.ms',<br />
datacolumn='corrected',spw='',field='3')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3C279_CO3_2.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='3C279_CO3_2.ms',<br />
datacolumn='corrected',spw='2:1900~2000',field='0')<br />
</source><br />
<br />
==Optional: Reconcile Titan's Coordinates==<br />
<br />
If you do not care to image Titan, then you can skip this step and simply continue on to the [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_4.5 imaging guide].<br />
<br />
Our earlier treatment of Titan's coordinates using [http://casa.nrao.edu/stable/docs/TaskRef/fixplanets-task.html fixplanets] replaced the zeros written by the ALMA control system with the correct position of the body at the instant of the first observation of that SB. As a result, it has slightly different positions in all three datasets, as seen by listobs:<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='Band7multi_april22.ms',verbose=F)<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
ID Code Name RA Decl Epoch SrcId nRows <br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 70866 <br />
1 none Titan 12:49:25.97588 -02.22.41.3024 J2000 1 4842 <br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 515151 <br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 40797 <br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 171153 <br />
5 none Titan 12:49:26.53729 -02.22.27.1521 J2000 0 4833 <br />
6 none Titan 12:49:26.53059 -02.22.18.7878 J2000 0 4833 <br />
</pre><br />
<br />
If we want to image such moving objects observed across multiple SBs, we need to bring the positions into agreement, otherwise {{clean}} will try to make a mosaic. Task [http://casa.nrao.edu/stable/docs/TaskRef/fixplanets-task.html fixplanets] can be used to do this. Here, we set the direction to the direction of the first dataset as reported by listobs. Note that the RA/Dec format is slightly different from the {{listobs}} output format. Also, we do not<br />
fix the uvw coordinates because they are already more correct now than they would be if we "fixed" them.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fixplanets(vis='Band7multi_april22.ms', field='Titan', direction='J2000 12h49m25.97588 -02d22m41.3024', fixuvw=False)<br />
</source><br />
<br />
Check the header information again to see that the information for Titan has changed for the second<br />
and third datasets. They will appear as fields 5 and 6.<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='Band7multi_april22.ms',verbose=F)<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
ID Code Name RA Decl Epoch SrcId <br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 70866 <br />
1 none Titan 12:49:25.97588 -02.22.41.3024 J2000 1 4842 <br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 515151 <br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 40797 <br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 171153 <br />
5 none Titan 12:49:25.97588 -02.22.41.3024 J2000 0 4833 <br />
6 none Titan 12:49:25.97588 -02.22.41.3024 J2000 0 4833 <br />
</pre><br />
<br />
==Optional: Split Calibrated Titan Data==<br />
<br />
When we {{split}} off the Titan data, a few dozen warnings like the following are written to the log:<br />
<pre><br />
2012-05-15 22:00:35 WARN split::SubMS::copySource() Invalid SOURCE ID in SOURCE table row 20 <br />
</pre><br />
These can be ignored, because they do not indicate any problem that will prevent you from imaging Titan correctly at a single position using all the data in the output ms.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Titan_cont.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='Titan_cont.ms',<br />
datacolumn='corrected',spw='0',field='1')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Titan_CO3_2.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='Titan_CO3_2.ms',<br />
datacolumn='corrected',spw='2',field='1')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Titan_unknown.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='Titan_unknown.ms',<br />
datacolumn='corrected',spw='3',field='1')<br />
</source><br />
<br />
==Continue on to Imaging of the Science Target==<br />
<br />
Now you can continue on to the [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_4.5 imaging guide].<br />
<br />
{{Checked 4.5.2}}</div>Sstierwahttps://casaguides.nrao.edu/index.php?title=TWHydraBand7_Calibration_4.5&diff=19475TWHydraBand7 Calibration 4.52016-05-18T04:20:42Z<p>Sstierwa: /* Initial Inspection and Flagging */</p>
<hr />
<div>[[Category:ALMA]][[Category:Calibration]][[Category:Spectral Line]]<br />
*'''This script assumes that you have downloaded TWHYA_BAND7_UnCalibratedMSAndTablesForReduction.tgz from [[TWHydraBand7#Getting_the_Data]]'''<br />
<br />
*'''An introduction to this data set is available at [[TWHydraBand7]].<br />
<br />
*'''This guide is designed for CASA 4.5.2 If you are using an older version of CASA please see [[TWHydraBand7_Calibration_4.3]].<br />
<br />
==Preparation==<br />
<br />
Once you have downloaded TWHYA_BAND7_UnCalibratedMSAndTablesForReduction.tgz, in a terminal unpack it with<br />
<br />
<source lang="bash"><br />
tar -zxvf TWHYA_BAND7_UnCalibratedMSAndTablesForReduction.tgz<br />
</source><br />
<br />
Please be aware that you will need about 100 GB of free space to do the data reduction. It is a good idea to check that now before you begin. Some of the plots described here require 9 GB of RAM; as little as 4 GB may be sufficient if additional data averaging is used when the plots are generated. When you are satisfied with the available drive space and memory on your machine:<br />
<br />
<source lang="bash"><br />
cd TWHYA_BAND7_UnCalibratedMSAndTablesForReduction<br />
</source><br />
<br />
'''NOTE: the calibration tables included in TWHYA_BAND7_UnCalibratedMSAndTablesForReduction CANNOT be used with CASA 4.5, they should be discarded, or moved out of the working directory.'''<br />
<br />
Then start CASA by typing 'casa' at a shell prompt. <br />
<br />
<source lang="bash"><br />
casa<br />
</source><br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.5.2. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.5.2'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
==Install Analysis Utilities==<br />
<br />
Analysis Utilities (or analysisUtils for short) is a small set of Python scripts that provide a number of analysis and plotting utilities for ALMA data reduction. This guide uses a few of these utilities. They are very easy to install (just download and untar). See <br />
<br />
http://casaguides.nrao.edu/index.php?title=Analysis_Utilities<br />
<br />
for a full description and download instructions. If you do not wish to do this, see the [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Calibration_for_CASA_3.3 CASA 3.3 version of the guide] for alternative (but slow) plotting options. Analysis Utilities are updated frequently so if its been a while since you installed it, its probably worth doing it again. If you are at an ALMA site or ARC, the analysis utilities are probably already installed and up to date.<br />
<br />
==Fix Titan's coordinates==<br />
<br />
'''Note that in the near future this step will be unnecessary.''' <br />
<br />
It is temporarily necessary to correct the positions of ephemeris objects observed during ALMA Cycle 0, because the control software revisions earlier than 9.0 erroneously write the data with coordinates of 00:00:00.0000 +00.00.00.0000 (J2000). For this dataset, we need to correct the position of the absolute flux calibrator Titan, as we can<br />
see from the first {{listobs}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -f X3c1.ms.listobs')<br />
listobs('X3c1.ms', verbose=T, listfile='X3c1.ms.listobs') <br />
</source><br />
<br />
You can view the listobs output files using command "less" from the CASA prompt.<br />
<br />
<pre style="background-color: #fffacd;"><br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 23625<br />
1 none Titan 00:00:00.00000 +00.00.00.0000 J2000 1 4842<br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 175176<br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 14832<br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 59877<br />
</pre><br />
<br />
To correct Titan's position, we will use the task [http://casa.nrao.edu/stable/docs/TaskRef/fixplanets-task.html fixplanets], which writes the actual coordinates at the instant of the first observation. This step takes a while because we are recalculating the uvw's accordingly.<br />
<source lang="python"><br />
# In CASA<br />
fixplanets(vis='X3c1.ms', field='Titan', fixuvw=True)<br />
</source><br />
<br />
Check the header information again with {{listobs}} to confirm that the information for Titan has changed:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -f X3c1.ms.listobs')<br />
listobs('X3c1.ms', verbose=T, listfile='X3c1.ms.listobs') <br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 23625<br />
1 none Titan 12:49:25.93349 -02.22.41.5638 J2000 1 4842<br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 175176<br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 14832<br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 59877<br />
</pre><br />
<br />
Now fix the other two measurement sets similarly:<br />
<source lang="python"><br />
# In CASA<br />
fixplanets(vis='X5d8.ms', field='Titan', fixuvw=True)<br />
fixplanets(vis='X7ef.ms', field='Titan', fixuvw=True)<br />
</source><br />
<br />
==Observing Log and Priors==<br />
<br />
Below is some information that may not be obvious from the data<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Like at most telescopes, the ALMA operators and astronomers at the site log any significant issues <br />
that were noticed from the online system during the observation. For these Band 7 observations of <br />
TW Hya on April 22, 2011, the only issue of note was that antenna DV04 could not observe at Band 7 <br />
and will need to be flagged. <br />
</pre><br />
<br />
First let's examine the basic properties of the data using {{listobs}}. Among other information we <br />
will be able to deduce what the source ids are and what each source was used for:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
3c279 is the bandpass calibrator (field id=0)<br />
Titan is the absolute flux calibrator (field id=1)<br />
J1147-382 is the secondary phase calibrator (field id=3)<br />
J1037-295 is the primary phase calibrator (field id=4)<br />
</pre><br />
<br />
<source lang="python"><br />
# In CASA<br />
data=['X3c1.ms','X5d8.ms','X7ef.ms']<br />
for vis in data:<br />
os.system('rm '+vis+'.listobs')<br />
listobs(vis, verbose=T, listfile=vis+'.listobs') <br />
</source><br />
<br />
You can view the {{listobs}} output files using command '''less''' from the CASA prompt. <br />
Below we copy select parts of the {{listobs}} output files for reference. <br />
<br />
<pre style="background-color: #fffacd;"><br />
X3c1.ms:<br />
Data records: 278352 Total integration time = 6109.06 seconds<br />
Observed from 22-Apr-2011/00:01:52.9 to 22-Apr-2011/01:43:42.0 (UTC)<br />
<br />
X5d8.ms:<br />
Data records: 278406 Total integration time = 5995.01 seconds<br />
Observed from 22-Apr-2011/01:48:05.8 to 22-Apr-2011/03:28:00.8 (UTC)<br />
<br />
X7ef.ms:<br />
Data records: 255717 Total integration time = 5407.49 seconds<br />
Observed from 22-Apr-2011/03:30:39.7 to 22-Apr-2011/05:00:47.2 (UTC)<br />
<br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 23625<br />
1 none Titan 12:49:25.97588 -02.22.41.3024 J2000 1 4842<br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 175176<br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 14832<br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 59877 <br />
<br />
SpwID #Chans Frame Ch1(MHz) ChanWid(kHz) TotBW(kHz) Corrs<br />
0 4 TOPO 184550 1500000 7500000 I<br />
1 128 TOPO 355740.062 15625 2000000 XX YY<br />
2 1 TOPO 356716.625 1796875 1796875 XX YY<br />
3 128 TOPO 356507.813 15625 2000000 XX YY<br />
4 1 TOPO 357484.375 1796875 1796875 XX YY<br />
5 128 TOPO 346792.187 15625 2000000 XX YY<br />
6 1 TOPO 345784.375 1796875 1796875 XX YY<br />
7 128 TOPO 345182.438 15625 2000000 XX YY<br />
8 1 TOPO 344174.625 1796875 1796875 XX YY<br />
9 128 TOPO 344386.763 15625 2000000 XX YY<br />
10 1 TOPO 343378.95 1796875 1796875 XX YY<br />
11 128 TOPO 346324.263 15625 2000000 XX YY<br />
12 1 TOPO 345316.45 1796875 1796875 XX YY<br />
13 128 TOPO 354402.388 15625 2000000 XX YY<br />
14 1 TOPO 355378.95 1796875 1796875 XX YY<br />
15 128 TOPO 356402.388 15625 2000000 XX YY<br />
16 1 TOPO 357378.95 1796875 1796875 XX YY<br />
17 3840 TOPO 356497.936 122.070312 468750 XX YY<br />
18 1 TOPO 356732.189 468750 468750 XX YY<br />
19 3840 TOPO 357734.314 122.070312 468750 XX YY<br />
20 1 TOPO 357499.939 468750 468750 XX YY<br />
21 3840 TOPO 346034.314 122.070312 468750 XX YY<br />
22 1 TOPO 345799.939 468750 468750 XX YY<br />
23 3840 TOPO 343955.936 122.070312 468750 XX YY<br />
24 1 TOPO 344190.189 468750 468750 XX YY<br />
<br />
Antennas: 9:<br />
Name Station Diam. Long. Lat.<br />
0 DV04 J505 12.0 m -067.45.18.0 -22.53.22.8<br />
1 DV06 T704 12.0 m -067.45.16.2 -22.53.22.1<br />
2 DV07 J510 12.0 m -067.45.17.8 -22.53.23.5<br />
3 DV08 T703 12.0 m -067.45.16.2 -22.53.23.9<br />
4 DV09 N602 12.0 m -067.45.17.4 -22.53.22.3<br />
5 DV10 N606 12.0 m -067.45.17.1 -22.53.23.6<br />
6 PM01 T702 12.0 m -067.45.18.6 -22.53.24.1<br />
7 PM02 T701 12.0 m -067.45.18.8 -22.53.22.2<br />
8 PM03 J504 12.0 m -067.45.17.0 -22.53.23.0<br />
</pre><br />
<br />
Things to Notice from above: <br />
*There are three different data sets acquired close together in time. We will calibrate each dataset independently and then combine the calibrated data prior to imaging. <br />
*Titan appears to have slightly different positions in each dataset because it is a moving body. In fact, at the time of observation, due to temporary data capture issue in the ALMA system, the position was written has (0,0). We have pre-corrected this error using fixplanets. Later in the tutorial, we will run fixplanets again to force all three datasets to have the same fixed position for Titan.<br />
*There are a lot of spectral windows! Don't be alarmed. In ALMA data, <br />
**spw=0 is always reserved for the water vapor radiometry data.<br />
**spw=9, 11, 13, 15 are the wideband (TDM) correlator mode with 128 channels per spw default settings for doing pointing and this is all they are used for in these data.<br />
**Currently Tsys data can only be taken in the wide (TDM) correlator mode with 128 channels per spw, these correspond to spws=1, 3, 5, 7 above. The frequencies of these TDM spws were carefully chosen so the the narrowband FDM spws fall within them.<br />
** The 0.5 GHz, high spectral resolution spws that contain all the real source data (science target and calibrators) are 17, 19, 21, and 23<br />
**For quicklook purposes, the ALMA online system produces a channel averaged spw for each channelized spw, these correspond to spw=2,4,6,8,10,12,14,16,18,20,22,24 and shouldn't be used for anything in post-processing as bandpass calibration etc has not been applied.<br />
<br />
In the portion of the {{listobs}} output that shows the timerange, the final column gives the scan intent. It is important to have a look at this because you can flag and do other operations in CASA using the scan intent as a selection option. Also, these intents will be used in the future for pipeline processing. You will usually want to use them to flag the CALIBRATE_POINTING* and CALIBRATE_ATMOS* (the latter correspond to the hot and cold load measurements used to calculate Tsys) data. This is essential for science or calibration data taken only in TDM (wide bandwidth) mode, i.e. the same mode that the pointing and Tsys data are taken in. For the current data however, that calibration data is recorded in different spws from the useful FDM (narrow bandwidth) data, so we'll be able to separate them by splitting them off at the final step prior to imaging.<br />
<br />
<figure id="Ant_pos.png"><br />
[[Image:Ant_pos.png|thumb|<caption>Antenna locations for the first dataset.</caption>]]<br />
</figure><br />
<br />
Before we move on, its also nice to get an idea where the antennas are with respect to each other. We can use {{plotants}} to plot their positions. It is a good idea to check each file since an antenna may have entered or exited the array between observations.<br />
<source lang="python"><br />
# In CASA<br />
for vis in data:<br />
plotants(vis=vis,figfile=vis+'.plotants.png')<br />
</source><br />
<br />
You can view the output images using any standard image viewer.<br />
<br />
==Create the Tsys and WVR Tables, and Examine ==<br />
<br />
Each ms include tables that contain the Tsys and WVR measurements associated with the visibility data.<br />
We must create calibration tables from these measurements. First we create the WVR calibration tables <br />
by running the task [http://casa.nrao.edu/stable/docs/TaskRef/wvrgcal-task.html wvrgcal]. This task <br />
examines the data for each ms as a whole and creates a calibration<br />
table containing only phase corrections for each antenna and spw. <br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
os.system('rm -rf '+asdm+'.wvr')<br />
wvrgcal(vis=asdm+'.ms', caltable=asdm+'.wvr', segsource=True, toffset=-1)<br />
</source><br />
<br />
Next we create the Tsys tables by running {{gencal}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
os.system('rm -rf '+asdm+'.tsys')<br />
gencal(vis=asdm+'.ms', caltable=asdm+'.tsys', caltype='tsys')<br />
</source><br />
<br />
It is very important that Tsys measurements taken as close in time and elevation as possible to a particular source are applied. To save telescope time, Tsys measurements are sometimes intentionally skipped in the scheduling block for specific sources. So the first step is to establish which sources have their own Tsys measurements and which do not. To do this, you may use the intent parameter of {{listobs}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
listobs(vis=asdm+'.ms', verbose=F, selectdata=True, intent='CALIBRATE_ATMOS*')<br />
</source><br />
<br />
<figure id="X3c1.tsys_vs_time_3.4.png"><br />
[[File:X3c1.tsys_vs_time_3.4.png|thumb|<caption>Tsys vs. time for spw 1 of the X3c1.ms data.</caption>]]<br />
</figure><br />
<figure id="X5d8.tsys_vs_time_3.4.png"><br />
[[File:X5d8.tsys_vs_time_3.4.png|thumb|<caption>Tsys vs. time for spw 1 of the X5d8.ms data.</caption>]]<br />
</figure><br />
<figure id="X7ef.tsys_vs_time_3.4.png"><br />
[[File:X7ef.tsys_vs_time_3.4.png|thumb|<caption>Tsys vs. time for spw 1 of the X7ef.ms data.</caption>]]<br />
</figure><br />
<br />
<pre style="background-color: #fffacd;"><br />
Fields: 4<br />
ID Code Name RA Decl Epoch SrcId nRows <br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 1116 <br />
1 none Titan 12:49:25.97588 -02.22.41.3024 J2000 1 1125 <br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 6795 <br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 6777 <br />
Spectral Windows: (9 unique spectral windows and 2 unique polarization setups)<br />
SpwID #Chans Frame Ch1(MHz) ChanWid(kHz) TotBW(kHz) Corrs <br />
0 4 TOPO 184550 1500000 7500000 I <br />
1 128 TOPO 355740.062 15625 2000000 XX YY <br />
2 1 TOPO 356716.625 1796875 1796875 XX YY <br />
3 128 TOPO 356507.813 15625 2000000 XX YY <br />
4 1 TOPO 357484.375 1796875 1796875 XX YY <br />
5 128 TOPO 346792.187 15625 2000000 XX YY <br />
6 1 TOPO 345784.375 1796875 1796875 XX YY <br />
7 128 TOPO 345182.438 15625 2000000 XX YY <br />
8 1 TOPO 344174.625 1796875 1796875 XX YY <br />
</pre><br />
<br />
Because field '3' (the secondary phase calibrator) does not appear in the list, it has no tsys. Since the secondary phase calibrator is close on the sky to the primary phase calibrator and observed near in time, we will transfer the Tsys from the primary to the secondary phase calibrator. <br />
Also notice that spws 1,3,5,7 are the only multi-channel spws that contain Tsys data. At present, Tsys measurements can only be obtained with TDM spectral setups (128 channels/dual pol). Because our science target is observed in FDM (3840 channels/dual pol), we will need to interpolate the measurements from TDM to FDM. But first, to inspect the Tsys vs. time, we use {{plotcal}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all = ['X3c1','X5d8','X7ef']<br />
tsysfields=['0','1','2','4']<br />
os.system('mkdir cal_plots; mkdir cal_plots/Tsys_plots') <br />
for asdm in basename_all:<br />
print "Plotting Tsys vs. time for "+asdm<br />
plotcal(caltable=asdm+'.tsys', xaxis='time',yaxis='tsys',<br />
antenna='1~8',plotrange=[0,0,100,500],<br />
iteration='antenna',subplot=421,poln='',spw='1:50~50',<br />
figfile='cal_plots/Tsys_plots/'+asdm+'.tsys_vs_time.png')<br />
if (asdm != basename_all[-1]):<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
To inspect Tsys vs. frequency, we use [[plotbandpass]]. There are many different options for plotbandpass, and we demonstrate some of the most useful ones. The option '''showtsky=T''' will overlay the effective temperature curve from the atmospheric model. This shows us the location of any atmospheric lines which will appear as emission lines in the autocorrelation data (from which the Tsys spectra are derived) from all antennas. In the<br />
example below, we set '''interactive=False''', which will produce many pages of plots as<br />
individual pngs but will only show the final page in the graphics window. To view all the pages we use the image viewer '''eog''' (Eye of GNOME) available on Linux. The alternative is to set '''interactive=True''' and examine the plots in the casa graphics window as they are produced.<br />
<br />
<figure id="X3c1.tsys.field0.DV04.spw1.t1.png"><br />
[[File:X3c1.tsys.field0.DV04.spw1.t1.png|thumb|<caption>Tsys vs. frequency on 3C279 for the X3c1.ms data, spw=1.</caption>]]<br />
</figure><br />
<figure id="X3c1.tsys.field0.DV04.spw3.t1.png"><br />
[[File:X3c1.tsys.field0.DV04.spw3.t1.png|thumb|<caption>Tsys vs. frequency on 3C279 for the X3c1.ms data, spw=3.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
print "Plotting Tsys vs. frequency for "+asdm<br />
for spw in [1,3,5,7]:<br />
for field in ['0','1']:<br />
plotbandpass(caltable=asdm+'.tsys', xaxis='freq',yaxis='amp',<br />
showtsky=T,subplot=42,field=field,<br />
spw=spw, interactive=False, plotrange=[0,0,0,0],<br />
figfile='cal_plots/Tsys_plots/'+asdm+'.tsys.field%s.png'%field,<br />
buildpdf=False)<br />
</source><br />
<br />
In <xr id="X3c1.tsys.field0.DV04.spw1.t1.png"/> and <xr id="X3c1.tsys.field0.DV04.spw3.t1.png"/> we see the effect of atmospheric ozone lines on the Tsys measurements associated with 3C279 in spw 1 and 3.<br />
<br />
For sources that have multiple Tsys measurements (typically the primary phase calibrator and/or the science target) one can use '''overlay="time"''' to overlay all the measurements for that source. This can help to identify any anomalous Tsys scans. As a fraction of the plots produced by this loop, here we show the Tsys recorded on spw=1 for TW Hya from the first dataset.<br />
<br />
<figure id="X3c1.tsys.field2.DV04.spw1.png"><br />
[[File:X3c1.tsys.field2.DV04.spw1.png|thumb|<caption>Tsys vs. freq for field 2, spw 1 of the X3c1.ms data (antennas 0..3).</caption>]]<br />
</figure><br />
<figure id="X3c1.tsys.field2.DV04.spw1.png"><br />
[[File:X3c1.tsys.field2.DV09.spw1.png|thumb|<caption>Tsys vs. freq for field 2, spw 1 of the X3c1.ms data (antennas 4..7).</caption>]]<br />
</figure><br />
<figure id="X3c1.tsys.field2.PM03.spw1.png"><br />
[[File:X3c1.tsys.field2.PM03.spw1.png|thumb|<caption>Tsys vs. freq for field 2, spw 1 of the X3c1.ms data (antenna 8).</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
print "Plotting Tsys vs. frequency for "+asdm<br />
for spw in [1,3,5,7]:<br />
for field in ['2','4']:<br />
plotbandpass(caltable=asdm+'.tsys', xaxis='freq',yaxis='amp',<br />
showtsky=T,subplot=22,field=field,<br />
overlay='time',spw=spw, interactive=False, plotrange=[0,0,0,0],<br />
figfile='cal_plots/Tsys_plots/'+asdm+'.tsys.field%s.png'%field,<br />
buildpdf = False)<br />
</source><br />
<br />
Alternatively, the '''overlay="antenna"''' option will quickly reveal any Antennas with discrepant Tsys values, as they<br />
will be obvious outliers. For FDM projects like this one, using the '''showfdm=True''' option can be helpful, as it<br />
will show where in the TDM bandpass each FDM spw was located. <br />
<figure id="X3c1.tsys.field0.spw1.t1.png"><br />
[[Image:X3c1.tsys.field0.spw1.t1.png|thumb|<caption>Tsys vs Freq for field 0, spw 1 of the X3c1.ms data with all antennas overlaid.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
tsysfields=['0','1','2','4'] <br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
print "Plotting Tsys vs. frequency for "+asdm<br />
for spw in [1,3,5,7]:<br />
for field in tsysfields:<br />
plotbandpass(caltable=asdm+'.tsys', xaxis='freq',yaxis='amp',<br />
showtsky=T,subplot=11,field=field,<br />
overlay='antenna',spw=spw, interactive=False,<br />
figfile='cal_plots/Tsys_plots/'+asdm+'.tsys.field%s.png'%field,<br />
buildpdf=False,showfdm=True)<br />
</source><br />
<br />
<br />
Note that DV04 consistently has a significantly higher Tsys than the rest of the antennas. We already know from the Observation log that<br />
we need to flag that antenna, but had we not had that information, examining this plot would have demonstrated the situation.<br />
<br />
==Apply the Tsys and WVR Tables, and Split ==<br />
<br />
Next we apply the calibrations. For the (4) sources with Tsys measurements, we use the '''field''' and '''gainfield''' parameters of {{applycal}} to apply solutions only to themselves. {{applycal}} has the ability to interpolate gain tables from one spw onto another spw. In this case, we want to interpolate the TDM Tsys values in spws 1,3,5,7 onto the FDM spws 17,19,21,23. We use the '''interp''' parameter to request linear interpolation in the time dimension and spline interpolation in the channel/frequency dimension. To map the solutions for each spw, we use the '''spwmap''' parameter, which requires a list of all spws for each gain table to be applied, or a blank list ([]) which is a shorthand notation to apply the solution for each spw to itself. While applying Tsys, we will also apply the wvr calibration tables; wvr data is usually always present for all sources. Below we first set some definitions so we can loop over the correct parameters:<br />
<br />
<source lang="python"><br />
# In CASA<br />
fdm='17,19,21,23'<br />
nocal='3' # This source had no Tsys measurements associated with it <br />
tsysfields=['0','1','2','4'] <br />
tsysmap = range(25)<br />
tsysmap[17] = 1<br />
tsysmap[19] = 3<br />
tsysmap[21] = 5<br />
tsysmap[23] = 7<br />
for asdm in basename_all:<br />
for field in tsysfields:<br />
applycal(vis=asdm+'.ms', spw=fdm, field=field, gainfield=field,<br />
gaintable=[asdm+'.tsys', asdm+'.wvr'], spwmap=[tsysmap,[]],<br />
interp=['linear,spline','nearest'], flagbackup=F, calwt=T)<br />
</source><br />
<br />
For the sources without Tsys (i.e. field=3), couple them with the best available source with Tsys (i.e. field=4).<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename_all:<br />
applycal(vis=asdm+'.ms', spw=fdm, field=nocal,<br />
gaintable=[asdm+'.tsys', asdm+'.wvr'], spwmap=[tsysmap,[]],<br />
gainfield=['4',nocal], interp=['linear,spline','nearest'],flagbackup=F,<br />
calwt=T)<br />
</source><br />
<br />
Check Tsys application with plotms. First we make plots with '''ydatacolumn='data'''' to look at the raw data. For <br />
simplicity we'll just look at the two strongest sources 3C279 and Titan.<br />
<br />
<figure id="X5d8_wvrtsys_corrected_spw19.png"><br />
[[Image:X5d8_wvrtsys_corrected_spw19.png|thumb|<caption>Spectral plots of 3C279 (black) and Titan (magenta) for spw=19 after Tsys and wvr correction.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X5d8.ms',spw='17,19,21,23',xaxis='frequency',yaxis='amp',field='0,1',<br />
antenna='*&*',avgtime='1e8',avgscan=T,coloraxis='field',iteraxis='spw',<br />
xselfscale=T,ydatacolumn='data')<br />
</source><br />
<br />
<figure id="X5d8_wvrtsys_corrected_spw21.png"><br />
[[Image:X5d8_wvrtsys_corrected_spw21.png|thumb|<caption>Spectral plots of 3C279 (black) and Titan (magenta) for spw=21 after Tsys and wvr correction.</caption>]]<br />
</figure><br />
<br />
'''Note''': the antenna='*&*' is specifying that we only want to see the cross-correlation data (i.e. not the autocorrelations).<br />
<br />
Use the '''green arrows''' on the {{plotms}} display to cycle through the 4 FDM spws. <br />
<br />
Now change '''Data Column''' to '''corrected''' on the "Axes" tab (this is the same as ydatacolumn in the task) and hit '''Plot''' button on the GUI. Flip through again.<br />
<br />
'''Things to notice:'''<br />
* The amplitude scale has changed due to application of Tsys<br />
* spw=17 is clean and flat<br />
* spw=19 shows a strong dip around channel 3000 (channels can be plotted by going to the Axes tab, and changing X Axis to Channel, then hit the Plot button)-- this is an atmospheric ozone absorption feature at 357.6 GHz. In the future, high spectral resolution Tsys measurements may help to remove the shape of the absorption, but until then we will need to flag this part of the spectrum.<br />
* spw=21 Titan shows both a narrow and a broad spectral feature. The broad feature is CO(3-2) and it completely fills the 0.5 GHz band so there are no line-free channels! Titan must be handled carefully when it is used as a calibrator because it contains strong line emission. Indeed, we will not be able to use the absolute flux transfer from this spw for other targets. When possible Titan should be avoided for absolute flux calibration. For these observations, no other suitable absolute flux calibrator was available.<br />
* spw=23 shows another strong line from Titan.<br />
<br />
Beyond these things to notice, the application of Tsys and wvr seem to have gone well. We can now split off only the narrow band FDM spectral windows for further processing.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename_all:<br />
newvis = asdm + '_wvrtsys.ms'<br />
os.system('rm -rf ' + newvis)<br />
split(vis=asdm+'.ms',outputvis=newvis,datacolumn='corrected',spw=fdm)<br />
</source><br />
<br />
'''Note''': After {{split}}, the spectral windows will be renumbered to 0, 1, 2, 3 corresponding to the old spw=17, 19, 21, 23, see {{listobs}} excerpt below.<br />
<br />
<pre style="background-color: #fffacd;"><br />
SpwID #Chans Frame Ch1(MHz) ChanWid(kHz) TotBW(kHz) Corrs <br />
0 3840 TOPO 356497.936 122.070312 468750 XX YY <br />
1 3840 TOPO 357734.314 122.070312 468750 XX YY <br />
2 3840 TOPO 346034.314 122.070312 468750 XX YY <br />
3 3840 TOPO 343955.936 122.070312 468750 XX YY <br />
</pre><br />
<br />
==Initial Inspection and Flagging==<br />
<br />
From here we begin to operate on the *wvrtsys.ms files. <br />
<br />
Before we begin flagging data, we unflag all data in the measurement sets. If this is your first pass through this section of the guide, no data in the measurement sets will have previously been flagged, and so you can skip the next splitdata step with mode set to 'unflag'. If you are rerunning the flagging commands below, running splitdata in 'unflag' mode will reset your flag columns to their original state.<br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
for vis in splitdata:<br />
flagdata(vis=vis, mode='unflag', action='apply', flagbackup=F)<br />
</source><br />
<br />
ALMA data contains both the cross correlation and autocorrelation data. Presently nothing more can be done with the autocorrelation data so we flag it. Additionally, for smaller configurations of the array, and northerly sources one antenna can ''shadow'' another, blocking its view. This data also needs to be flagged. Finally, the observing log told us DV04 was not behaving properly at Band 7 and shouldn't be used so we flag that as well.<br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
for vis in splitdata:<br />
flagdata(vis=vis, mode='manual', autocorr=True, action = 'apply', flagbackup=T)<br />
flagdata(vis=vis, mode='shadow',tolerance=12.0, action='apply', flagbackup=F)<br />
flagdata(vis=vis, mode='manual', antenna='DV04', action='apply', flagbackup=F)<br />
</source><br />
<br />
Next we inspect the data with {{plotms}} for additional issues that need flagging, first looking at amplitude vs. time for each of the three datasets. Use the '''green''' arrows on the plotms gui to cycle through spws. <br />
<br />
<figure id="Tsyswvr_time_spw0_X3x1.png"><br />
[[Image:Tsyswvr_time_spw0_X3x1.png|thumb|<caption>Amplitude as a function of time for X3c1_wvrtsys.ms, spw=0</caption>]]<br />
</figure><br />
<br />
'''Note''': when '''iteraxis''' is invoked in {{plotms}}, unzoom does not always work properly. If you have trouble with this, flip to next page and then back to current one. This usually fixes the problem.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X5d8_wvrtsys.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X7ef_wvrtsys.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw')<br />
</source><br />
<br />
<figure id="Tsyswvr_time_spw2corr_X3x1.png"><br />
[[Image:Tsyswvr_time_spw2corr_X3x1.png|thumb|<caption>Amplitude as a function of time for X3x1_wvrtsys.ms, spw=2 with colorize='corr'.</caption>]]<br />
</figure><br />
<br />
'''Things to Notice:'''<br />
* In spw=2 there are some low points in all three data files. Use the "Mark Regions" box (left of center on bottom row of icons) to draw small box on low points. Then click the magnifying glass icon to the right of center. The output will be sent to the logger window. '''Note''': keep the marked region small or you can overwhelm the buffer. Locate suggests correlation YY on PM03 is the culprit. <br />
<br />
To see this more clearly you can rerun {{plotms}} with '''coloraxis='field'''' switched to '''coloraxis='corr''''<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='2',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='corr')<br />
</source><br />
<br />
To further check, you can exclude PM03 from the plot using '''antenna='!PM03'.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='2',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='corr',antenna='!PM03')<br />
</source><br />
<br />
Having confirmed the problem antenna, we flag it below. <br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
for vis in splitdata:<br />
flagdata(vis=vis, mode='manual', action= 'apply', flagbackup=T,<br />
spw='2',<br />
antenna='PM03')<br />
</source><br />
<br />
'''Next we need to inspect the spectral properties of the data to look for issues.'''<br />
<br />
First we look at phase as a function of frequency for an antenna like DV06 for which we have not yet identified any problems. <br />
'''coloraxis='baselines'''' (note this parameter is called '''Colorize''' in the GUI "Display" tab) will show each baseline as a different color. Significant delay errors or baseline errors will show up as phase slopes in these plots. Again you will want to page through the spectral windows.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='',xaxis='frequency',yaxis='phase',field='0',antenna='DV06',<br />
avgtime='1e8',avgscan=T,coloraxis='baseline',iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X5d8_wvrtsys.ms',spw='',xaxis='frequency',yaxis='phase',field='0',antenna='DV06',<br />
avgtime='1e8',avgscan=T,coloraxis='baseline',iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X7ef_wvrtsys.ms',spw='',xaxis='frequency',yaxis='phase',field='0',antenna='DV06',<br />
avgtime='1e8',avgscan=T,coloraxis='baseline',iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
Overall these plots look good: they show the phases varying slowly in a correlated way (i.e. without rapid or unpredictable scatter).<br />
<br />
<figure id="Birdies_spw2_X3x1.png"><br />
[[Image:Birdies_spw2_X3x1.png|thumb|<caption>Phase calibrators (brown and green) and TW Hya (orange) showing both real CO(3-2) emission in TW Hya and weak ''birdie'' spectral features in all three sources for spw=2.</caption>]]<br />
</figure><br />
<br />
With such high spectral resolution data, one often sees occasional "birdies" in the data. These are typically very narrow spectral features that are internally generated in the system. As ALMA development continues across observation cycles, the number of birdies should decrease. They are easiest to check for by looking at amplitude vs. frequency for sources observed over a long time range (for sensitivity). It is helpful to look at more than one source to verify the nature of the emission. Below we look at both calibrators (brown and green) and TW Hya (orange). If you have enough sensitivity birdies should be seen on all sources, however, be careful not to mistake real line emission for a birdie even on a calibrator - they can be present as we've seen for Titan. Most often birdies will only appear on a subset of antennas and so can often be identified and eliminated that way.<br />
<br />
<figure id="Birdies_spw3_X3x1.png"><br />
[[Image:Birdies_spw3_X3x1.png|thumb|<caption>Phase calibrators (brown and green) and TW Hya (orange) showing only weak birdie spectral features in spw=3.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='',xaxis='channel',yaxis='amp',field='2,3,4',<br />
avgtime='1e8',avgscan=T,coloraxis='field',iteraxis='spw',xselfscale=T,yselfscale=T)<br />
</source><br />
<br />
Do a quick check that other two datasets are the same (they are usually similar if the source of internal resonance hasn't changed in the meantime).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X5d8_wvrtsys.ms',spw='',xaxis='channel',yaxis='amp',field='2,3,4',<br />
avgtime='1e8',avgscan=T,coloraxis='field',iteraxis='spw',xselfscale=T,yselfscale=T)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X7ef_wvrtsys.ms',spw='',xaxis='channel',yaxis='amp',field='2,3,4',<br />
avgtime='1e8',avgscan=T,coloraxis='field',iteraxis='spw',xselfscale=T,yselfscale=T)<br />
</source><br />
<br />
Now you can zoom in on each region to get channels for flagging, or to save time just go ahead and run the flagging command below where this has been done for you.<br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
for vis in splitdata:<br />
flagdata(vis=vis, mode='manual', action='apply', flagbackup=T,<br />
spw='0:1067~1068;1279~1280;2367~2368;3775~3776, 1:1279~1280;2367~2368;3775~3776, 2:1279~1280;3775~3776, 3:831~832;1535~1536;2367~2368;3775~3776;3839~3839')<br />
</source><br />
<br />
Replete in {{plotms}} using the plotms commands directly above to check that flagging has been done as anticipated.<br />
<br />
==Flag Calibrator Spectral Features==<br />
<br />
In this section, we will flag spectral features in the calibrators so they do not skew the calibration solutions. First make plots of 3C279 and Titan in channel space to get channels for flagging. <br />
<br />
<figure id="3C279_Titan_spw1.png"><br />
[[Image:3C279_Titan_spw1.png|thumb|<caption>Spectral plots of 3C279 (black) and Titan (magenta) for spw=1 after Tsys and wvr correction.</caption>]]<br />
</figure><br />
<figure id="3c279_meso_freq.png"><br />
[[Image:3c279_meso_freq.png|thumb|<caption>Zoomed spectral plot of 3C279 showing mesospheric absorption of CO(3-2) in frequency space.</caption>]]<br />
</figure><br />
<figure id="3c279_meso_chann.png"><br />
[[Image:3c279_meso_chann.png|thumb|<caption>Zoomed spectral plot of 3C279 showing mesospheric absorption of CO(3-2) in channel space.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='channel',yaxis='amp',field='0,1',<br />
avgtime='1e8',coloraxis='field',iteraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
The figure to the right shows a broad absorption line in spw 1 at channel 3000. This is the ozone absorption line at 357.62982 GHz. However, there is another narrow absorption feature in the spectra (spw 2) that is most easily seen on 3C279 (because it is the strongest calibrator). Let's look at it first in frequency space.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='2:1600~2300',xaxis='frequency',yaxis='amp',<br />
field='0',avgtime='1e8',coloraxis='field')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
The absorption feature lies exactly at the rest frequency for CO 3-2 (345.79599 GHz). Because it is so narrow (< 1 MHz), it must originate from a very low pressure region (i.e. high altitude) in the Earth's atmosphere, otherwise it would be more pressure broadened. Indeed, the first detection of CO in the mesosphere was made over 35 years ago (see, e.g. [http://adsabs.harvard.edu/abs/1976Sci...191.1174W Waters et al. 1976] or [http://adsabs.harvard.edu/abs/1979JGR....84..416G Goldsmith et al. 1979]). Be aware that the line is stronger as you go up the CO ladder (strength ~ J^3 for low J) because the temperature at that altitude (~50km) is about 250 K. In April 2011, the apparent depth of the feature was about 10% in the 2-1 line and 35% in the 3-2 line. However, the depth of the absorption feature is exaggerated due to the way ALMA normalizes the cross-correlation spectra by the autocorrelation spectra prior to storage. While this technique generally leads to a flat bandpass shape, it will accentuate telluric features because they are emission lines in the single dish spectrum (e.g. JCMT observations of mesospheric CO 3-2 can be found in [http://adsabs.harvard.edu/abs/1993MNRAS.264..673P Preston et al. 1993]). Finally, note that large seasonal variations in the line strength have been reported from observations at [http://adsabs.harvard.edu/abs/2003GeoRL..30j..39F Onsala]. <br />
<br />
Now, let's re-plot the line with channel number as the x-axis in order to get the channel range for flagging. <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='2:1600~2300',xaxis='channel',yaxis='amp',<br />
field='0',avgtime='1e8',coloraxis='field')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Now lets look at Titan in more detail.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='channel',yaxis='amp',field='1',<br />
avgtime='1e8',coloraxis='field',iteraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Explicitly back up the flag tables so that flagged regions can be restored later.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
flagmanager(vis=asdm+'.ms',mode='save',versionname=asdm+'.before_calspectralflags')<br />
</source><br />
<br />
<figure id="Titan_spw2.png"><br />
[[Image:Titan_spw2.png|thumb|<caption>Spectral plot of Titan (magenta) for spw=2.</caption>]]<br />
</figure><br />
<br />
Flag absorption features for all sources.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
print "Flagging absorption features in all sources for "+asdm<br />
flagdata(vis=asdm+'.ms', mode='manual', spw='1:2000~3839, 2:1945~1960')<br />
</source><br />
<br />
<figure id="Titan_spw3.png"><br />
[[Image:Titan_spw3.png|thumb|<caption>Spectral plot of Titan (magenta) for spw=3.</caption>]]<br />
</figure><br />
<br />
Now we need to flag emission. The very broad CO(3-2) in spw=2 of Titan will prevent us from using it as a calibrator for this spectral window since there are no line-free channels (we will transfer, phase, amplitude, and absolute flux from another Titan spw below). We do want to flag the narrower Titan line in spw=3.<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
flagmanager(vis=asdm+'.ms',mode='save',versionname=asdm+'.before_emissionflags')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
print "Flagging emission for "+asdm<br />
flagdata(vis=asdm+'.ms', mode='manual', <br />
field='1',<br />
spw='3:1000~3000')<br />
</source><br />
<br />
If you like, check that the right things have been flagged.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='channel',yaxis='amp',field='0,1',<br />
avgtime='1e8',coloraxis='field',iteraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
==Set Up the Flux Calibrator Model==<br />
<br />
Fill the model data column for Titan with a model for the flux density as a function of baseline. The model is a uniformly illuminated disk with the size obtained from the JPL Horizons ephemeris.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
setjy(vis=asdm+'.ms',field='1',usescratch=F,<br />
standard='Butler-JPL-Horizons 2010',scalebychan=F)<br />
</source><br />
<br />
<figure id="Titan amp vs uvdist.png"><br />
[[Image:Titan amp vs uvdist.png|thumb|<caption>Plot of Titan model for each of the 4 spws. We used the Butler-JPL-Horizons 2010 standard to compute this model.</caption>]]<br />
</figure><br />
<br />
After running setjy, it is a good idea to plot the model in order to confirm that it makes sense. In this case, Titan is partially resolved, so we expect the flux density to drop with uv distance, but not so much as to pass through a null. We also expect it to be brighter at higher frequencies since it has a thermal blackbody spectrum.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',field='1',xaxis='uvdist',yaxis='amp',coloraxis='spw',<br />
ydatacolumn='model')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<figure id="twhydra_X3c1_wvrtsys_2012_titan_model.png">[[File:twhydra_X3c1_wvrtsys_2012_titan_model.png|thumb|right|<caption>Titan model produced by 'Butler-JPL-Horizons 2012'.</caption>]]</figure><br />
<br />
<br/><br />
<div class="noprint" style="float:none; border:0px solid blue;background-color:#F6CEF5;padding:2px;"><br />
The setjy invocation, above, uses the flux density standard '''standard='Butler-JPL-Horizons 2010' '''. A more updated standard is also available: '''standard='Butler-JPL-Horizons 2012' '''. <xr id="twhydra_X3c1_wvrtsys_2012_titan_model.png"/> shows the Titan model produced using the updated standard. The motivated reader may wish to rerun {{setjy}} using the updated model. We will highlight later in this tutorial, and in the imaging tutorial that follows, the effects of using the updated model.<br />
</div><br />
<br />
==Bandpass Calibration==<br />
<br />
First we need to check how the amplitude and phase of 3C279 behave as a function of time. In order to set<br />
a fixed scale on the y-axis, we first make a plot of all the data, excluding antenna DV04. (We must specify '''ydatacolumn='data' ''' explicitly here because the default value of '''ydatacolumn''' equals the value used in the previous execution of {{plotms}}. In the previous execution '''ydatacolumn''' was set to '''model'''. See the online help, <tt>help plotms</tt>, for details.)<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',xaxis='time',yaxis='amp',coloraxis='corr',<br />
field='0',avgchannel='3840',ydatacolumn='data')<br />
</source><br />
<br />
<figure id="ThreeScansAmp.png"><br />
[[Image:ThreeScansAmp.png|thumb|<caption>Amplitude variation for three 3C279 scans, spw 0 (for one representative baseline).</caption>]]<br />
</figure><br />
<br />
We see that the uncalibrated amplitudes range between 0.2-0.4, so let's set this as our<br />
scale and examine a representative baseline (DV06-DV07) to see how the amplitude changes with time. <br />
<br />
<source lang="python"><br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for spw in ['0','1','2','3']:<br />
for asdm in basename:<br />
print "Now showing spw %s from %s" % (spw, asdm+'.ms')<br />
plotms(vis=asdm+'.ms',spw=spw,xaxis='time',yaxis='amp',coloraxis='corr',iteraxis='spw',<br />
field='0',avgchannel='3840',antenna='DV06&DV07',plotrange=[0,0,0.2,0.4])<br />
user_check=raw_input('press enter to go to the next plot\n')<br />
</source><br />
<br />
<figure id="ThreeScansPhase.png"><br />
[[Image:ThreeScansPhase.png|thumb|<caption>Phase variation for three 3C279 scans, spw 0 (for one representative baseline).</caption>]]<br />
</figure><br />
<br />
Page through the measurement sets for each spw. This shows significant variations in the amplitude across the three measurement sets.<br />
Now do the same with phase.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for spw in ['0','1','2','3']:<br />
for asdm in basename:<br />
print "Now showing spw %s from %s" % (spw, asdm+'.ms')<br />
plotms(vis=asdm+'.ms',spw=spw,xaxis='time',yaxis='phase',coloraxis='corr',iteraxis='spw',<br />
field='0',avgchannel='3840',antenna='DV06&DV07',plotrange=[0,0,-180,180])<br />
user_check=raw_input('press enter to go to the next plot\n')<br />
</source><br />
<br />
This examination reveals two findings: (1) significant variation in the phase across the three scans, as well as (2) smaller but significant variations within a scan. The first finding suggests that we do not want to combine the scans for bandpass calibration, but instead derive an independent bandpass for each scan. Actually what is more important than a DC offset is if the '''shape''' of the amplitude or phase changes from scan to scan. There isn't enough S/N to tell for sure so we will keep them separate. This situation is often the case, which is why we did not concatenate the three datasets prior to calibration. The second finding suggests that we need to correct the phase vs. time behavior of the bandpass calibrator (3C279; field=0) within each scan, before doing the bandpass. We want to chose a relatively narrow range of channels near the center of the spws so that the bandpass phase slopes (to be corrected with the bandpass calibration itself) do not decorrelate the signal. You need to avoid spectral regions that were completely flagged above.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.bpphase.gcal')<br />
gaincal(vis=asdm+'.ms',caltable=asdm+'.bpphase.gcal',<br />
field='0',spw='0~3:900~1100',refant='DV06',<br />
calmode='p',solint='int',minsnr=2.0,minblperant=4)<br />
</source><br />
<br />
<figure id="X7ef_wvrtsys.bpphase.X.png"><br />
[[Image:X7ef_wvrtsys.bpphase.X.png|thumb|<caption>Phase only solutions for correlation X on the third scan of the bandpass calibrator 3C279.</caption>]]<br />
</figure><br />
<br />
Inspect the phase-only calibration solutions for the bandpass calibrator. Look for any noisy solutions. We do XX and YY separately to reduce confusion in the plot. It will help if you make your plotcal window wide.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.bpphase.gcal',xaxis='time',yaxis='phase',spw='',antenna='1~8', <br />
iteration='antenna',subplot=421,plotrange=[0,0,-180,180],<br />
figfile=asdm+'.bpphase.X.png',poln='X')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
In the plotcal gui you can use the magnifying glass symbol to zoom in on one of the scans to see the phase variations. The colors are the 4 different spws.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.bpphase.gcal',xaxis='time',yaxis='phase',spw='',antenna='1~8', <br />
iteration='antenna',subplot=421,plotrange=[0,0,-180,180],<br />
figfile=asdm+'.bpphase.Y.png',poln='Y')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Next we apply this phase-only correction on the fly while calculating the bandpass solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.bandpass.bcal')<br />
bandpass(vis=asdm+'.ms',caltable=asdm+'.bandpass.bcal',<br />
field='0',spw='',combine='',refant='DV06',<br />
solint='inf',solnorm=T,minblperant=4, bandtype='B', fillgaps=17,<br />
gaintable=asdm+'.bpphase.gcal')<br />
</source><br />
<br />
You will see some error messages in the terminal, these are just related to the flagged channels. We set fillgaps=17 to interpolate across the smaller regions of flagged channels (mesospheric features and birdies).<br />
<br />
<figure id="Bandpass.ampspw0.png"><br />
[[Image:Bandpass.ampspw0.png|thumb|<caption>Bandpass amplitude solution plots.</caption>]]<br />
</figure><br />
<figure id="Bandpass.phasespw0.png"><br />
[[Image:Bandpass.phasespw0.png|thumb|<caption>Bandpass phase solution plots.</caption>]]<br />
</figure><br />
<br />
'''A few words about solint and combine:'''<br />
<br />
In {{bandpass}}, the use of '''solint='inf'''' (as in "infinite") will derive a bandpass<br />
solution for each 3C279 scan, '''unless''' '''combine='scan'''' (which is the default). Here we set combine=' ' explicitly so that it does not combine the scans into one bandpass. Likewise, field boundaries are only crossed if combine='field', and spw boundaries are only crossed if combine='spw'. In some cases it can be helpful to combine fields if you suffer from lack of S/N, but it is never a good idea to combine spws. <br />
<br />
Now inspect the phase and amplitude solutions. You are looking for excursions from smooth fits, or particularly noisy solutions compared to the others. <br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
for spw in [0,1,2,3]:<br />
plotbandpass(asdm+'.bandpass.bcal',xaxis='freq',yaxis='amp', spw=spw,<br />
antenna='1~8', subplot=42, figfile=asdm+'.bandpass.amp', showatm=T,<br />
interactive=True)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
for spw in [0,1,2,3]:<br />
plotbandpass(asdm+'.bandpass.bcal',xaxis='freq',yaxis='phase',spw=spw,<br />
antenna='1~8',subplot=42,figfile=asdm+'.bandpass.phs', showatm=T,<br />
interactive=True)<br />
</source><br />
<br />
The values of phase on DV06 are very close to zero because it was used as the reference antenna.<br />
<br />
==Gain Calibration==<br />
<br />
Now that we have a bandpass solution to apply we can solve for the antenna-based phase and amplitude gain calibration. Since the phase changes on a much shorter timescale than the amplitude, we will solve for them separately. In particular, if the phase changes significantly over a scan time, the amplitude would be decorrelated, if the un-corrected phase were averaged over this timescale. Note that we re-solve for the gain solutions of the bandpass calibrator, so we can derive new solutions that are corrected for the bandpass shape. Since the bandpass calibrator will not be used again, this is not strictly necessary, but is useful to check its calibrated flux density for example. <br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.intphase.gcal')<br />
gaincal(vis=asdm+'.ms',caltable=asdm+'.intphase.gcal',<br />
field='0,1,3,4',spw='0~3:40~3800',refant='DV06',<br />
calmode='p',solint='int',minsnr=2.0,minblperant=4,<br />
gaintable=[asdm+'.bandpass.bcal'])<br />
</source><br />
<br />
Here '''solint='int' ''' coupled with '''calmode='p' ''' will derive a single phase solution for each 10 second integration. Note that the bandpass table is applied on-the-fly before solving for the phase solutions, however the bandpass is NOT applied to the data permanently until applycal is run later on. <br />
<br />
Although '''solint='int' ''' (i.e. the integration time of 10 seconds) is the best choice to apply before solving for the amplitude solutions, it is not a good idea to use this to apply to the target. This is because the phase-scatter within a scan can dominate the interpolation between calibrator scans. Instead, we also solve for the phase on the scan time, '''solint='inf' ''' (but '''combine=' ' ''', since we want one solution per scan) for application to the target later on. Unlike the bandpass task, for {{gaincal}}, the default of the combine parameter is '''combine=' ' '''. <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.scanphase.gcal')<br />
gaincal(vis=asdm+'.ms',caltable=asdm+'.scanphase.gcal',<br />
field='0,1,3,4',spw='0~3:40~3800',refant='DV06',<br />
calmode='p',solint='inf',minsnr=2.0,minblperant=4,<br />
gaintable=[asdm+'.bandpass.bcal'])<br />
</source><br />
<br />
Alternatively, instead of making a separate phase solution for application to the target, one can also run {{smoothcal}} to smooth the solutions derived on the integration time. <br />
<br />
Next we apply the bandpass and '''solint='int' ''' phase-only calibration solutions on-the-fly to derive amplitude solutions. Here the use of '''solint='inf' ''', but '''combine=' ' ''' will result in one solution per scan interval. <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.amp.gcal')<br />
gaincal(vis=asdm+'.ms',caltable=asdm+'.amp.gcal',<br />
field='0,1,3,4',spw='0~3:40~3800',refant='DV06',<br />
calmode='ap',solint='inf',minsnr=2.0,minblperant=4,<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal'])<br />
</source><br />
<br />
Now carefully inspect all these solutions looking for discrepant solutions. If you see any, you will need to flag them and rerun the calibration tasks above. <br />
<br />
We make plots in X and Y separately for clarity. The colors are showing the spectral windows.<br />
<figure id="X3c1_wvrtsys.intphase_X.png"><br />
[[Image:X3c1_wvrtsys.intphase_X.png|thumb|<caption>Phase solutions for the X polarization for every integration time of the first dataset.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.intphase.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',iteration='antenna',subplot=421,<br />
plotrange=[0,0,-180,180],poln='X',figfile=asdm+'.intphase_X.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.intphase.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',iteration='antenna',subplot=421,<br />
plotrange=[0,0,-180,180],poln='Y',figfile=asdm+'.intphase_Y.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<figure id="X3c1_wvrtsys.scanphase_X.png"><br />
[[Image:X3c1_wvrtsys.scanphase_X.png|thumb|<caption>Phase solutions for the X polarization for each scan of the first dataset.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.scanphase.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',iteration='antenna',subplot=421,<br />
plotrange=[0,0,-180,180],poln='X',figfile=asdm+'.scanphase_X.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.scanphase.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',iteration='antenna',subplot=421,<br />
plotrange=[0,0,-180,180],poln='Y',figfile=asdm+'.scanphase_Y.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Since we have taken out the phase as best we can by applying the '''solint='int' ''' phase-only solution, this plot will give a good idea of the residual phase error. If you see scatter of more than a few degrees here, you should consider going back and looking for more data to flag, particularly bad timeranges etc. <br />
<br />
<figure id="X3c1_wvrtsys.amp_phase.png"><br />
[[Image:X3c1_wvrtsys.amp_phase.png|thumb|<caption>Residual phase after applying intphase.gcal for both correlations in the first dataset.</caption>]]<br />
</figure><br />
<figure id="X3c1_wvrtsys.amp_X.png"><br />
[[Image:X3c1_wvrtsys.amp_X.png|thumb|<caption>Amplitude solutions on a scan interval for correlation X in the first dataset.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.amp.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',plotrange=[0,0,-1,1],<br />
iteration='antenna',subplot=421,figfile=asdm+'.amp_phase.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
These are very small, as they should be. Now look at the amplitude solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.amp.gcal',xaxis='time',yaxis='amp',antenna='1~8', <br />
iteration='antenna',subplot=421,spw='',poln='X',<br />
plotrange=[0,0,0.0,0.3],figfile=asdm+'.amp_X.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.amp.gcal',xaxis='time',yaxis='amp',antenna='1~8', <br />
iteration='antenna',subplot=421,spw='',poln='Y',<br />
plotrange=[0,0,0.0,0.3],figfile=asdm+'.amp_Y.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
==Flux Calibration==<br />
<br />
Next we use the flux calibrator (whose flux density was set in {{setjy}} above) to derive the flux density of the other calibrators. Note that the flux table REPLACES the amp.gcal in terms of future application of the calibration to the data, i.e. the flux table contains both the amp.gcal and flux scaling. Unlike the gain calibration steps, this is not an incremental table.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.flux.cal')<br />
fluxscale(vis=asdm+'.ms',caltable=asdm+'.amp.gcal',<br />
fluxtable=asdm+'.flux.cal',reference='1',refspwmap=[0,1,3,3],<br />
listfile=asdm+'.fluxscale.txt')<br />
</source><br />
<br />
Its a good idea to record the derived fluxscale values using the listfile option. The values can also be viewed in the Log Messages window.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Found reference field(s): Titan<br />
Found transfer field(s): 3c279 J1147-382=QSO J1037-295=QSO<br />
Spw=2 will be referenced to spw=3<br />
Flux density for 3c279 in SpW=0 (freq=3.56498e+11 Hz) is: 10.537 +/- 0.0183518 (SNR = 574.169, N = 16)<br />
Flux density for 3c279 in SpW=1 (freq=3.57734e+11 Hz) is: 10.6933 +/- 0.0264134 (SNR = 404.842, N = 16)<br />
Flux density for 3c279 in SpW=2 (freq=3.46034e+11 Hz) (ref SpW=3) is: 10.251 +/- 0.0477949 (SNR = 214.479, N = 14)<br />
Flux density for 3c279 in SpW=3 (freq=3.43956e+11 Hz) is: 9.91798 +/- 0.020167 (SNR = 491.791, N = 16)<br />
Flux density for J1147-382=QSO in SpW=0 (freq=3.56498e+11 Hz) is: 1.03399 +/- 0.0167344 (SNR = 61.7887, N = 16)<br />
Flux density for J1147-382=QSO in SpW=1 (freq=3.57734e+11 Hz) is: 0.844817 +/- 0.0191013 (SNR = 44.2283, N = 16)<br />
Flux density for J1147-382=QSO in SpW=2 (freq=3.46034e+11 Hz) (ref SpW=3) is: 0.987193 +/- 0.024391 (SNR = 40.4737, N = 14)<br />
Flux density for J1147-382=QSO in SpW=3 (freq=3.43956e+11 Hz) is: 1.28859 +/- 0.0194364 (SNR = 66.298, N = 16)<br />
Flux density for J1037-295=QSO in SpW=0 (freq=3.56498e+11 Hz) is: 0.968281 +/- 0.00895224 (SNR = 108.161, N = 16)<br />
Flux density for J1037-295=QSO in SpW=1 (freq=3.57734e+11 Hz) is: 0.75916 +/- 0.015366 (SNR = 49.4053, N = 16)<br />
Flux density for J1037-295=QSO in SpW=2 (freq=3.46034e+11 Hz) (ref SpW=3) is: 0.948551 +/- 0.0165421 (SNR = 57.3416, N = 14)<br />
Flux density for J1037-295=QSO in SpW=3 (freq=3.43956e+11 Hz) is: 1.21905 +/- 0.0139967 (SNR = 87.0956, N = 16)<br />
Fitted spectrum for 3c279 with fitorder=1: Flux density = 10.2962 +/- 0.0450319 (freq=351.002 GHz) spidx=1.70757 +/- 0.245737<br />
Fitted spectrum for J1147-382=QSO with fitorder=1: Flux density = 1.06853 +/- 0.0709817 (freq=351.002 GHz) spidx=-6.77353 +/- 3.71867<br />
Fitted spectrum for J1037-295=QSO with fitorder=1: Flux density = 1.01822 +/- 0.0654586 (freq=351.002 GHz) spidx=-6.28977 +/- 3.71453<br />
Storing result in X7ef_wvrtsys.flux.cal<br />
Writing solutions to table: X7ef_wvrtsys.flux.cal<br />
</pre><br />
<br />
<figure id="x3c1_wvrtsys.flux_X.png"><br />
[[Image:x3c1_wvrtsys.flux_X.png|thumb|<caption>Absolute flux calibration solutions for correlation X for the first dataset.</caption>]]<br />
</figure><br />
<br />
<div class="noprint" style="float:none; border:0px solid blue;background-color:#F6CEF5;padding:2px;"><br />
If you used the updated (Butler-JPL-Horizons 2012) flux density standard when you ran {{setjy}} earlier in this tutorial, the derived flux values for the calibrators will be slightly different. For example, when averaged over the 3 measurement sets, 3c279 in spectral window 0 has a flux of 10.77 Jy using the 2010 standard and 10.63 Jy using the 2012 standard; as a second example, J1147-382 in SPW 3 has an average flux of 1.13 Jy (2010 standard) and 1.15 Jy (2012 standard). <br />
</div><br />
<br />
Now look at the flux solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.flux.cal',xaxis='time',yaxis='amp',antenna='1~8', <br />
iteration='antenna',subplot=421,spw='',poln='X',<br />
plotrange=[0,0,0.0,0.3],figfile=asdm+'.flux_X.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.flux.cal',xaxis='time',yaxis='amp',antenna='1~8', <br />
iteration='antenna',subplot=421,spw='',poln='Y',<br />
plotrange=[0,0,0.0,0.3],figfile=asdm+'.flux_Y.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
==Apply Calibration and Inspect==<br />
<br />
Now we can use the {{flagmanager}} if we want to restore any of the spectral flagging we did prior to bandpass calibration. <br />
In this case, we choose to restore the flags of the emission lines on Titan, because we are interested in seeing how<br />
strong they are compared to the continuum. However, we leave the strong ozone line and mesospheric CO line flagged on all <br />
sources, because we want to get the most accurate continuum flux density for the science target. <br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
flagmanager(vis=asdm+'.ms',mode='restore',versionname=asdm+'.before_emissionflags')<br />
</source><br />
<br />
Next we apply the calibration solutions to each source individually, using the '''gainfield''' parameter to specify which calibrator's solutions should be applied from each of the '''gaintable''' calibration tables. <br />
<br />
First, we do 3C279 (the bandpass calibrator), applying all 3 of its solutions to itself (that's why gainfield contains three zeros):<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='0',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['0','0','0'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
Next, we do Titan (the absolute flux calibrator) using the bandpass solution from 3C279:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='1',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['0','1','1'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
For the secondary phase calibrator, we apply the phase and flux solutions from the primary phase calibrator. This will allow us to check how well the phase transfer to the science target (TW Hya) has worked:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='3',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.scanphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','linear','linear'],<br />
gainfield=['0','4','4'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
Next is the Primary phase calibrator:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='4',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['0','4','4'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
Finally, for the Science Target TW Hya, we apply the phase solutions from both the primary and secondary phase calibrators:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='2',<br />
interp=['nearest','linear','linear'],<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.scanphase.gcal',asdm+'.flux.cal'],<br />
gainfield=['0','3,4','3,4'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
Now we can check the results of applying the calibration solutions.<br />
<br />
<figure id="Corrected_vs_time_1.png"><br />
[[Image:Corrected_vs_time_1.png|thumb|<caption>The calibrated data for the first dataset (amplitude vs. time).</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw',ydatacolumn='corrected')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
In amplitude, it looks good but there are some noisy points toward the end of the first scheduling block, but it mostly only affects the secondary phase calibrator (green). In phase, we expect all the points to cluster about zero. The large scatter in phase on the secondary phase calibrator is readily apparent: <br />
<br />
<figure id="Corrected_phase_vs_time_1.png"><br />
[[Image:Corrected_phase_vs_time_1.png|thumb|<caption>The calibrated data on the calibrators for the first dataset (phase vs. time).</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='time',yaxis='phase',field='0,1,3,4',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw',ydatacolumn='corrected')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Let's check whether the situation improves when we apply this calibrator's solutions to itself rather than transferring the solutions from the primary phase calibrator (which is 17 degrees away, and observed at a different time). <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='3',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['0','3','3'],flagbackup=T, calwt=T)<br />
</source><br />
<br />
<figure id="Corrected_vs_time_1_field3.png"><br />
[[Image:Corrected_vs_time_1_field3.png|thumb|<caption>The calibrated data for the first dataset (amplitude vs. time), but now with field 3, the secondary phase calibrator, calibrated with itself.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw',ydatacolumn='corrected')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<figure id="Corrected_phase_vs_time_1_field3.png"><br />
[[Image:Corrected_phase_vs_time_1_field3.png|thumb|<caption>The calibrated data from the first dataset (phase vs. time), but now with field 3, the secondary phase calibrator, calibrated with itself.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='time',yaxis='phase',field='0,1,3,4',<br />
avgchannel='3840', coloraxis='field',iteraxis='spw',<br />
ydatacolumn='corrected')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Indeed, the secondary calibrator looks better now in amplitude and phase. This is an indication that the calibration transfer is not working well in this timerange. Because the effect is not catastrophic and we know we can self-calibrate on TW Hya later, we will let this go for now. Or, if you want you can delve deeper into the data and try to solve the mystery... <br />
<br />
In any case, we will re-issue the original {{applycal}} so that it is this calibration that our subsequent {{split}} will use. This will allow us to check the effect of correcting the secondary phase calibrator with the primary phase calibrator later. <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='3',<br />
gaintable=[asdm+'.bandpass.bcal', asdm+'.scanphase.gcal', asdm+'.flux.cal'],<br />
interp=['nearest','linear','linear'],<br />
gainfield=['0','4','4'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
<br />
Let's check the spectral calibration now. First 3C279 and Titan:<br />
<br />
<figure id="X3c1_spw2_corrected_3.4.png"><br />
[[Image:X3c1_spw2_corrected_3.4.png|thumb|<caption>Spectral UV-plots of 3C279 and Titan of spw=2 for the first dataset.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='frequency',yaxis='amp',field='0,1',<br />
avgtime='1e8',avgscan=T,coloraxis='field',ydatacolumn='corrected',<br />
iteraxis='spw',xselfscale=T)<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Flip through the spws. These look good. Next the two phase calibrators:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='frequency',yaxis='amp',field='3,4',<br />
avgtime='1e8',avgscan=T,coloraxis='field',ydatacolumn='corrected',<br />
iteraxis='spw',xselfscale=T)<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Flip through the spws. This also looks good, the secondary phase calibrator is a bit noisier but this is normal. The upswing at the lower frequency end of spw=3 will probably need to be flagged on the science target as well. It corresponds to the edge of an atmospheric feature.<br />
<br />
Now for the exciting part, what does the science target look like...<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='frequency',yaxis='amp',field='2',<br />
avgtime='1e8',avgscan=T,coloraxis='field',ydatacolumn='corrected',<br />
iteraxis='spw',xselfscale=T)<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
We see HCO+(4-3) in spw=0 and CO(3-2) in spw=2 as expected. Because the shape of the <br />
line profiles varies with baseline, you can already tell that the line emission is resolved.<br />
<br />
<figure id="X3c1_CO3_2_uvplot_3.4.png"><br />
[[Image:X3c1_CO3_2_uvplot_3.4.png|thumb|<caption>UV-Plot of the TW Hya CO(3-2) emission from the first dataset.</caption>]]<br />
</figure><br />
<figure id="X3c1_HCOp4_3_uvplot_3.4.png"><br />
[[Image:X3c1_HCOp4_3_uvplot_3.4.png|thumb|<caption>UV-Plot of the TW Hya HCO+(4-3) emission from the first dataset.</caption>]]<br />
</figure><br />
<br />
Now check that the velocity of TWHydra is correct in the LSRK frame, it should be around 2.88 km/s.<br />
* CO 3-2 rest freq 345.79599 GHz<br />
* HCO+ 4-3 rest freq 356.7342 GHz<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='2',xaxis='velocity',yaxis='amp',field='2',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',<br />
restfreq='345.79599GHz', plotrange=[-10,15,0,0],coloraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='0',xaxis='velocity',yaxis='amp',field='2',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',<br />
restfreq='356.7342GHz',plotrange=[-10,15,0,0],coloraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Both lines show up at the expected velocity.<br />
<br />
<br />
==Concatenate the Data==<br />
<br />
Here we will concatenate the three datasets prior to imaging.<br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
os.system('rm -rf Band7multi_april22.ms')<br />
concat(vis=splitdata,concatvis='Band7multi_april22.ms')<br />
</source><br />
<br />
If you like you can run listobs on new combined dataset<br />
<br />
<source lang="python"><br />
# In CASA<br />
listfile = 'Band7multi_april22.listobs.txt'<br />
os.system('rm ' + listfile)<br />
listobs(vis='Band7multi_april22.ms',verbose=F, listfile=listfile)<br />
</source><br />
<br />
<figure id="All_spw2_corrected_3.4.png"><br />
[[Image:All_spw2_corrected_3.4.png|thumb|<caption>Spectral UV-plots of 3C279 and Titan of spw=2 for the combined datasets.</caption>]]<br />
</figure><br />
<br />
You can also examine the spectral uv plots for the combined dataset to see the improvement in S/N: <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='Band7multi_april22.ms',spw='',xaxis='frequency',yaxis='amp',field='0,1',<br />
avgtime='1e8',avgscan=T,coloraxis='field',ydatacolumn='corrected',<br />
iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
<figure id="All_CO3_2_uvplot_3.4.png"><br />
[[Image:All_CO3_2_uvplot_3.4.png|thumb|<caption>UV-Plot of the TW Hya CO(3-2) emission from the combined datasets.</caption>]]<br />
</figure><br />
<br />
...and the CO line profile for the combined dataset: <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='Band7multi_april22.ms',spw='2',xaxis='velocity',yaxis='amp',field='2',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',restfreq='345.79599GHz',<br />
plotrange=[-10,15,0,0],coloraxis='spw')<br />
</source><br />
<br />
==Split Calibrated Data==<br />
<br />
Now we split off the calibrated data for the Science Target as well as the interesting parts of the calibrators for imaging.<br />
<br />
When we {{split}} off the Titan data, a few dozen warnings like the following are written to the log:<br />
<pre><br />
2012-05-15 22:00:35 WARN split::SubMS::copySource() Invalid SOURCE ID in SOURCE table row 20 <br />
</pre><br />
These can be ignored, because they do not indicate any problem that will prevent you from imaging Titan correctly at a single position using all the data in the output ms.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_corrected.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='TWHydra_corrected.ms',<br />
datacolumn='corrected',spw='',field='2')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf J1037_corrected.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='J1037_corrected.ms',<br />
datacolumn='corrected',spw='',field='4')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf J1147_corrected.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='J1147_corrected.ms',<br />
datacolumn='corrected',spw='',field='3')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3C279_CO3_2.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='3C279_CO3_2.ms',<br />
datacolumn='corrected',spw='2:1900~2000',field='0')<br />
</source><br />
<br />
==Optional: Reconcile Titan's Coordinates==<br />
<br />
If you do not care to image Titan, then you can skip this step and simply continue on to the [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_4.5 imaging guide].<br />
<br />
Our earlier treatment of Titan's coordinates using [http://casa.nrao.edu/stable/docs/TaskRef/fixplanets-task.html fixplanets] replaced the zeros written by the ALMA control system with the correct position of the body at the instant of the first observation of that SB. As a result, it has slightly different positions in all three datasets, as seen by listobs:<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='Band7multi_april22.ms',verbose=F)<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
ID Code Name RA Decl Epoch SrcId nRows <br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 70866 <br />
1 none Titan 12:49:25.97588 -02.22.41.3024 J2000 1 4842 <br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 515151 <br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 40797 <br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 171153 <br />
5 none Titan 12:49:26.53729 -02.22.27.1521 J2000 0 4833 <br />
6 none Titan 12:49:26.53059 -02.22.18.7878 J2000 0 4833 <br />
</pre><br />
<br />
If we want to image such moving objects observed across multiple SBs, we need to bring the positions into agreement, otherwise {{clean}} will try to make a mosaic. Task [http://casa.nrao.edu/stable/docs/TaskRef/fixplanets-task.html fixplanets] can be used to do this. Here, we set the direction to the direction of the first dataset as reported by listobs. Note that the RA/Dec format is slightly different from the {{listobs}} output format. Also, we do not<br />
fix the uvw coordinates because they are already more correct now than they would be if we "fixed" them.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fixplanets(vis='Band7multi_april22.ms', field='Titan', direction='J2000 12h49m25.97588 -02d22m41.3024', fixuvw=False)<br />
</source><br />
<br />
Check the header information again to see that the information for Titan has changed for the second<br />
and third datasets. They will appear as fields 5 and 6.<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='Band7multi_april22.ms',verbose=F)<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
ID Code Name RA Decl Epoch SrcId <br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 70866 <br />
1 none Titan 12:49:25.97588 -02.22.41.3024 J2000 1 4842 <br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 515151 <br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 40797 <br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 171153 <br />
5 none Titan 12:49:25.97588 -02.22.41.3024 J2000 0 4833 <br />
6 none Titan 12:49:25.97588 -02.22.41.3024 J2000 0 4833 <br />
</pre><br />
<br />
==Optional: Split Calibrated Titan Data==<br />
<br />
When we {{split}} off the Titan data, a few dozen warnings like the following are written to the log:<br />
<pre><br />
2012-05-15 22:00:35 WARN split::SubMS::copySource() Invalid SOURCE ID in SOURCE table row 20 <br />
</pre><br />
These can be ignored, because they do not indicate any problem that will prevent you from imaging Titan correctly at a single position using all the data in the output ms.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Titan_cont.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='Titan_cont.ms',<br />
datacolumn='corrected',spw='0',field='1')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Titan_CO3_2.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='Titan_CO3_2.ms',<br />
datacolumn='corrected',spw='2',field='1')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Titan_unknown.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='Titan_unknown.ms',<br />
datacolumn='corrected',spw='3',field='1')<br />
</source><br />
<br />
==Continue on to Imaging of the Science Target==<br />
<br />
Now you can continue on to the [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_4.5 imaging guide].<br />
<br />
{{Checked 4.5.2}}</div>Sstierwahttps://casaguides.nrao.edu/index.php?title=TWHydraBand7_Calibration_4.5&diff=19474TWHydraBand7 Calibration 4.52016-05-18T04:17:15Z<p>Sstierwa: /* Initial Inspection and Flagging */</p>
<hr />
<div>[[Category:ALMA]][[Category:Calibration]][[Category:Spectral Line]]<br />
*'''This script assumes that you have downloaded TWHYA_BAND7_UnCalibratedMSAndTablesForReduction.tgz from [[TWHydraBand7#Getting_the_Data]]'''<br />
<br />
*'''An introduction to this data set is available at [[TWHydraBand7]].<br />
<br />
*'''This guide is designed for CASA 4.5.2 If you are using an older version of CASA please see [[TWHydraBand7_Calibration_4.3]].<br />
<br />
==Preparation==<br />
<br />
Once you have downloaded TWHYA_BAND7_UnCalibratedMSAndTablesForReduction.tgz, in a terminal unpack it with<br />
<br />
<source lang="bash"><br />
tar -zxvf TWHYA_BAND7_UnCalibratedMSAndTablesForReduction.tgz<br />
</source><br />
<br />
Please be aware that you will need about 100 GB of free space to do the data reduction. It is a good idea to check that now before you begin. Some of the plots described here require 9 GB of RAM; as little as 4 GB may be sufficient if additional data averaging is used when the plots are generated. When you are satisfied with the available drive space and memory on your machine:<br />
<br />
<source lang="bash"><br />
cd TWHYA_BAND7_UnCalibratedMSAndTablesForReduction<br />
</source><br />
<br />
'''NOTE: the calibration tables included in TWHYA_BAND7_UnCalibratedMSAndTablesForReduction CANNOT be used with CASA 4.5, they should be discarded, or moved out of the working directory.'''<br />
<br />
Then start CASA by typing 'casa' at a shell prompt. <br />
<br />
<source lang="bash"><br />
casa<br />
</source><br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.5.2. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.5.2'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
==Install Analysis Utilities==<br />
<br />
Analysis Utilities (or analysisUtils for short) is a small set of Python scripts that provide a number of analysis and plotting utilities for ALMA data reduction. This guide uses a few of these utilities. They are very easy to install (just download and untar). See <br />
<br />
http://casaguides.nrao.edu/index.php?title=Analysis_Utilities<br />
<br />
for a full description and download instructions. If you do not wish to do this, see the [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Calibration_for_CASA_3.3 CASA 3.3 version of the guide] for alternative (but slow) plotting options. Analysis Utilities are updated frequently so if its been a while since you installed it, its probably worth doing it again. If you are at an ALMA site or ARC, the analysis utilities are probably already installed and up to date.<br />
<br />
==Fix Titan's coordinates==<br />
<br />
'''Note that in the near future this step will be unnecessary.''' <br />
<br />
It is temporarily necessary to correct the positions of ephemeris objects observed during ALMA Cycle 0, because the control software revisions earlier than 9.0 erroneously write the data with coordinates of 00:00:00.0000 +00.00.00.0000 (J2000). For this dataset, we need to correct the position of the absolute flux calibrator Titan, as we can<br />
see from the first {{listobs}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -f X3c1.ms.listobs')<br />
listobs('X3c1.ms', verbose=T, listfile='X3c1.ms.listobs') <br />
</source><br />
<br />
You can view the listobs output files using command "less" from the CASA prompt.<br />
<br />
<pre style="background-color: #fffacd;"><br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 23625<br />
1 none Titan 00:00:00.00000 +00.00.00.0000 J2000 1 4842<br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 175176<br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 14832<br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 59877<br />
</pre><br />
<br />
To correct Titan's position, we will use the task [http://casa.nrao.edu/stable/docs/TaskRef/fixplanets-task.html fixplanets], which writes the actual coordinates at the instant of the first observation. This step takes a while because we are recalculating the uvw's accordingly.<br />
<source lang="python"><br />
# In CASA<br />
fixplanets(vis='X3c1.ms', field='Titan', fixuvw=True)<br />
</source><br />
<br />
Check the header information again with {{listobs}} to confirm that the information for Titan has changed:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -f X3c1.ms.listobs')<br />
listobs('X3c1.ms', verbose=T, listfile='X3c1.ms.listobs') <br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 23625<br />
1 none Titan 12:49:25.93349 -02.22.41.5638 J2000 1 4842<br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 175176<br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 14832<br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 59877<br />
</pre><br />
<br />
Now fix the other two measurement sets similarly:<br />
<source lang="python"><br />
# In CASA<br />
fixplanets(vis='X5d8.ms', field='Titan', fixuvw=True)<br />
fixplanets(vis='X7ef.ms', field='Titan', fixuvw=True)<br />
</source><br />
<br />
==Observing Log and Priors==<br />
<br />
Below is some information that may not be obvious from the data<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Like at most telescopes, the ALMA operators and astronomers at the site log any significant issues <br />
that were noticed from the online system during the observation. For these Band 7 observations of <br />
TW Hya on April 22, 2011, the only issue of note was that antenna DV04 could not observe at Band 7 <br />
and will need to be flagged. <br />
</pre><br />
<br />
First let's examine the basic properties of the data using {{listobs}}. Among other information we <br />
will be able to deduce what the source ids are and what each source was used for:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
3c279 is the bandpass calibrator (field id=0)<br />
Titan is the absolute flux calibrator (field id=1)<br />
J1147-382 is the secondary phase calibrator (field id=3)<br />
J1037-295 is the primary phase calibrator (field id=4)<br />
</pre><br />
<br />
<source lang="python"><br />
# In CASA<br />
data=['X3c1.ms','X5d8.ms','X7ef.ms']<br />
for vis in data:<br />
os.system('rm '+vis+'.listobs')<br />
listobs(vis, verbose=T, listfile=vis+'.listobs') <br />
</source><br />
<br />
You can view the {{listobs}} output files using command '''less''' from the CASA prompt. <br />
Below we copy select parts of the {{listobs}} output files for reference. <br />
<br />
<pre style="background-color: #fffacd;"><br />
X3c1.ms:<br />
Data records: 278352 Total integration time = 6109.06 seconds<br />
Observed from 22-Apr-2011/00:01:52.9 to 22-Apr-2011/01:43:42.0 (UTC)<br />
<br />
X5d8.ms:<br />
Data records: 278406 Total integration time = 5995.01 seconds<br />
Observed from 22-Apr-2011/01:48:05.8 to 22-Apr-2011/03:28:00.8 (UTC)<br />
<br />
X7ef.ms:<br />
Data records: 255717 Total integration time = 5407.49 seconds<br />
Observed from 22-Apr-2011/03:30:39.7 to 22-Apr-2011/05:00:47.2 (UTC)<br />
<br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 23625<br />
1 none Titan 12:49:25.97588 -02.22.41.3024 J2000 1 4842<br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 175176<br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 14832<br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 59877 <br />
<br />
SpwID #Chans Frame Ch1(MHz) ChanWid(kHz) TotBW(kHz) Corrs<br />
0 4 TOPO 184550 1500000 7500000 I<br />
1 128 TOPO 355740.062 15625 2000000 XX YY<br />
2 1 TOPO 356716.625 1796875 1796875 XX YY<br />
3 128 TOPO 356507.813 15625 2000000 XX YY<br />
4 1 TOPO 357484.375 1796875 1796875 XX YY<br />
5 128 TOPO 346792.187 15625 2000000 XX YY<br />
6 1 TOPO 345784.375 1796875 1796875 XX YY<br />
7 128 TOPO 345182.438 15625 2000000 XX YY<br />
8 1 TOPO 344174.625 1796875 1796875 XX YY<br />
9 128 TOPO 344386.763 15625 2000000 XX YY<br />
10 1 TOPO 343378.95 1796875 1796875 XX YY<br />
11 128 TOPO 346324.263 15625 2000000 XX YY<br />
12 1 TOPO 345316.45 1796875 1796875 XX YY<br />
13 128 TOPO 354402.388 15625 2000000 XX YY<br />
14 1 TOPO 355378.95 1796875 1796875 XX YY<br />
15 128 TOPO 356402.388 15625 2000000 XX YY<br />
16 1 TOPO 357378.95 1796875 1796875 XX YY<br />
17 3840 TOPO 356497.936 122.070312 468750 XX YY<br />
18 1 TOPO 356732.189 468750 468750 XX YY<br />
19 3840 TOPO 357734.314 122.070312 468750 XX YY<br />
20 1 TOPO 357499.939 468750 468750 XX YY<br />
21 3840 TOPO 346034.314 122.070312 468750 XX YY<br />
22 1 TOPO 345799.939 468750 468750 XX YY<br />
23 3840 TOPO 343955.936 122.070312 468750 XX YY<br />
24 1 TOPO 344190.189 468750 468750 XX YY<br />
<br />
Antennas: 9:<br />
Name Station Diam. Long. Lat.<br />
0 DV04 J505 12.0 m -067.45.18.0 -22.53.22.8<br />
1 DV06 T704 12.0 m -067.45.16.2 -22.53.22.1<br />
2 DV07 J510 12.0 m -067.45.17.8 -22.53.23.5<br />
3 DV08 T703 12.0 m -067.45.16.2 -22.53.23.9<br />
4 DV09 N602 12.0 m -067.45.17.4 -22.53.22.3<br />
5 DV10 N606 12.0 m -067.45.17.1 -22.53.23.6<br />
6 PM01 T702 12.0 m -067.45.18.6 -22.53.24.1<br />
7 PM02 T701 12.0 m -067.45.18.8 -22.53.22.2<br />
8 PM03 J504 12.0 m -067.45.17.0 -22.53.23.0<br />
</pre><br />
<br />
Things to Notice from above: <br />
*There are three different data sets acquired close together in time. We will calibrate each dataset independently and then combine the calibrated data prior to imaging. <br />
*Titan appears to have slightly different positions in each dataset because it is a moving body. In fact, at the time of observation, due to temporary data capture issue in the ALMA system, the position was written has (0,0). We have pre-corrected this error using fixplanets. Later in the tutorial, we will run fixplanets again to force all three datasets to have the same fixed position for Titan.<br />
*There are a lot of spectral windows! Don't be alarmed. In ALMA data, <br />
**spw=0 is always reserved for the water vapor radiometry data.<br />
**spw=9, 11, 13, 15 are the wideband (TDM) correlator mode with 128 channels per spw default settings for doing pointing and this is all they are used for in these data.<br />
**Currently Tsys data can only be taken in the wide (TDM) correlator mode with 128 channels per spw, these correspond to spws=1, 3, 5, 7 above. The frequencies of these TDM spws were carefully chosen so the the narrowband FDM spws fall within them.<br />
** The 0.5 GHz, high spectral resolution spws that contain all the real source data (science target and calibrators) are 17, 19, 21, and 23<br />
**For quicklook purposes, the ALMA online system produces a channel averaged spw for each channelized spw, these correspond to spw=2,4,6,8,10,12,14,16,18,20,22,24 and shouldn't be used for anything in post-processing as bandpass calibration etc has not been applied.<br />
<br />
In the portion of the {{listobs}} output that shows the timerange, the final column gives the scan intent. It is important to have a look at this because you can flag and do other operations in CASA using the scan intent as a selection option. Also, these intents will be used in the future for pipeline processing. You will usually want to use them to flag the CALIBRATE_POINTING* and CALIBRATE_ATMOS* (the latter correspond to the hot and cold load measurements used to calculate Tsys) data. This is essential for science or calibration data taken only in TDM (wide bandwidth) mode, i.e. the same mode that the pointing and Tsys data are taken in. For the current data however, that calibration data is recorded in different spws from the useful FDM (narrow bandwidth) data, so we'll be able to separate them by splitting them off at the final step prior to imaging.<br />
<br />
<figure id="Ant_pos.png"><br />
[[Image:Ant_pos.png|thumb|<caption>Antenna locations for the first dataset.</caption>]]<br />
</figure><br />
<br />
Before we move on, its also nice to get an idea where the antennas are with respect to each other. We can use {{plotants}} to plot their positions. It is a good idea to check each file since an antenna may have entered or exited the array between observations.<br />
<source lang="python"><br />
# In CASA<br />
for vis in data:<br />
plotants(vis=vis,figfile=vis+'.plotants.png')<br />
</source><br />
<br />
You can view the output images using any standard image viewer.<br />
<br />
==Create the Tsys and WVR Tables, and Examine ==<br />
<br />
Each ms include tables that contain the Tsys and WVR measurements associated with the visibility data.<br />
We must create calibration tables from these measurements. First we create the WVR calibration tables <br />
by running the task [http://casa.nrao.edu/stable/docs/TaskRef/wvrgcal-task.html wvrgcal]. This task <br />
examines the data for each ms as a whole and creates a calibration<br />
table containing only phase corrections for each antenna and spw. <br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
os.system('rm -rf '+asdm+'.wvr')<br />
wvrgcal(vis=asdm+'.ms', caltable=asdm+'.wvr', segsource=True, toffset=-1)<br />
</source><br />
<br />
Next we create the Tsys tables by running {{gencal}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
os.system('rm -rf '+asdm+'.tsys')<br />
gencal(vis=asdm+'.ms', caltable=asdm+'.tsys', caltype='tsys')<br />
</source><br />
<br />
It is very important that Tsys measurements taken as close in time and elevation as possible to a particular source are applied. To save telescope time, Tsys measurements are sometimes intentionally skipped in the scheduling block for specific sources. So the first step is to establish which sources have their own Tsys measurements and which do not. To do this, you may use the intent parameter of {{listobs}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
listobs(vis=asdm+'.ms', verbose=F, selectdata=True, intent='CALIBRATE_ATMOS*')<br />
</source><br />
<br />
<figure id="X3c1.tsys_vs_time_3.4.png"><br />
[[File:X3c1.tsys_vs_time_3.4.png|thumb|<caption>Tsys vs. time for spw 1 of the X3c1.ms data.</caption>]]<br />
</figure><br />
<figure id="X5d8.tsys_vs_time_3.4.png"><br />
[[File:X5d8.tsys_vs_time_3.4.png|thumb|<caption>Tsys vs. time for spw 1 of the X5d8.ms data.</caption>]]<br />
</figure><br />
<figure id="X7ef.tsys_vs_time_3.4.png"><br />
[[File:X7ef.tsys_vs_time_3.4.png|thumb|<caption>Tsys vs. time for spw 1 of the X7ef.ms data.</caption>]]<br />
</figure><br />
<br />
<pre style="background-color: #fffacd;"><br />
Fields: 4<br />
ID Code Name RA Decl Epoch SrcId nRows <br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 1116 <br />
1 none Titan 12:49:25.97588 -02.22.41.3024 J2000 1 1125 <br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 6795 <br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 6777 <br />
Spectral Windows: (9 unique spectral windows and 2 unique polarization setups)<br />
SpwID #Chans Frame Ch1(MHz) ChanWid(kHz) TotBW(kHz) Corrs <br />
0 4 TOPO 184550 1500000 7500000 I <br />
1 128 TOPO 355740.062 15625 2000000 XX YY <br />
2 1 TOPO 356716.625 1796875 1796875 XX YY <br />
3 128 TOPO 356507.813 15625 2000000 XX YY <br />
4 1 TOPO 357484.375 1796875 1796875 XX YY <br />
5 128 TOPO 346792.187 15625 2000000 XX YY <br />
6 1 TOPO 345784.375 1796875 1796875 XX YY <br />
7 128 TOPO 345182.438 15625 2000000 XX YY <br />
8 1 TOPO 344174.625 1796875 1796875 XX YY <br />
</pre><br />
<br />
Because field '3' (the secondary phase calibrator) does not appear in the list, it has no tsys. Since the secondary phase calibrator is close on the sky to the primary phase calibrator and observed near in time, we will transfer the Tsys from the primary to the secondary phase calibrator. <br />
Also notice that spws 1,3,5,7 are the only multi-channel spws that contain Tsys data. At present, Tsys measurements can only be obtained with TDM spectral setups (128 channels/dual pol). Because our science target is observed in FDM (3840 channels/dual pol), we will need to interpolate the measurements from TDM to FDM. But first, to inspect the Tsys vs. time, we use {{plotcal}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all = ['X3c1','X5d8','X7ef']<br />
tsysfields=['0','1','2','4']<br />
os.system('mkdir cal_plots; mkdir cal_plots/Tsys_plots') <br />
for asdm in basename_all:<br />
print "Plotting Tsys vs. time for "+asdm<br />
plotcal(caltable=asdm+'.tsys', xaxis='time',yaxis='tsys',<br />
antenna='1~8',plotrange=[0,0,100,500],<br />
iteration='antenna',subplot=421,poln='',spw='1:50~50',<br />
figfile='cal_plots/Tsys_plots/'+asdm+'.tsys_vs_time.png')<br />
if (asdm != basename_all[-1]):<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
To inspect Tsys vs. frequency, we use [[plotbandpass]]. There are many different options for plotbandpass, and we demonstrate some of the most useful ones. The option '''showtsky=T''' will overlay the effective temperature curve from the atmospheric model. This shows us the location of any atmospheric lines which will appear as emission lines in the autocorrelation data (from which the Tsys spectra are derived) from all antennas. In the<br />
example below, we set '''interactive=False''', which will produce many pages of plots as<br />
individual pngs but will only show the final page in the graphics window. To view all the pages we use the image viewer '''eog''' (Eye of GNOME) available on Linux. The alternative is to set '''interactive=True''' and examine the plots in the casa graphics window as they are produced.<br />
<br />
<figure id="X3c1.tsys.field0.DV04.spw1.t1.png"><br />
[[File:X3c1.tsys.field0.DV04.spw1.t1.png|thumb|<caption>Tsys vs. frequency on 3C279 for the X3c1.ms data, spw=1.</caption>]]<br />
</figure><br />
<figure id="X3c1.tsys.field0.DV04.spw3.t1.png"><br />
[[File:X3c1.tsys.field0.DV04.spw3.t1.png|thumb|<caption>Tsys vs. frequency on 3C279 for the X3c1.ms data, spw=3.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
print "Plotting Tsys vs. frequency for "+asdm<br />
for spw in [1,3,5,7]:<br />
for field in ['0','1']:<br />
plotbandpass(caltable=asdm+'.tsys', xaxis='freq',yaxis='amp',<br />
showtsky=T,subplot=42,field=field,<br />
spw=spw, interactive=False, plotrange=[0,0,0,0],<br />
figfile='cal_plots/Tsys_plots/'+asdm+'.tsys.field%s.png'%field,<br />
buildpdf=False)<br />
</source><br />
<br />
In <xr id="X3c1.tsys.field0.DV04.spw1.t1.png"/> and <xr id="X3c1.tsys.field0.DV04.spw3.t1.png"/> we see the effect of atmospheric ozone lines on the Tsys measurements associated with 3C279 in spw 1 and 3.<br />
<br />
For sources that have multiple Tsys measurements (typically the primary phase calibrator and/or the science target) one can use '''overlay="time"''' to overlay all the measurements for that source. This can help to identify any anomalous Tsys scans. As a fraction of the plots produced by this loop, here we show the Tsys recorded on spw=1 for TW Hya from the first dataset.<br />
<br />
<figure id="X3c1.tsys.field2.DV04.spw1.png"><br />
[[File:X3c1.tsys.field2.DV04.spw1.png|thumb|<caption>Tsys vs. freq for field 2, spw 1 of the X3c1.ms data (antennas 0..3).</caption>]]<br />
</figure><br />
<figure id="X3c1.tsys.field2.DV04.spw1.png"><br />
[[File:X3c1.tsys.field2.DV09.spw1.png|thumb|<caption>Tsys vs. freq for field 2, spw 1 of the X3c1.ms data (antennas 4..7).</caption>]]<br />
</figure><br />
<figure id="X3c1.tsys.field2.PM03.spw1.png"><br />
[[File:X3c1.tsys.field2.PM03.spw1.png|thumb|<caption>Tsys vs. freq for field 2, spw 1 of the X3c1.ms data (antenna 8).</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
print "Plotting Tsys vs. frequency for "+asdm<br />
for spw in [1,3,5,7]:<br />
for field in ['2','4']:<br />
plotbandpass(caltable=asdm+'.tsys', xaxis='freq',yaxis='amp',<br />
showtsky=T,subplot=22,field=field,<br />
overlay='time',spw=spw, interactive=False, plotrange=[0,0,0,0],<br />
figfile='cal_plots/Tsys_plots/'+asdm+'.tsys.field%s.png'%field,<br />
buildpdf = False)<br />
</source><br />
<br />
Alternatively, the '''overlay="antenna"''' option will quickly reveal any Antennas with discrepant Tsys values, as they<br />
will be obvious outliers. For FDM projects like this one, using the '''showfdm=True''' option can be helpful, as it<br />
will show where in the TDM bandpass each FDM spw was located. <br />
<figure id="X3c1.tsys.field0.spw1.t1.png"><br />
[[Image:X3c1.tsys.field0.spw1.t1.png|thumb|<caption>Tsys vs Freq for field 0, spw 1 of the X3c1.ms data with all antennas overlaid.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
tsysfields=['0','1','2','4'] <br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
print "Plotting Tsys vs. frequency for "+asdm<br />
for spw in [1,3,5,7]:<br />
for field in tsysfields:<br />
plotbandpass(caltable=asdm+'.tsys', xaxis='freq',yaxis='amp',<br />
showtsky=T,subplot=11,field=field,<br />
overlay='antenna',spw=spw, interactive=False,<br />
figfile='cal_plots/Tsys_plots/'+asdm+'.tsys.field%s.png'%field,<br />
buildpdf=False,showfdm=True)<br />
</source><br />
<br />
<br />
Note that DV04 consistently has a significantly higher Tsys than the rest of the antennas. We already know from the Observation log that<br />
we need to flag that antenna, but had we not had that information, examining this plot would have demonstrated the situation.<br />
<br />
==Apply the Tsys and WVR Tables, and Split ==<br />
<br />
Next we apply the calibrations. For the (4) sources with Tsys measurements, we use the '''field''' and '''gainfield''' parameters of {{applycal}} to apply solutions only to themselves. {{applycal}} has the ability to interpolate gain tables from one spw onto another spw. In this case, we want to interpolate the TDM Tsys values in spws 1,3,5,7 onto the FDM spws 17,19,21,23. We use the '''interp''' parameter to request linear interpolation in the time dimension and spline interpolation in the channel/frequency dimension. To map the solutions for each spw, we use the '''spwmap''' parameter, which requires a list of all spws for each gain table to be applied, or a blank list ([]) which is a shorthand notation to apply the solution for each spw to itself. While applying Tsys, we will also apply the wvr calibration tables; wvr data is usually always present for all sources. Below we first set some definitions so we can loop over the correct parameters:<br />
<br />
<source lang="python"><br />
# In CASA<br />
fdm='17,19,21,23'<br />
nocal='3' # This source had no Tsys measurements associated with it <br />
tsysfields=['0','1','2','4'] <br />
tsysmap = range(25)<br />
tsysmap[17] = 1<br />
tsysmap[19] = 3<br />
tsysmap[21] = 5<br />
tsysmap[23] = 7<br />
for asdm in basename_all:<br />
for field in tsysfields:<br />
applycal(vis=asdm+'.ms', spw=fdm, field=field, gainfield=field,<br />
gaintable=[asdm+'.tsys', asdm+'.wvr'], spwmap=[tsysmap,[]],<br />
interp=['linear,spline','nearest'], flagbackup=F, calwt=T)<br />
</source><br />
<br />
For the sources without Tsys (i.e. field=3), couple them with the best available source with Tsys (i.e. field=4).<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename_all:<br />
applycal(vis=asdm+'.ms', spw=fdm, field=nocal,<br />
gaintable=[asdm+'.tsys', asdm+'.wvr'], spwmap=[tsysmap,[]],<br />
gainfield=['4',nocal], interp=['linear,spline','nearest'],flagbackup=F,<br />
calwt=T)<br />
</source><br />
<br />
Check Tsys application with plotms. First we make plots with '''ydatacolumn='data'''' to look at the raw data. For <br />
simplicity we'll just look at the two strongest sources 3C279 and Titan.<br />
<br />
<figure id="X5d8_wvrtsys_corrected_spw19.png"><br />
[[Image:X5d8_wvrtsys_corrected_spw19.png|thumb|<caption>Spectral plots of 3C279 (black) and Titan (magenta) for spw=19 after Tsys and wvr correction.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X5d8.ms',spw='17,19,21,23',xaxis='frequency',yaxis='amp',field='0,1',<br />
antenna='*&*',avgtime='1e8',avgscan=T,coloraxis='field',iteraxis='spw',<br />
xselfscale=T,ydatacolumn='data')<br />
</source><br />
<br />
<figure id="X5d8_wvrtsys_corrected_spw21.png"><br />
[[Image:X5d8_wvrtsys_corrected_spw21.png|thumb|<caption>Spectral plots of 3C279 (black) and Titan (magenta) for spw=21 after Tsys and wvr correction.</caption>]]<br />
</figure><br />
<br />
'''Note''': the antenna='*&*' is specifying that we only want to see the cross-correlation data (i.e. not the autocorrelations).<br />
<br />
Use the '''green arrows''' on the {{plotms}} display to cycle through the 4 FDM spws. <br />
<br />
Now change '''Data Column''' to '''corrected''' on the "Axes" tab (this is the same as ydatacolumn in the task) and hit '''Plot''' button on the GUI. Flip through again.<br />
<br />
'''Things to notice:'''<br />
* The amplitude scale has changed due to application of Tsys<br />
* spw=17 is clean and flat<br />
* spw=19 shows a strong dip around channel 3000 (channels can be plotted by going to the Axes tab, and changing X Axis to Channel, then hit the Plot button)-- this is an atmospheric ozone absorption feature at 357.6 GHz. In the future, high spectral resolution Tsys measurements may help to remove the shape of the absorption, but until then we will need to flag this part of the spectrum.<br />
* spw=21 Titan shows both a narrow and a broad spectral feature. The broad feature is CO(3-2) and it completely fills the 0.5 GHz band so there are no line-free channels! Titan must be handled carefully when it is used as a calibrator because it contains strong line emission. Indeed, we will not be able to use the absolute flux transfer from this spw for other targets. When possible Titan should be avoided for absolute flux calibration. For these observations, no other suitable absolute flux calibrator was available.<br />
* spw=23 shows another strong line from Titan.<br />
<br />
Beyond these things to notice, the application of Tsys and wvr seem to have gone well. We can now split off only the narrow band FDM spectral windows for further processing.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename_all:<br />
newvis = asdm + '_wvrtsys.ms'<br />
os.system('rm -rf ' + newvis)<br />
split(vis=asdm+'.ms',outputvis=newvis,datacolumn='corrected',spw=fdm)<br />
</source><br />
<br />
'''Note''': After {{split}}, the spectral windows will be renumbered to 0, 1, 2, 3 corresponding to the old spw=17, 19, 21, 23, see {{listobs}} excerpt below.<br />
<br />
<pre style="background-color: #fffacd;"><br />
SpwID #Chans Frame Ch1(MHz) ChanWid(kHz) TotBW(kHz) Corrs <br />
0 3840 TOPO 356497.936 122.070312 468750 XX YY <br />
1 3840 TOPO 357734.314 122.070312 468750 XX YY <br />
2 3840 TOPO 346034.314 122.070312 468750 XX YY <br />
3 3840 TOPO 343955.936 122.070312 468750 XX YY <br />
</pre><br />
<br />
==Initial Inspection and Flagging==<br />
<br />
From here we begin to operate on the *wvrtsys.ms files. <br />
<br />
Before we begin flagging data, we unflag all data in the measurement sets. If this is your first pass through this section of the guide, no data in the measurement sets will have previously been flagged, and so you can skip the next splitdata step with mode set to 'unflag'. If you are rerunning the flagging commands below, running splitdata in 'unflag' mode will reset your flag columns to their original state.<br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
for vis in splitdata:<br />
flagdata(vis=vis, mode='unflag', action='apply', flagbackup=F)<br />
</source><br />
<br />
ALMA data contains both the cross correlation and autocorrelation data. Presently nothing more can be done with the autocorrelation data so we flag it. Additionally, for smaller configurations of the array, and northerly sources one antenna can ''shadow'' another, blocking its view. This data also needs to be flagged. Finally, the observing log told us DV04 was not behaving properly at Band 7 and shouldn't be used so we flag that as well.<br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
for vis in splitdata:<br />
flagdata(vis=vis, mode='manual', autocorr=True, action = 'apply', flagbackup=T)<br />
flagdata(vis=vis, mode='shadow',tolerance=12.0, action='apply', flagbackup=F)<br />
flagdata(vis=vis, mode='manual', antenna='DV04', action='apply', flagbackup=F)<br />
</source><br />
<br />
Next we inspect the data with {{plotms}} for additional issues that need flagging, first looking at amplitude vs. time for each of the three datasets. Use the '''green''' arrows on the plotms gui to cycle through spws. <br />
<br />
<figure id="Tsyswvr_time_spw0_X3x1.png"><br />
[[Image:Tsyswvr_time_spw0_X3x1.png|thumb|<caption>Amplitude as a function of time for X3c1_wvrtsys.ms, spw=0</caption>]]<br />
</figure><br />
<br />
'''Note''': when '''iteraxis''' is invoked in {{plotms}}, unzoom does not always work properly. If you have trouble with this, flip to next page and then back to current one. This usually fixes the problem.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X5d8_wvrtsys.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X7ef_wvrtsys.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw')<br />
</source><br />
<br />
<figure id="Tsyswvr_time_spw2corr_X3x1.png"><br />
[[Image:Tsyswvr_time_spw2corr_X3x1.png|thumb|<caption>Amplitude as a function of time for X3x1_wvrtsys.ms, spw=2 with colorize='corr'.</caption>]]<br />
</figure><br />
<br />
'''Things to Notice:'''<br />
* In spw=2 there are some low points in all three data files. Use the "Mark Regions" box (left of center on bottom row of icons) to draw small box on low points. Then click the magnifying glass icon to the right of center. The output will be sent to the logger window. '''Note''': keep the marked region small or you can overwhelm the buffer. Locate suggests correlation YY on PM03 is the culprit. <br />
<br />
To see this more clearly you can rerun {{plotms}} with '''coloraxis='field'''' switched to '''coloraxis='corr''''<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='2',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='corr')<br />
</source><br />
<br />
To further check, you can exclude PM03 from the plot using '''antenna='!PM03'.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='2',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='corr',antenna='!PM03')<br />
</source><br />
<br />
Having confirmed the problem antenna, we flag it below. <br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
for vis in splitdata:<br />
flagdata(vis=vis, mode='manual', action= 'apply', flagbackup=T,<br />
spw='2',<br />
antenna='PM03')<br />
</source><br />
<br />
'''Next we need to inspect the spectral properties of the data to look for issues.'''<br />
<br />
First we look at phase as a function of frequency for an antenna like DV06 for which we have not yet identified any problems. <br />
'''coloraxis='baselines'''' (note this parameter is called '''Colorize''' in the GUI "Display" tab) will show each baseline as a different color. Significant delay errors or baseline errors will show up as phase slopes in these plots. Again you will want to page through the spectral windows.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='',xaxis='frequency',yaxis='phase',field='0',antenna='DV06',<br />
avgtime='1e8',avgscan=T,coloraxis='baseline',iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X5d8_wvrtsys.ms',spw='',xaxis='frequency',yaxis='phase',field='0',antenna='DV06',<br />
avgtime='1e8',avgscan=T,coloraxis='baseline',iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X7ef_wvrtsys.ms',spw='',xaxis='frequency',yaxis='phase',field='0',antenna='DV06',<br />
avgtime='1e8',avgscan=T,coloraxis='baseline',iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
Overall these plots look good: they show the phases varying slowly in a correlated way (i.e. without rapid or unpredictable scatter).<br />
<br />
<figure id="Birdies_spw2_X3x1.png"><br />
[[Image:Birdies_spw2_X3x1.png|thumb|<caption>Phase calibrators (brown and green) and TW Hya (orange) showing both real CO(3-2) emission in TW Hya and weak ''birdie'' spectral features in all three sources for spw=2.</caption>]]<br />
</figure><br />
<br />
With such high spectral resolution data, one often sees occasional "birdies" in the data. These are typically very narrow spectral features that are internally generated in the system. As ALMA development continues across observation cycles, the number of birdies should decrease. They are easiest to check for by looking at amplitude vs. frequency for sources observed over a long time range (for sensitivity). It is helpful to look at more than one source to verify the nature of the emission. Below we look at both calibrators (brown and green) and TW Hya (orange). If you have enough sensitivity birdies should be seen on all sources, however, be careful not to mistake real line emission for a birdie even on a calibrator - they can be present as we've seen for Titan. Most often birdies will only appear on a subset of antennas and so can often be identified and eliminated that way.<br />
<br />
<figure id="Birdies_spw3_X3x1.png"><br />
[[Image:Birdies_spw3_X3x1.png|thumb|<caption>Phase calibrators (brown and green) and TW Hya (orange) showing only weak birdie spectral features in spw=3.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='',xaxis='channel',yaxis='amp',field='2,3,4',<br />
avgtime='1e8',avgscan=T,coloraxis='field',iteraxis='spw',xselfscale=T,yselfscale=T)<br />
</source><br />
<br />
Do a quick check that other two datasets are the same (they are usually similar if the source of internal resonance hasn't changed in the meantime).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X5d8_wvrtsys.ms',spw='',xaxis='channel',yaxis='amp',field='2,3,4',<br />
avgtime='1e8',avgscan=T,coloraxis='field',iteraxis='spw',xselfscale=T,yselfscale=T)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X7ef_wvrtsys.ms',spw='',xaxis='channel',yaxis='amp',field='2,3,4',<br />
avgtime='1e8',avgscan=T,coloraxis='field',iteraxis='spw',xselfscale=T,yselfscale=T)<br />
</source><br />
<br />
Now you can zoom in on each region to get channels for flagging, or to save time just go ahead and run the flagging command below where this has been done for you.<br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
for vis in splitdata:<br />
flagdata(vis=vis, mode='manual', action='apply', flagbackup=T,<br />
spw='0:1067~1068;1279~1280;2367~2368;3775~3776, 1:1279~1280;2367~2368;3775~3776, 2:1279~1280;3775~3776, 3:831~832;1535~1536;2367~2368;3775~3776;3839~3839')<br />
</source><br />
<br />
Replot in {{plotms}} to check that flagging has been done as anticipated.<br />
<br />
==Flag Calibrator Spectral Features==<br />
<br />
In this section, we will flag spectral features in the calibrators so they do not skew the calibration solutions. First make plots of 3C279 and Titan in channel space to get channels for flagging. <br />
<br />
<figure id="3C279_Titan_spw1.png"><br />
[[Image:3C279_Titan_spw1.png|thumb|<caption>Spectral plots of 3C279 (black) and Titan (magenta) for spw=1 after Tsys and wvr correction.</caption>]]<br />
</figure><br />
<figure id="3c279_meso_freq.png"><br />
[[Image:3c279_meso_freq.png|thumb|<caption>Zoomed spectral plot of 3C279 showing mesospheric absorption of CO(3-2) in frequency space.</caption>]]<br />
</figure><br />
<figure id="3c279_meso_chann.png"><br />
[[Image:3c279_meso_chann.png|thumb|<caption>Zoomed spectral plot of 3C279 showing mesospheric absorption of CO(3-2) in channel space.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='channel',yaxis='amp',field='0,1',<br />
avgtime='1e8',coloraxis='field',iteraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
The figure to the right shows a broad absorption line in spw 1 at channel 3000. This is the ozone absorption line at 357.62982 GHz. However, there is another narrow absorption feature in the spectra (spw 2) that is most easily seen on 3C279 (because it is the strongest calibrator). Let's look at it first in frequency space.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='2:1600~2300',xaxis='frequency',yaxis='amp',<br />
field='0',avgtime='1e8',coloraxis='field')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
The absorption feature lies exactly at the rest frequency for CO 3-2 (345.79599 GHz). Because it is so narrow (< 1 MHz), it must originate from a very low pressure region (i.e. high altitude) in the Earth's atmosphere, otherwise it would be more pressure broadened. Indeed, the first detection of CO in the mesosphere was made over 35 years ago (see, e.g. [http://adsabs.harvard.edu/abs/1976Sci...191.1174W Waters et al. 1976] or [http://adsabs.harvard.edu/abs/1979JGR....84..416G Goldsmith et al. 1979]). Be aware that the line is stronger as you go up the CO ladder (strength ~ J^3 for low J) because the temperature at that altitude (~50km) is about 250 K. In April 2011, the apparent depth of the feature was about 10% in the 2-1 line and 35% in the 3-2 line. However, the depth of the absorption feature is exaggerated due to the way ALMA normalizes the cross-correlation spectra by the autocorrelation spectra prior to storage. While this technique generally leads to a flat bandpass shape, it will accentuate telluric features because they are emission lines in the single dish spectrum (e.g. JCMT observations of mesospheric CO 3-2 can be found in [http://adsabs.harvard.edu/abs/1993MNRAS.264..673P Preston et al. 1993]). Finally, note that large seasonal variations in the line strength have been reported from observations at [http://adsabs.harvard.edu/abs/2003GeoRL..30j..39F Onsala]. <br />
<br />
Now, let's re-plot the line with channel number as the x-axis in order to get the channel range for flagging. <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='2:1600~2300',xaxis='channel',yaxis='amp',<br />
field='0',avgtime='1e8',coloraxis='field')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Now lets look at Titan in more detail.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='channel',yaxis='amp',field='1',<br />
avgtime='1e8',coloraxis='field',iteraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Explicitly back up the flag tables so that flagged regions can be restored later.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
flagmanager(vis=asdm+'.ms',mode='save',versionname=asdm+'.before_calspectralflags')<br />
</source><br />
<br />
<figure id="Titan_spw2.png"><br />
[[Image:Titan_spw2.png|thumb|<caption>Spectral plot of Titan (magenta) for spw=2.</caption>]]<br />
</figure><br />
<br />
Flag absorption features for all sources.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
print "Flagging absorption features in all sources for "+asdm<br />
flagdata(vis=asdm+'.ms', mode='manual', spw='1:2000~3839, 2:1945~1960')<br />
</source><br />
<br />
<figure id="Titan_spw3.png"><br />
[[Image:Titan_spw3.png|thumb|<caption>Spectral plot of Titan (magenta) for spw=3.</caption>]]<br />
</figure><br />
<br />
Now we need to flag emission. The very broad CO(3-2) in spw=2 of Titan will prevent us from using it as a calibrator for this spectral window since there are no line-free channels (we will transfer, phase, amplitude, and absolute flux from another Titan spw below). We do want to flag the narrower Titan line in spw=3.<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
flagmanager(vis=asdm+'.ms',mode='save',versionname=asdm+'.before_emissionflags')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
print "Flagging emission for "+asdm<br />
flagdata(vis=asdm+'.ms', mode='manual', <br />
field='1',<br />
spw='3:1000~3000')<br />
</source><br />
<br />
If you like, check that the right things have been flagged.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='channel',yaxis='amp',field='0,1',<br />
avgtime='1e8',coloraxis='field',iteraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
==Set Up the Flux Calibrator Model==<br />
<br />
Fill the model data column for Titan with a model for the flux density as a function of baseline. The model is a uniformly illuminated disk with the size obtained from the JPL Horizons ephemeris.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
setjy(vis=asdm+'.ms',field='1',usescratch=F,<br />
standard='Butler-JPL-Horizons 2010',scalebychan=F)<br />
</source><br />
<br />
<figure id="Titan amp vs uvdist.png"><br />
[[Image:Titan amp vs uvdist.png|thumb|<caption>Plot of Titan model for each of the 4 spws. We used the Butler-JPL-Horizons 2010 standard to compute this model.</caption>]]<br />
</figure><br />
<br />
After running setjy, it is a good idea to plot the model in order to confirm that it makes sense. In this case, Titan is partially resolved, so we expect the flux density to drop with uv distance, but not so much as to pass through a null. We also expect it to be brighter at higher frequencies since it has a thermal blackbody spectrum.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',field='1',xaxis='uvdist',yaxis='amp',coloraxis='spw',<br />
ydatacolumn='model')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<figure id="twhydra_X3c1_wvrtsys_2012_titan_model.png">[[File:twhydra_X3c1_wvrtsys_2012_titan_model.png|thumb|right|<caption>Titan model produced by 'Butler-JPL-Horizons 2012'.</caption>]]</figure><br />
<br />
<br/><br />
<div class="noprint" style="float:none; border:0px solid blue;background-color:#F6CEF5;padding:2px;"><br />
The setjy invocation, above, uses the flux density standard '''standard='Butler-JPL-Horizons 2010' '''. A more updated standard is also available: '''standard='Butler-JPL-Horizons 2012' '''. <xr id="twhydra_X3c1_wvrtsys_2012_titan_model.png"/> shows the Titan model produced using the updated standard. The motivated reader may wish to rerun {{setjy}} using the updated model. We will highlight later in this tutorial, and in the imaging tutorial that follows, the effects of using the updated model.<br />
</div><br />
<br />
==Bandpass Calibration==<br />
<br />
First we need to check how the amplitude and phase of 3C279 behave as a function of time. In order to set<br />
a fixed scale on the y-axis, we first make a plot of all the data, excluding antenna DV04. (We must specify '''ydatacolumn='data' ''' explicitly here because the default value of '''ydatacolumn''' equals the value used in the previous execution of {{plotms}}. In the previous execution '''ydatacolumn''' was set to '''model'''. See the online help, <tt>help plotms</tt>, for details.)<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',xaxis='time',yaxis='amp',coloraxis='corr',<br />
field='0',avgchannel='3840',ydatacolumn='data')<br />
</source><br />
<br />
<figure id="ThreeScansAmp.png"><br />
[[Image:ThreeScansAmp.png|thumb|<caption>Amplitude variation for three 3C279 scans, spw 0 (for one representative baseline).</caption>]]<br />
</figure><br />
<br />
We see that the uncalibrated amplitudes range between 0.2-0.4, so let's set this as our<br />
scale and examine a representative baseline (DV06-DV07) to see how the amplitude changes with time. <br />
<br />
<source lang="python"><br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for spw in ['0','1','2','3']:<br />
for asdm in basename:<br />
print "Now showing spw %s from %s" % (spw, asdm+'.ms')<br />
plotms(vis=asdm+'.ms',spw=spw,xaxis='time',yaxis='amp',coloraxis='corr',iteraxis='spw',<br />
field='0',avgchannel='3840',antenna='DV06&DV07',plotrange=[0,0,0.2,0.4])<br />
user_check=raw_input('press enter to go to the next plot\n')<br />
</source><br />
<br />
<figure id="ThreeScansPhase.png"><br />
[[Image:ThreeScansPhase.png|thumb|<caption>Phase variation for three 3C279 scans, spw 0 (for one representative baseline).</caption>]]<br />
</figure><br />
<br />
Page through the measurement sets for each spw. This shows significant variations in the amplitude across the three measurement sets.<br />
Now do the same with phase.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for spw in ['0','1','2','3']:<br />
for asdm in basename:<br />
print "Now showing spw %s from %s" % (spw, asdm+'.ms')<br />
plotms(vis=asdm+'.ms',spw=spw,xaxis='time',yaxis='phase',coloraxis='corr',iteraxis='spw',<br />
field='0',avgchannel='3840',antenna='DV06&DV07',plotrange=[0,0,-180,180])<br />
user_check=raw_input('press enter to go to the next plot\n')<br />
</source><br />
<br />
This examination reveals two findings: (1) significant variation in the phase across the three scans, as well as (2) smaller but significant variations within a scan. The first finding suggests that we do not want to combine the scans for bandpass calibration, but instead derive an independent bandpass for each scan. Actually what is more important than a DC offset is if the '''shape''' of the amplitude or phase changes from scan to scan. There isn't enough S/N to tell for sure so we will keep them separate. This situation is often the case, which is why we did not concatenate the three datasets prior to calibration. The second finding suggests that we need to correct the phase vs. time behavior of the bandpass calibrator (3C279; field=0) within each scan, before doing the bandpass. We want to chose a relatively narrow range of channels near the center of the spws so that the bandpass phase slopes (to be corrected with the bandpass calibration itself) do not decorrelate the signal. You need to avoid spectral regions that were completely flagged above.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.bpphase.gcal')<br />
gaincal(vis=asdm+'.ms',caltable=asdm+'.bpphase.gcal',<br />
field='0',spw='0~3:900~1100',refant='DV06',<br />
calmode='p',solint='int',minsnr=2.0,minblperant=4)<br />
</source><br />
<br />
<figure id="X7ef_wvrtsys.bpphase.X.png"><br />
[[Image:X7ef_wvrtsys.bpphase.X.png|thumb|<caption>Phase only solutions for correlation X on the third scan of the bandpass calibrator 3C279.</caption>]]<br />
</figure><br />
<br />
Inspect the phase-only calibration solutions for the bandpass calibrator. Look for any noisy solutions. We do XX and YY separately to reduce confusion in the plot. It will help if you make your plotcal window wide.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.bpphase.gcal',xaxis='time',yaxis='phase',spw='',antenna='1~8', <br />
iteration='antenna',subplot=421,plotrange=[0,0,-180,180],<br />
figfile=asdm+'.bpphase.X.png',poln='X')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
In the plotcal gui you can use the magnifying glass symbol to zoom in on one of the scans to see the phase variations. The colors are the 4 different spws.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.bpphase.gcal',xaxis='time',yaxis='phase',spw='',antenna='1~8', <br />
iteration='antenna',subplot=421,plotrange=[0,0,-180,180],<br />
figfile=asdm+'.bpphase.Y.png',poln='Y')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Next we apply this phase-only correction on the fly while calculating the bandpass solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.bandpass.bcal')<br />
bandpass(vis=asdm+'.ms',caltable=asdm+'.bandpass.bcal',<br />
field='0',spw='',combine='',refant='DV06',<br />
solint='inf',solnorm=T,minblperant=4, bandtype='B', fillgaps=17,<br />
gaintable=asdm+'.bpphase.gcal')<br />
</source><br />
<br />
You will see some error messages in the terminal, these are just related to the flagged channels. We set fillgaps=17 to interpolate across the smaller regions of flagged channels (mesospheric features and birdies).<br />
<br />
<figure id="Bandpass.ampspw0.png"><br />
[[Image:Bandpass.ampspw0.png|thumb|<caption>Bandpass amplitude solution plots.</caption>]]<br />
</figure><br />
<figure id="Bandpass.phasespw0.png"><br />
[[Image:Bandpass.phasespw0.png|thumb|<caption>Bandpass phase solution plots.</caption>]]<br />
</figure><br />
<br />
'''A few words about solint and combine:'''<br />
<br />
In {{bandpass}}, the use of '''solint='inf'''' (as in "infinite") will derive a bandpass<br />
solution for each 3C279 scan, '''unless''' '''combine='scan'''' (which is the default). Here we set combine=' ' explicitly so that it does not combine the scans into one bandpass. Likewise, field boundaries are only crossed if combine='field', and spw boundaries are only crossed if combine='spw'. In some cases it can be helpful to combine fields if you suffer from lack of S/N, but it is never a good idea to combine spws. <br />
<br />
Now inspect the phase and amplitude solutions. You are looking for excursions from smooth fits, or particularly noisy solutions compared to the others. <br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
for spw in [0,1,2,3]:<br />
plotbandpass(asdm+'.bandpass.bcal',xaxis='freq',yaxis='amp', spw=spw,<br />
antenna='1~8', subplot=42, figfile=asdm+'.bandpass.amp', showatm=T,<br />
interactive=True)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
for spw in [0,1,2,3]:<br />
plotbandpass(asdm+'.bandpass.bcal',xaxis='freq',yaxis='phase',spw=spw,<br />
antenna='1~8',subplot=42,figfile=asdm+'.bandpass.phs', showatm=T,<br />
interactive=True)<br />
</source><br />
<br />
The values of phase on DV06 are very close to zero because it was used as the reference antenna.<br />
<br />
==Gain Calibration==<br />
<br />
Now that we have a bandpass solution to apply we can solve for the antenna-based phase and amplitude gain calibration. Since the phase changes on a much shorter timescale than the amplitude, we will solve for them separately. In particular, if the phase changes significantly over a scan time, the amplitude would be decorrelated, if the un-corrected phase were averaged over this timescale. Note that we re-solve for the gain solutions of the bandpass calibrator, so we can derive new solutions that are corrected for the bandpass shape. Since the bandpass calibrator will not be used again, this is not strictly necessary, but is useful to check its calibrated flux density for example. <br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.intphase.gcal')<br />
gaincal(vis=asdm+'.ms',caltable=asdm+'.intphase.gcal',<br />
field='0,1,3,4',spw='0~3:40~3800',refant='DV06',<br />
calmode='p',solint='int',minsnr=2.0,minblperant=4,<br />
gaintable=[asdm+'.bandpass.bcal'])<br />
</source><br />
<br />
Here '''solint='int' ''' coupled with '''calmode='p' ''' will derive a single phase solution for each 10 second integration. Note that the bandpass table is applied on-the-fly before solving for the phase solutions, however the bandpass is NOT applied to the data permanently until applycal is run later on. <br />
<br />
Although '''solint='int' ''' (i.e. the integration time of 10 seconds) is the best choice to apply before solving for the amplitude solutions, it is not a good idea to use this to apply to the target. This is because the phase-scatter within a scan can dominate the interpolation between calibrator scans. Instead, we also solve for the phase on the scan time, '''solint='inf' ''' (but '''combine=' ' ''', since we want one solution per scan) for application to the target later on. Unlike the bandpass task, for {{gaincal}}, the default of the combine parameter is '''combine=' ' '''. <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.scanphase.gcal')<br />
gaincal(vis=asdm+'.ms',caltable=asdm+'.scanphase.gcal',<br />
field='0,1,3,4',spw='0~3:40~3800',refant='DV06',<br />
calmode='p',solint='inf',minsnr=2.0,minblperant=4,<br />
gaintable=[asdm+'.bandpass.bcal'])<br />
</source><br />
<br />
Alternatively, instead of making a separate phase solution for application to the target, one can also run {{smoothcal}} to smooth the solutions derived on the integration time. <br />
<br />
Next we apply the bandpass and '''solint='int' ''' phase-only calibration solutions on-the-fly to derive amplitude solutions. Here the use of '''solint='inf' ''', but '''combine=' ' ''' will result in one solution per scan interval. <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.amp.gcal')<br />
gaincal(vis=asdm+'.ms',caltable=asdm+'.amp.gcal',<br />
field='0,1,3,4',spw='0~3:40~3800',refant='DV06',<br />
calmode='ap',solint='inf',minsnr=2.0,minblperant=4,<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal'])<br />
</source><br />
<br />
Now carefully inspect all these solutions looking for discrepant solutions. If you see any, you will need to flag them and rerun the calibration tasks above. <br />
<br />
We make plots in X and Y separately for clarity. The colors are showing the spectral windows.<br />
<figure id="X3c1_wvrtsys.intphase_X.png"><br />
[[Image:X3c1_wvrtsys.intphase_X.png|thumb|<caption>Phase solutions for the X polarization for every integration time of the first dataset.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.intphase.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',iteration='antenna',subplot=421,<br />
plotrange=[0,0,-180,180],poln='X',figfile=asdm+'.intphase_X.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.intphase.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',iteration='antenna',subplot=421,<br />
plotrange=[0,0,-180,180],poln='Y',figfile=asdm+'.intphase_Y.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<figure id="X3c1_wvrtsys.scanphase_X.png"><br />
[[Image:X3c1_wvrtsys.scanphase_X.png|thumb|<caption>Phase solutions for the X polarization for each scan of the first dataset.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.scanphase.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',iteration='antenna',subplot=421,<br />
plotrange=[0,0,-180,180],poln='X',figfile=asdm+'.scanphase_X.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.scanphase.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',iteration='antenna',subplot=421,<br />
plotrange=[0,0,-180,180],poln='Y',figfile=asdm+'.scanphase_Y.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Since we have taken out the phase as best we can by applying the '''solint='int' ''' phase-only solution, this plot will give a good idea of the residual phase error. If you see scatter of more than a few degrees here, you should consider going back and looking for more data to flag, particularly bad timeranges etc. <br />
<br />
<figure id="X3c1_wvrtsys.amp_phase.png"><br />
[[Image:X3c1_wvrtsys.amp_phase.png|thumb|<caption>Residual phase after applying intphase.gcal for both correlations in the first dataset.</caption>]]<br />
</figure><br />
<figure id="X3c1_wvrtsys.amp_X.png"><br />
[[Image:X3c1_wvrtsys.amp_X.png|thumb|<caption>Amplitude solutions on a scan interval for correlation X in the first dataset.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.amp.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',plotrange=[0,0,-1,1],<br />
iteration='antenna',subplot=421,figfile=asdm+'.amp_phase.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
These are very small, as they should be. Now look at the amplitude solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.amp.gcal',xaxis='time',yaxis='amp',antenna='1~8', <br />
iteration='antenna',subplot=421,spw='',poln='X',<br />
plotrange=[0,0,0.0,0.3],figfile=asdm+'.amp_X.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.amp.gcal',xaxis='time',yaxis='amp',antenna='1~8', <br />
iteration='antenna',subplot=421,spw='',poln='Y',<br />
plotrange=[0,0,0.0,0.3],figfile=asdm+'.amp_Y.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
==Flux Calibration==<br />
<br />
Next we use the flux calibrator (whose flux density was set in {{setjy}} above) to derive the flux density of the other calibrators. Note that the flux table REPLACES the amp.gcal in terms of future application of the calibration to the data, i.e. the flux table contains both the amp.gcal and flux scaling. Unlike the gain calibration steps, this is not an incremental table.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.flux.cal')<br />
fluxscale(vis=asdm+'.ms',caltable=asdm+'.amp.gcal',<br />
fluxtable=asdm+'.flux.cal',reference='1',refspwmap=[0,1,3,3],<br />
listfile=asdm+'.fluxscale.txt')<br />
</source><br />
<br />
Its a good idea to record the derived fluxscale values using the listfile option. The values can also be viewed in the Log Messages window.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Found reference field(s): Titan<br />
Found transfer field(s): 3c279 J1147-382=QSO J1037-295=QSO<br />
Spw=2 will be referenced to spw=3<br />
Flux density for 3c279 in SpW=0 (freq=3.56498e+11 Hz) is: 10.537 +/- 0.0183518 (SNR = 574.169, N = 16)<br />
Flux density for 3c279 in SpW=1 (freq=3.57734e+11 Hz) is: 10.6933 +/- 0.0264134 (SNR = 404.842, N = 16)<br />
Flux density for 3c279 in SpW=2 (freq=3.46034e+11 Hz) (ref SpW=3) is: 10.251 +/- 0.0477949 (SNR = 214.479, N = 14)<br />
Flux density for 3c279 in SpW=3 (freq=3.43956e+11 Hz) is: 9.91798 +/- 0.020167 (SNR = 491.791, N = 16)<br />
Flux density for J1147-382=QSO in SpW=0 (freq=3.56498e+11 Hz) is: 1.03399 +/- 0.0167344 (SNR = 61.7887, N = 16)<br />
Flux density for J1147-382=QSO in SpW=1 (freq=3.57734e+11 Hz) is: 0.844817 +/- 0.0191013 (SNR = 44.2283, N = 16)<br />
Flux density for J1147-382=QSO in SpW=2 (freq=3.46034e+11 Hz) (ref SpW=3) is: 0.987193 +/- 0.024391 (SNR = 40.4737, N = 14)<br />
Flux density for J1147-382=QSO in SpW=3 (freq=3.43956e+11 Hz) is: 1.28859 +/- 0.0194364 (SNR = 66.298, N = 16)<br />
Flux density for J1037-295=QSO in SpW=0 (freq=3.56498e+11 Hz) is: 0.968281 +/- 0.00895224 (SNR = 108.161, N = 16)<br />
Flux density for J1037-295=QSO in SpW=1 (freq=3.57734e+11 Hz) is: 0.75916 +/- 0.015366 (SNR = 49.4053, N = 16)<br />
Flux density for J1037-295=QSO in SpW=2 (freq=3.46034e+11 Hz) (ref SpW=3) is: 0.948551 +/- 0.0165421 (SNR = 57.3416, N = 14)<br />
Flux density for J1037-295=QSO in SpW=3 (freq=3.43956e+11 Hz) is: 1.21905 +/- 0.0139967 (SNR = 87.0956, N = 16)<br />
Fitted spectrum for 3c279 with fitorder=1: Flux density = 10.2962 +/- 0.0450319 (freq=351.002 GHz) spidx=1.70757 +/- 0.245737<br />
Fitted spectrum for J1147-382=QSO with fitorder=1: Flux density = 1.06853 +/- 0.0709817 (freq=351.002 GHz) spidx=-6.77353 +/- 3.71867<br />
Fitted spectrum for J1037-295=QSO with fitorder=1: Flux density = 1.01822 +/- 0.0654586 (freq=351.002 GHz) spidx=-6.28977 +/- 3.71453<br />
Storing result in X7ef_wvrtsys.flux.cal<br />
Writing solutions to table: X7ef_wvrtsys.flux.cal<br />
</pre><br />
<br />
<figure id="x3c1_wvrtsys.flux_X.png"><br />
[[Image:x3c1_wvrtsys.flux_X.png|thumb|<caption>Absolute flux calibration solutions for correlation X for the first dataset.</caption>]]<br />
</figure><br />
<br />
<div class="noprint" style="float:none; border:0px solid blue;background-color:#F6CEF5;padding:2px;"><br />
If you used the updated (Butler-JPL-Horizons 2012) flux density standard when you ran {{setjy}} earlier in this tutorial, the derived flux values for the calibrators will be slightly different. For example, when averaged over the 3 measurement sets, 3c279 in spectral window 0 has a flux of 10.77 Jy using the 2010 standard and 10.63 Jy using the 2012 standard; as a second example, J1147-382 in SPW 3 has an average flux of 1.13 Jy (2010 standard) and 1.15 Jy (2012 standard). <br />
</div><br />
<br />
Now look at the flux solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.flux.cal',xaxis='time',yaxis='amp',antenna='1~8', <br />
iteration='antenna',subplot=421,spw='',poln='X',<br />
plotrange=[0,0,0.0,0.3],figfile=asdm+'.flux_X.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.flux.cal',xaxis='time',yaxis='amp',antenna='1~8', <br />
iteration='antenna',subplot=421,spw='',poln='Y',<br />
plotrange=[0,0,0.0,0.3],figfile=asdm+'.flux_Y.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
==Apply Calibration and Inspect==<br />
<br />
Now we can use the {{flagmanager}} if we want to restore any of the spectral flagging we did prior to bandpass calibration. <br />
In this case, we choose to restore the flags of the emission lines on Titan, because we are interested in seeing how<br />
strong they are compared to the continuum. However, we leave the strong ozone line and mesospheric CO line flagged on all <br />
sources, because we want to get the most accurate continuum flux density for the science target. <br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
flagmanager(vis=asdm+'.ms',mode='restore',versionname=asdm+'.before_emissionflags')<br />
</source><br />
<br />
Next we apply the calibration solutions to each source individually, using the '''gainfield''' parameter to specify which calibrator's solutions should be applied from each of the '''gaintable''' calibration tables. <br />
<br />
First, we do 3C279 (the bandpass calibrator), applying all 3 of its solutions to itself (that's why gainfield contains three zeros):<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='0',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['0','0','0'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
Next, we do Titan (the absolute flux calibrator) using the bandpass solution from 3C279:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='1',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['0','1','1'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
For the secondary phase calibrator, we apply the phase and flux solutions from the primary phase calibrator. This will allow us to check how well the phase transfer to the science target (TW Hya) has worked:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='3',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.scanphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','linear','linear'],<br />
gainfield=['0','4','4'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
Next is the Primary phase calibrator:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='4',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['0','4','4'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
Finally, for the Science Target TW Hya, we apply the phase solutions from both the primary and secondary phase calibrators:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='2',<br />
interp=['nearest','linear','linear'],<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.scanphase.gcal',asdm+'.flux.cal'],<br />
gainfield=['0','3,4','3,4'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
Now we can check the results of applying the calibration solutions.<br />
<br />
<figure id="Corrected_vs_time_1.png"><br />
[[Image:Corrected_vs_time_1.png|thumb|<caption>The calibrated data for the first dataset (amplitude vs. time).</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw',ydatacolumn='corrected')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
In amplitude, it looks good but there are some noisy points toward the end of the first scheduling block, but it mostly only affects the secondary phase calibrator (green). In phase, we expect all the points to cluster about zero. The large scatter in phase on the secondary phase calibrator is readily apparent: <br />
<br />
<figure id="Corrected_phase_vs_time_1.png"><br />
[[Image:Corrected_phase_vs_time_1.png|thumb|<caption>The calibrated data on the calibrators for the first dataset (phase vs. time).</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='time',yaxis='phase',field='0,1,3,4',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw',ydatacolumn='corrected')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Let's check whether the situation improves when we apply this calibrator's solutions to itself rather than transferring the solutions from the primary phase calibrator (which is 17 degrees away, and observed at a different time). <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='3',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['0','3','3'],flagbackup=T, calwt=T)<br />
</source><br />
<br />
<figure id="Corrected_vs_time_1_field3.png"><br />
[[Image:Corrected_vs_time_1_field3.png|thumb|<caption>The calibrated data for the first dataset (amplitude vs. time), but now with field 3, the secondary phase calibrator, calibrated with itself.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw',ydatacolumn='corrected')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<figure id="Corrected_phase_vs_time_1_field3.png"><br />
[[Image:Corrected_phase_vs_time_1_field3.png|thumb|<caption>The calibrated data from the first dataset (phase vs. time), but now with field 3, the secondary phase calibrator, calibrated with itself.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='time',yaxis='phase',field='0,1,3,4',<br />
avgchannel='3840', coloraxis='field',iteraxis='spw',<br />
ydatacolumn='corrected')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Indeed, the secondary calibrator looks better now in amplitude and phase. This is an indication that the calibration transfer is not working well in this timerange. Because the effect is not catastrophic and we know we can self-calibrate on TW Hya later, we will let this go for now. Or, if you want you can delve deeper into the data and try to solve the mystery... <br />
<br />
In any case, we will re-issue the original {{applycal}} so that it is this calibration that our subsequent {{split}} will use. This will allow us to check the effect of correcting the secondary phase calibrator with the primary phase calibrator later. <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='3',<br />
gaintable=[asdm+'.bandpass.bcal', asdm+'.scanphase.gcal', asdm+'.flux.cal'],<br />
interp=['nearest','linear','linear'],<br />
gainfield=['0','4','4'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
<br />
Let's check the spectral calibration now. First 3C279 and Titan:<br />
<br />
<figure id="X3c1_spw2_corrected_3.4.png"><br />
[[Image:X3c1_spw2_corrected_3.4.png|thumb|<caption>Spectral UV-plots of 3C279 and Titan of spw=2 for the first dataset.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='frequency',yaxis='amp',field='0,1',<br />
avgtime='1e8',avgscan=T,coloraxis='field',ydatacolumn='corrected',<br />
iteraxis='spw',xselfscale=T)<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Flip through the spws. These look good. Next the two phase calibrators:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='frequency',yaxis='amp',field='3,4',<br />
avgtime='1e8',avgscan=T,coloraxis='field',ydatacolumn='corrected',<br />
iteraxis='spw',xselfscale=T)<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Flip through the spws. This also looks good, the secondary phase calibrator is a bit noisier but this is normal. The upswing at the lower frequency end of spw=3 will probably need to be flagged on the science target as well. It corresponds to the edge of an atmospheric feature.<br />
<br />
Now for the exciting part, what does the science target look like...<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='frequency',yaxis='amp',field='2',<br />
avgtime='1e8',avgscan=T,coloraxis='field',ydatacolumn='corrected',<br />
iteraxis='spw',xselfscale=T)<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
We see HCO+(4-3) in spw=0 and CO(3-2) in spw=2 as expected. Because the shape of the <br />
line profiles varies with baseline, you can already tell that the line emission is resolved.<br />
<br />
<figure id="X3c1_CO3_2_uvplot_3.4.png"><br />
[[Image:X3c1_CO3_2_uvplot_3.4.png|thumb|<caption>UV-Plot of the TW Hya CO(3-2) emission from the first dataset.</caption>]]<br />
</figure><br />
<figure id="X3c1_HCOp4_3_uvplot_3.4.png"><br />
[[Image:X3c1_HCOp4_3_uvplot_3.4.png|thumb|<caption>UV-Plot of the TW Hya HCO+(4-3) emission from the first dataset.</caption>]]<br />
</figure><br />
<br />
Now check that the velocity of TWHydra is correct in the LSRK frame, it should be around 2.88 km/s.<br />
* CO 3-2 rest freq 345.79599 GHz<br />
* HCO+ 4-3 rest freq 356.7342 GHz<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='2',xaxis='velocity',yaxis='amp',field='2',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',<br />
restfreq='345.79599GHz', plotrange=[-10,15,0,0],coloraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='0',xaxis='velocity',yaxis='amp',field='2',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',<br />
restfreq='356.7342GHz',plotrange=[-10,15,0,0],coloraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Both lines show up at the expected velocity.<br />
<br />
<br />
==Concatenate the Data==<br />
<br />
Here we will concatenate the three datasets prior to imaging.<br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
os.system('rm -rf Band7multi_april22.ms')<br />
concat(vis=splitdata,concatvis='Band7multi_april22.ms')<br />
</source><br />
<br />
If you like you can run listobs on new combined dataset<br />
<br />
<source lang="python"><br />
# In CASA<br />
listfile = 'Band7multi_april22.listobs.txt'<br />
os.system('rm ' + listfile)<br />
listobs(vis='Band7multi_april22.ms',verbose=F, listfile=listfile)<br />
</source><br />
<br />
<figure id="All_spw2_corrected_3.4.png"><br />
[[Image:All_spw2_corrected_3.4.png|thumb|<caption>Spectral UV-plots of 3C279 and Titan of spw=2 for the combined datasets.</caption>]]<br />
</figure><br />
<br />
You can also examine the spectral uv plots for the combined dataset to see the improvement in S/N: <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='Band7multi_april22.ms',spw='',xaxis='frequency',yaxis='amp',field='0,1',<br />
avgtime='1e8',avgscan=T,coloraxis='field',ydatacolumn='corrected',<br />
iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
<figure id="All_CO3_2_uvplot_3.4.png"><br />
[[Image:All_CO3_2_uvplot_3.4.png|thumb|<caption>UV-Plot of the TW Hya CO(3-2) emission from the combined datasets.</caption>]]<br />
</figure><br />
<br />
...and the CO line profile for the combined dataset: <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='Band7multi_april22.ms',spw='2',xaxis='velocity',yaxis='amp',field='2',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',restfreq='345.79599GHz',<br />
plotrange=[-10,15,0,0],coloraxis='spw')<br />
</source><br />
<br />
==Split Calibrated Data==<br />
<br />
Now we split off the calibrated data for the Science Target as well as the interesting parts of the calibrators for imaging.<br />
<br />
When we {{split}} off the Titan data, a few dozen warnings like the following are written to the log:<br />
<pre><br />
2012-05-15 22:00:35 WARN split::SubMS::copySource() Invalid SOURCE ID in SOURCE table row 20 <br />
</pre><br />
These can be ignored, because they do not indicate any problem that will prevent you from imaging Titan correctly at a single position using all the data in the output ms.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_corrected.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='TWHydra_corrected.ms',<br />
datacolumn='corrected',spw='',field='2')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf J1037_corrected.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='J1037_corrected.ms',<br />
datacolumn='corrected',spw='',field='4')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf J1147_corrected.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='J1147_corrected.ms',<br />
datacolumn='corrected',spw='',field='3')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3C279_CO3_2.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='3C279_CO3_2.ms',<br />
datacolumn='corrected',spw='2:1900~2000',field='0')<br />
</source><br />
<br />
==Optional: Reconcile Titan's Coordinates==<br />
<br />
If you do not care to image Titan, then you can skip this step and simply continue on to the [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_4.5 imaging guide].<br />
<br />
Our earlier treatment of Titan's coordinates using [http://casa.nrao.edu/stable/docs/TaskRef/fixplanets-task.html fixplanets] replaced the zeros written by the ALMA control system with the correct position of the body at the instant of the first observation of that SB. As a result, it has slightly different positions in all three datasets, as seen by listobs:<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='Band7multi_april22.ms',verbose=F)<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
ID Code Name RA Decl Epoch SrcId nRows <br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 70866 <br />
1 none Titan 12:49:25.97588 -02.22.41.3024 J2000 1 4842 <br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 515151 <br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 40797 <br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 171153 <br />
5 none Titan 12:49:26.53729 -02.22.27.1521 J2000 0 4833 <br />
6 none Titan 12:49:26.53059 -02.22.18.7878 J2000 0 4833 <br />
</pre><br />
<br />
If we want to image such moving objects observed across multiple SBs, we need to bring the positions into agreement, otherwise {{clean}} will try to make a mosaic. Task [http://casa.nrao.edu/stable/docs/TaskRef/fixplanets-task.html fixplanets] can be used to do this. Here, we set the direction to the direction of the first dataset as reported by listobs. Note that the RA/Dec format is slightly different from the {{listobs}} output format. Also, we do not<br />
fix the uvw coordinates because they are already more correct now than they would be if we "fixed" them.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fixplanets(vis='Band7multi_april22.ms', field='Titan', direction='J2000 12h49m25.97588 -02d22m41.3024', fixuvw=False)<br />
</source><br />
<br />
Check the header information again to see that the information for Titan has changed for the second<br />
and third datasets. They will appear as fields 5 and 6.<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='Band7multi_april22.ms',verbose=F)<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
ID Code Name RA Decl Epoch SrcId <br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 70866 <br />
1 none Titan 12:49:25.97588 -02.22.41.3024 J2000 1 4842 <br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 515151 <br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 40797 <br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 171153 <br />
5 none Titan 12:49:25.97588 -02.22.41.3024 J2000 0 4833 <br />
6 none Titan 12:49:25.97588 -02.22.41.3024 J2000 0 4833 <br />
</pre><br />
<br />
==Optional: Split Calibrated Titan Data==<br />
<br />
When we {{split}} off the Titan data, a few dozen warnings like the following are written to the log:<br />
<pre><br />
2012-05-15 22:00:35 WARN split::SubMS::copySource() Invalid SOURCE ID in SOURCE table row 20 <br />
</pre><br />
These can be ignored, because they do not indicate any problem that will prevent you from imaging Titan correctly at a single position using all the data in the output ms.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Titan_cont.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='Titan_cont.ms',<br />
datacolumn='corrected',spw='0',field='1')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Titan_CO3_2.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='Titan_CO3_2.ms',<br />
datacolumn='corrected',spw='2',field='1')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Titan_unknown.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='Titan_unknown.ms',<br />
datacolumn='corrected',spw='3',field='1')<br />
</source><br />
<br />
==Continue on to Imaging of the Science Target==<br />
<br />
Now you can continue on to the [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_4.5 imaging guide].<br />
<br />
{{Checked 4.5.2}}</div>Sstierwahttps://casaguides.nrao.edu/index.php?title=TWHydraBand7_Calibration_4.5&diff=19473TWHydraBand7 Calibration 4.52016-05-18T04:10:12Z<p>Sstierwa: /* Initial Inspection and Flagging */</p>
<hr />
<div>[[Category:ALMA]][[Category:Calibration]][[Category:Spectral Line]]<br />
*'''This script assumes that you have downloaded TWHYA_BAND7_UnCalibratedMSAndTablesForReduction.tgz from [[TWHydraBand7#Getting_the_Data]]'''<br />
<br />
*'''An introduction to this data set is available at [[TWHydraBand7]].<br />
<br />
*'''This guide is designed for CASA 4.5.2 If you are using an older version of CASA please see [[TWHydraBand7_Calibration_4.3]].<br />
<br />
==Preparation==<br />
<br />
Once you have downloaded TWHYA_BAND7_UnCalibratedMSAndTablesForReduction.tgz, in a terminal unpack it with<br />
<br />
<source lang="bash"><br />
tar -zxvf TWHYA_BAND7_UnCalibratedMSAndTablesForReduction.tgz<br />
</source><br />
<br />
Please be aware that you will need about 100 GB of free space to do the data reduction. It is a good idea to check that now before you begin. Some of the plots described here require 9 GB of RAM; as little as 4 GB may be sufficient if additional data averaging is used when the plots are generated. When you are satisfied with the available drive space and memory on your machine:<br />
<br />
<source lang="bash"><br />
cd TWHYA_BAND7_UnCalibratedMSAndTablesForReduction<br />
</source><br />
<br />
'''NOTE: the calibration tables included in TWHYA_BAND7_UnCalibratedMSAndTablesForReduction CANNOT be used with CASA 4.5, they should be discarded, or moved out of the working directory.'''<br />
<br />
Then start CASA by typing 'casa' at a shell prompt. <br />
<br />
<source lang="bash"><br />
casa<br />
</source><br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.5.2. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.5.2'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
==Install Analysis Utilities==<br />
<br />
Analysis Utilities (or analysisUtils for short) is a small set of Python scripts that provide a number of analysis and plotting utilities for ALMA data reduction. This guide uses a few of these utilities. They are very easy to install (just download and untar). See <br />
<br />
http://casaguides.nrao.edu/index.php?title=Analysis_Utilities<br />
<br />
for a full description and download instructions. If you do not wish to do this, see the [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Calibration_for_CASA_3.3 CASA 3.3 version of the guide] for alternative (but slow) plotting options. Analysis Utilities are updated frequently so if its been a while since you installed it, its probably worth doing it again. If you are at an ALMA site or ARC, the analysis utilities are probably already installed and up to date.<br />
<br />
==Fix Titan's coordinates==<br />
<br />
'''Note that in the near future this step will be unnecessary.''' <br />
<br />
It is temporarily necessary to correct the positions of ephemeris objects observed during ALMA Cycle 0, because the control software revisions earlier than 9.0 erroneously write the data with coordinates of 00:00:00.0000 +00.00.00.0000 (J2000). For this dataset, we need to correct the position of the absolute flux calibrator Titan, as we can<br />
see from the first {{listobs}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -f X3c1.ms.listobs')<br />
listobs('X3c1.ms', verbose=T, listfile='X3c1.ms.listobs') <br />
</source><br />
<br />
You can view the listobs output files using command "less" from the CASA prompt.<br />
<br />
<pre style="background-color: #fffacd;"><br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 23625<br />
1 none Titan 00:00:00.00000 +00.00.00.0000 J2000 1 4842<br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 175176<br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 14832<br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 59877<br />
</pre><br />
<br />
To correct Titan's position, we will use the task [http://casa.nrao.edu/stable/docs/TaskRef/fixplanets-task.html fixplanets], which writes the actual coordinates at the instant of the first observation. This step takes a while because we are recalculating the uvw's accordingly.<br />
<source lang="python"><br />
# In CASA<br />
fixplanets(vis='X3c1.ms', field='Titan', fixuvw=True)<br />
</source><br />
<br />
Check the header information again with {{listobs}} to confirm that the information for Titan has changed:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -f X3c1.ms.listobs')<br />
listobs('X3c1.ms', verbose=T, listfile='X3c1.ms.listobs') <br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 23625<br />
1 none Titan 12:49:25.93349 -02.22.41.5638 J2000 1 4842<br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 175176<br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 14832<br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 59877<br />
</pre><br />
<br />
Now fix the other two measurement sets similarly:<br />
<source lang="python"><br />
# In CASA<br />
fixplanets(vis='X5d8.ms', field='Titan', fixuvw=True)<br />
fixplanets(vis='X7ef.ms', field='Titan', fixuvw=True)<br />
</source><br />
<br />
==Observing Log and Priors==<br />
<br />
Below is some information that may not be obvious from the data<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Like at most telescopes, the ALMA operators and astronomers at the site log any significant issues <br />
that were noticed from the online system during the observation. For these Band 7 observations of <br />
TW Hya on April 22, 2011, the only issue of note was that antenna DV04 could not observe at Band 7 <br />
and will need to be flagged. <br />
</pre><br />
<br />
First let's examine the basic properties of the data using {{listobs}}. Among other information we <br />
will be able to deduce what the source ids are and what each source was used for:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
3c279 is the bandpass calibrator (field id=0)<br />
Titan is the absolute flux calibrator (field id=1)<br />
J1147-382 is the secondary phase calibrator (field id=3)<br />
J1037-295 is the primary phase calibrator (field id=4)<br />
</pre><br />
<br />
<source lang="python"><br />
# In CASA<br />
data=['X3c1.ms','X5d8.ms','X7ef.ms']<br />
for vis in data:<br />
os.system('rm '+vis+'.listobs')<br />
listobs(vis, verbose=T, listfile=vis+'.listobs') <br />
</source><br />
<br />
You can view the {{listobs}} output files using command '''less''' from the CASA prompt. <br />
Below we copy select parts of the {{listobs}} output files for reference. <br />
<br />
<pre style="background-color: #fffacd;"><br />
X3c1.ms:<br />
Data records: 278352 Total integration time = 6109.06 seconds<br />
Observed from 22-Apr-2011/00:01:52.9 to 22-Apr-2011/01:43:42.0 (UTC)<br />
<br />
X5d8.ms:<br />
Data records: 278406 Total integration time = 5995.01 seconds<br />
Observed from 22-Apr-2011/01:48:05.8 to 22-Apr-2011/03:28:00.8 (UTC)<br />
<br />
X7ef.ms:<br />
Data records: 255717 Total integration time = 5407.49 seconds<br />
Observed from 22-Apr-2011/03:30:39.7 to 22-Apr-2011/05:00:47.2 (UTC)<br />
<br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 23625<br />
1 none Titan 12:49:25.97588 -02.22.41.3024 J2000 1 4842<br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 175176<br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 14832<br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 59877 <br />
<br />
SpwID #Chans Frame Ch1(MHz) ChanWid(kHz) TotBW(kHz) Corrs<br />
0 4 TOPO 184550 1500000 7500000 I<br />
1 128 TOPO 355740.062 15625 2000000 XX YY<br />
2 1 TOPO 356716.625 1796875 1796875 XX YY<br />
3 128 TOPO 356507.813 15625 2000000 XX YY<br />
4 1 TOPO 357484.375 1796875 1796875 XX YY<br />
5 128 TOPO 346792.187 15625 2000000 XX YY<br />
6 1 TOPO 345784.375 1796875 1796875 XX YY<br />
7 128 TOPO 345182.438 15625 2000000 XX YY<br />
8 1 TOPO 344174.625 1796875 1796875 XX YY<br />
9 128 TOPO 344386.763 15625 2000000 XX YY<br />
10 1 TOPO 343378.95 1796875 1796875 XX YY<br />
11 128 TOPO 346324.263 15625 2000000 XX YY<br />
12 1 TOPO 345316.45 1796875 1796875 XX YY<br />
13 128 TOPO 354402.388 15625 2000000 XX YY<br />
14 1 TOPO 355378.95 1796875 1796875 XX YY<br />
15 128 TOPO 356402.388 15625 2000000 XX YY<br />
16 1 TOPO 357378.95 1796875 1796875 XX YY<br />
17 3840 TOPO 356497.936 122.070312 468750 XX YY<br />
18 1 TOPO 356732.189 468750 468750 XX YY<br />
19 3840 TOPO 357734.314 122.070312 468750 XX YY<br />
20 1 TOPO 357499.939 468750 468750 XX YY<br />
21 3840 TOPO 346034.314 122.070312 468750 XX YY<br />
22 1 TOPO 345799.939 468750 468750 XX YY<br />
23 3840 TOPO 343955.936 122.070312 468750 XX YY<br />
24 1 TOPO 344190.189 468750 468750 XX YY<br />
<br />
Antennas: 9:<br />
Name Station Diam. Long. Lat.<br />
0 DV04 J505 12.0 m -067.45.18.0 -22.53.22.8<br />
1 DV06 T704 12.0 m -067.45.16.2 -22.53.22.1<br />
2 DV07 J510 12.0 m -067.45.17.8 -22.53.23.5<br />
3 DV08 T703 12.0 m -067.45.16.2 -22.53.23.9<br />
4 DV09 N602 12.0 m -067.45.17.4 -22.53.22.3<br />
5 DV10 N606 12.0 m -067.45.17.1 -22.53.23.6<br />
6 PM01 T702 12.0 m -067.45.18.6 -22.53.24.1<br />
7 PM02 T701 12.0 m -067.45.18.8 -22.53.22.2<br />
8 PM03 J504 12.0 m -067.45.17.0 -22.53.23.0<br />
</pre><br />
<br />
Things to Notice from above: <br />
*There are three different data sets acquired close together in time. We will calibrate each dataset independently and then combine the calibrated data prior to imaging. <br />
*Titan appears to have slightly different positions in each dataset because it is a moving body. In fact, at the time of observation, due to temporary data capture issue in the ALMA system, the position was written has (0,0). We have pre-corrected this error using fixplanets. Later in the tutorial, we will run fixplanets again to force all three datasets to have the same fixed position for Titan.<br />
*There are a lot of spectral windows! Don't be alarmed. In ALMA data, <br />
**spw=0 is always reserved for the water vapor radiometry data.<br />
**spw=9, 11, 13, 15 are the wideband (TDM) correlator mode with 128 channels per spw default settings for doing pointing and this is all they are used for in these data.<br />
**Currently Tsys data can only be taken in the wide (TDM) correlator mode with 128 channels per spw, these correspond to spws=1, 3, 5, 7 above. The frequencies of these TDM spws were carefully chosen so the the narrowband FDM spws fall within them.<br />
** The 0.5 GHz, high spectral resolution spws that contain all the real source data (science target and calibrators) are 17, 19, 21, and 23<br />
**For quicklook purposes, the ALMA online system produces a channel averaged spw for each channelized spw, these correspond to spw=2,4,6,8,10,12,14,16,18,20,22,24 and shouldn't be used for anything in post-processing as bandpass calibration etc has not been applied.<br />
<br />
In the portion of the {{listobs}} output that shows the timerange, the final column gives the scan intent. It is important to have a look at this because you can flag and do other operations in CASA using the scan intent as a selection option. Also, these intents will be used in the future for pipeline processing. You will usually want to use them to flag the CALIBRATE_POINTING* and CALIBRATE_ATMOS* (the latter correspond to the hot and cold load measurements used to calculate Tsys) data. This is essential for science or calibration data taken only in TDM (wide bandwidth) mode, i.e. the same mode that the pointing and Tsys data are taken in. For the current data however, that calibration data is recorded in different spws from the useful FDM (narrow bandwidth) data, so we'll be able to separate them by splitting them off at the final step prior to imaging.<br />
<br />
<figure id="Ant_pos.png"><br />
[[Image:Ant_pos.png|thumb|<caption>Antenna locations for the first dataset.</caption>]]<br />
</figure><br />
<br />
Before we move on, its also nice to get an idea where the antennas are with respect to each other. We can use {{plotants}} to plot their positions. It is a good idea to check each file since an antenna may have entered or exited the array between observations.<br />
<source lang="python"><br />
# In CASA<br />
for vis in data:<br />
plotants(vis=vis,figfile=vis+'.plotants.png')<br />
</source><br />
<br />
You can view the output images using any standard image viewer.<br />
<br />
==Create the Tsys and WVR Tables, and Examine ==<br />
<br />
Each ms include tables that contain the Tsys and WVR measurements associated with the visibility data.<br />
We must create calibration tables from these measurements. First we create the WVR calibration tables <br />
by running the task [http://casa.nrao.edu/stable/docs/TaskRef/wvrgcal-task.html wvrgcal]. This task <br />
examines the data for each ms as a whole and creates a calibration<br />
table containing only phase corrections for each antenna and spw. <br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
os.system('rm -rf '+asdm+'.wvr')<br />
wvrgcal(vis=asdm+'.ms', caltable=asdm+'.wvr', segsource=True, toffset=-1)<br />
</source><br />
<br />
Next we create the Tsys tables by running {{gencal}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
os.system('rm -rf '+asdm+'.tsys')<br />
gencal(vis=asdm+'.ms', caltable=asdm+'.tsys', caltype='tsys')<br />
</source><br />
<br />
It is very important that Tsys measurements taken as close in time and elevation as possible to a particular source are applied. To save telescope time, Tsys measurements are sometimes intentionally skipped in the scheduling block for specific sources. So the first step is to establish which sources have their own Tsys measurements and which do not. To do this, you may use the intent parameter of {{listobs}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
listobs(vis=asdm+'.ms', verbose=F, selectdata=True, intent='CALIBRATE_ATMOS*')<br />
</source><br />
<br />
<figure id="X3c1.tsys_vs_time_3.4.png"><br />
[[File:X3c1.tsys_vs_time_3.4.png|thumb|<caption>Tsys vs. time for spw 1 of the X3c1.ms data.</caption>]]<br />
</figure><br />
<figure id="X5d8.tsys_vs_time_3.4.png"><br />
[[File:X5d8.tsys_vs_time_3.4.png|thumb|<caption>Tsys vs. time for spw 1 of the X5d8.ms data.</caption>]]<br />
</figure><br />
<figure id="X7ef.tsys_vs_time_3.4.png"><br />
[[File:X7ef.tsys_vs_time_3.4.png|thumb|<caption>Tsys vs. time for spw 1 of the X7ef.ms data.</caption>]]<br />
</figure><br />
<br />
<pre style="background-color: #fffacd;"><br />
Fields: 4<br />
ID Code Name RA Decl Epoch SrcId nRows <br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 1116 <br />
1 none Titan 12:49:25.97588 -02.22.41.3024 J2000 1 1125 <br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 6795 <br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 6777 <br />
Spectral Windows: (9 unique spectral windows and 2 unique polarization setups)<br />
SpwID #Chans Frame Ch1(MHz) ChanWid(kHz) TotBW(kHz) Corrs <br />
0 4 TOPO 184550 1500000 7500000 I <br />
1 128 TOPO 355740.062 15625 2000000 XX YY <br />
2 1 TOPO 356716.625 1796875 1796875 XX YY <br />
3 128 TOPO 356507.813 15625 2000000 XX YY <br />
4 1 TOPO 357484.375 1796875 1796875 XX YY <br />
5 128 TOPO 346792.187 15625 2000000 XX YY <br />
6 1 TOPO 345784.375 1796875 1796875 XX YY <br />
7 128 TOPO 345182.438 15625 2000000 XX YY <br />
8 1 TOPO 344174.625 1796875 1796875 XX YY <br />
</pre><br />
<br />
Because field '3' (the secondary phase calibrator) does not appear in the list, it has no tsys. Since the secondary phase calibrator is close on the sky to the primary phase calibrator and observed near in time, we will transfer the Tsys from the primary to the secondary phase calibrator. <br />
Also notice that spws 1,3,5,7 are the only multi-channel spws that contain Tsys data. At present, Tsys measurements can only be obtained with TDM spectral setups (128 channels/dual pol). Because our science target is observed in FDM (3840 channels/dual pol), we will need to interpolate the measurements from TDM to FDM. But first, to inspect the Tsys vs. time, we use {{plotcal}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all = ['X3c1','X5d8','X7ef']<br />
tsysfields=['0','1','2','4']<br />
os.system('mkdir cal_plots; mkdir cal_plots/Tsys_plots') <br />
for asdm in basename_all:<br />
print "Plotting Tsys vs. time for "+asdm<br />
plotcal(caltable=asdm+'.tsys', xaxis='time',yaxis='tsys',<br />
antenna='1~8',plotrange=[0,0,100,500],<br />
iteration='antenna',subplot=421,poln='',spw='1:50~50',<br />
figfile='cal_plots/Tsys_plots/'+asdm+'.tsys_vs_time.png')<br />
if (asdm != basename_all[-1]):<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
To inspect Tsys vs. frequency, we use [[plotbandpass]]. There are many different options for plotbandpass, and we demonstrate some of the most useful ones. The option '''showtsky=T''' will overlay the effective temperature curve from the atmospheric model. This shows us the location of any atmospheric lines which will appear as emission lines in the autocorrelation data (from which the Tsys spectra are derived) from all antennas. In the<br />
example below, we set '''interactive=False''', which will produce many pages of plots as<br />
individual pngs but will only show the final page in the graphics window. To view all the pages we use the image viewer '''eog''' (Eye of GNOME) available on Linux. The alternative is to set '''interactive=True''' and examine the plots in the casa graphics window as they are produced.<br />
<br />
<figure id="X3c1.tsys.field0.DV04.spw1.t1.png"><br />
[[File:X3c1.tsys.field0.DV04.spw1.t1.png|thumb|<caption>Tsys vs. frequency on 3C279 for the X3c1.ms data, spw=1.</caption>]]<br />
</figure><br />
<figure id="X3c1.tsys.field0.DV04.spw3.t1.png"><br />
[[File:X3c1.tsys.field0.DV04.spw3.t1.png|thumb|<caption>Tsys vs. frequency on 3C279 for the X3c1.ms data, spw=3.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
print "Plotting Tsys vs. frequency for "+asdm<br />
for spw in [1,3,5,7]:<br />
for field in ['0','1']:<br />
plotbandpass(caltable=asdm+'.tsys', xaxis='freq',yaxis='amp',<br />
showtsky=T,subplot=42,field=field,<br />
spw=spw, interactive=False, plotrange=[0,0,0,0],<br />
figfile='cal_plots/Tsys_plots/'+asdm+'.tsys.field%s.png'%field,<br />
buildpdf=False)<br />
</source><br />
<br />
In <xr id="X3c1.tsys.field0.DV04.spw1.t1.png"/> and <xr id="X3c1.tsys.field0.DV04.spw3.t1.png"/> we see the effect of atmospheric ozone lines on the Tsys measurements associated with 3C279 in spw 1 and 3.<br />
<br />
For sources that have multiple Tsys measurements (typically the primary phase calibrator and/or the science target) one can use '''overlay="time"''' to overlay all the measurements for that source. This can help to identify any anomalous Tsys scans. As a fraction of the plots produced by this loop, here we show the Tsys recorded on spw=1 for TW Hya from the first dataset.<br />
<br />
<figure id="X3c1.tsys.field2.DV04.spw1.png"><br />
[[File:X3c1.tsys.field2.DV04.spw1.png|thumb|<caption>Tsys vs. freq for field 2, spw 1 of the X3c1.ms data (antennas 0..3).</caption>]]<br />
</figure><br />
<figure id="X3c1.tsys.field2.DV04.spw1.png"><br />
[[File:X3c1.tsys.field2.DV09.spw1.png|thumb|<caption>Tsys vs. freq for field 2, spw 1 of the X3c1.ms data (antennas 4..7).</caption>]]<br />
</figure><br />
<figure id="X3c1.tsys.field2.PM03.spw1.png"><br />
[[File:X3c1.tsys.field2.PM03.spw1.png|thumb|<caption>Tsys vs. freq for field 2, spw 1 of the X3c1.ms data (antenna 8).</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
print "Plotting Tsys vs. frequency for "+asdm<br />
for spw in [1,3,5,7]:<br />
for field in ['2','4']:<br />
plotbandpass(caltable=asdm+'.tsys', xaxis='freq',yaxis='amp',<br />
showtsky=T,subplot=22,field=field,<br />
overlay='time',spw=spw, interactive=False, plotrange=[0,0,0,0],<br />
figfile='cal_plots/Tsys_plots/'+asdm+'.tsys.field%s.png'%field,<br />
buildpdf = False)<br />
</source><br />
<br />
Alternatively, the '''overlay="antenna"''' option will quickly reveal any Antennas with discrepant Tsys values, as they<br />
will be obvious outliers. For FDM projects like this one, using the '''showfdm=True''' option can be helpful, as it<br />
will show where in the TDM bandpass each FDM spw was located. <br />
<figure id="X3c1.tsys.field0.spw1.t1.png"><br />
[[Image:X3c1.tsys.field0.spw1.t1.png|thumb|<caption>Tsys vs Freq for field 0, spw 1 of the X3c1.ms data with all antennas overlaid.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
tsysfields=['0','1','2','4'] <br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
print "Plotting Tsys vs. frequency for "+asdm<br />
for spw in [1,3,5,7]:<br />
for field in tsysfields:<br />
plotbandpass(caltable=asdm+'.tsys', xaxis='freq',yaxis='amp',<br />
showtsky=T,subplot=11,field=field,<br />
overlay='antenna',spw=spw, interactive=False,<br />
figfile='cal_plots/Tsys_plots/'+asdm+'.tsys.field%s.png'%field,<br />
buildpdf=False,showfdm=True)<br />
</source><br />
<br />
<br />
Note that DV04 consistently has a significantly higher Tsys than the rest of the antennas. We already know from the Observation log that<br />
we need to flag that antenna, but had we not had that information, examining this plot would have demonstrated the situation.<br />
<br />
==Apply the Tsys and WVR Tables, and Split ==<br />
<br />
Next we apply the calibrations. For the (4) sources with Tsys measurements, we use the '''field''' and '''gainfield''' parameters of {{applycal}} to apply solutions only to themselves. {{applycal}} has the ability to interpolate gain tables from one spw onto another spw. In this case, we want to interpolate the TDM Tsys values in spws 1,3,5,7 onto the FDM spws 17,19,21,23. We use the '''interp''' parameter to request linear interpolation in the time dimension and spline interpolation in the channel/frequency dimension. To map the solutions for each spw, we use the '''spwmap''' parameter, which requires a list of all spws for each gain table to be applied, or a blank list ([]) which is a shorthand notation to apply the solution for each spw to itself. While applying Tsys, we will also apply the wvr calibration tables; wvr data is usually always present for all sources. Below we first set some definitions so we can loop over the correct parameters:<br />
<br />
<source lang="python"><br />
# In CASA<br />
fdm='17,19,21,23'<br />
nocal='3' # This source had no Tsys measurements associated with it <br />
tsysfields=['0','1','2','4'] <br />
tsysmap = range(25)<br />
tsysmap[17] = 1<br />
tsysmap[19] = 3<br />
tsysmap[21] = 5<br />
tsysmap[23] = 7<br />
for asdm in basename_all:<br />
for field in tsysfields:<br />
applycal(vis=asdm+'.ms', spw=fdm, field=field, gainfield=field,<br />
gaintable=[asdm+'.tsys', asdm+'.wvr'], spwmap=[tsysmap,[]],<br />
interp=['linear,spline','nearest'], flagbackup=F, calwt=T)<br />
</source><br />
<br />
For the sources without Tsys (i.e. field=3), couple them with the best available source with Tsys (i.e. field=4).<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename_all:<br />
applycal(vis=asdm+'.ms', spw=fdm, field=nocal,<br />
gaintable=[asdm+'.tsys', asdm+'.wvr'], spwmap=[tsysmap,[]],<br />
gainfield=['4',nocal], interp=['linear,spline','nearest'],flagbackup=F,<br />
calwt=T)<br />
</source><br />
<br />
Check Tsys application with plotms. First we make plots with '''ydatacolumn='data'''' to look at the raw data. For <br />
simplicity we'll just look at the two strongest sources 3C279 and Titan.<br />
<br />
<figure id="X5d8_wvrtsys_corrected_spw19.png"><br />
[[Image:X5d8_wvrtsys_corrected_spw19.png|thumb|<caption>Spectral plots of 3C279 (black) and Titan (magenta) for spw=19 after Tsys and wvr correction.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X5d8.ms',spw='17,19,21,23',xaxis='frequency',yaxis='amp',field='0,1',<br />
antenna='*&*',avgtime='1e8',avgscan=T,coloraxis='field',iteraxis='spw',<br />
xselfscale=T,ydatacolumn='data')<br />
</source><br />
<br />
<figure id="X5d8_wvrtsys_corrected_spw21.png"><br />
[[Image:X5d8_wvrtsys_corrected_spw21.png|thumb|<caption>Spectral plots of 3C279 (black) and Titan (magenta) for spw=21 after Tsys and wvr correction.</caption>]]<br />
</figure><br />
<br />
'''Note''': the antenna='*&*' is specifying that we only want to see the cross-correlation data (i.e. not the autocorrelations).<br />
<br />
Use the '''green arrows''' on the {{plotms}} display to cycle through the 4 FDM spws. <br />
<br />
Now change '''Data Column''' to '''corrected''' on the "Axes" tab (this is the same as ydatacolumn in the task) and hit '''Plot''' button on the GUI. Flip through again.<br />
<br />
'''Things to notice:'''<br />
* The amplitude scale has changed due to application of Tsys<br />
* spw=17 is clean and flat<br />
* spw=19 shows a strong dip around channel 3000 (channels can be plotted by going to the Axes tab, and changing X Axis to Channel, then hit the Plot button)-- this is an atmospheric ozone absorption feature at 357.6 GHz. In the future, high spectral resolution Tsys measurements may help to remove the shape of the absorption, but until then we will need to flag this part of the spectrum.<br />
* spw=21 Titan shows both a narrow and a broad spectral feature. The broad feature is CO(3-2) and it completely fills the 0.5 GHz band so there are no line-free channels! Titan must be handled carefully when it is used as a calibrator because it contains strong line emission. Indeed, we will not be able to use the absolute flux transfer from this spw for other targets. When possible Titan should be avoided for absolute flux calibration. For these observations, no other suitable absolute flux calibrator was available.<br />
* spw=23 shows another strong line from Titan.<br />
<br />
Beyond these things to notice, the application of Tsys and wvr seem to have gone well. We can now split off only the narrow band FDM spectral windows for further processing.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename_all:<br />
newvis = asdm + '_wvrtsys.ms'<br />
os.system('rm -rf ' + newvis)<br />
split(vis=asdm+'.ms',outputvis=newvis,datacolumn='corrected',spw=fdm)<br />
</source><br />
<br />
'''Note''': After {{split}}, the spectral windows will be renumbered to 0, 1, 2, 3 corresponding to the old spw=17, 19, 21, 23, see {{listobs}} excerpt below.<br />
<br />
<pre style="background-color: #fffacd;"><br />
SpwID #Chans Frame Ch1(MHz) ChanWid(kHz) TotBW(kHz) Corrs <br />
0 3840 TOPO 356497.936 122.070312 468750 XX YY <br />
1 3840 TOPO 357734.314 122.070312 468750 XX YY <br />
2 3840 TOPO 346034.314 122.070312 468750 XX YY <br />
3 3840 TOPO 343955.936 122.070312 468750 XX YY <br />
</pre><br />
<br />
==Initial Inspection and Flagging==<br />
<br />
From here we begin to operate on the *wvrtsys.ms files. <br />
<br />
Before we begin flagging data, we unflag all data in the measurement sets. If this is your first pass through this section of the guide, no data in the measurement sets will have previously been flagged, and so you can skip the next splitdata step with mode set to 'unflag'. If you are rerunning the flagging commands below, running splitdata in 'unflag' mode will reset your flag columns to their original state.<br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
for vis in splitdata:<br />
flagdata(vis=vis, mode='unflag', action='apply', flagbackup=F)<br />
</source><br />
<br />
ALMA data contains both the cross correlation and autocorrelation data. Presently nothing more can be done with the autocorrelation data so we flag it. Additionally, for smaller configurations of the array, and northerly sources one antenna can ''shadow'' another, blocking its view. This data also needs to be flagged. Finally, the observing log told us DV04 was not behaving properly at Band 7 and shouldn't be used so we flag that as well.<br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
for vis in splitdata:<br />
flagdata(vis=vis, mode='manual', autocorr=True, action = 'apply', flagbackup=T)<br />
flagdata(vis=vis, mode='shadow',tolerance=12.0, action='apply', flagbackup=F)<br />
flagdata(vis=vis, mode='manual', antenna='DV04', action='apply', flagbackup=F)<br />
</source><br />
<br />
Next we inspect the data with {{plotms}} for additional issues that need flagging, first looking at amplitude vs. time for each of the three datasets. Use the '''green''' arrows on the plotms gui to cycle through spws. <br />
<br />
<figure id="Tsyswvr_time_spw0_X3x1.png"><br />
[[Image:Tsyswvr_time_spw0_X3x1.png|thumb|<caption>Amplitude as a function of time for X3c1_wvrtsys.ms, spw=0</caption>]]<br />
</figure><br />
<br />
'''Note''': when '''iteraxis''' is invoked in {{plotms}}, unzoom does not always work properly. If you have trouble with this, flip to next page and then back to current one. This usually fixes the problem.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X5d8_wvrtsys.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X7ef_wvrtsys.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw')<br />
</source><br />
<br />
<figure id="Tsyswvr_time_spw2corr_X3x1.png"><br />
[[Image:Tsyswvr_time_spw2corr_X3x1.png|thumb|<caption>Amplitude as a function of time for X3x1_wvrtsys.ms, spw=2 with colorize='corr'.</caption>]]<br />
</figure><br />
<br />
'''Things to Notice:'''<br />
* In spw=2 there are some low points in all three data files. Use the "Mark Regions" box (left of center on bottom row of icons) to draw small box on low points. Then click the magnifying glass icon to the right of center. The output will be sent to the logger window. '''Note''': keep the marked region small or you can overwhelm the buffer. Locate suggests correlation YY on PM03 is the culprit. <br />
<br />
To see this more clearly you can rerun {{plotms}} with '''coloraxis='field'''' switched to '''coloraxis='corr''''<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='2',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='corr')<br />
</source><br />
<br />
To further check, you can exclude PM03 from the plot using '''antenna='!PM03'.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='2',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='corr',antenna='!PM03')<br />
</source><br />
<br />
Having confirmed the problem antenna, we flag it below. <br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
for vis in splitdata:<br />
flagdata(vis=vis, mode='manual', action= 'apply', flagbackup=T,<br />
spw='2',<br />
antenna='PM03',<br />
correlation='YY')<br />
</source><br />
<br />
'''Next we need to inspect the spectral properties of the data to look for issues.'''<br />
<br />
First we look at phase as a function of frequency for a well behaved antenna like DV06. <br />
'''coloraxis='baselines'''' (note this parameter is called '''Colorize''' in the GUI "Display" tab) will show each baseline as a different color. Significant delay errors or baseline errors will show up as phase slopes in these plots. Again you will want to page through the spectral windows.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='',xaxis='frequency',yaxis='phase',field='0',antenna='DV06',<br />
avgtime='1e8',avgscan=T,coloraxis='baseline',iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X5d8_wvrtsys.ms',spw='',xaxis='frequency',yaxis='phase',field='0',antenna='DV06',<br />
avgtime='1e8',avgscan=T,coloraxis='baseline',iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X7ef_wvrtsys.ms',spw='',xaxis='frequency',yaxis='phase',field='0',antenna='DV06',<br />
avgtime='1e8',avgscan=T,coloraxis='baseline',iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
Overall these plots look good with no large delays or baseline errors apparent.<br />
<br />
<figure id="Birdies_spw2_X3x1.png"><br />
[[Image:Birdies_spw2_X3x1.png|thumb|<caption>Phase calibrators (brown and green) and TW Hya (orange) showing both real CO(3-2) emission in TW Hya and weak ''birdie'' spectral features in all three sources for spw=2.</caption>]]<br />
</figure><br />
<br />
With such high spectral resolution data, one often sees occasional "birdies" in the data. These are typically very narrow weak spectral features that are internally generated in the system. Over time as we track down issues the number of birdies should decrease, but you should always check. This is easiest to do by looking at amplitude vs. frequency for sources observed over a long time range (for sensitivity). It is helpful to look at more than one source to verify the nature of the emission. Below we look at both calibrators (brown and green) and TW Hya (orange). If you have enough sensitivity birdies should be seen on all sources, however, be careful not to mistake real line emission for a birdie even on a calibrator - they can be present as we've seen for Titan.<br />
<br />
<figure id="Birdies_spw3_X3x1.png"><br />
[[Image:Birdies_spw3_X3x1.png|thumb|<caption>Phase calibrators (brown and green) and TW Hya (orange) showing only weak birdie spectral features in spw=3.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='',xaxis='channel',yaxis='amp',field='2,3,4',<br />
avgtime='1e8',avgscan=T,coloraxis='field',iteraxis='spw',xselfscale=T,yselfscale=T)<br />
</source><br />
<br />
Do a quick check that other two datasets are the same (they are usually similar if the source of internal resonance hasn't changed in the meantime).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X5d8_wvrtsys.ms',spw='',xaxis='channel',yaxis='amp',field='2,3,4',<br />
avgtime='1e8',avgscan=T,coloraxis='field',iteraxis='spw',xselfscale=T,yselfscale=T)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X7ef_wvrtsys.ms',spw='',xaxis='channel',yaxis='amp',field='2,3,4',<br />
avgtime='1e8',avgscan=T,coloraxis='field',iteraxis='spw',xselfscale=T,yselfscale=T)<br />
</source><br />
<br />
Now you can zoom in on each region to get channels for flagging, or to save time just go ahead and run the flagging command below where this has been done for you.<br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
for vis in splitdata:<br />
flagdata(vis=vis, mode='manual', action='apply', flagbackup=T,<br />
spw='0:1067~1068;1279~1280;2367~2368;3775~3776, 1:1279~1280;2367~2368;3775~3776, 2:1279~1280;3775~3776, 3:831~832;1535~1536;2367~2368;3775~3776;3839~3839')<br />
</source><br />
<br />
Replot in {{plotms}} to check that flagging has been done as anticipated.<br />
<br />
==Flag Calibrator Spectral Features==<br />
<br />
In this section, we will flag spectral features in the calibrators so they do not skew the calibration solutions. First make plots of 3C279 and Titan in channel space to get channels for flagging. <br />
<br />
<figure id="3C279_Titan_spw1.png"><br />
[[Image:3C279_Titan_spw1.png|thumb|<caption>Spectral plots of 3C279 (black) and Titan (magenta) for spw=1 after Tsys and wvr correction.</caption>]]<br />
</figure><br />
<figure id="3c279_meso_freq.png"><br />
[[Image:3c279_meso_freq.png|thumb|<caption>Zoomed spectral plot of 3C279 showing mesospheric absorption of CO(3-2) in frequency space.</caption>]]<br />
</figure><br />
<figure id="3c279_meso_chann.png"><br />
[[Image:3c279_meso_chann.png|thumb|<caption>Zoomed spectral plot of 3C279 showing mesospheric absorption of CO(3-2) in channel space.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='channel',yaxis='amp',field='0,1',<br />
avgtime='1e8',coloraxis='field',iteraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
The figure to the right shows a broad absorption line in spw 1 at channel 3000. This is the ozone absorption line at 357.62982 GHz. However, there is another narrow absorption feature in the spectra (spw 2) that is most easily seen on 3C279 (because it is the strongest calibrator). Let's look at it first in frequency space.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='2:1600~2300',xaxis='frequency',yaxis='amp',<br />
field='0',avgtime='1e8',coloraxis='field')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
The absorption feature lies exactly at the rest frequency for CO 3-2 (345.79599 GHz). Because it is so narrow (< 1 MHz), it must originate from a very low pressure region (i.e. high altitude) in the Earth's atmosphere, otherwise it would be more pressure broadened. Indeed, the first detection of CO in the mesosphere was made over 35 years ago (see, e.g. [http://adsabs.harvard.edu/abs/1976Sci...191.1174W Waters et al. 1976] or [http://adsabs.harvard.edu/abs/1979JGR....84..416G Goldsmith et al. 1979]). Be aware that the line is stronger as you go up the CO ladder (strength ~ J^3 for low J) because the temperature at that altitude (~50km) is about 250 K. In April 2011, the apparent depth of the feature was about 10% in the 2-1 line and 35% in the 3-2 line. However, the depth of the absorption feature is exaggerated due to the way ALMA normalizes the cross-correlation spectra by the autocorrelation spectra prior to storage. While this technique generally leads to a flat bandpass shape, it will accentuate telluric features because they are emission lines in the single dish spectrum (e.g. JCMT observations of mesospheric CO 3-2 can be found in [http://adsabs.harvard.edu/abs/1993MNRAS.264..673P Preston et al. 1993]). Finally, note that large seasonal variations in the line strength have been reported from observations at [http://adsabs.harvard.edu/abs/2003GeoRL..30j..39F Onsala]. <br />
<br />
Now, let's re-plot the line with channel number as the x-axis in order to get the channel range for flagging. <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='2:1600~2300',xaxis='channel',yaxis='amp',<br />
field='0',avgtime='1e8',coloraxis='field')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Now lets look at Titan in more detail.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='channel',yaxis='amp',field='1',<br />
avgtime='1e8',coloraxis='field',iteraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Explicitly back up the flag tables so that flagged regions can be restored later.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
flagmanager(vis=asdm+'.ms',mode='save',versionname=asdm+'.before_calspectralflags')<br />
</source><br />
<br />
<figure id="Titan_spw2.png"><br />
[[Image:Titan_spw2.png|thumb|<caption>Spectral plot of Titan (magenta) for spw=2.</caption>]]<br />
</figure><br />
<br />
Flag absorption features for all sources.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
print "Flagging absorption features in all sources for "+asdm<br />
flagdata(vis=asdm+'.ms', mode='manual', spw='1:2000~3839, 2:1945~1960')<br />
</source><br />
<br />
<figure id="Titan_spw3.png"><br />
[[Image:Titan_spw3.png|thumb|<caption>Spectral plot of Titan (magenta) for spw=3.</caption>]]<br />
</figure><br />
<br />
Now we need to flag emission. The very broad CO(3-2) in spw=2 of Titan will prevent us from using it as a calibrator for this spectral window since there are no line-free channels (we will transfer, phase, amplitude, and absolute flux from another Titan spw below). We do want to flag the narrower Titan line in spw=3.<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
flagmanager(vis=asdm+'.ms',mode='save',versionname=asdm+'.before_emissionflags')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
print "Flagging emission for "+asdm<br />
flagdata(vis=asdm+'.ms', mode='manual', <br />
field='1',<br />
spw='3:1000~3000')<br />
</source><br />
<br />
If you like, check that the right things have been flagged.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='channel',yaxis='amp',field='0,1',<br />
avgtime='1e8',coloraxis='field',iteraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
==Set Up the Flux Calibrator Model==<br />
<br />
Fill the model data column for Titan with a model for the flux density as a function of baseline. The model is a uniformly illuminated disk with the size obtained from the JPL Horizons ephemeris.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
setjy(vis=asdm+'.ms',field='1',usescratch=F,<br />
standard='Butler-JPL-Horizons 2010',scalebychan=F)<br />
</source><br />
<br />
<figure id="Titan amp vs uvdist.png"><br />
[[Image:Titan amp vs uvdist.png|thumb|<caption>Plot of Titan model for each of the 4 spws. We used the Butler-JPL-Horizons 2010 standard to compute this model.</caption>]]<br />
</figure><br />
<br />
After running setjy, it is a good idea to plot the model in order to confirm that it makes sense. In this case, Titan is partially resolved, so we expect the flux density to drop with uv distance, but not so much as to pass through a null. We also expect it to be brighter at higher frequencies since it has a thermal blackbody spectrum.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',field='1',xaxis='uvdist',yaxis='amp',coloraxis='spw',<br />
ydatacolumn='model')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<figure id="twhydra_X3c1_wvrtsys_2012_titan_model.png">[[File:twhydra_X3c1_wvrtsys_2012_titan_model.png|thumb|right|<caption>Titan model produced by 'Butler-JPL-Horizons 2012'.</caption>]]</figure><br />
<br />
<br/><br />
<div class="noprint" style="float:none; border:0px solid blue;background-color:#F6CEF5;padding:2px;"><br />
The setjy invocation, above, uses the flux density standard '''standard='Butler-JPL-Horizons 2010' '''. A more updated standard is also available: '''standard='Butler-JPL-Horizons 2012' '''. <xr id="twhydra_X3c1_wvrtsys_2012_titan_model.png"/> shows the Titan model produced using the updated standard. The motivated reader may wish to rerun {{setjy}} using the updated model. We will highlight later in this tutorial, and in the imaging tutorial that follows, the effects of using the updated model.<br />
</div><br />
<br />
==Bandpass Calibration==<br />
<br />
First we need to check how the amplitude and phase of 3C279 behave as a function of time. In order to set<br />
a fixed scale on the y-axis, we first make a plot of all the data, excluding antenna DV04. (We must specify '''ydatacolumn='data' ''' explicitly here because the default value of '''ydatacolumn''' equals the value used in the previous execution of {{plotms}}. In the previous execution '''ydatacolumn''' was set to '''model'''. See the online help, <tt>help plotms</tt>, for details.)<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',xaxis='time',yaxis='amp',coloraxis='corr',<br />
field='0',avgchannel='3840',ydatacolumn='data')<br />
</source><br />
<br />
<figure id="ThreeScansAmp.png"><br />
[[Image:ThreeScansAmp.png|thumb|<caption>Amplitude variation for three 3C279 scans, spw 0 (for one representative baseline).</caption>]]<br />
</figure><br />
<br />
We see that the uncalibrated amplitudes range between 0.2-0.4, so let's set this as our<br />
scale and examine a representative baseline (DV06-DV07) to see how the amplitude changes with time. <br />
<br />
<source lang="python"><br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for spw in ['0','1','2','3']:<br />
for asdm in basename:<br />
print "Now showing spw %s from %s" % (spw, asdm+'.ms')<br />
plotms(vis=asdm+'.ms',spw=spw,xaxis='time',yaxis='amp',coloraxis='corr',iteraxis='spw',<br />
field='0',avgchannel='3840',antenna='DV06&DV07',plotrange=[0,0,0.2,0.4])<br />
user_check=raw_input('press enter to go to the next plot\n')<br />
</source><br />
<br />
<figure id="ThreeScansPhase.png"><br />
[[Image:ThreeScansPhase.png|thumb|<caption>Phase variation for three 3C279 scans, spw 0 (for one representative baseline).</caption>]]<br />
</figure><br />
<br />
Page through the measurement sets for each spw. This shows significant variations in the amplitude across the three measurement sets.<br />
Now do the same with phase.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for spw in ['0','1','2','3']:<br />
for asdm in basename:<br />
print "Now showing spw %s from %s" % (spw, asdm+'.ms')<br />
plotms(vis=asdm+'.ms',spw=spw,xaxis='time',yaxis='phase',coloraxis='corr',iteraxis='spw',<br />
field='0',avgchannel='3840',antenna='DV06&DV07',plotrange=[0,0,-180,180])<br />
user_check=raw_input('press enter to go to the next plot\n')<br />
</source><br />
<br />
This examination reveals two findings: (1) significant variation in the phase across the three scans, as well as (2) smaller but significant variations within a scan. The first finding suggests that we do not want to combine the scans for bandpass calibration, but instead derive an independent bandpass for each scan. Actually what is more important than a DC offset is if the '''shape''' of the amplitude or phase changes from scan to scan. There isn't enough S/N to tell for sure so we will keep them separate. This situation is often the case, which is why we did not concatenate the three datasets prior to calibration. The second finding suggests that we need to correct the phase vs. time behavior of the bandpass calibrator (3C279; field=0) within each scan, before doing the bandpass. We want to chose a relatively narrow range of channels near the center of the spws so that the bandpass phase slopes (to be corrected with the bandpass calibration itself) do not decorrelate the signal. You need to avoid spectral regions that were completely flagged above.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.bpphase.gcal')<br />
gaincal(vis=asdm+'.ms',caltable=asdm+'.bpphase.gcal',<br />
field='0',spw='0~3:900~1100',refant='DV06',<br />
calmode='p',solint='int',minsnr=2.0,minblperant=4)<br />
</source><br />
<br />
<figure id="X7ef_wvrtsys.bpphase.X.png"><br />
[[Image:X7ef_wvrtsys.bpphase.X.png|thumb|<caption>Phase only solutions for correlation X on the third scan of the bandpass calibrator 3C279.</caption>]]<br />
</figure><br />
<br />
Inspect the phase-only calibration solutions for the bandpass calibrator. Look for any noisy solutions. We do XX and YY separately to reduce confusion in the plot. It will help if you make your plotcal window wide.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.bpphase.gcal',xaxis='time',yaxis='phase',spw='',antenna='1~8', <br />
iteration='antenna',subplot=421,plotrange=[0,0,-180,180],<br />
figfile=asdm+'.bpphase.X.png',poln='X')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
In the plotcal gui you can use the magnifying glass symbol to zoom in on one of the scans to see the phase variations. The colors are the 4 different spws.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.bpphase.gcal',xaxis='time',yaxis='phase',spw='',antenna='1~8', <br />
iteration='antenna',subplot=421,plotrange=[0,0,-180,180],<br />
figfile=asdm+'.bpphase.Y.png',poln='Y')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Next we apply this phase-only correction on the fly while calculating the bandpass solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.bandpass.bcal')<br />
bandpass(vis=asdm+'.ms',caltable=asdm+'.bandpass.bcal',<br />
field='0',spw='',combine='',refant='DV06',<br />
solint='inf',solnorm=T,minblperant=4, bandtype='B', fillgaps=17,<br />
gaintable=asdm+'.bpphase.gcal')<br />
</source><br />
<br />
You will see some error messages in the terminal, these are just related to the flagged channels. We set fillgaps=17 to interpolate across the smaller regions of flagged channels (mesospheric features and birdies).<br />
<br />
<figure id="Bandpass.ampspw0.png"><br />
[[Image:Bandpass.ampspw0.png|thumb|<caption>Bandpass amplitude solution plots.</caption>]]<br />
</figure><br />
<figure id="Bandpass.phasespw0.png"><br />
[[Image:Bandpass.phasespw0.png|thumb|<caption>Bandpass phase solution plots.</caption>]]<br />
</figure><br />
<br />
'''A few words about solint and combine:'''<br />
<br />
In {{bandpass}}, the use of '''solint='inf'''' (as in "infinite") will derive a bandpass<br />
solution for each 3C279 scan, '''unless''' '''combine='scan'''' (which is the default). Here we set combine=' ' explicitly so that it does not combine the scans into one bandpass. Likewise, field boundaries are only crossed if combine='field', and spw boundaries are only crossed if combine='spw'. In some cases it can be helpful to combine fields if you suffer from lack of S/N, but it is never a good idea to combine spws. <br />
<br />
Now inspect the phase and amplitude solutions. You are looking for excursions from smooth fits, or particularly noisy solutions compared to the others. <br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
for spw in [0,1,2,3]:<br />
plotbandpass(asdm+'.bandpass.bcal',xaxis='freq',yaxis='amp', spw=spw,<br />
antenna='1~8', subplot=42, figfile=asdm+'.bandpass.amp', showatm=T,<br />
interactive=True)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
for spw in [0,1,2,3]:<br />
plotbandpass(asdm+'.bandpass.bcal',xaxis='freq',yaxis='phase',spw=spw,<br />
antenna='1~8',subplot=42,figfile=asdm+'.bandpass.phs', showatm=T,<br />
interactive=True)<br />
</source><br />
<br />
The values of phase on DV06 are very close to zero because it was used as the reference antenna.<br />
<br />
==Gain Calibration==<br />
<br />
Now that we have a bandpass solution to apply we can solve for the antenna-based phase and amplitude gain calibration. Since the phase changes on a much shorter timescale than the amplitude, we will solve for them separately. In particular, if the phase changes significantly over a scan time, the amplitude would be decorrelated, if the un-corrected phase were averaged over this timescale. Note that we re-solve for the gain solutions of the bandpass calibrator, so we can derive new solutions that are corrected for the bandpass shape. Since the bandpass calibrator will not be used again, this is not strictly necessary, but is useful to check its calibrated flux density for example. <br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.intphase.gcal')<br />
gaincal(vis=asdm+'.ms',caltable=asdm+'.intphase.gcal',<br />
field='0,1,3,4',spw='0~3:40~3800',refant='DV06',<br />
calmode='p',solint='int',minsnr=2.0,minblperant=4,<br />
gaintable=[asdm+'.bandpass.bcal'])<br />
</source><br />
<br />
Here '''solint='int' ''' coupled with '''calmode='p' ''' will derive a single phase solution for each 10 second integration. Note that the bandpass table is applied on-the-fly before solving for the phase solutions, however the bandpass is NOT applied to the data permanently until applycal is run later on. <br />
<br />
Although '''solint='int' ''' (i.e. the integration time of 10 seconds) is the best choice to apply before solving for the amplitude solutions, it is not a good idea to use this to apply to the target. This is because the phase-scatter within a scan can dominate the interpolation between calibrator scans. Instead, we also solve for the phase on the scan time, '''solint='inf' ''' (but '''combine=' ' ''', since we want one solution per scan) for application to the target later on. Unlike the bandpass task, for {{gaincal}}, the default of the combine parameter is '''combine=' ' '''. <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.scanphase.gcal')<br />
gaincal(vis=asdm+'.ms',caltable=asdm+'.scanphase.gcal',<br />
field='0,1,3,4',spw='0~3:40~3800',refant='DV06',<br />
calmode='p',solint='inf',minsnr=2.0,minblperant=4,<br />
gaintable=[asdm+'.bandpass.bcal'])<br />
</source><br />
<br />
Alternatively, instead of making a separate phase solution for application to the target, one can also run {{smoothcal}} to smooth the solutions derived on the integration time. <br />
<br />
Next we apply the bandpass and '''solint='int' ''' phase-only calibration solutions on-the-fly to derive amplitude solutions. Here the use of '''solint='inf' ''', but '''combine=' ' ''' will result in one solution per scan interval. <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.amp.gcal')<br />
gaincal(vis=asdm+'.ms',caltable=asdm+'.amp.gcal',<br />
field='0,1,3,4',spw='0~3:40~3800',refant='DV06',<br />
calmode='ap',solint='inf',minsnr=2.0,minblperant=4,<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal'])<br />
</source><br />
<br />
Now carefully inspect all these solutions looking for discrepant solutions. If you see any, you will need to flag them and rerun the calibration tasks above. <br />
<br />
We make plots in X and Y separately for clarity. The colors are showing the spectral windows.<br />
<figure id="X3c1_wvrtsys.intphase_X.png"><br />
[[Image:X3c1_wvrtsys.intphase_X.png|thumb|<caption>Phase solutions for the X polarization for every integration time of the first dataset.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.intphase.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',iteration='antenna',subplot=421,<br />
plotrange=[0,0,-180,180],poln='X',figfile=asdm+'.intphase_X.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.intphase.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',iteration='antenna',subplot=421,<br />
plotrange=[0,0,-180,180],poln='Y',figfile=asdm+'.intphase_Y.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<figure id="X3c1_wvrtsys.scanphase_X.png"><br />
[[Image:X3c1_wvrtsys.scanphase_X.png|thumb|<caption>Phase solutions for the X polarization for each scan of the first dataset.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.scanphase.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',iteration='antenna',subplot=421,<br />
plotrange=[0,0,-180,180],poln='X',figfile=asdm+'.scanphase_X.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.scanphase.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',iteration='antenna',subplot=421,<br />
plotrange=[0,0,-180,180],poln='Y',figfile=asdm+'.scanphase_Y.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Since we have taken out the phase as best we can by applying the '''solint='int' ''' phase-only solution, this plot will give a good idea of the residual phase error. If you see scatter of more than a few degrees here, you should consider going back and looking for more data to flag, particularly bad timeranges etc. <br />
<br />
<figure id="X3c1_wvrtsys.amp_phase.png"><br />
[[Image:X3c1_wvrtsys.amp_phase.png|thumb|<caption>Residual phase after applying intphase.gcal for both correlations in the first dataset.</caption>]]<br />
</figure><br />
<figure id="X3c1_wvrtsys.amp_X.png"><br />
[[Image:X3c1_wvrtsys.amp_X.png|thumb|<caption>Amplitude solutions on a scan interval for correlation X in the first dataset.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.amp.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',plotrange=[0,0,-1,1],<br />
iteration='antenna',subplot=421,figfile=asdm+'.amp_phase.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
These are very small, as they should be. Now look at the amplitude solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.amp.gcal',xaxis='time',yaxis='amp',antenna='1~8', <br />
iteration='antenna',subplot=421,spw='',poln='X',<br />
plotrange=[0,0,0.0,0.3],figfile=asdm+'.amp_X.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.amp.gcal',xaxis='time',yaxis='amp',antenna='1~8', <br />
iteration='antenna',subplot=421,spw='',poln='Y',<br />
plotrange=[0,0,0.0,0.3],figfile=asdm+'.amp_Y.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
==Flux Calibration==<br />
<br />
Next we use the flux calibrator (whose flux density was set in {{setjy}} above) to derive the flux density of the other calibrators. Note that the flux table REPLACES the amp.gcal in terms of future application of the calibration to the data, i.e. the flux table contains both the amp.gcal and flux scaling. Unlike the gain calibration steps, this is not an incremental table.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.flux.cal')<br />
fluxscale(vis=asdm+'.ms',caltable=asdm+'.amp.gcal',<br />
fluxtable=asdm+'.flux.cal',reference='1',refspwmap=[0,1,3,3],<br />
listfile=asdm+'.fluxscale.txt')<br />
</source><br />
<br />
Its a good idea to record the derived fluxscale values using the listfile option. The values can also be viewed in the Log Messages window.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Found reference field(s): Titan<br />
Found transfer field(s): 3c279 J1147-382=QSO J1037-295=QSO<br />
Spw=2 will be referenced to spw=3<br />
Flux density for 3c279 in SpW=0 (freq=3.56498e+11 Hz) is: 10.537 +/- 0.0183518 (SNR = 574.169, N = 16)<br />
Flux density for 3c279 in SpW=1 (freq=3.57734e+11 Hz) is: 10.6933 +/- 0.0264134 (SNR = 404.842, N = 16)<br />
Flux density for 3c279 in SpW=2 (freq=3.46034e+11 Hz) (ref SpW=3) is: 10.251 +/- 0.0477949 (SNR = 214.479, N = 14)<br />
Flux density for 3c279 in SpW=3 (freq=3.43956e+11 Hz) is: 9.91798 +/- 0.020167 (SNR = 491.791, N = 16)<br />
Flux density for J1147-382=QSO in SpW=0 (freq=3.56498e+11 Hz) is: 1.03399 +/- 0.0167344 (SNR = 61.7887, N = 16)<br />
Flux density for J1147-382=QSO in SpW=1 (freq=3.57734e+11 Hz) is: 0.844817 +/- 0.0191013 (SNR = 44.2283, N = 16)<br />
Flux density for J1147-382=QSO in SpW=2 (freq=3.46034e+11 Hz) (ref SpW=3) is: 0.987193 +/- 0.024391 (SNR = 40.4737, N = 14)<br />
Flux density for J1147-382=QSO in SpW=3 (freq=3.43956e+11 Hz) is: 1.28859 +/- 0.0194364 (SNR = 66.298, N = 16)<br />
Flux density for J1037-295=QSO in SpW=0 (freq=3.56498e+11 Hz) is: 0.968281 +/- 0.00895224 (SNR = 108.161, N = 16)<br />
Flux density for J1037-295=QSO in SpW=1 (freq=3.57734e+11 Hz) is: 0.75916 +/- 0.015366 (SNR = 49.4053, N = 16)<br />
Flux density for J1037-295=QSO in SpW=2 (freq=3.46034e+11 Hz) (ref SpW=3) is: 0.948551 +/- 0.0165421 (SNR = 57.3416, N = 14)<br />
Flux density for J1037-295=QSO in SpW=3 (freq=3.43956e+11 Hz) is: 1.21905 +/- 0.0139967 (SNR = 87.0956, N = 16)<br />
Fitted spectrum for 3c279 with fitorder=1: Flux density = 10.2962 +/- 0.0450319 (freq=351.002 GHz) spidx=1.70757 +/- 0.245737<br />
Fitted spectrum for J1147-382=QSO with fitorder=1: Flux density = 1.06853 +/- 0.0709817 (freq=351.002 GHz) spidx=-6.77353 +/- 3.71867<br />
Fitted spectrum for J1037-295=QSO with fitorder=1: Flux density = 1.01822 +/- 0.0654586 (freq=351.002 GHz) spidx=-6.28977 +/- 3.71453<br />
Storing result in X7ef_wvrtsys.flux.cal<br />
Writing solutions to table: X7ef_wvrtsys.flux.cal<br />
</pre><br />
<br />
<figure id="x3c1_wvrtsys.flux_X.png"><br />
[[Image:x3c1_wvrtsys.flux_X.png|thumb|<caption>Absolute flux calibration solutions for correlation X for the first dataset.</caption>]]<br />
</figure><br />
<br />
<div class="noprint" style="float:none; border:0px solid blue;background-color:#F6CEF5;padding:2px;"><br />
If you used the updated (Butler-JPL-Horizons 2012) flux density standard when you ran {{setjy}} earlier in this tutorial, the derived flux values for the calibrators will be slightly different. For example, when averaged over the 3 measurement sets, 3c279 in spectral window 0 has a flux of 10.77 Jy using the 2010 standard and 10.63 Jy using the 2012 standard; as a second example, J1147-382 in SPW 3 has an average flux of 1.13 Jy (2010 standard) and 1.15 Jy (2012 standard). <br />
</div><br />
<br />
Now look at the flux solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.flux.cal',xaxis='time',yaxis='amp',antenna='1~8', <br />
iteration='antenna',subplot=421,spw='',poln='X',<br />
plotrange=[0,0,0.0,0.3],figfile=asdm+'.flux_X.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.flux.cal',xaxis='time',yaxis='amp',antenna='1~8', <br />
iteration='antenna',subplot=421,spw='',poln='Y',<br />
plotrange=[0,0,0.0,0.3],figfile=asdm+'.flux_Y.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
==Apply Calibration and Inspect==<br />
<br />
Now we can use the {{flagmanager}} if we want to restore any of the spectral flagging we did prior to bandpass calibration. <br />
In this case, we choose to restore the flags of the emission lines on Titan, because we are interested in seeing how<br />
strong they are compared to the continuum. However, we leave the strong ozone line and mesospheric CO line flagged on all <br />
sources, because we want to get the most accurate continuum flux density for the science target. <br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
flagmanager(vis=asdm+'.ms',mode='restore',versionname=asdm+'.before_emissionflags')<br />
</source><br />
<br />
Next we apply the calibration solutions to each source individually, using the '''gainfield''' parameter to specify which calibrator's solutions should be applied from each of the '''gaintable''' calibration tables. <br />
<br />
First, we do 3C279 (the bandpass calibrator), applying all 3 of its solutions to itself (that's why gainfield contains three zeros):<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='0',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['0','0','0'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
Next, we do Titan (the absolute flux calibrator) using the bandpass solution from 3C279:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='1',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['0','1','1'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
For the secondary phase calibrator, we apply the phase and flux solutions from the primary phase calibrator. This will allow us to check how well the phase transfer to the science target (TW Hya) has worked:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='3',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.scanphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','linear','linear'],<br />
gainfield=['0','4','4'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
Next is the Primary phase calibrator:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='4',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['0','4','4'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
Finally, for the Science Target TW Hya, we apply the phase solutions from both the primary and secondary phase calibrators:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='2',<br />
interp=['nearest','linear','linear'],<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.scanphase.gcal',asdm+'.flux.cal'],<br />
gainfield=['0','3,4','3,4'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
Now we can check the results of applying the calibration solutions.<br />
<br />
<figure id="Corrected_vs_time_1.png"><br />
[[Image:Corrected_vs_time_1.png|thumb|<caption>The calibrated data for the first dataset (amplitude vs. time).</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw',ydatacolumn='corrected')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
In amplitude, it looks good but there are some noisy points toward the end of the first scheduling block, but it mostly only affects the secondary phase calibrator (green). In phase, we expect all the points to cluster about zero. The large scatter in phase on the secondary phase calibrator is readily apparent: <br />
<br />
<figure id="Corrected_phase_vs_time_1.png"><br />
[[Image:Corrected_phase_vs_time_1.png|thumb|<caption>The calibrated data on the calibrators for the first dataset (phase vs. time).</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='time',yaxis='phase',field='0,1,3,4',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw',ydatacolumn='corrected')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Let's check whether the situation improves when we apply this calibrator's solutions to itself rather than transferring the solutions from the primary phase calibrator (which is 17 degrees away, and observed at a different time). <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='3',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['0','3','3'],flagbackup=T, calwt=T)<br />
</source><br />
<br />
<figure id="Corrected_vs_time_1_field3.png"><br />
[[Image:Corrected_vs_time_1_field3.png|thumb|<caption>The calibrated data for the first dataset (amplitude vs. time), but now with field 3, the secondary phase calibrator, calibrated with itself.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw',ydatacolumn='corrected')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<figure id="Corrected_phase_vs_time_1_field3.png"><br />
[[Image:Corrected_phase_vs_time_1_field3.png|thumb|<caption>The calibrated data from the first dataset (phase vs. time), but now with field 3, the secondary phase calibrator, calibrated with itself.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='time',yaxis='phase',field='0,1,3,4',<br />
avgchannel='3840', coloraxis='field',iteraxis='spw',<br />
ydatacolumn='corrected')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Indeed, the secondary calibrator looks better now in amplitude and phase. This is an indication that the calibration transfer is not working well in this timerange. Because the effect is not catastrophic and we know we can self-calibrate on TW Hya later, we will let this go for now. Or, if you want you can delve deeper into the data and try to solve the mystery... <br />
<br />
In any case, we will re-issue the original {{applycal}} so that it is this calibration that our subsequent {{split}} will use. This will allow us to check the effect of correcting the secondary phase calibrator with the primary phase calibrator later. <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='3',<br />
gaintable=[asdm+'.bandpass.bcal', asdm+'.scanphase.gcal', asdm+'.flux.cal'],<br />
interp=['nearest','linear','linear'],<br />
gainfield=['0','4','4'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
<br />
Let's check the spectral calibration now. First 3C279 and Titan:<br />
<br />
<figure id="X3c1_spw2_corrected_3.4.png"><br />
[[Image:X3c1_spw2_corrected_3.4.png|thumb|<caption>Spectral UV-plots of 3C279 and Titan of spw=2 for the first dataset.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='frequency',yaxis='amp',field='0,1',<br />
avgtime='1e8',avgscan=T,coloraxis='field',ydatacolumn='corrected',<br />
iteraxis='spw',xselfscale=T)<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Flip through the spws. These look good. Next the two phase calibrators:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='frequency',yaxis='amp',field='3,4',<br />
avgtime='1e8',avgscan=T,coloraxis='field',ydatacolumn='corrected',<br />
iteraxis='spw',xselfscale=T)<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Flip through the spws. This also looks good, the secondary phase calibrator is a bit noisier but this is normal. The upswing at the lower frequency end of spw=3 will probably need to be flagged on the science target as well. It corresponds to the edge of an atmospheric feature.<br />
<br />
Now for the exciting part, what does the science target look like...<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='frequency',yaxis='amp',field='2',<br />
avgtime='1e8',avgscan=T,coloraxis='field',ydatacolumn='corrected',<br />
iteraxis='spw',xselfscale=T)<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
We see HCO+(4-3) in spw=0 and CO(3-2) in spw=2 as expected. Because the shape of the <br />
line profiles varies with baseline, you can already tell that the line emission is resolved.<br />
<br />
<figure id="X3c1_CO3_2_uvplot_3.4.png"><br />
[[Image:X3c1_CO3_2_uvplot_3.4.png|thumb|<caption>UV-Plot of the TW Hya CO(3-2) emission from the first dataset.</caption>]]<br />
</figure><br />
<figure id="X3c1_HCOp4_3_uvplot_3.4.png"><br />
[[Image:X3c1_HCOp4_3_uvplot_3.4.png|thumb|<caption>UV-Plot of the TW Hya HCO+(4-3) emission from the first dataset.</caption>]]<br />
</figure><br />
<br />
Now check that the velocity of TWHydra is correct in the LSRK frame, it should be around 2.88 km/s.<br />
* CO 3-2 rest freq 345.79599 GHz<br />
* HCO+ 4-3 rest freq 356.7342 GHz<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='2',xaxis='velocity',yaxis='amp',field='2',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',<br />
restfreq='345.79599GHz', plotrange=[-10,15,0,0],coloraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='0',xaxis='velocity',yaxis='amp',field='2',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',<br />
restfreq='356.7342GHz',plotrange=[-10,15,0,0],coloraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Both lines show up at the expected velocity.<br />
<br />
<br />
==Concatenate the Data==<br />
<br />
Here we will concatenate the three datasets prior to imaging.<br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
os.system('rm -rf Band7multi_april22.ms')<br />
concat(vis=splitdata,concatvis='Band7multi_april22.ms')<br />
</source><br />
<br />
If you like you can run listobs on new combined dataset<br />
<br />
<source lang="python"><br />
# In CASA<br />
listfile = 'Band7multi_april22.listobs.txt'<br />
os.system('rm ' + listfile)<br />
listobs(vis='Band7multi_april22.ms',verbose=F, listfile=listfile)<br />
</source><br />
<br />
<figure id="All_spw2_corrected_3.4.png"><br />
[[Image:All_spw2_corrected_3.4.png|thumb|<caption>Spectral UV-plots of 3C279 and Titan of spw=2 for the combined datasets.</caption>]]<br />
</figure><br />
<br />
You can also examine the spectral uv plots for the combined dataset to see the improvement in S/N: <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='Band7multi_april22.ms',spw='',xaxis='frequency',yaxis='amp',field='0,1',<br />
avgtime='1e8',avgscan=T,coloraxis='field',ydatacolumn='corrected',<br />
iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
<figure id="All_CO3_2_uvplot_3.4.png"><br />
[[Image:All_CO3_2_uvplot_3.4.png|thumb|<caption>UV-Plot of the TW Hya CO(3-2) emission from the combined datasets.</caption>]]<br />
</figure><br />
<br />
...and the CO line profile for the combined dataset: <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='Band7multi_april22.ms',spw='2',xaxis='velocity',yaxis='amp',field='2',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',restfreq='345.79599GHz',<br />
plotrange=[-10,15,0,0],coloraxis='spw')<br />
</source><br />
<br />
==Split Calibrated Data==<br />
<br />
Now we split off the calibrated data for the Science Target as well as the interesting parts of the calibrators for imaging.<br />
<br />
When we {{split}} off the Titan data, a few dozen warnings like the following are written to the log:<br />
<pre><br />
2012-05-15 22:00:35 WARN split::SubMS::copySource() Invalid SOURCE ID in SOURCE table row 20 <br />
</pre><br />
These can be ignored, because they do not indicate any problem that will prevent you from imaging Titan correctly at a single position using all the data in the output ms.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_corrected.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='TWHydra_corrected.ms',<br />
datacolumn='corrected',spw='',field='2')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf J1037_corrected.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='J1037_corrected.ms',<br />
datacolumn='corrected',spw='',field='4')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf J1147_corrected.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='J1147_corrected.ms',<br />
datacolumn='corrected',spw='',field='3')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3C279_CO3_2.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='3C279_CO3_2.ms',<br />
datacolumn='corrected',spw='2:1900~2000',field='0')<br />
</source><br />
<br />
==Optional: Reconcile Titan's Coordinates==<br />
<br />
If you do not care to image Titan, then you can skip this step and simply continue on to the [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_4.5 imaging guide].<br />
<br />
Our earlier treatment of Titan's coordinates using [http://casa.nrao.edu/stable/docs/TaskRef/fixplanets-task.html fixplanets] replaced the zeros written by the ALMA control system with the correct position of the body at the instant of the first observation of that SB. As a result, it has slightly different positions in all three datasets, as seen by listobs:<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='Band7multi_april22.ms',verbose=F)<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
ID Code Name RA Decl Epoch SrcId nRows <br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 70866 <br />
1 none Titan 12:49:25.97588 -02.22.41.3024 J2000 1 4842 <br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 515151 <br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 40797 <br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 171153 <br />
5 none Titan 12:49:26.53729 -02.22.27.1521 J2000 0 4833 <br />
6 none Titan 12:49:26.53059 -02.22.18.7878 J2000 0 4833 <br />
</pre><br />
<br />
If we want to image such moving objects observed across multiple SBs, we need to bring the positions into agreement, otherwise {{clean}} will try to make a mosaic. Task [http://casa.nrao.edu/stable/docs/TaskRef/fixplanets-task.html fixplanets] can be used to do this. Here, we set the direction to the direction of the first dataset as reported by listobs. Note that the RA/Dec format is slightly different from the {{listobs}} output format. Also, we do not<br />
fix the uvw coordinates because they are already more correct now than they would be if we "fixed" them.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fixplanets(vis='Band7multi_april22.ms', field='Titan', direction='J2000 12h49m25.97588 -02d22m41.3024', fixuvw=False)<br />
</source><br />
<br />
Check the header information again to see that the information for Titan has changed for the second<br />
and third datasets. They will appear as fields 5 and 6.<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='Band7multi_april22.ms',verbose=F)<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
ID Code Name RA Decl Epoch SrcId <br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 70866 <br />
1 none Titan 12:49:25.97588 -02.22.41.3024 J2000 1 4842 <br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 515151 <br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 40797 <br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 171153 <br />
5 none Titan 12:49:25.97588 -02.22.41.3024 J2000 0 4833 <br />
6 none Titan 12:49:25.97588 -02.22.41.3024 J2000 0 4833 <br />
</pre><br />
<br />
==Optional: Split Calibrated Titan Data==<br />
<br />
When we {{split}} off the Titan data, a few dozen warnings like the following are written to the log:<br />
<pre><br />
2012-05-15 22:00:35 WARN split::SubMS::copySource() Invalid SOURCE ID in SOURCE table row 20 <br />
</pre><br />
These can be ignored, because they do not indicate any problem that will prevent you from imaging Titan correctly at a single position using all the data in the output ms.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Titan_cont.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='Titan_cont.ms',<br />
datacolumn='corrected',spw='0',field='1')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Titan_CO3_2.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='Titan_CO3_2.ms',<br />
datacolumn='corrected',spw='2',field='1')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Titan_unknown.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='Titan_unknown.ms',<br />
datacolumn='corrected',spw='3',field='1')<br />
</source><br />
<br />
==Continue on to Imaging of the Science Target==<br />
<br />
Now you can continue on to the [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_4.5 imaging guide].<br />
<br />
{{Checked 4.5.2}}</div>Sstierwahttps://casaguides.nrao.edu/index.php?title=TWHydraBand7_Calibration_4.5&diff=19472TWHydraBand7 Calibration 4.52016-05-18T03:59:36Z<p>Sstierwa: /* Preparation */</p>
<hr />
<div>[[Category:ALMA]][[Category:Calibration]][[Category:Spectral Line]]<br />
*'''This script assumes that you have downloaded TWHYA_BAND7_UnCalibratedMSAndTablesForReduction.tgz from [[TWHydraBand7#Getting_the_Data]]'''<br />
<br />
*'''An introduction to this data set is available at [[TWHydraBand7]].<br />
<br />
*'''This guide is designed for CASA 4.5.2 If you are using an older version of CASA please see [[TWHydraBand7_Calibration_4.3]].<br />
<br />
==Preparation==<br />
<br />
Once you have downloaded TWHYA_BAND7_UnCalibratedMSAndTablesForReduction.tgz, in a terminal unpack it with<br />
<br />
<source lang="bash"><br />
tar -zxvf TWHYA_BAND7_UnCalibratedMSAndTablesForReduction.tgz<br />
</source><br />
<br />
Please be aware that you will need about 100 GB of free space to do the data reduction. It is a good idea to check that now before you begin. Some of the plots described here require 9 GB of RAM; as little as 4 GB may be sufficient if additional data averaging is used when the plots are generated. When you are satisfied with the available drive space and memory on your machine:<br />
<br />
<source lang="bash"><br />
cd TWHYA_BAND7_UnCalibratedMSAndTablesForReduction<br />
</source><br />
<br />
'''NOTE: the calibration tables included in TWHYA_BAND7_UnCalibratedMSAndTablesForReduction CANNOT be used with CASA 4.5, they should be discarded, or moved out of the working directory.'''<br />
<br />
Then start CASA by typing 'casa' at a shell prompt. <br />
<br />
<source lang="bash"><br />
casa<br />
</source><br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.5.2. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.5.2'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
==Install Analysis Utilities==<br />
<br />
Analysis Utilities (or analysisUtils for short) is a small set of Python scripts that provide a number of analysis and plotting utilities for ALMA data reduction. This guide uses a few of these utilities. They are very easy to install (just download and untar). See <br />
<br />
http://casaguides.nrao.edu/index.php?title=Analysis_Utilities<br />
<br />
for a full description and download instructions. If you do not wish to do this, see the [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Calibration_for_CASA_3.3 CASA 3.3 version of the guide] for alternative (but slow) plotting options. Analysis Utilities are updated frequently so if its been a while since you installed it, its probably worth doing it again. If you are at an ALMA site or ARC, the analysis utilities are probably already installed and up to date.<br />
<br />
==Fix Titan's coordinates==<br />
<br />
'''Note that in the near future this step will be unnecessary.''' <br />
<br />
It is temporarily necessary to correct the positions of ephemeris objects observed during ALMA Cycle 0, because the control software revisions earlier than 9.0 erroneously write the data with coordinates of 00:00:00.0000 +00.00.00.0000 (J2000). For this dataset, we need to correct the position of the absolute flux calibrator Titan, as we can<br />
see from the first {{listobs}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -f X3c1.ms.listobs')<br />
listobs('X3c1.ms', verbose=T, listfile='X3c1.ms.listobs') <br />
</source><br />
<br />
You can view the listobs output files using command "less" from the CASA prompt.<br />
<br />
<pre style="background-color: #fffacd;"><br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 23625<br />
1 none Titan 00:00:00.00000 +00.00.00.0000 J2000 1 4842<br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 175176<br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 14832<br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 59877<br />
</pre><br />
<br />
To correct Titan's position, we will use the task [http://casa.nrao.edu/stable/docs/TaskRef/fixplanets-task.html fixplanets], which writes the actual coordinates at the instant of the first observation. This step takes a while because we are recalculating the uvw's accordingly.<br />
<source lang="python"><br />
# In CASA<br />
fixplanets(vis='X3c1.ms', field='Titan', fixuvw=True)<br />
</source><br />
<br />
Check the header information again with {{listobs}} to confirm that the information for Titan has changed:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -f X3c1.ms.listobs')<br />
listobs('X3c1.ms', verbose=T, listfile='X3c1.ms.listobs') <br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 23625<br />
1 none Titan 12:49:25.93349 -02.22.41.5638 J2000 1 4842<br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 175176<br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 14832<br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 59877<br />
</pre><br />
<br />
Now fix the other two measurement sets similarly:<br />
<source lang="python"><br />
# In CASA<br />
fixplanets(vis='X5d8.ms', field='Titan', fixuvw=True)<br />
fixplanets(vis='X7ef.ms', field='Titan', fixuvw=True)<br />
</source><br />
<br />
==Observing Log and Priors==<br />
<br />
Below is some information that may not be obvious from the data<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Like at most telescopes, the ALMA operators and astronomers at the site log any significant issues <br />
that were noticed from the online system during the observation. For these Band 7 observations of <br />
TW Hya on April 22, 2011, the only issue of note was that antenna DV04 could not observe at Band 7 <br />
and will need to be flagged. <br />
</pre><br />
<br />
First let's examine the basic properties of the data using {{listobs}}. Among other information we <br />
will be able to deduce what the source ids are and what each source was used for:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
3c279 is the bandpass calibrator (field id=0)<br />
Titan is the absolute flux calibrator (field id=1)<br />
J1147-382 is the secondary phase calibrator (field id=3)<br />
J1037-295 is the primary phase calibrator (field id=4)<br />
</pre><br />
<br />
<source lang="python"><br />
# In CASA<br />
data=['X3c1.ms','X5d8.ms','X7ef.ms']<br />
for vis in data:<br />
os.system('rm '+vis+'.listobs')<br />
listobs(vis, verbose=T, listfile=vis+'.listobs') <br />
</source><br />
<br />
You can view the {{listobs}} output files using command '''less''' from the CASA prompt. <br />
Below we copy select parts of the {{listobs}} output files for reference. <br />
<br />
<pre style="background-color: #fffacd;"><br />
X3c1.ms:<br />
Data records: 278352 Total integration time = 6109.06 seconds<br />
Observed from 22-Apr-2011/00:01:52.9 to 22-Apr-2011/01:43:42.0 (UTC)<br />
<br />
X5d8.ms:<br />
Data records: 278406 Total integration time = 5995.01 seconds<br />
Observed from 22-Apr-2011/01:48:05.8 to 22-Apr-2011/03:28:00.8 (UTC)<br />
<br />
X7ef.ms:<br />
Data records: 255717 Total integration time = 5407.49 seconds<br />
Observed from 22-Apr-2011/03:30:39.7 to 22-Apr-2011/05:00:47.2 (UTC)<br />
<br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 23625<br />
1 none Titan 12:49:25.97588 -02.22.41.3024 J2000 1 4842<br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 175176<br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 14832<br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 59877 <br />
<br />
SpwID #Chans Frame Ch1(MHz) ChanWid(kHz) TotBW(kHz) Corrs<br />
0 4 TOPO 184550 1500000 7500000 I<br />
1 128 TOPO 355740.062 15625 2000000 XX YY<br />
2 1 TOPO 356716.625 1796875 1796875 XX YY<br />
3 128 TOPO 356507.813 15625 2000000 XX YY<br />
4 1 TOPO 357484.375 1796875 1796875 XX YY<br />
5 128 TOPO 346792.187 15625 2000000 XX YY<br />
6 1 TOPO 345784.375 1796875 1796875 XX YY<br />
7 128 TOPO 345182.438 15625 2000000 XX YY<br />
8 1 TOPO 344174.625 1796875 1796875 XX YY<br />
9 128 TOPO 344386.763 15625 2000000 XX YY<br />
10 1 TOPO 343378.95 1796875 1796875 XX YY<br />
11 128 TOPO 346324.263 15625 2000000 XX YY<br />
12 1 TOPO 345316.45 1796875 1796875 XX YY<br />
13 128 TOPO 354402.388 15625 2000000 XX YY<br />
14 1 TOPO 355378.95 1796875 1796875 XX YY<br />
15 128 TOPO 356402.388 15625 2000000 XX YY<br />
16 1 TOPO 357378.95 1796875 1796875 XX YY<br />
17 3840 TOPO 356497.936 122.070312 468750 XX YY<br />
18 1 TOPO 356732.189 468750 468750 XX YY<br />
19 3840 TOPO 357734.314 122.070312 468750 XX YY<br />
20 1 TOPO 357499.939 468750 468750 XX YY<br />
21 3840 TOPO 346034.314 122.070312 468750 XX YY<br />
22 1 TOPO 345799.939 468750 468750 XX YY<br />
23 3840 TOPO 343955.936 122.070312 468750 XX YY<br />
24 1 TOPO 344190.189 468750 468750 XX YY<br />
<br />
Antennas: 9:<br />
Name Station Diam. Long. Lat.<br />
0 DV04 J505 12.0 m -067.45.18.0 -22.53.22.8<br />
1 DV06 T704 12.0 m -067.45.16.2 -22.53.22.1<br />
2 DV07 J510 12.0 m -067.45.17.8 -22.53.23.5<br />
3 DV08 T703 12.0 m -067.45.16.2 -22.53.23.9<br />
4 DV09 N602 12.0 m -067.45.17.4 -22.53.22.3<br />
5 DV10 N606 12.0 m -067.45.17.1 -22.53.23.6<br />
6 PM01 T702 12.0 m -067.45.18.6 -22.53.24.1<br />
7 PM02 T701 12.0 m -067.45.18.8 -22.53.22.2<br />
8 PM03 J504 12.0 m -067.45.17.0 -22.53.23.0<br />
</pre><br />
<br />
Things to Notice from above: <br />
*There are three different data sets acquired close together in time. We will calibrate each dataset independently and then combine the calibrated data prior to imaging. <br />
*Titan appears to have slightly different positions in each dataset because it is a moving body. In fact, at the time of observation, due to temporary data capture issue in the ALMA system, the position was written has (0,0). We have pre-corrected this error using fixplanets. Later in the tutorial, we will run fixplanets again to force all three datasets to have the same fixed position for Titan.<br />
*There are a lot of spectral windows! Don't be alarmed. In ALMA data, <br />
**spw=0 is always reserved for the water vapor radiometry data.<br />
**spw=9, 11, 13, 15 are the wideband (TDM) correlator mode with 128 channels per spw default settings for doing pointing and this is all they are used for in these data.<br />
**Currently Tsys data can only be taken in the wide (TDM) correlator mode with 128 channels per spw, these correspond to spws=1, 3, 5, 7 above. The frequencies of these TDM spws were carefully chosen so the the narrowband FDM spws fall within them.<br />
** The 0.5 GHz, high spectral resolution spws that contain all the real source data (science target and calibrators) are 17, 19, 21, and 23<br />
**For quicklook purposes, the ALMA online system produces a channel averaged spw for each channelized spw, these correspond to spw=2,4,6,8,10,12,14,16,18,20,22,24 and shouldn't be used for anything in post-processing as bandpass calibration etc has not been applied.<br />
<br />
In the portion of the {{listobs}} output that shows the timerange, the final column gives the scan intent. It is important to have a look at this because you can flag and do other operations in CASA using the scan intent as a selection option. Also, these intents will be used in the future for pipeline processing. You will usually want to use them to flag the CALIBRATE_POINTING* and CALIBRATE_ATMOS* (the latter correspond to the hot and cold load measurements used to calculate Tsys) data. This is essential for science or calibration data taken only in TDM (wide bandwidth) mode, i.e. the same mode that the pointing and Tsys data are taken in. For the current data however, that calibration data is recorded in different spws from the useful FDM (narrow bandwidth) data, so we'll be able to separate them by splitting them off at the final step prior to imaging.<br />
<br />
<figure id="Ant_pos.png"><br />
[[Image:Ant_pos.png|thumb|<caption>Antenna locations for the first dataset.</caption>]]<br />
</figure><br />
<br />
Before we move on, its also nice to get an idea where the antennas are with respect to each other. We can use {{plotants}} to plot their positions. It is a good idea to check each file since an antenna may have entered or exited the array between observations.<br />
<source lang="python"><br />
# In CASA<br />
for vis in data:<br />
plotants(vis=vis,figfile=vis+'.plotants.png')<br />
</source><br />
<br />
You can view the output images using any standard image viewer.<br />
<br />
==Create the Tsys and WVR Tables, and Examine ==<br />
<br />
Each ms include tables that contain the Tsys and WVR measurements associated with the visibility data.<br />
We must create calibration tables from these measurements. First we create the WVR calibration tables <br />
by running the task [http://casa.nrao.edu/stable/docs/TaskRef/wvrgcal-task.html wvrgcal]. This task <br />
examines the data for each ms as a whole and creates a calibration<br />
table containing only phase corrections for each antenna and spw. <br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
os.system('rm -rf '+asdm+'.wvr')<br />
wvrgcal(vis=asdm+'.ms', caltable=asdm+'.wvr', segsource=True, toffset=-1)<br />
</source><br />
<br />
Next we create the Tsys tables by running {{gencal}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
os.system('rm -rf '+asdm+'.tsys')<br />
gencal(vis=asdm+'.ms', caltable=asdm+'.tsys', caltype='tsys')<br />
</source><br />
<br />
It is very important that Tsys measurements taken as close in time and elevation as possible to a particular source are applied. To save telescope time, Tsys measurements are sometimes intentionally skipped in the scheduling block for specific sources. So the first step is to establish which sources have their own Tsys measurements and which do not. To do this, you may use the intent parameter of {{listobs}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
listobs(vis=asdm+'.ms', verbose=F, selectdata=True, intent='CALIBRATE_ATMOS*')<br />
</source><br />
<br />
<figure id="X3c1.tsys_vs_time_3.4.png"><br />
[[File:X3c1.tsys_vs_time_3.4.png|thumb|<caption>Tsys vs. time for spw 1 of the X3c1.ms data.</caption>]]<br />
</figure><br />
<figure id="X5d8.tsys_vs_time_3.4.png"><br />
[[File:X5d8.tsys_vs_time_3.4.png|thumb|<caption>Tsys vs. time for spw 1 of the X5d8.ms data.</caption>]]<br />
</figure><br />
<figure id="X7ef.tsys_vs_time_3.4.png"><br />
[[File:X7ef.tsys_vs_time_3.4.png|thumb|<caption>Tsys vs. time for spw 1 of the X7ef.ms data.</caption>]]<br />
</figure><br />
<br />
<pre style="background-color: #fffacd;"><br />
Fields: 4<br />
ID Code Name RA Decl Epoch SrcId nRows <br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 1116 <br />
1 none Titan 12:49:25.97588 -02.22.41.3024 J2000 1 1125 <br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 6795 <br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 6777 <br />
Spectral Windows: (9 unique spectral windows and 2 unique polarization setups)<br />
SpwID #Chans Frame Ch1(MHz) ChanWid(kHz) TotBW(kHz) Corrs <br />
0 4 TOPO 184550 1500000 7500000 I <br />
1 128 TOPO 355740.062 15625 2000000 XX YY <br />
2 1 TOPO 356716.625 1796875 1796875 XX YY <br />
3 128 TOPO 356507.813 15625 2000000 XX YY <br />
4 1 TOPO 357484.375 1796875 1796875 XX YY <br />
5 128 TOPO 346792.187 15625 2000000 XX YY <br />
6 1 TOPO 345784.375 1796875 1796875 XX YY <br />
7 128 TOPO 345182.438 15625 2000000 XX YY <br />
8 1 TOPO 344174.625 1796875 1796875 XX YY <br />
</pre><br />
<br />
Because field '3' (the secondary phase calibrator) does not appear in the list, it has no tsys. Since the secondary phase calibrator is close on the sky to the primary phase calibrator and observed near in time, we will transfer the Tsys from the primary to the secondary phase calibrator. <br />
Also notice that spws 1,3,5,7 are the only multi-channel spws that contain Tsys data. At present, Tsys measurements can only be obtained with TDM spectral setups (128 channels/dual pol). Because our science target is observed in FDM (3840 channels/dual pol), we will need to interpolate the measurements from TDM to FDM. But first, to inspect the Tsys vs. time, we use {{plotcal}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all = ['X3c1','X5d8','X7ef']<br />
tsysfields=['0','1','2','4']<br />
os.system('mkdir cal_plots; mkdir cal_plots/Tsys_plots') <br />
for asdm in basename_all:<br />
print "Plotting Tsys vs. time for "+asdm<br />
plotcal(caltable=asdm+'.tsys', xaxis='time',yaxis='tsys',<br />
antenna='1~8',plotrange=[0,0,100,500],<br />
iteration='antenna',subplot=421,poln='',spw='1:50~50',<br />
figfile='cal_plots/Tsys_plots/'+asdm+'.tsys_vs_time.png')<br />
if (asdm != basename_all[-1]):<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
To inspect Tsys vs. frequency, we use [[plotbandpass]]. There are many different options for plotbandpass, and we demonstrate some of the most useful ones. The option '''showtsky=T''' will overlay the effective temperature curve from the atmospheric model. This shows us the location of any atmospheric lines which will appear as emission lines in the autocorrelation data (from which the Tsys spectra are derived) from all antennas. In the<br />
example below, we set '''interactive=False''', which will produce many pages of plots as<br />
individual pngs but will only show the final page in the graphics window. To view all the pages we use the image viewer '''eog''' (Eye of GNOME) available on Linux. The alternative is to set '''interactive=True''' and examine the plots in the casa graphics window as they are produced.<br />
<br />
<figure id="X3c1.tsys.field0.DV04.spw1.t1.png"><br />
[[File:X3c1.tsys.field0.DV04.spw1.t1.png|thumb|<caption>Tsys vs. frequency on 3C279 for the X3c1.ms data, spw=1.</caption>]]<br />
</figure><br />
<figure id="X3c1.tsys.field0.DV04.spw3.t1.png"><br />
[[File:X3c1.tsys.field0.DV04.spw3.t1.png|thumb|<caption>Tsys vs. frequency on 3C279 for the X3c1.ms data, spw=3.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
print "Plotting Tsys vs. frequency for "+asdm<br />
for spw in [1,3,5,7]:<br />
for field in ['0','1']:<br />
plotbandpass(caltable=asdm+'.tsys', xaxis='freq',yaxis='amp',<br />
showtsky=T,subplot=42,field=field,<br />
spw=spw, interactive=False, plotrange=[0,0,0,0],<br />
figfile='cal_plots/Tsys_plots/'+asdm+'.tsys.field%s.png'%field,<br />
buildpdf=False)<br />
</source><br />
<br />
In <xr id="X3c1.tsys.field0.DV04.spw1.t1.png"/> and <xr id="X3c1.tsys.field0.DV04.spw3.t1.png"/> we see the effect of atmospheric ozone lines on the Tsys measurements associated with 3C279 in spw 1 and 3.<br />
<br />
For sources that have multiple Tsys measurements (typically the primary phase calibrator and/or the science target) one can use '''overlay="time"''' to overlay all the measurements for that source. This can help to identify any anomalous Tsys scans. As a fraction of the plots produced by this loop, here we show the Tsys recorded on spw=1 for TW Hya from the first dataset.<br />
<br />
<figure id="X3c1.tsys.field2.DV04.spw1.png"><br />
[[File:X3c1.tsys.field2.DV04.spw1.png|thumb|<caption>Tsys vs. freq for field 2, spw 1 of the X3c1.ms data (antennas 0..3).</caption>]]<br />
</figure><br />
<figure id="X3c1.tsys.field2.DV04.spw1.png"><br />
[[File:X3c1.tsys.field2.DV09.spw1.png|thumb|<caption>Tsys vs. freq for field 2, spw 1 of the X3c1.ms data (antennas 4..7).</caption>]]<br />
</figure><br />
<figure id="X3c1.tsys.field2.PM03.spw1.png"><br />
[[File:X3c1.tsys.field2.PM03.spw1.png|thumb|<caption>Tsys vs. freq for field 2, spw 1 of the X3c1.ms data (antenna 8).</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
print "Plotting Tsys vs. frequency for "+asdm<br />
for spw in [1,3,5,7]:<br />
for field in ['2','4']:<br />
plotbandpass(caltable=asdm+'.tsys', xaxis='freq',yaxis='amp',<br />
showtsky=T,subplot=22,field=field,<br />
overlay='time',spw=spw, interactive=False, plotrange=[0,0,0,0],<br />
figfile='cal_plots/Tsys_plots/'+asdm+'.tsys.field%s.png'%field,<br />
buildpdf = False)<br />
</source><br />
<br />
Alternatively, the '''overlay="antenna"''' option will quickly reveal any Antennas with discrepant Tsys values, as they<br />
will be obvious outliers. For FDM projects like this one, using the '''showfdm=True''' option can be helpful, as it<br />
will show where in the TDM bandpass each FDM spw was located. <br />
<figure id="X3c1.tsys.field0.spw1.t1.png"><br />
[[Image:X3c1.tsys.field0.spw1.t1.png|thumb|<caption>Tsys vs Freq for field 0, spw 1 of the X3c1.ms data with all antennas overlaid.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
tsysfields=['0','1','2','4'] <br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
print "Plotting Tsys vs. frequency for "+asdm<br />
for spw in [1,3,5,7]:<br />
for field in tsysfields:<br />
plotbandpass(caltable=asdm+'.tsys', xaxis='freq',yaxis='amp',<br />
showtsky=T,subplot=11,field=field,<br />
overlay='antenna',spw=spw, interactive=False,<br />
figfile='cal_plots/Tsys_plots/'+asdm+'.tsys.field%s.png'%field,<br />
buildpdf=False,showfdm=True)<br />
</source><br />
<br />
<br />
Note that DV04 consistently has a significantly higher Tsys than the rest of the antennas. We already know from the Observation log that<br />
we need to flag that antenna, but had we not had that information, examining this plot would have demonstrated the situation.<br />
<br />
==Apply the Tsys and WVR Tables, and Split ==<br />
<br />
Next we apply the calibrations. For the (4) sources with Tsys measurements, we use the '''field''' and '''gainfield''' parameters of {{applycal}} to apply solutions only to themselves. {{applycal}} has the ability to interpolate gain tables from one spw onto another spw. In this case, we want to interpolate the TDM Tsys values in spws 1,3,5,7 onto the FDM spws 17,19,21,23. We use the '''interp''' parameter to request linear interpolation in the time dimension and spline interpolation in the channel/frequency dimension. To map the solutions for each spw, we use the '''spwmap''' parameter, which requires a list of all spws for each gain table to be applied, or a blank list ([]) which is a shorthand notation to apply the solution for each spw to itself. While applying Tsys, we will also apply the wvr calibration tables; wvr data is usually always present for all sources. Below we first set some definitions so we can loop over the correct parameters:<br />
<br />
<source lang="python"><br />
# In CASA<br />
fdm='17,19,21,23'<br />
nocal='3' # This source had no Tsys measurements associated with it <br />
tsysfields=['0','1','2','4'] <br />
tsysmap = range(25)<br />
tsysmap[17] = 1<br />
tsysmap[19] = 3<br />
tsysmap[21] = 5<br />
tsysmap[23] = 7<br />
for asdm in basename_all:<br />
for field in tsysfields:<br />
applycal(vis=asdm+'.ms', spw=fdm, field=field, gainfield=field,<br />
gaintable=[asdm+'.tsys', asdm+'.wvr'], spwmap=[tsysmap,[]],<br />
interp=['linear,spline','nearest'], flagbackup=F, calwt=T)<br />
</source><br />
<br />
For the sources without Tsys (i.e. field=3), couple them with the best available source with Tsys (i.e. field=4).<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename_all:<br />
applycal(vis=asdm+'.ms', spw=fdm, field=nocal,<br />
gaintable=[asdm+'.tsys', asdm+'.wvr'], spwmap=[tsysmap,[]],<br />
gainfield=['4',nocal], interp=['linear,spline','nearest'],flagbackup=F,<br />
calwt=T)<br />
</source><br />
<br />
Check Tsys application with plotms. First we make plots with '''ydatacolumn='data'''' to look at the raw data. For <br />
simplicity we'll just look at the two strongest sources 3C279 and Titan.<br />
<br />
<figure id="X5d8_wvrtsys_corrected_spw19.png"><br />
[[Image:X5d8_wvrtsys_corrected_spw19.png|thumb|<caption>Spectral plots of 3C279 (black) and Titan (magenta) for spw=19 after Tsys and wvr correction.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X5d8.ms',spw='17,19,21,23',xaxis='frequency',yaxis='amp',field='0,1',<br />
antenna='*&*',avgtime='1e8',avgscan=T,coloraxis='field',iteraxis='spw',<br />
xselfscale=T,ydatacolumn='data')<br />
</source><br />
<br />
<figure id="X5d8_wvrtsys_corrected_spw21.png"><br />
[[Image:X5d8_wvrtsys_corrected_spw21.png|thumb|<caption>Spectral plots of 3C279 (black) and Titan (magenta) for spw=21 after Tsys and wvr correction.</caption>]]<br />
</figure><br />
<br />
'''Note''': the antenna='*&*' is specifying that we only want to see the cross-correlation data (i.e. not the autocorrelations).<br />
<br />
Use the '''green arrows''' on the {{plotms}} display to cycle through the 4 FDM spws. <br />
<br />
Now change '''Data Column''' to '''corrected''' on the "Axes" tab (this is the same as ydatacolumn in the task) and hit '''Plot''' button on the GUI. Flip through again.<br />
<br />
'''Things to notice:'''<br />
* The amplitude scale has changed due to application of Tsys<br />
* spw=17 is clean and flat<br />
* spw=19 shows a strong dip around channel 3000 (channels can be plotted by going to the Axes tab, and changing X Axis to Channel, then hit the Plot button)-- this is an atmospheric ozone absorption feature at 357.6 GHz. In the future, high spectral resolution Tsys measurements may help to remove the shape of the absorption, but until then we will need to flag this part of the spectrum.<br />
* spw=21 Titan shows both a narrow and a broad spectral feature. The broad feature is CO(3-2) and it completely fills the 0.5 GHz band so there are no line-free channels! Titan must be handled carefully when it is used as a calibrator because it contains strong line emission. Indeed, we will not be able to use the absolute flux transfer from this spw for other targets. When possible Titan should be avoided for absolute flux calibration. For these observations, no other suitable absolute flux calibrator was available.<br />
* spw=23 shows another strong line from Titan.<br />
<br />
Beyond these things to notice, the application of Tsys and wvr seem to have gone well. We can now split off only the narrow band FDM spectral windows for further processing.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename_all:<br />
newvis = asdm + '_wvrtsys.ms'<br />
os.system('rm -rf ' + newvis)<br />
split(vis=asdm+'.ms',outputvis=newvis,datacolumn='corrected',spw=fdm)<br />
</source><br />
<br />
'''Note''': After {{split}}, the spectral windows will be renumbered to 0, 1, 2, 3 corresponding to the old spw=17, 19, 21, 23, see {{listobs}} excerpt below.<br />
<br />
<pre style="background-color: #fffacd;"><br />
SpwID #Chans Frame Ch1(MHz) ChanWid(kHz) TotBW(kHz) Corrs <br />
0 3840 TOPO 356497.936 122.070312 468750 XX YY <br />
1 3840 TOPO 357734.314 122.070312 468750 XX YY <br />
2 3840 TOPO 346034.314 122.070312 468750 XX YY <br />
3 3840 TOPO 343955.936 122.070312 468750 XX YY <br />
</pre><br />
<br />
==Initial Inspection and Flagging==<br />
<br />
From here we begin to operate on the *wvrtsys.ms files. <br />
<br />
Before we begin flagging data, we unflag all data in the measurement sets. If this is your first pass through this section of the guide, no data in the measurement sets will be flagged, and you can skip this step. If you are rerunning the flagging commands below, this will reset your flag columns to their original state.<br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
for vis in splitdata:<br />
flagdata(vis=vis, mode='unflag', action='apply', flagbackup=F)<br />
</source><br />
<br />
ALMA data contains both the cross correlation and autocorrelation data. Presently nothing more can be done with the autocorrelation data so we flag it. Additionally, for smaller configurations of the array, and northerly sources one antenna can ''shadow'' another, blocking its view. This data also needs to be flagged. Finally, the observing log told us DV04 was not behaving properly at Band 7 and shouldn't be used so we flag that as well.<br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
for vis in splitdata:<br />
flagdata(vis=vis, mode='manual', autocorr=True, action = 'apply', flagbackup=T)<br />
flagdata(vis=vis, mode='shadow',tolerance=12.0, action='apply', flagbackup=F)<br />
flagdata(vis=vis, mode='manual', antenna='DV04', action='apply', flagbackup=F)<br />
</source><br />
<br />
Next we inspect the data with {{plotms}} for additional issues that need flagging, first looking at amplitude vs. time for each of the three datasets. Use the '''green''' arrows on the plotms gui to cycle through spws. <br />
<br />
<figure id="Tsyswvr_time_spw0_X3x1.png"><br />
[[Image:Tsyswvr_time_spw0_X3x1.png|thumb|<caption>Amplitude as a function of time for X3c1_wvrtsys.ms, spw=0</caption>]]<br />
</figure><br />
<br />
'''Note''': when '''iteraxis''' is invoked in {{plotms}}, unzoom does not always work properly. If you have trouble with this, flip to next page and then back to current one. This usually fixes the problem.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X5d8_wvrtsys.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X7ef_wvrtsys.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw')<br />
</source><br />
<br />
<figure id="Tsyswvr_time_spw2corr_X3x1.png"><br />
[[Image:Tsyswvr_time_spw2corr_X3x1.png|thumb|<caption>Amplitude as a function of time for X3x1_wvrtsys.ms, spw=2 with colorize='corr'.</caption>]]<br />
</figure><br />
<br />
'''Things to Notice:'''<br />
* In spw=2 there are some low points in all three data files. Use the "Mark Regions" box (left of center on bottom row of icons) to draw small box on low points. Then click the magnifying glass icon to the right of center. The output will be sent to the logger window. '''Note''': keep the marked region small or you can overwhelm the buffer. Locate suggests correlation YY on PM03 is the culprit. <br />
<br />
To see this more clearly you can rerun {{plotms}} with '''coloraxis='field'''' switched to '''coloraxis='corr''''<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='2',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='corr')<br />
</source><br />
<br />
To further check, you can exclude PM03 from the plot using '''antenna='!PM03'.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='2',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='corr',antenna='!PM03')<br />
</source><br />
<br />
Having confirmed the problem antenna, we flag it below. <br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
for vis in splitdata:<br />
flagdata(vis=vis, mode='manual', action= 'apply', flagbackup=T,<br />
spw='2',<br />
antenna='PM03',<br />
correlation='YY')<br />
</source><br />
<br />
'''Next we need to inspect the spectral properties of the data to look for issues.'''<br />
<br />
First we look at phase as a function of frequency for a well behaved antenna like DV06. <br />
'''coloraxis='baselines'''' (note this parameter is called '''Colorize''' in the GUI "Display" tab) will show each baseline as a different color. Significant delay errors or baseline errors will show up as phase slopes in these plots. Again you will want to page through the spectral windows.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='',xaxis='frequency',yaxis='phase',field='0',antenna='DV06',<br />
avgtime='1e8',avgscan=T,coloraxis='baseline',iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X5d8_wvrtsys.ms',spw='',xaxis='frequency',yaxis='phase',field='0',antenna='DV06',<br />
avgtime='1e8',avgscan=T,coloraxis='baseline',iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X7ef_wvrtsys.ms',spw='',xaxis='frequency',yaxis='phase',field='0',antenna='DV06',<br />
avgtime='1e8',avgscan=T,coloraxis='baseline',iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
Overall these plots look good with no large delays or baseline errors apparent.<br />
<br />
<figure id="Birdies_spw2_X3x1.png"><br />
[[Image:Birdies_spw2_X3x1.png|thumb|<caption>Phase calibrators (brown and green) and TW Hya (orange) showing both real CO(3-2) emission in TW Hya and weak ''birdie'' spectral features in all three sources for spw=2.</caption>]]<br />
</figure><br />
<br />
With such high spectral resolution data, one often sees occasional "birdies" in the data. These are typically very narrow weak spectral features that are internally generated in the system. Over time as we track down issues the number of birdies should decrease, but you should always check. This is easiest to do by looking at amplitude vs. frequency for sources observed over a long time range (for sensitivity). It is helpful to look at more than one source to verify the nature of the emission. Below we look at both calibrators (brown and green) and TW Hya (orange). If you have enough sensitivity birdies should be seen on all sources, however, be careful not to mistake real line emission for a birdie even on a calibrator - they can be present as we've seen for Titan.<br />
<br />
<figure id="Birdies_spw3_X3x1.png"><br />
[[Image:Birdies_spw3_X3x1.png|thumb|<caption>Phase calibrators (brown and green) and TW Hya (orange) showing only weak birdie spectral features in spw=3.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='',xaxis='channel',yaxis='amp',field='2,3,4',<br />
avgtime='1e8',avgscan=T,coloraxis='field',iteraxis='spw',xselfscale=T,yselfscale=T)<br />
</source><br />
<br />
Do a quick check that other two datasets are the same (they are usually similar if the source of internal resonance hasn't changed in the meantime).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X5d8_wvrtsys.ms',spw='',xaxis='channel',yaxis='amp',field='2,3,4',<br />
avgtime='1e8',avgscan=T,coloraxis='field',iteraxis='spw',xselfscale=T,yselfscale=T)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X7ef_wvrtsys.ms',spw='',xaxis='channel',yaxis='amp',field='2,3,4',<br />
avgtime='1e8',avgscan=T,coloraxis='field',iteraxis='spw',xselfscale=T,yselfscale=T)<br />
</source><br />
<br />
Now you can zoom in on each region to get channels for flagging, or to save time just go ahead and run the flagging command below where this has been done for you.<br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
for vis in splitdata:<br />
flagdata(vis=vis, mode='manual', action='apply', flagbackup=T,<br />
spw='0:1067~1068;1279~1280;2367~2368;3775~3776, 1:1279~1280;2367~2368;3775~3776, 2:1279~1280;3775~3776, 3:831~832;1535~1536;2367~2368;3775~3776;3839~3839')<br />
</source><br />
<br />
Replot in {{plotms}} to check that flagging has been done as anticipated.<br />
<br />
==Flag Calibrator Spectral Features==<br />
<br />
In this section, we will flag spectral features in the calibrators so they do not skew the calibration solutions. First make plots of 3C279 and Titan in channel space to get channels for flagging. <br />
<br />
<figure id="3C279_Titan_spw1.png"><br />
[[Image:3C279_Titan_spw1.png|thumb|<caption>Spectral plots of 3C279 (black) and Titan (magenta) for spw=1 after Tsys and wvr correction.</caption>]]<br />
</figure><br />
<figure id="3c279_meso_freq.png"><br />
[[Image:3c279_meso_freq.png|thumb|<caption>Zoomed spectral plot of 3C279 showing mesospheric absorption of CO(3-2) in frequency space.</caption>]]<br />
</figure><br />
<figure id="3c279_meso_chann.png"><br />
[[Image:3c279_meso_chann.png|thumb|<caption>Zoomed spectral plot of 3C279 showing mesospheric absorption of CO(3-2) in channel space.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='channel',yaxis='amp',field='0,1',<br />
avgtime='1e8',coloraxis='field',iteraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
The figure to the right shows a broad absorption line in spw 1 at channel 3000. This is the ozone absorption line at 357.62982 GHz. However, there is another narrow absorption feature in the spectra (spw 2) that is most easily seen on 3C279 (because it is the strongest calibrator). Let's look at it first in frequency space.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='2:1600~2300',xaxis='frequency',yaxis='amp',<br />
field='0',avgtime='1e8',coloraxis='field')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
The absorption feature lies exactly at the rest frequency for CO 3-2 (345.79599 GHz). Because it is so narrow (< 1 MHz), it must originate from a very low pressure region (i.e. high altitude) in the Earth's atmosphere, otherwise it would be more pressure broadened. Indeed, the first detection of CO in the mesosphere was made over 35 years ago (see, e.g. [http://adsabs.harvard.edu/abs/1976Sci...191.1174W Waters et al. 1976] or [http://adsabs.harvard.edu/abs/1979JGR....84..416G Goldsmith et al. 1979]). Be aware that the line is stronger as you go up the CO ladder (strength ~ J^3 for low J) because the temperature at that altitude (~50km) is about 250 K. In April 2011, the apparent depth of the feature was about 10% in the 2-1 line and 35% in the 3-2 line. However, the depth of the absorption feature is exaggerated due to the way ALMA normalizes the cross-correlation spectra by the autocorrelation spectra prior to storage. While this technique generally leads to a flat bandpass shape, it will accentuate telluric features because they are emission lines in the single dish spectrum (e.g. JCMT observations of mesospheric CO 3-2 can be found in [http://adsabs.harvard.edu/abs/1993MNRAS.264..673P Preston et al. 1993]). Finally, note that large seasonal variations in the line strength have been reported from observations at [http://adsabs.harvard.edu/abs/2003GeoRL..30j..39F Onsala]. <br />
<br />
Now, let's re-plot the line with channel number as the x-axis in order to get the channel range for flagging. <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='2:1600~2300',xaxis='channel',yaxis='amp',<br />
field='0',avgtime='1e8',coloraxis='field')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Now lets look at Titan in more detail.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='channel',yaxis='amp',field='1',<br />
avgtime='1e8',coloraxis='field',iteraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Explicitly back up the flag tables so that flagged regions can be restored later.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
flagmanager(vis=asdm+'.ms',mode='save',versionname=asdm+'.before_calspectralflags')<br />
</source><br />
<br />
<figure id="Titan_spw2.png"><br />
[[Image:Titan_spw2.png|thumb|<caption>Spectral plot of Titan (magenta) for spw=2.</caption>]]<br />
</figure><br />
<br />
Flag absorption features for all sources.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
print "Flagging absorption features in all sources for "+asdm<br />
flagdata(vis=asdm+'.ms', mode='manual', spw='1:2000~3839, 2:1945~1960')<br />
</source><br />
<br />
<figure id="Titan_spw3.png"><br />
[[Image:Titan_spw3.png|thumb|<caption>Spectral plot of Titan (magenta) for spw=3.</caption>]]<br />
</figure><br />
<br />
Now we need to flag emission. The very broad CO(3-2) in spw=2 of Titan will prevent us from using it as a calibrator for this spectral window since there are no line-free channels (we will transfer, phase, amplitude, and absolute flux from another Titan spw below). We do want to flag the narrower Titan line in spw=3.<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
flagmanager(vis=asdm+'.ms',mode='save',versionname=asdm+'.before_emissionflags')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
print "Flagging emission for "+asdm<br />
flagdata(vis=asdm+'.ms', mode='manual', <br />
field='1',<br />
spw='3:1000~3000')<br />
</source><br />
<br />
If you like, check that the right things have been flagged.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='channel',yaxis='amp',field='0,1',<br />
avgtime='1e8',coloraxis='field',iteraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
==Set Up the Flux Calibrator Model==<br />
<br />
Fill the model data column for Titan with a model for the flux density as a function of baseline. The model is a uniformly illuminated disk with the size obtained from the JPL Horizons ephemeris.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
setjy(vis=asdm+'.ms',field='1',usescratch=F,<br />
standard='Butler-JPL-Horizons 2010',scalebychan=F)<br />
</source><br />
<br />
<figure id="Titan amp vs uvdist.png"><br />
[[Image:Titan amp vs uvdist.png|thumb|<caption>Plot of Titan model for each of the 4 spws. We used the Butler-JPL-Horizons 2010 standard to compute this model.</caption>]]<br />
</figure><br />
<br />
After running setjy, it is a good idea to plot the model in order to confirm that it makes sense. In this case, Titan is partially resolved, so we expect the flux density to drop with uv distance, but not so much as to pass through a null. We also expect it to be brighter at higher frequencies since it has a thermal blackbody spectrum.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',field='1',xaxis='uvdist',yaxis='amp',coloraxis='spw',<br />
ydatacolumn='model')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<figure id="twhydra_X3c1_wvrtsys_2012_titan_model.png">[[File:twhydra_X3c1_wvrtsys_2012_titan_model.png|thumb|right|<caption>Titan model produced by 'Butler-JPL-Horizons 2012'.</caption>]]</figure><br />
<br />
<br/><br />
<div class="noprint" style="float:none; border:0px solid blue;background-color:#F6CEF5;padding:2px;"><br />
The setjy invocation, above, uses the flux density standard '''standard='Butler-JPL-Horizons 2010' '''. A more updated standard is also available: '''standard='Butler-JPL-Horizons 2012' '''. <xr id="twhydra_X3c1_wvrtsys_2012_titan_model.png"/> shows the Titan model produced using the updated standard. The motivated reader may wish to rerun {{setjy}} using the updated model. We will highlight later in this tutorial, and in the imaging tutorial that follows, the effects of using the updated model.<br />
</div><br />
<br />
==Bandpass Calibration==<br />
<br />
First we need to check how the amplitude and phase of 3C279 behave as a function of time. In order to set<br />
a fixed scale on the y-axis, we first make a plot of all the data, excluding antenna DV04. (We must specify '''ydatacolumn='data' ''' explicitly here because the default value of '''ydatacolumn''' equals the value used in the previous execution of {{plotms}}. In the previous execution '''ydatacolumn''' was set to '''model'''. See the online help, <tt>help plotms</tt>, for details.)<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',xaxis='time',yaxis='amp',coloraxis='corr',<br />
field='0',avgchannel='3840',ydatacolumn='data')<br />
</source><br />
<br />
<figure id="ThreeScansAmp.png"><br />
[[Image:ThreeScansAmp.png|thumb|<caption>Amplitude variation for three 3C279 scans, spw 0 (for one representative baseline).</caption>]]<br />
</figure><br />
<br />
We see that the uncalibrated amplitudes range between 0.2-0.4, so let's set this as our<br />
scale and examine a representative baseline (DV06-DV07) to see how the amplitude changes with time. <br />
<br />
<source lang="python"><br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for spw in ['0','1','2','3']:<br />
for asdm in basename:<br />
print "Now showing spw %s from %s" % (spw, asdm+'.ms')<br />
plotms(vis=asdm+'.ms',spw=spw,xaxis='time',yaxis='amp',coloraxis='corr',iteraxis='spw',<br />
field='0',avgchannel='3840',antenna='DV06&DV07',plotrange=[0,0,0.2,0.4])<br />
user_check=raw_input('press enter to go to the next plot\n')<br />
</source><br />
<br />
<figure id="ThreeScansPhase.png"><br />
[[Image:ThreeScansPhase.png|thumb|<caption>Phase variation for three 3C279 scans, spw 0 (for one representative baseline).</caption>]]<br />
</figure><br />
<br />
Page through the measurement sets for each spw. This shows significant variations in the amplitude across the three measurement sets.<br />
Now do the same with phase.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for spw in ['0','1','2','3']:<br />
for asdm in basename:<br />
print "Now showing spw %s from %s" % (spw, asdm+'.ms')<br />
plotms(vis=asdm+'.ms',spw=spw,xaxis='time',yaxis='phase',coloraxis='corr',iteraxis='spw',<br />
field='0',avgchannel='3840',antenna='DV06&DV07',plotrange=[0,0,-180,180])<br />
user_check=raw_input('press enter to go to the next plot\n')<br />
</source><br />
<br />
This examination reveals two findings: (1) significant variation in the phase across the three scans, as well as (2) smaller but significant variations within a scan. The first finding suggests that we do not want to combine the scans for bandpass calibration, but instead derive an independent bandpass for each scan. Actually what is more important than a DC offset is if the '''shape''' of the amplitude or phase changes from scan to scan. There isn't enough S/N to tell for sure so we will keep them separate. This situation is often the case, which is why we did not concatenate the three datasets prior to calibration. The second finding suggests that we need to correct the phase vs. time behavior of the bandpass calibrator (3C279; field=0) within each scan, before doing the bandpass. We want to chose a relatively narrow range of channels near the center of the spws so that the bandpass phase slopes (to be corrected with the bandpass calibration itself) do not decorrelate the signal. You need to avoid spectral regions that were completely flagged above.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.bpphase.gcal')<br />
gaincal(vis=asdm+'.ms',caltable=asdm+'.bpphase.gcal',<br />
field='0',spw='0~3:900~1100',refant='DV06',<br />
calmode='p',solint='int',minsnr=2.0,minblperant=4)<br />
</source><br />
<br />
<figure id="X7ef_wvrtsys.bpphase.X.png"><br />
[[Image:X7ef_wvrtsys.bpphase.X.png|thumb|<caption>Phase only solutions for correlation X on the third scan of the bandpass calibrator 3C279.</caption>]]<br />
</figure><br />
<br />
Inspect the phase-only calibration solutions for the bandpass calibrator. Look for any noisy solutions. We do XX and YY separately to reduce confusion in the plot. It will help if you make your plotcal window wide.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.bpphase.gcal',xaxis='time',yaxis='phase',spw='',antenna='1~8', <br />
iteration='antenna',subplot=421,plotrange=[0,0,-180,180],<br />
figfile=asdm+'.bpphase.X.png',poln='X')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
In the plotcal gui you can use the magnifying glass symbol to zoom in on one of the scans to see the phase variations. The colors are the 4 different spws.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.bpphase.gcal',xaxis='time',yaxis='phase',spw='',antenna='1~8', <br />
iteration='antenna',subplot=421,plotrange=[0,0,-180,180],<br />
figfile=asdm+'.bpphase.Y.png',poln='Y')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Next we apply this phase-only correction on the fly while calculating the bandpass solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.bandpass.bcal')<br />
bandpass(vis=asdm+'.ms',caltable=asdm+'.bandpass.bcal',<br />
field='0',spw='',combine='',refant='DV06',<br />
solint='inf',solnorm=T,minblperant=4, bandtype='B', fillgaps=17,<br />
gaintable=asdm+'.bpphase.gcal')<br />
</source><br />
<br />
You will see some error messages in the terminal, these are just related to the flagged channels. We set fillgaps=17 to interpolate across the smaller regions of flagged channels (mesospheric features and birdies).<br />
<br />
<figure id="Bandpass.ampspw0.png"><br />
[[Image:Bandpass.ampspw0.png|thumb|<caption>Bandpass amplitude solution plots.</caption>]]<br />
</figure><br />
<figure id="Bandpass.phasespw0.png"><br />
[[Image:Bandpass.phasespw0.png|thumb|<caption>Bandpass phase solution plots.</caption>]]<br />
</figure><br />
<br />
'''A few words about solint and combine:'''<br />
<br />
In {{bandpass}}, the use of '''solint='inf'''' (as in "infinite") will derive a bandpass<br />
solution for each 3C279 scan, '''unless''' '''combine='scan'''' (which is the default). Here we set combine=' ' explicitly so that it does not combine the scans into one bandpass. Likewise, field boundaries are only crossed if combine='field', and spw boundaries are only crossed if combine='spw'. In some cases it can be helpful to combine fields if you suffer from lack of S/N, but it is never a good idea to combine spws. <br />
<br />
Now inspect the phase and amplitude solutions. You are looking for excursions from smooth fits, or particularly noisy solutions compared to the others. <br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
for spw in [0,1,2,3]:<br />
plotbandpass(asdm+'.bandpass.bcal',xaxis='freq',yaxis='amp', spw=spw,<br />
antenna='1~8', subplot=42, figfile=asdm+'.bandpass.amp', showatm=T,<br />
interactive=True)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
for spw in [0,1,2,3]:<br />
plotbandpass(asdm+'.bandpass.bcal',xaxis='freq',yaxis='phase',spw=spw,<br />
antenna='1~8',subplot=42,figfile=asdm+'.bandpass.phs', showatm=T,<br />
interactive=True)<br />
</source><br />
<br />
The values of phase on DV06 are very close to zero because it was used as the reference antenna.<br />
<br />
==Gain Calibration==<br />
<br />
Now that we have a bandpass solution to apply we can solve for the antenna-based phase and amplitude gain calibration. Since the phase changes on a much shorter timescale than the amplitude, we will solve for them separately. In particular, if the phase changes significantly over a scan time, the amplitude would be decorrelated, if the un-corrected phase were averaged over this timescale. Note that we re-solve for the gain solutions of the bandpass calibrator, so we can derive new solutions that are corrected for the bandpass shape. Since the bandpass calibrator will not be used again, this is not strictly necessary, but is useful to check its calibrated flux density for example. <br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.intphase.gcal')<br />
gaincal(vis=asdm+'.ms',caltable=asdm+'.intphase.gcal',<br />
field='0,1,3,4',spw='0~3:40~3800',refant='DV06',<br />
calmode='p',solint='int',minsnr=2.0,minblperant=4,<br />
gaintable=[asdm+'.bandpass.bcal'])<br />
</source><br />
<br />
Here '''solint='int' ''' coupled with '''calmode='p' ''' will derive a single phase solution for each 10 second integration. Note that the bandpass table is applied on-the-fly before solving for the phase solutions, however the bandpass is NOT applied to the data permanently until applycal is run later on. <br />
<br />
Although '''solint='int' ''' (i.e. the integration time of 10 seconds) is the best choice to apply before solving for the amplitude solutions, it is not a good idea to use this to apply to the target. This is because the phase-scatter within a scan can dominate the interpolation between calibrator scans. Instead, we also solve for the phase on the scan time, '''solint='inf' ''' (but '''combine=' ' ''', since we want one solution per scan) for application to the target later on. Unlike the bandpass task, for {{gaincal}}, the default of the combine parameter is '''combine=' ' '''. <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.scanphase.gcal')<br />
gaincal(vis=asdm+'.ms',caltable=asdm+'.scanphase.gcal',<br />
field='0,1,3,4',spw='0~3:40~3800',refant='DV06',<br />
calmode='p',solint='inf',minsnr=2.0,minblperant=4,<br />
gaintable=[asdm+'.bandpass.bcal'])<br />
</source><br />
<br />
Alternatively, instead of making a separate phase solution for application to the target, one can also run {{smoothcal}} to smooth the solutions derived on the integration time. <br />
<br />
Next we apply the bandpass and '''solint='int' ''' phase-only calibration solutions on-the-fly to derive amplitude solutions. Here the use of '''solint='inf' ''', but '''combine=' ' ''' will result in one solution per scan interval. <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.amp.gcal')<br />
gaincal(vis=asdm+'.ms',caltable=asdm+'.amp.gcal',<br />
field='0,1,3,4',spw='0~3:40~3800',refant='DV06',<br />
calmode='ap',solint='inf',minsnr=2.0,minblperant=4,<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal'])<br />
</source><br />
<br />
Now carefully inspect all these solutions looking for discrepant solutions. If you see any, you will need to flag them and rerun the calibration tasks above. <br />
<br />
We make plots in X and Y separately for clarity. The colors are showing the spectral windows.<br />
<figure id="X3c1_wvrtsys.intphase_X.png"><br />
[[Image:X3c1_wvrtsys.intphase_X.png|thumb|<caption>Phase solutions for the X polarization for every integration time of the first dataset.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.intphase.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',iteration='antenna',subplot=421,<br />
plotrange=[0,0,-180,180],poln='X',figfile=asdm+'.intphase_X.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.intphase.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',iteration='antenna',subplot=421,<br />
plotrange=[0,0,-180,180],poln='Y',figfile=asdm+'.intphase_Y.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<figure id="X3c1_wvrtsys.scanphase_X.png"><br />
[[Image:X3c1_wvrtsys.scanphase_X.png|thumb|<caption>Phase solutions for the X polarization for each scan of the first dataset.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.scanphase.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',iteration='antenna',subplot=421,<br />
plotrange=[0,0,-180,180],poln='X',figfile=asdm+'.scanphase_X.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.scanphase.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',iteration='antenna',subplot=421,<br />
plotrange=[0,0,-180,180],poln='Y',figfile=asdm+'.scanphase_Y.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Since we have taken out the phase as best we can by applying the '''solint='int' ''' phase-only solution, this plot will give a good idea of the residual phase error. If you see scatter of more than a few degrees here, you should consider going back and looking for more data to flag, particularly bad timeranges etc. <br />
<br />
<figure id="X3c1_wvrtsys.amp_phase.png"><br />
[[Image:X3c1_wvrtsys.amp_phase.png|thumb|<caption>Residual phase after applying intphase.gcal for both correlations in the first dataset.</caption>]]<br />
</figure><br />
<figure id="X3c1_wvrtsys.amp_X.png"><br />
[[Image:X3c1_wvrtsys.amp_X.png|thumb|<caption>Amplitude solutions on a scan interval for correlation X in the first dataset.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.amp.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',plotrange=[0,0,-1,1],<br />
iteration='antenna',subplot=421,figfile=asdm+'.amp_phase.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
These are very small, as they should be. Now look at the amplitude solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.amp.gcal',xaxis='time',yaxis='amp',antenna='1~8', <br />
iteration='antenna',subplot=421,spw='',poln='X',<br />
plotrange=[0,0,0.0,0.3],figfile=asdm+'.amp_X.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.amp.gcal',xaxis='time',yaxis='amp',antenna='1~8', <br />
iteration='antenna',subplot=421,spw='',poln='Y',<br />
plotrange=[0,0,0.0,0.3],figfile=asdm+'.amp_Y.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
==Flux Calibration==<br />
<br />
Next we use the flux calibrator (whose flux density was set in {{setjy}} above) to derive the flux density of the other calibrators. Note that the flux table REPLACES the amp.gcal in terms of future application of the calibration to the data, i.e. the flux table contains both the amp.gcal and flux scaling. Unlike the gain calibration steps, this is not an incremental table.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.flux.cal')<br />
fluxscale(vis=asdm+'.ms',caltable=asdm+'.amp.gcal',<br />
fluxtable=asdm+'.flux.cal',reference='1',refspwmap=[0,1,3,3],<br />
listfile=asdm+'.fluxscale.txt')<br />
</source><br />
<br />
Its a good idea to record the derived fluxscale values using the listfile option. The values can also be viewed in the Log Messages window.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Found reference field(s): Titan<br />
Found transfer field(s): 3c279 J1147-382=QSO J1037-295=QSO<br />
Spw=2 will be referenced to spw=3<br />
Flux density for 3c279 in SpW=0 (freq=3.56498e+11 Hz) is: 10.537 +/- 0.0183518 (SNR = 574.169, N = 16)<br />
Flux density for 3c279 in SpW=1 (freq=3.57734e+11 Hz) is: 10.6933 +/- 0.0264134 (SNR = 404.842, N = 16)<br />
Flux density for 3c279 in SpW=2 (freq=3.46034e+11 Hz) (ref SpW=3) is: 10.251 +/- 0.0477949 (SNR = 214.479, N = 14)<br />
Flux density for 3c279 in SpW=3 (freq=3.43956e+11 Hz) is: 9.91798 +/- 0.020167 (SNR = 491.791, N = 16)<br />
Flux density for J1147-382=QSO in SpW=0 (freq=3.56498e+11 Hz) is: 1.03399 +/- 0.0167344 (SNR = 61.7887, N = 16)<br />
Flux density for J1147-382=QSO in SpW=1 (freq=3.57734e+11 Hz) is: 0.844817 +/- 0.0191013 (SNR = 44.2283, N = 16)<br />
Flux density for J1147-382=QSO in SpW=2 (freq=3.46034e+11 Hz) (ref SpW=3) is: 0.987193 +/- 0.024391 (SNR = 40.4737, N = 14)<br />
Flux density for J1147-382=QSO in SpW=3 (freq=3.43956e+11 Hz) is: 1.28859 +/- 0.0194364 (SNR = 66.298, N = 16)<br />
Flux density for J1037-295=QSO in SpW=0 (freq=3.56498e+11 Hz) is: 0.968281 +/- 0.00895224 (SNR = 108.161, N = 16)<br />
Flux density for J1037-295=QSO in SpW=1 (freq=3.57734e+11 Hz) is: 0.75916 +/- 0.015366 (SNR = 49.4053, N = 16)<br />
Flux density for J1037-295=QSO in SpW=2 (freq=3.46034e+11 Hz) (ref SpW=3) is: 0.948551 +/- 0.0165421 (SNR = 57.3416, N = 14)<br />
Flux density for J1037-295=QSO in SpW=3 (freq=3.43956e+11 Hz) is: 1.21905 +/- 0.0139967 (SNR = 87.0956, N = 16)<br />
Fitted spectrum for 3c279 with fitorder=1: Flux density = 10.2962 +/- 0.0450319 (freq=351.002 GHz) spidx=1.70757 +/- 0.245737<br />
Fitted spectrum for J1147-382=QSO with fitorder=1: Flux density = 1.06853 +/- 0.0709817 (freq=351.002 GHz) spidx=-6.77353 +/- 3.71867<br />
Fitted spectrum for J1037-295=QSO with fitorder=1: Flux density = 1.01822 +/- 0.0654586 (freq=351.002 GHz) spidx=-6.28977 +/- 3.71453<br />
Storing result in X7ef_wvrtsys.flux.cal<br />
Writing solutions to table: X7ef_wvrtsys.flux.cal<br />
</pre><br />
<br />
<figure id="x3c1_wvrtsys.flux_X.png"><br />
[[Image:x3c1_wvrtsys.flux_X.png|thumb|<caption>Absolute flux calibration solutions for correlation X for the first dataset.</caption>]]<br />
</figure><br />
<br />
<div class="noprint" style="float:none; border:0px solid blue;background-color:#F6CEF5;padding:2px;"><br />
If you used the updated (Butler-JPL-Horizons 2012) flux density standard when you ran {{setjy}} earlier in this tutorial, the derived flux values for the calibrators will be slightly different. For example, when averaged over the 3 measurement sets, 3c279 in spectral window 0 has a flux of 10.77 Jy using the 2010 standard and 10.63 Jy using the 2012 standard; as a second example, J1147-382 in SPW 3 has an average flux of 1.13 Jy (2010 standard) and 1.15 Jy (2012 standard). <br />
</div><br />
<br />
Now look at the flux solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.flux.cal',xaxis='time',yaxis='amp',antenna='1~8', <br />
iteration='antenna',subplot=421,spw='',poln='X',<br />
plotrange=[0,0,0.0,0.3],figfile=asdm+'.flux_X.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.flux.cal',xaxis='time',yaxis='amp',antenna='1~8', <br />
iteration='antenna',subplot=421,spw='',poln='Y',<br />
plotrange=[0,0,0.0,0.3],figfile=asdm+'.flux_Y.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
==Apply Calibration and Inspect==<br />
<br />
Now we can use the {{flagmanager}} if we want to restore any of the spectral flagging we did prior to bandpass calibration. <br />
In this case, we choose to restore the flags of the emission lines on Titan, because we are interested in seeing how<br />
strong they are compared to the continuum. However, we leave the strong ozone line and mesospheric CO line flagged on all <br />
sources, because we want to get the most accurate continuum flux density for the science target. <br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
flagmanager(vis=asdm+'.ms',mode='restore',versionname=asdm+'.before_emissionflags')<br />
</source><br />
<br />
Next we apply the calibration solutions to each source individually, using the '''gainfield''' parameter to specify which calibrator's solutions should be applied from each of the '''gaintable''' calibration tables. <br />
<br />
First, we do 3C279 (the bandpass calibrator), applying all 3 of its solutions to itself (that's why gainfield contains three zeros):<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='0',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['0','0','0'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
Next, we do Titan (the absolute flux calibrator) using the bandpass solution from 3C279:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='1',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['0','1','1'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
For the secondary phase calibrator, we apply the phase and flux solutions from the primary phase calibrator. This will allow us to check how well the phase transfer to the science target (TW Hya) has worked:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='3',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.scanphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','linear','linear'],<br />
gainfield=['0','4','4'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
Next is the Primary phase calibrator:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='4',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['0','4','4'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
Finally, for the Science Target TW Hya, we apply the phase solutions from both the primary and secondary phase calibrators:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='2',<br />
interp=['nearest','linear','linear'],<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.scanphase.gcal',asdm+'.flux.cal'],<br />
gainfield=['0','3,4','3,4'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
Now we can check the results of applying the calibration solutions.<br />
<br />
<figure id="Corrected_vs_time_1.png"><br />
[[Image:Corrected_vs_time_1.png|thumb|<caption>The calibrated data for the first dataset (amplitude vs. time).</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw',ydatacolumn='corrected')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
In amplitude, it looks good but there are some noisy points toward the end of the first scheduling block, but it mostly only affects the secondary phase calibrator (green). In phase, we expect all the points to cluster about zero. The large scatter in phase on the secondary phase calibrator is readily apparent: <br />
<br />
<figure id="Corrected_phase_vs_time_1.png"><br />
[[Image:Corrected_phase_vs_time_1.png|thumb|<caption>The calibrated data on the calibrators for the first dataset (phase vs. time).</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='time',yaxis='phase',field='0,1,3,4',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw',ydatacolumn='corrected')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Let's check whether the situation improves when we apply this calibrator's solutions to itself rather than transferring the solutions from the primary phase calibrator (which is 17 degrees away, and observed at a different time). <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='3',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['0','3','3'],flagbackup=T, calwt=T)<br />
</source><br />
<br />
<figure id="Corrected_vs_time_1_field3.png"><br />
[[Image:Corrected_vs_time_1_field3.png|thumb|<caption>The calibrated data for the first dataset (amplitude vs. time), but now with field 3, the secondary phase calibrator, calibrated with itself.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw',ydatacolumn='corrected')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<figure id="Corrected_phase_vs_time_1_field3.png"><br />
[[Image:Corrected_phase_vs_time_1_field3.png|thumb|<caption>The calibrated data from the first dataset (phase vs. time), but now with field 3, the secondary phase calibrator, calibrated with itself.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='time',yaxis='phase',field='0,1,3,4',<br />
avgchannel='3840', coloraxis='field',iteraxis='spw',<br />
ydatacolumn='corrected')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Indeed, the secondary calibrator looks better now in amplitude and phase. This is an indication that the calibration transfer is not working well in this timerange. Because the effect is not catastrophic and we know we can self-calibrate on TW Hya later, we will let this go for now. Or, if you want you can delve deeper into the data and try to solve the mystery... <br />
<br />
In any case, we will re-issue the original {{applycal}} so that it is this calibration that our subsequent {{split}} will use. This will allow us to check the effect of correcting the secondary phase calibrator with the primary phase calibrator later. <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='3',<br />
gaintable=[asdm+'.bandpass.bcal', asdm+'.scanphase.gcal', asdm+'.flux.cal'],<br />
interp=['nearest','linear','linear'],<br />
gainfield=['0','4','4'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
<br />
Let's check the spectral calibration now. First 3C279 and Titan:<br />
<br />
<figure id="X3c1_spw2_corrected_3.4.png"><br />
[[Image:X3c1_spw2_corrected_3.4.png|thumb|<caption>Spectral UV-plots of 3C279 and Titan of spw=2 for the first dataset.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='frequency',yaxis='amp',field='0,1',<br />
avgtime='1e8',avgscan=T,coloraxis='field',ydatacolumn='corrected',<br />
iteraxis='spw',xselfscale=T)<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Flip through the spws. These look good. Next the two phase calibrators:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='frequency',yaxis='amp',field='3,4',<br />
avgtime='1e8',avgscan=T,coloraxis='field',ydatacolumn='corrected',<br />
iteraxis='spw',xselfscale=T)<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Flip through the spws. This also looks good, the secondary phase calibrator is a bit noisier but this is normal. The upswing at the lower frequency end of spw=3 will probably need to be flagged on the science target as well. It corresponds to the edge of an atmospheric feature.<br />
<br />
Now for the exciting part, what does the science target look like...<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='frequency',yaxis='amp',field='2',<br />
avgtime='1e8',avgscan=T,coloraxis='field',ydatacolumn='corrected',<br />
iteraxis='spw',xselfscale=T)<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
We see HCO+(4-3) in spw=0 and CO(3-2) in spw=2 as expected. Because the shape of the <br />
line profiles varies with baseline, you can already tell that the line emission is resolved.<br />
<br />
<figure id="X3c1_CO3_2_uvplot_3.4.png"><br />
[[Image:X3c1_CO3_2_uvplot_3.4.png|thumb|<caption>UV-Plot of the TW Hya CO(3-2) emission from the first dataset.</caption>]]<br />
</figure><br />
<figure id="X3c1_HCOp4_3_uvplot_3.4.png"><br />
[[Image:X3c1_HCOp4_3_uvplot_3.4.png|thumb|<caption>UV-Plot of the TW Hya HCO+(4-3) emission from the first dataset.</caption>]]<br />
</figure><br />
<br />
Now check that the velocity of TWHydra is correct in the LSRK frame, it should be around 2.88 km/s.<br />
* CO 3-2 rest freq 345.79599 GHz<br />
* HCO+ 4-3 rest freq 356.7342 GHz<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='2',xaxis='velocity',yaxis='amp',field='2',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',<br />
restfreq='345.79599GHz', plotrange=[-10,15,0,0],coloraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='0',xaxis='velocity',yaxis='amp',field='2',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',<br />
restfreq='356.7342GHz',plotrange=[-10,15,0,0],coloraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Both lines show up at the expected velocity.<br />
<br />
<br />
==Concatenate the Data==<br />
<br />
Here we will concatenate the three datasets prior to imaging.<br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
os.system('rm -rf Band7multi_april22.ms')<br />
concat(vis=splitdata,concatvis='Band7multi_april22.ms')<br />
</source><br />
<br />
If you like you can run listobs on new combined dataset<br />
<br />
<source lang="python"><br />
# In CASA<br />
listfile = 'Band7multi_april22.listobs.txt'<br />
os.system('rm ' + listfile)<br />
listobs(vis='Band7multi_april22.ms',verbose=F, listfile=listfile)<br />
</source><br />
<br />
<figure id="All_spw2_corrected_3.4.png"><br />
[[Image:All_spw2_corrected_3.4.png|thumb|<caption>Spectral UV-plots of 3C279 and Titan of spw=2 for the combined datasets.</caption>]]<br />
</figure><br />
<br />
You can also examine the spectral uv plots for the combined dataset to see the improvement in S/N: <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='Band7multi_april22.ms',spw='',xaxis='frequency',yaxis='amp',field='0,1',<br />
avgtime='1e8',avgscan=T,coloraxis='field',ydatacolumn='corrected',<br />
iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
<figure id="All_CO3_2_uvplot_3.4.png"><br />
[[Image:All_CO3_2_uvplot_3.4.png|thumb|<caption>UV-Plot of the TW Hya CO(3-2) emission from the combined datasets.</caption>]]<br />
</figure><br />
<br />
...and the CO line profile for the combined dataset: <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='Band7multi_april22.ms',spw='2',xaxis='velocity',yaxis='amp',field='2',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',restfreq='345.79599GHz',<br />
plotrange=[-10,15,0,0],coloraxis='spw')<br />
</source><br />
<br />
==Split Calibrated Data==<br />
<br />
Now we split off the calibrated data for the Science Target as well as the interesting parts of the calibrators for imaging.<br />
<br />
When we {{split}} off the Titan data, a few dozen warnings like the following are written to the log:<br />
<pre><br />
2012-05-15 22:00:35 WARN split::SubMS::copySource() Invalid SOURCE ID in SOURCE table row 20 <br />
</pre><br />
These can be ignored, because they do not indicate any problem that will prevent you from imaging Titan correctly at a single position using all the data in the output ms.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_corrected.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='TWHydra_corrected.ms',<br />
datacolumn='corrected',spw='',field='2')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf J1037_corrected.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='J1037_corrected.ms',<br />
datacolumn='corrected',spw='',field='4')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf J1147_corrected.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='J1147_corrected.ms',<br />
datacolumn='corrected',spw='',field='3')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3C279_CO3_2.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='3C279_CO3_2.ms',<br />
datacolumn='corrected',spw='2:1900~2000',field='0')<br />
</source><br />
<br />
==Optional: Reconcile Titan's Coordinates==<br />
<br />
If you do not care to image Titan, then you can skip this step and simply continue on to the [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_4.5 imaging guide].<br />
<br />
Our earlier treatment of Titan's coordinates using [http://casa.nrao.edu/stable/docs/TaskRef/fixplanets-task.html fixplanets] replaced the zeros written by the ALMA control system with the correct position of the body at the instant of the first observation of that SB. As a result, it has slightly different positions in all three datasets, as seen by listobs:<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='Band7multi_april22.ms',verbose=F)<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
ID Code Name RA Decl Epoch SrcId nRows <br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 70866 <br />
1 none Titan 12:49:25.97588 -02.22.41.3024 J2000 1 4842 <br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 515151 <br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 40797 <br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 171153 <br />
5 none Titan 12:49:26.53729 -02.22.27.1521 J2000 0 4833 <br />
6 none Titan 12:49:26.53059 -02.22.18.7878 J2000 0 4833 <br />
</pre><br />
<br />
If we want to image such moving objects observed across multiple SBs, we need to bring the positions into agreement, otherwise {{clean}} will try to make a mosaic. Task [http://casa.nrao.edu/stable/docs/TaskRef/fixplanets-task.html fixplanets] can be used to do this. Here, we set the direction to the direction of the first dataset as reported by listobs. Note that the RA/Dec format is slightly different from the {{listobs}} output format. Also, we do not<br />
fix the uvw coordinates because they are already more correct now than they would be if we "fixed" them.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fixplanets(vis='Band7multi_april22.ms', field='Titan', direction='J2000 12h49m25.97588 -02d22m41.3024', fixuvw=False)<br />
</source><br />
<br />
Check the header information again to see that the information for Titan has changed for the second<br />
and third datasets. They will appear as fields 5 and 6.<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='Band7multi_april22.ms',verbose=F)<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
ID Code Name RA Decl Epoch SrcId <br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 70866 <br />
1 none Titan 12:49:25.97588 -02.22.41.3024 J2000 1 4842 <br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 515151 <br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 40797 <br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 171153 <br />
5 none Titan 12:49:25.97588 -02.22.41.3024 J2000 0 4833 <br />
6 none Titan 12:49:25.97588 -02.22.41.3024 J2000 0 4833 <br />
</pre><br />
<br />
==Optional: Split Calibrated Titan Data==<br />
<br />
When we {{split}} off the Titan data, a few dozen warnings like the following are written to the log:<br />
<pre><br />
2012-05-15 22:00:35 WARN split::SubMS::copySource() Invalid SOURCE ID in SOURCE table row 20 <br />
</pre><br />
These can be ignored, because they do not indicate any problem that will prevent you from imaging Titan correctly at a single position using all the data in the output ms.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Titan_cont.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='Titan_cont.ms',<br />
datacolumn='corrected',spw='0',field='1')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Titan_CO3_2.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='Titan_CO3_2.ms',<br />
datacolumn='corrected',spw='2',field='1')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Titan_unknown.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='Titan_unknown.ms',<br />
datacolumn='corrected',spw='3',field='1')<br />
</source><br />
<br />
==Continue on to Imaging of the Science Target==<br />
<br />
Now you can continue on to the [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_4.5 imaging guide].<br />
<br />
{{Checked 4.5.2}}</div>Sstierwahttps://casaguides.nrao.edu/index.php?title=TWHydraBand7_Calibration_4.5&diff=19471TWHydraBand7 Calibration 4.52016-05-18T03:58:58Z<p>Sstierwa: </p>
<hr />
<div>[[Category:ALMA]][[Category:Calibration]][[Category:Spectral Line]]<br />
*'''This script assumes that you have downloaded TWHYA_BAND7_UnCalibratedMSAndTablesForReduction.tgz from [[TWHydraBand7#Getting_the_Data]]'''<br />
<br />
*'''An introduction to this data set is available at [[TWHydraBand7]].<br />
<br />
*'''This guide is designed for CASA 4.5.2 If you are using an older version of CASA please see [[TWHydraBand7_Calibration_4.3]].<br />
<br />
==Preparation==<br />
<br />
Once you have downloaded TWHYA_BAND7_UnCalibratedMSAndTablesForReduction.tgz, in a terminal unpack it with<br />
<br />
<source lang="bash"><br />
tar -zxvf TWHYA_BAND7_UnCalibratedMSAndTablesForReduction.tgz<br />
</source><br />
<br />
Please be aware that you will need about 100 GB of free space to do the data reduction. It is a good idea to check that now before you begin. Some of the plots described here require 9 GB of RAM; as little as 4 GB may be sufficient if additional data averaging is used when the plots are generated. When you are satisfied with the available drive space and memory on your machine:<br />
<br />
<source lang="bash"><br />
cd TWHYA_BAND7_UnCalibratedMSAndTablesForReduction<br />
</source><br />
<br />
'''NOTE: the calibration tables included in TWHYA_BAND7_UnCalibratedMSAndTablesForReduction CANNOT be used with CASA 4.5, they should be discarded, or moved out of the working directory.'''<br />
<br />
Then start CASA by typing casa at a shell prompt. <br />
<br />
<source lang="bash"><br />
casa<br />
</source><br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.5.2. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.5.2'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
==Install Analysis Utilities==<br />
<br />
Analysis Utilities (or analysisUtils for short) is a small set of Python scripts that provide a number of analysis and plotting utilities for ALMA data reduction. This guide uses a few of these utilities. They are very easy to install (just download and untar). See <br />
<br />
http://casaguides.nrao.edu/index.php?title=Analysis_Utilities<br />
<br />
for a full description and download instructions. If you do not wish to do this, see the [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Calibration_for_CASA_3.3 CASA 3.3 version of the guide] for alternative (but slow) plotting options. Analysis Utilities are updated frequently so if its been a while since you installed it, its probably worth doing it again. If you are at an ALMA site or ARC, the analysis utilities are probably already installed and up to date.<br />
<br />
==Fix Titan's coordinates==<br />
<br />
'''Note that in the near future this step will be unnecessary.''' <br />
<br />
It is temporarily necessary to correct the positions of ephemeris objects observed during ALMA Cycle 0, because the control software revisions earlier than 9.0 erroneously write the data with coordinates of 00:00:00.0000 +00.00.00.0000 (J2000). For this dataset, we need to correct the position of the absolute flux calibrator Titan, as we can<br />
see from the first {{listobs}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -f X3c1.ms.listobs')<br />
listobs('X3c1.ms', verbose=T, listfile='X3c1.ms.listobs') <br />
</source><br />
<br />
You can view the listobs output files using command "less" from the CASA prompt.<br />
<br />
<pre style="background-color: #fffacd;"><br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 23625<br />
1 none Titan 00:00:00.00000 +00.00.00.0000 J2000 1 4842<br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 175176<br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 14832<br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 59877<br />
</pre><br />
<br />
To correct Titan's position, we will use the task [http://casa.nrao.edu/stable/docs/TaskRef/fixplanets-task.html fixplanets], which writes the actual coordinates at the instant of the first observation. This step takes a while because we are recalculating the uvw's accordingly.<br />
<source lang="python"><br />
# In CASA<br />
fixplanets(vis='X3c1.ms', field='Titan', fixuvw=True)<br />
</source><br />
<br />
Check the header information again with {{listobs}} to confirm that the information for Titan has changed:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -f X3c1.ms.listobs')<br />
listobs('X3c1.ms', verbose=T, listfile='X3c1.ms.listobs') <br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 23625<br />
1 none Titan 12:49:25.93349 -02.22.41.5638 J2000 1 4842<br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 175176<br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 14832<br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 59877<br />
</pre><br />
<br />
Now fix the other two measurement sets similarly:<br />
<source lang="python"><br />
# In CASA<br />
fixplanets(vis='X5d8.ms', field='Titan', fixuvw=True)<br />
fixplanets(vis='X7ef.ms', field='Titan', fixuvw=True)<br />
</source><br />
<br />
==Observing Log and Priors==<br />
<br />
Below is some information that may not be obvious from the data<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Like at most telescopes, the ALMA operators and astronomers at the site log any significant issues <br />
that were noticed from the online system during the observation. For these Band 7 observations of <br />
TW Hya on April 22, 2011, the only issue of note was that antenna DV04 could not observe at Band 7 <br />
and will need to be flagged. <br />
</pre><br />
<br />
First let's examine the basic properties of the data using {{listobs}}. Among other information we <br />
will be able to deduce what the source ids are and what each source was used for:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
3c279 is the bandpass calibrator (field id=0)<br />
Titan is the absolute flux calibrator (field id=1)<br />
J1147-382 is the secondary phase calibrator (field id=3)<br />
J1037-295 is the primary phase calibrator (field id=4)<br />
</pre><br />
<br />
<source lang="python"><br />
# In CASA<br />
data=['X3c1.ms','X5d8.ms','X7ef.ms']<br />
for vis in data:<br />
os.system('rm '+vis+'.listobs')<br />
listobs(vis, verbose=T, listfile=vis+'.listobs') <br />
</source><br />
<br />
You can view the {{listobs}} output files using command '''less''' from the CASA prompt. <br />
Below we copy select parts of the {{listobs}} output files for reference. <br />
<br />
<pre style="background-color: #fffacd;"><br />
X3c1.ms:<br />
Data records: 278352 Total integration time = 6109.06 seconds<br />
Observed from 22-Apr-2011/00:01:52.9 to 22-Apr-2011/01:43:42.0 (UTC)<br />
<br />
X5d8.ms:<br />
Data records: 278406 Total integration time = 5995.01 seconds<br />
Observed from 22-Apr-2011/01:48:05.8 to 22-Apr-2011/03:28:00.8 (UTC)<br />
<br />
X7ef.ms:<br />
Data records: 255717 Total integration time = 5407.49 seconds<br />
Observed from 22-Apr-2011/03:30:39.7 to 22-Apr-2011/05:00:47.2 (UTC)<br />
<br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 23625<br />
1 none Titan 12:49:25.97588 -02.22.41.3024 J2000 1 4842<br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 175176<br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 14832<br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 59877 <br />
<br />
SpwID #Chans Frame Ch1(MHz) ChanWid(kHz) TotBW(kHz) Corrs<br />
0 4 TOPO 184550 1500000 7500000 I<br />
1 128 TOPO 355740.062 15625 2000000 XX YY<br />
2 1 TOPO 356716.625 1796875 1796875 XX YY<br />
3 128 TOPO 356507.813 15625 2000000 XX YY<br />
4 1 TOPO 357484.375 1796875 1796875 XX YY<br />
5 128 TOPO 346792.187 15625 2000000 XX YY<br />
6 1 TOPO 345784.375 1796875 1796875 XX YY<br />
7 128 TOPO 345182.438 15625 2000000 XX YY<br />
8 1 TOPO 344174.625 1796875 1796875 XX YY<br />
9 128 TOPO 344386.763 15625 2000000 XX YY<br />
10 1 TOPO 343378.95 1796875 1796875 XX YY<br />
11 128 TOPO 346324.263 15625 2000000 XX YY<br />
12 1 TOPO 345316.45 1796875 1796875 XX YY<br />
13 128 TOPO 354402.388 15625 2000000 XX YY<br />
14 1 TOPO 355378.95 1796875 1796875 XX YY<br />
15 128 TOPO 356402.388 15625 2000000 XX YY<br />
16 1 TOPO 357378.95 1796875 1796875 XX YY<br />
17 3840 TOPO 356497.936 122.070312 468750 XX YY<br />
18 1 TOPO 356732.189 468750 468750 XX YY<br />
19 3840 TOPO 357734.314 122.070312 468750 XX YY<br />
20 1 TOPO 357499.939 468750 468750 XX YY<br />
21 3840 TOPO 346034.314 122.070312 468750 XX YY<br />
22 1 TOPO 345799.939 468750 468750 XX YY<br />
23 3840 TOPO 343955.936 122.070312 468750 XX YY<br />
24 1 TOPO 344190.189 468750 468750 XX YY<br />
<br />
Antennas: 9:<br />
Name Station Diam. Long. Lat.<br />
0 DV04 J505 12.0 m -067.45.18.0 -22.53.22.8<br />
1 DV06 T704 12.0 m -067.45.16.2 -22.53.22.1<br />
2 DV07 J510 12.0 m -067.45.17.8 -22.53.23.5<br />
3 DV08 T703 12.0 m -067.45.16.2 -22.53.23.9<br />
4 DV09 N602 12.0 m -067.45.17.4 -22.53.22.3<br />
5 DV10 N606 12.0 m -067.45.17.1 -22.53.23.6<br />
6 PM01 T702 12.0 m -067.45.18.6 -22.53.24.1<br />
7 PM02 T701 12.0 m -067.45.18.8 -22.53.22.2<br />
8 PM03 J504 12.0 m -067.45.17.0 -22.53.23.0<br />
</pre><br />
<br />
Things to Notice from above: <br />
*There are three different data sets acquired close together in time. We will calibrate each dataset independently and then combine the calibrated data prior to imaging. <br />
*Titan appears to have slightly different positions in each dataset because it is a moving body. In fact, at the time of observation, due to temporary data capture issue in the ALMA system, the position was written has (0,0). We have pre-corrected this error using fixplanets. Later in the tutorial, we will run fixplanets again to force all three datasets to have the same fixed position for Titan.<br />
*There are a lot of spectral windows! Don't be alarmed. In ALMA data, <br />
**spw=0 is always reserved for the water vapor radiometry data.<br />
**spw=9, 11, 13, 15 are the wideband (TDM) correlator mode with 128 channels per spw default settings for doing pointing and this is all they are used for in these data.<br />
**Currently Tsys data can only be taken in the wide (TDM) correlator mode with 128 channels per spw, these correspond to spws=1, 3, 5, 7 above. The frequencies of these TDM spws were carefully chosen so the the narrowband FDM spws fall within them.<br />
** The 0.5 GHz, high spectral resolution spws that contain all the real source data (science target and calibrators) are 17, 19, 21, and 23<br />
**For quicklook purposes, the ALMA online system produces a channel averaged spw for each channelized spw, these correspond to spw=2,4,6,8,10,12,14,16,18,20,22,24 and shouldn't be used for anything in post-processing as bandpass calibration etc has not been applied.<br />
<br />
In the portion of the {{listobs}} output that shows the timerange, the final column gives the scan intent. It is important to have a look at this because you can flag and do other operations in CASA using the scan intent as a selection option. Also, these intents will be used in the future for pipeline processing. You will usually want to use them to flag the CALIBRATE_POINTING* and CALIBRATE_ATMOS* (the latter correspond to the hot and cold load measurements used to calculate Tsys) data. This is essential for science or calibration data taken only in TDM (wide bandwidth) mode, i.e. the same mode that the pointing and Tsys data are taken in. For the current data however, that calibration data is recorded in different spws from the useful FDM (narrow bandwidth) data, so we'll be able to separate them by splitting them off at the final step prior to imaging.<br />
<br />
<figure id="Ant_pos.png"><br />
[[Image:Ant_pos.png|thumb|<caption>Antenna locations for the first dataset.</caption>]]<br />
</figure><br />
<br />
Before we move on, its also nice to get an idea where the antennas are with respect to each other. We can use {{plotants}} to plot their positions. It is a good idea to check each file since an antenna may have entered or exited the array between observations.<br />
<source lang="python"><br />
# In CASA<br />
for vis in data:<br />
plotants(vis=vis,figfile=vis+'.plotants.png')<br />
</source><br />
<br />
You can view the output images using any standard image viewer.<br />
<br />
==Create the Tsys and WVR Tables, and Examine ==<br />
<br />
Each ms include tables that contain the Tsys and WVR measurements associated with the visibility data.<br />
We must create calibration tables from these measurements. First we create the WVR calibration tables <br />
by running the task [http://casa.nrao.edu/stable/docs/TaskRef/wvrgcal-task.html wvrgcal]. This task <br />
examines the data for each ms as a whole and creates a calibration<br />
table containing only phase corrections for each antenna and spw. <br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
os.system('rm -rf '+asdm+'.wvr')<br />
wvrgcal(vis=asdm+'.ms', caltable=asdm+'.wvr', segsource=True, toffset=-1)<br />
</source><br />
<br />
Next we create the Tsys tables by running {{gencal}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
os.system('rm -rf '+asdm+'.tsys')<br />
gencal(vis=asdm+'.ms', caltable=asdm+'.tsys', caltype='tsys')<br />
</source><br />
<br />
It is very important that Tsys measurements taken as close in time and elevation as possible to a particular source are applied. To save telescope time, Tsys measurements are sometimes intentionally skipped in the scheduling block for specific sources. So the first step is to establish which sources have their own Tsys measurements and which do not. To do this, you may use the intent parameter of {{listobs}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
listobs(vis=asdm+'.ms', verbose=F, selectdata=True, intent='CALIBRATE_ATMOS*')<br />
</source><br />
<br />
<figure id="X3c1.tsys_vs_time_3.4.png"><br />
[[File:X3c1.tsys_vs_time_3.4.png|thumb|<caption>Tsys vs. time for spw 1 of the X3c1.ms data.</caption>]]<br />
</figure><br />
<figure id="X5d8.tsys_vs_time_3.4.png"><br />
[[File:X5d8.tsys_vs_time_3.4.png|thumb|<caption>Tsys vs. time for spw 1 of the X5d8.ms data.</caption>]]<br />
</figure><br />
<figure id="X7ef.tsys_vs_time_3.4.png"><br />
[[File:X7ef.tsys_vs_time_3.4.png|thumb|<caption>Tsys vs. time for spw 1 of the X7ef.ms data.</caption>]]<br />
</figure><br />
<br />
<pre style="background-color: #fffacd;"><br />
Fields: 4<br />
ID Code Name RA Decl Epoch SrcId nRows <br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 1116 <br />
1 none Titan 12:49:25.97588 -02.22.41.3024 J2000 1 1125 <br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 6795 <br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 6777 <br />
Spectral Windows: (9 unique spectral windows and 2 unique polarization setups)<br />
SpwID #Chans Frame Ch1(MHz) ChanWid(kHz) TotBW(kHz) Corrs <br />
0 4 TOPO 184550 1500000 7500000 I <br />
1 128 TOPO 355740.062 15625 2000000 XX YY <br />
2 1 TOPO 356716.625 1796875 1796875 XX YY <br />
3 128 TOPO 356507.813 15625 2000000 XX YY <br />
4 1 TOPO 357484.375 1796875 1796875 XX YY <br />
5 128 TOPO 346792.187 15625 2000000 XX YY <br />
6 1 TOPO 345784.375 1796875 1796875 XX YY <br />
7 128 TOPO 345182.438 15625 2000000 XX YY <br />
8 1 TOPO 344174.625 1796875 1796875 XX YY <br />
</pre><br />
<br />
Because field '3' (the secondary phase calibrator) does not appear in the list, it has no tsys. Since the secondary phase calibrator is close on the sky to the primary phase calibrator and observed near in time, we will transfer the Tsys from the primary to the secondary phase calibrator. <br />
Also notice that spws 1,3,5,7 are the only multi-channel spws that contain Tsys data. At present, Tsys measurements can only be obtained with TDM spectral setups (128 channels/dual pol). Because our science target is observed in FDM (3840 channels/dual pol), we will need to interpolate the measurements from TDM to FDM. But first, to inspect the Tsys vs. time, we use {{plotcal}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all = ['X3c1','X5d8','X7ef']<br />
tsysfields=['0','1','2','4']<br />
os.system('mkdir cal_plots; mkdir cal_plots/Tsys_plots') <br />
for asdm in basename_all:<br />
print "Plotting Tsys vs. time for "+asdm<br />
plotcal(caltable=asdm+'.tsys', xaxis='time',yaxis='tsys',<br />
antenna='1~8',plotrange=[0,0,100,500],<br />
iteration='antenna',subplot=421,poln='',spw='1:50~50',<br />
figfile='cal_plots/Tsys_plots/'+asdm+'.tsys_vs_time.png')<br />
if (asdm != basename_all[-1]):<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
To inspect Tsys vs. frequency, we use [[plotbandpass]]. There are many different options for plotbandpass, and we demonstrate some of the most useful ones. The option '''showtsky=T''' will overlay the effective temperature curve from the atmospheric model. This shows us the location of any atmospheric lines which will appear as emission lines in the autocorrelation data (from which the Tsys spectra are derived) from all antennas. In the<br />
example below, we set '''interactive=False''', which will produce many pages of plots as<br />
individual pngs but will only show the final page in the graphics window. To view all the pages we use the image viewer '''eog''' (Eye of GNOME) available on Linux. The alternative is to set '''interactive=True''' and examine the plots in the casa graphics window as they are produced.<br />
<br />
<figure id="X3c1.tsys.field0.DV04.spw1.t1.png"><br />
[[File:X3c1.tsys.field0.DV04.spw1.t1.png|thumb|<caption>Tsys vs. frequency on 3C279 for the X3c1.ms data, spw=1.</caption>]]<br />
</figure><br />
<figure id="X3c1.tsys.field0.DV04.spw3.t1.png"><br />
[[File:X3c1.tsys.field0.DV04.spw3.t1.png|thumb|<caption>Tsys vs. frequency on 3C279 for the X3c1.ms data, spw=3.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
print "Plotting Tsys vs. frequency for "+asdm<br />
for spw in [1,3,5,7]:<br />
for field in ['0','1']:<br />
plotbandpass(caltable=asdm+'.tsys', xaxis='freq',yaxis='amp',<br />
showtsky=T,subplot=42,field=field,<br />
spw=spw, interactive=False, plotrange=[0,0,0,0],<br />
figfile='cal_plots/Tsys_plots/'+asdm+'.tsys.field%s.png'%field,<br />
buildpdf=False)<br />
</source><br />
<br />
In <xr id="X3c1.tsys.field0.DV04.spw1.t1.png"/> and <xr id="X3c1.tsys.field0.DV04.spw3.t1.png"/> we see the effect of atmospheric ozone lines on the Tsys measurements associated with 3C279 in spw 1 and 3.<br />
<br />
For sources that have multiple Tsys measurements (typically the primary phase calibrator and/or the science target) one can use '''overlay="time"''' to overlay all the measurements for that source. This can help to identify any anomalous Tsys scans. As a fraction of the plots produced by this loop, here we show the Tsys recorded on spw=1 for TW Hya from the first dataset.<br />
<br />
<figure id="X3c1.tsys.field2.DV04.spw1.png"><br />
[[File:X3c1.tsys.field2.DV04.spw1.png|thumb|<caption>Tsys vs. freq for field 2, spw 1 of the X3c1.ms data (antennas 0..3).</caption>]]<br />
</figure><br />
<figure id="X3c1.tsys.field2.DV04.spw1.png"><br />
[[File:X3c1.tsys.field2.DV09.spw1.png|thumb|<caption>Tsys vs. freq for field 2, spw 1 of the X3c1.ms data (antennas 4..7).</caption>]]<br />
</figure><br />
<figure id="X3c1.tsys.field2.PM03.spw1.png"><br />
[[File:X3c1.tsys.field2.PM03.spw1.png|thumb|<caption>Tsys vs. freq for field 2, spw 1 of the X3c1.ms data (antenna 8).</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
print "Plotting Tsys vs. frequency for "+asdm<br />
for spw in [1,3,5,7]:<br />
for field in ['2','4']:<br />
plotbandpass(caltable=asdm+'.tsys', xaxis='freq',yaxis='amp',<br />
showtsky=T,subplot=22,field=field,<br />
overlay='time',spw=spw, interactive=False, plotrange=[0,0,0,0],<br />
figfile='cal_plots/Tsys_plots/'+asdm+'.tsys.field%s.png'%field,<br />
buildpdf = False)<br />
</source><br />
<br />
Alternatively, the '''overlay="antenna"''' option will quickly reveal any Antennas with discrepant Tsys values, as they<br />
will be obvious outliers. For FDM projects like this one, using the '''showfdm=True''' option can be helpful, as it<br />
will show where in the TDM bandpass each FDM spw was located. <br />
<figure id="X3c1.tsys.field0.spw1.t1.png"><br />
[[Image:X3c1.tsys.field0.spw1.t1.png|thumb|<caption>Tsys vs Freq for field 0, spw 1 of the X3c1.ms data with all antennas overlaid.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
tsysfields=['0','1','2','4'] <br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
print "Plotting Tsys vs. frequency for "+asdm<br />
for spw in [1,3,5,7]:<br />
for field in tsysfields:<br />
plotbandpass(caltable=asdm+'.tsys', xaxis='freq',yaxis='amp',<br />
showtsky=T,subplot=11,field=field,<br />
overlay='antenna',spw=spw, interactive=False,<br />
figfile='cal_plots/Tsys_plots/'+asdm+'.tsys.field%s.png'%field,<br />
buildpdf=False,showfdm=True)<br />
</source><br />
<br />
<br />
Note that DV04 consistently has a significantly higher Tsys than the rest of the antennas. We already know from the Observation log that<br />
we need to flag that antenna, but had we not had that information, examining this plot would have demonstrated the situation.<br />
<br />
==Apply the Tsys and WVR Tables, and Split ==<br />
<br />
Next we apply the calibrations. For the (4) sources with Tsys measurements, we use the '''field''' and '''gainfield''' parameters of {{applycal}} to apply solutions only to themselves. {{applycal}} has the ability to interpolate gain tables from one spw onto another spw. In this case, we want to interpolate the TDM Tsys values in spws 1,3,5,7 onto the FDM spws 17,19,21,23. We use the '''interp''' parameter to request linear interpolation in the time dimension and spline interpolation in the channel/frequency dimension. To map the solutions for each spw, we use the '''spwmap''' parameter, which requires a list of all spws for each gain table to be applied, or a blank list ([]) which is a shorthand notation to apply the solution for each spw to itself. While applying Tsys, we will also apply the wvr calibration tables; wvr data is usually always present for all sources. Below we first set some definitions so we can loop over the correct parameters:<br />
<br />
<source lang="python"><br />
# In CASA<br />
fdm='17,19,21,23'<br />
nocal='3' # This source had no Tsys measurements associated with it <br />
tsysfields=['0','1','2','4'] <br />
tsysmap = range(25)<br />
tsysmap[17] = 1<br />
tsysmap[19] = 3<br />
tsysmap[21] = 5<br />
tsysmap[23] = 7<br />
for asdm in basename_all:<br />
for field in tsysfields:<br />
applycal(vis=asdm+'.ms', spw=fdm, field=field, gainfield=field,<br />
gaintable=[asdm+'.tsys', asdm+'.wvr'], spwmap=[tsysmap,[]],<br />
interp=['linear,spline','nearest'], flagbackup=F, calwt=T)<br />
</source><br />
<br />
For the sources without Tsys (i.e. field=3), couple them with the best available source with Tsys (i.e. field=4).<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename_all:<br />
applycal(vis=asdm+'.ms', spw=fdm, field=nocal,<br />
gaintable=[asdm+'.tsys', asdm+'.wvr'], spwmap=[tsysmap,[]],<br />
gainfield=['4',nocal], interp=['linear,spline','nearest'],flagbackup=F,<br />
calwt=T)<br />
</source><br />
<br />
Check Tsys application with plotms. First we make plots with '''ydatacolumn='data'''' to look at the raw data. For <br />
simplicity we'll just look at the two strongest sources 3C279 and Titan.<br />
<br />
<figure id="X5d8_wvrtsys_corrected_spw19.png"><br />
[[Image:X5d8_wvrtsys_corrected_spw19.png|thumb|<caption>Spectral plots of 3C279 (black) and Titan (magenta) for spw=19 after Tsys and wvr correction.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X5d8.ms',spw='17,19,21,23',xaxis='frequency',yaxis='amp',field='0,1',<br />
antenna='*&*',avgtime='1e8',avgscan=T,coloraxis='field',iteraxis='spw',<br />
xselfscale=T,ydatacolumn='data')<br />
</source><br />
<br />
<figure id="X5d8_wvrtsys_corrected_spw21.png"><br />
[[Image:X5d8_wvrtsys_corrected_spw21.png|thumb|<caption>Spectral plots of 3C279 (black) and Titan (magenta) for spw=21 after Tsys and wvr correction.</caption>]]<br />
</figure><br />
<br />
'''Note''': the antenna='*&*' is specifying that we only want to see the cross-correlation data (i.e. not the autocorrelations).<br />
<br />
Use the '''green arrows''' on the {{plotms}} display to cycle through the 4 FDM spws. <br />
<br />
Now change '''Data Column''' to '''corrected''' on the "Axes" tab (this is the same as ydatacolumn in the task) and hit '''Plot''' button on the GUI. Flip through again.<br />
<br />
'''Things to notice:'''<br />
* The amplitude scale has changed due to application of Tsys<br />
* spw=17 is clean and flat<br />
* spw=19 shows a strong dip around channel 3000 (channels can be plotted by going to the Axes tab, and changing X Axis to Channel, then hit the Plot button)-- this is an atmospheric ozone absorption feature at 357.6 GHz. In the future, high spectral resolution Tsys measurements may help to remove the shape of the absorption, but until then we will need to flag this part of the spectrum.<br />
* spw=21 Titan shows both a narrow and a broad spectral feature. The broad feature is CO(3-2) and it completely fills the 0.5 GHz band so there are no line-free channels! Titan must be handled carefully when it is used as a calibrator because it contains strong line emission. Indeed, we will not be able to use the absolute flux transfer from this spw for other targets. When possible Titan should be avoided for absolute flux calibration. For these observations, no other suitable absolute flux calibrator was available.<br />
* spw=23 shows another strong line from Titan.<br />
<br />
Beyond these things to notice, the application of Tsys and wvr seem to have gone well. We can now split off only the narrow band FDM spectral windows for further processing.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename_all:<br />
newvis = asdm + '_wvrtsys.ms'<br />
os.system('rm -rf ' + newvis)<br />
split(vis=asdm+'.ms',outputvis=newvis,datacolumn='corrected',spw=fdm)<br />
</source><br />
<br />
'''Note''': After {{split}}, the spectral windows will be renumbered to 0, 1, 2, 3 corresponding to the old spw=17, 19, 21, 23, see {{listobs}} excerpt below.<br />
<br />
<pre style="background-color: #fffacd;"><br />
SpwID #Chans Frame Ch1(MHz) ChanWid(kHz) TotBW(kHz) Corrs <br />
0 3840 TOPO 356497.936 122.070312 468750 XX YY <br />
1 3840 TOPO 357734.314 122.070312 468750 XX YY <br />
2 3840 TOPO 346034.314 122.070312 468750 XX YY <br />
3 3840 TOPO 343955.936 122.070312 468750 XX YY <br />
</pre><br />
<br />
==Initial Inspection and Flagging==<br />
<br />
From here we begin to operate on the *wvrtsys.ms files. <br />
<br />
Before we begin flagging data, we unflag all data in the measurement sets. If this is your first pass through this section of the guide, no data in the measurement sets will be flagged, and you can skip this step. If you are rerunning the flagging commands below, this will reset your flag columns to their original state.<br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
for vis in splitdata:<br />
flagdata(vis=vis, mode='unflag', action='apply', flagbackup=F)<br />
</source><br />
<br />
ALMA data contains both the cross correlation and autocorrelation data. Presently nothing more can be done with the autocorrelation data so we flag it. Additionally, for smaller configurations of the array, and northerly sources one antenna can ''shadow'' another, blocking its view. This data also needs to be flagged. Finally, the observing log told us DV04 was not behaving properly at Band 7 and shouldn't be used so we flag that as well.<br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
for vis in splitdata:<br />
flagdata(vis=vis, mode='manual', autocorr=True, action = 'apply', flagbackup=T)<br />
flagdata(vis=vis, mode='shadow',tolerance=12.0, action='apply', flagbackup=F)<br />
flagdata(vis=vis, mode='manual', antenna='DV04', action='apply', flagbackup=F)<br />
</source><br />
<br />
Next we inspect the data with {{plotms}} for additional issues that need flagging, first looking at amplitude vs. time for each of the three datasets. Use the '''green''' arrows on the plotms gui to cycle through spws. <br />
<br />
<figure id="Tsyswvr_time_spw0_X3x1.png"><br />
[[Image:Tsyswvr_time_spw0_X3x1.png|thumb|<caption>Amplitude as a function of time for X3c1_wvrtsys.ms, spw=0</caption>]]<br />
</figure><br />
<br />
'''Note''': when '''iteraxis''' is invoked in {{plotms}}, unzoom does not always work properly. If you have trouble with this, flip to next page and then back to current one. This usually fixes the problem.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X5d8_wvrtsys.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X7ef_wvrtsys.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw')<br />
</source><br />
<br />
<figure id="Tsyswvr_time_spw2corr_X3x1.png"><br />
[[Image:Tsyswvr_time_spw2corr_X3x1.png|thumb|<caption>Amplitude as a function of time for X3x1_wvrtsys.ms, spw=2 with colorize='corr'.</caption>]]<br />
</figure><br />
<br />
'''Things to Notice:'''<br />
* In spw=2 there are some low points in all three data files. Use the "Mark Regions" box (left of center on bottom row of icons) to draw small box on low points. Then click the magnifying glass icon to the right of center. The output will be sent to the logger window. '''Note''': keep the marked region small or you can overwhelm the buffer. Locate suggests correlation YY on PM03 is the culprit. <br />
<br />
To see this more clearly you can rerun {{plotms}} with '''coloraxis='field'''' switched to '''coloraxis='corr''''<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='2',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='corr')<br />
</source><br />
<br />
To further check, you can exclude PM03 from the plot using '''antenna='!PM03'.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='2',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='corr',antenna='!PM03')<br />
</source><br />
<br />
Having confirmed the problem antenna, we flag it below. <br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
for vis in splitdata:<br />
flagdata(vis=vis, mode='manual', action= 'apply', flagbackup=T,<br />
spw='2',<br />
antenna='PM03',<br />
correlation='YY')<br />
</source><br />
<br />
'''Next we need to inspect the spectral properties of the data to look for issues.'''<br />
<br />
First we look at phase as a function of frequency for a well behaved antenna like DV06. <br />
'''coloraxis='baselines'''' (note this parameter is called '''Colorize''' in the GUI "Display" tab) will show each baseline as a different color. Significant delay errors or baseline errors will show up as phase slopes in these plots. Again you will want to page through the spectral windows.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='',xaxis='frequency',yaxis='phase',field='0',antenna='DV06',<br />
avgtime='1e8',avgscan=T,coloraxis='baseline',iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X5d8_wvrtsys.ms',spw='',xaxis='frequency',yaxis='phase',field='0',antenna='DV06',<br />
avgtime='1e8',avgscan=T,coloraxis='baseline',iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X7ef_wvrtsys.ms',spw='',xaxis='frequency',yaxis='phase',field='0',antenna='DV06',<br />
avgtime='1e8',avgscan=T,coloraxis='baseline',iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
Overall these plots look good with no large delays or baseline errors apparent.<br />
<br />
<figure id="Birdies_spw2_X3x1.png"><br />
[[Image:Birdies_spw2_X3x1.png|thumb|<caption>Phase calibrators (brown and green) and TW Hya (orange) showing both real CO(3-2) emission in TW Hya and weak ''birdie'' spectral features in all three sources for spw=2.</caption>]]<br />
</figure><br />
<br />
With such high spectral resolution data, one often sees occasional "birdies" in the data. These are typically very narrow weak spectral features that are internally generated in the system. Over time as we track down issues the number of birdies should decrease, but you should always check. This is easiest to do by looking at amplitude vs. frequency for sources observed over a long time range (for sensitivity). It is helpful to look at more than one source to verify the nature of the emission. Below we look at both calibrators (brown and green) and TW Hya (orange). If you have enough sensitivity birdies should be seen on all sources, however, be careful not to mistake real line emission for a birdie even on a calibrator - they can be present as we've seen for Titan.<br />
<br />
<figure id="Birdies_spw3_X3x1.png"><br />
[[Image:Birdies_spw3_X3x1.png|thumb|<caption>Phase calibrators (brown and green) and TW Hya (orange) showing only weak birdie spectral features in spw=3.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='',xaxis='channel',yaxis='amp',field='2,3,4',<br />
avgtime='1e8',avgscan=T,coloraxis='field',iteraxis='spw',xselfscale=T,yselfscale=T)<br />
</source><br />
<br />
Do a quick check that other two datasets are the same (they are usually similar if the source of internal resonance hasn't changed in the meantime).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X5d8_wvrtsys.ms',spw='',xaxis='channel',yaxis='amp',field='2,3,4',<br />
avgtime='1e8',avgscan=T,coloraxis='field',iteraxis='spw',xselfscale=T,yselfscale=T)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X7ef_wvrtsys.ms',spw='',xaxis='channel',yaxis='amp',field='2,3,4',<br />
avgtime='1e8',avgscan=T,coloraxis='field',iteraxis='spw',xselfscale=T,yselfscale=T)<br />
</source><br />
<br />
Now you can zoom in on each region to get channels for flagging, or to save time just go ahead and run the flagging command below where this has been done for you.<br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
for vis in splitdata:<br />
flagdata(vis=vis, mode='manual', action='apply', flagbackup=T,<br />
spw='0:1067~1068;1279~1280;2367~2368;3775~3776, 1:1279~1280;2367~2368;3775~3776, 2:1279~1280;3775~3776, 3:831~832;1535~1536;2367~2368;3775~3776;3839~3839')<br />
</source><br />
<br />
Replot in {{plotms}} to check that flagging has been done as anticipated.<br />
<br />
==Flag Calibrator Spectral Features==<br />
<br />
In this section, we will flag spectral features in the calibrators so they do not skew the calibration solutions. First make plots of 3C279 and Titan in channel space to get channels for flagging. <br />
<br />
<figure id="3C279_Titan_spw1.png"><br />
[[Image:3C279_Titan_spw1.png|thumb|<caption>Spectral plots of 3C279 (black) and Titan (magenta) for spw=1 after Tsys and wvr correction.</caption>]]<br />
</figure><br />
<figure id="3c279_meso_freq.png"><br />
[[Image:3c279_meso_freq.png|thumb|<caption>Zoomed spectral plot of 3C279 showing mesospheric absorption of CO(3-2) in frequency space.</caption>]]<br />
</figure><br />
<figure id="3c279_meso_chann.png"><br />
[[Image:3c279_meso_chann.png|thumb|<caption>Zoomed spectral plot of 3C279 showing mesospheric absorption of CO(3-2) in channel space.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='channel',yaxis='amp',field='0,1',<br />
avgtime='1e8',coloraxis='field',iteraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
The figure to the right shows a broad absorption line in spw 1 at channel 3000. This is the ozone absorption line at 357.62982 GHz. However, there is another narrow absorption feature in the spectra (spw 2) that is most easily seen on 3C279 (because it is the strongest calibrator). Let's look at it first in frequency space.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='2:1600~2300',xaxis='frequency',yaxis='amp',<br />
field='0',avgtime='1e8',coloraxis='field')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
The absorption feature lies exactly at the rest frequency for CO 3-2 (345.79599 GHz). Because it is so narrow (< 1 MHz), it must originate from a very low pressure region (i.e. high altitude) in the Earth's atmosphere, otherwise it would be more pressure broadened. Indeed, the first detection of CO in the mesosphere was made over 35 years ago (see, e.g. [http://adsabs.harvard.edu/abs/1976Sci...191.1174W Waters et al. 1976] or [http://adsabs.harvard.edu/abs/1979JGR....84..416G Goldsmith et al. 1979]). Be aware that the line is stronger as you go up the CO ladder (strength ~ J^3 for low J) because the temperature at that altitude (~50km) is about 250 K. In April 2011, the apparent depth of the feature was about 10% in the 2-1 line and 35% in the 3-2 line. However, the depth of the absorption feature is exaggerated due to the way ALMA normalizes the cross-correlation spectra by the autocorrelation spectra prior to storage. While this technique generally leads to a flat bandpass shape, it will accentuate telluric features because they are emission lines in the single dish spectrum (e.g. JCMT observations of mesospheric CO 3-2 can be found in [http://adsabs.harvard.edu/abs/1993MNRAS.264..673P Preston et al. 1993]). Finally, note that large seasonal variations in the line strength have been reported from observations at [http://adsabs.harvard.edu/abs/2003GeoRL..30j..39F Onsala]. <br />
<br />
Now, let's re-plot the line with channel number as the x-axis in order to get the channel range for flagging. <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='2:1600~2300',xaxis='channel',yaxis='amp',<br />
field='0',avgtime='1e8',coloraxis='field')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Now lets look at Titan in more detail.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='channel',yaxis='amp',field='1',<br />
avgtime='1e8',coloraxis='field',iteraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Explicitly back up the flag tables so that flagged regions can be restored later.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
flagmanager(vis=asdm+'.ms',mode='save',versionname=asdm+'.before_calspectralflags')<br />
</source><br />
<br />
<figure id="Titan_spw2.png"><br />
[[Image:Titan_spw2.png|thumb|<caption>Spectral plot of Titan (magenta) for spw=2.</caption>]]<br />
</figure><br />
<br />
Flag absorption features for all sources.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
print "Flagging absorption features in all sources for "+asdm<br />
flagdata(vis=asdm+'.ms', mode='manual', spw='1:2000~3839, 2:1945~1960')<br />
</source><br />
<br />
<figure id="Titan_spw3.png"><br />
[[Image:Titan_spw3.png|thumb|<caption>Spectral plot of Titan (magenta) for spw=3.</caption>]]<br />
</figure><br />
<br />
Now we need to flag emission. The very broad CO(3-2) in spw=2 of Titan will prevent us from using it as a calibrator for this spectral window since there are no line-free channels (we will transfer, phase, amplitude, and absolute flux from another Titan spw below). We do want to flag the narrower Titan line in spw=3.<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
flagmanager(vis=asdm+'.ms',mode='save',versionname=asdm+'.before_emissionflags')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
print "Flagging emission for "+asdm<br />
flagdata(vis=asdm+'.ms', mode='manual', <br />
field='1',<br />
spw='3:1000~3000')<br />
</source><br />
<br />
If you like, check that the right things have been flagged.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='channel',yaxis='amp',field='0,1',<br />
avgtime='1e8',coloraxis='field',iteraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
==Set Up the Flux Calibrator Model==<br />
<br />
Fill the model data column for Titan with a model for the flux density as a function of baseline. The model is a uniformly illuminated disk with the size obtained from the JPL Horizons ephemeris.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
setjy(vis=asdm+'.ms',field='1',usescratch=F,<br />
standard='Butler-JPL-Horizons 2010',scalebychan=F)<br />
</source><br />
<br />
<figure id="Titan amp vs uvdist.png"><br />
[[Image:Titan amp vs uvdist.png|thumb|<caption>Plot of Titan model for each of the 4 spws. We used the Butler-JPL-Horizons 2010 standard to compute this model.</caption>]]<br />
</figure><br />
<br />
After running setjy, it is a good idea to plot the model in order to confirm that it makes sense. In this case, Titan is partially resolved, so we expect the flux density to drop with uv distance, but not so much as to pass through a null. We also expect it to be brighter at higher frequencies since it has a thermal blackbody spectrum.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',field='1',xaxis='uvdist',yaxis='amp',coloraxis='spw',<br />
ydatacolumn='model')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<figure id="twhydra_X3c1_wvrtsys_2012_titan_model.png">[[File:twhydra_X3c1_wvrtsys_2012_titan_model.png|thumb|right|<caption>Titan model produced by 'Butler-JPL-Horizons 2012'.</caption>]]</figure><br />
<br />
<br/><br />
<div class="noprint" style="float:none; border:0px solid blue;background-color:#F6CEF5;padding:2px;"><br />
The setjy invocation, above, uses the flux density standard '''standard='Butler-JPL-Horizons 2010' '''. A more updated standard is also available: '''standard='Butler-JPL-Horizons 2012' '''. <xr id="twhydra_X3c1_wvrtsys_2012_titan_model.png"/> shows the Titan model produced using the updated standard. The motivated reader may wish to rerun {{setjy}} using the updated model. We will highlight later in this tutorial, and in the imaging tutorial that follows, the effects of using the updated model.<br />
</div><br />
<br />
==Bandpass Calibration==<br />
<br />
First we need to check how the amplitude and phase of 3C279 behave as a function of time. In order to set<br />
a fixed scale on the y-axis, we first make a plot of all the data, excluding antenna DV04. (We must specify '''ydatacolumn='data' ''' explicitly here because the default value of '''ydatacolumn''' equals the value used in the previous execution of {{plotms}}. In the previous execution '''ydatacolumn''' was set to '''model'''. See the online help, <tt>help plotms</tt>, for details.)<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',xaxis='time',yaxis='amp',coloraxis='corr',<br />
field='0',avgchannel='3840',ydatacolumn='data')<br />
</source><br />
<br />
<figure id="ThreeScansAmp.png"><br />
[[Image:ThreeScansAmp.png|thumb|<caption>Amplitude variation for three 3C279 scans, spw 0 (for one representative baseline).</caption>]]<br />
</figure><br />
<br />
We see that the uncalibrated amplitudes range between 0.2-0.4, so let's set this as our<br />
scale and examine a representative baseline (DV06-DV07) to see how the amplitude changes with time. <br />
<br />
<source lang="python"><br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for spw in ['0','1','2','3']:<br />
for asdm in basename:<br />
print "Now showing spw %s from %s" % (spw, asdm+'.ms')<br />
plotms(vis=asdm+'.ms',spw=spw,xaxis='time',yaxis='amp',coloraxis='corr',iteraxis='spw',<br />
field='0',avgchannel='3840',antenna='DV06&DV07',plotrange=[0,0,0.2,0.4])<br />
user_check=raw_input('press enter to go to the next plot\n')<br />
</source><br />
<br />
<figure id="ThreeScansPhase.png"><br />
[[Image:ThreeScansPhase.png|thumb|<caption>Phase variation for three 3C279 scans, spw 0 (for one representative baseline).</caption>]]<br />
</figure><br />
<br />
Page through the measurement sets for each spw. This shows significant variations in the amplitude across the three measurement sets.<br />
Now do the same with phase.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for spw in ['0','1','2','3']:<br />
for asdm in basename:<br />
print "Now showing spw %s from %s" % (spw, asdm+'.ms')<br />
plotms(vis=asdm+'.ms',spw=spw,xaxis='time',yaxis='phase',coloraxis='corr',iteraxis='spw',<br />
field='0',avgchannel='3840',antenna='DV06&DV07',plotrange=[0,0,-180,180])<br />
user_check=raw_input('press enter to go to the next plot\n')<br />
</source><br />
<br />
This examination reveals two findings: (1) significant variation in the phase across the three scans, as well as (2) smaller but significant variations within a scan. The first finding suggests that we do not want to combine the scans for bandpass calibration, but instead derive an independent bandpass for each scan. Actually what is more important than a DC offset is if the '''shape''' of the amplitude or phase changes from scan to scan. There isn't enough S/N to tell for sure so we will keep them separate. This situation is often the case, which is why we did not concatenate the three datasets prior to calibration. The second finding suggests that we need to correct the phase vs. time behavior of the bandpass calibrator (3C279; field=0) within each scan, before doing the bandpass. We want to chose a relatively narrow range of channels near the center of the spws so that the bandpass phase slopes (to be corrected with the bandpass calibration itself) do not decorrelate the signal. You need to avoid spectral regions that were completely flagged above.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.bpphase.gcal')<br />
gaincal(vis=asdm+'.ms',caltable=asdm+'.bpphase.gcal',<br />
field='0',spw='0~3:900~1100',refant='DV06',<br />
calmode='p',solint='int',minsnr=2.0,minblperant=4)<br />
</source><br />
<br />
<figure id="X7ef_wvrtsys.bpphase.X.png"><br />
[[Image:X7ef_wvrtsys.bpphase.X.png|thumb|<caption>Phase only solutions for correlation X on the third scan of the bandpass calibrator 3C279.</caption>]]<br />
</figure><br />
<br />
Inspect the phase-only calibration solutions for the bandpass calibrator. Look for any noisy solutions. We do XX and YY separately to reduce confusion in the plot. It will help if you make your plotcal window wide.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.bpphase.gcal',xaxis='time',yaxis='phase',spw='',antenna='1~8', <br />
iteration='antenna',subplot=421,plotrange=[0,0,-180,180],<br />
figfile=asdm+'.bpphase.X.png',poln='X')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
In the plotcal gui you can use the magnifying glass symbol to zoom in on one of the scans to see the phase variations. The colors are the 4 different spws.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.bpphase.gcal',xaxis='time',yaxis='phase',spw='',antenna='1~8', <br />
iteration='antenna',subplot=421,plotrange=[0,0,-180,180],<br />
figfile=asdm+'.bpphase.Y.png',poln='Y')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Next we apply this phase-only correction on the fly while calculating the bandpass solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.bandpass.bcal')<br />
bandpass(vis=asdm+'.ms',caltable=asdm+'.bandpass.bcal',<br />
field='0',spw='',combine='',refant='DV06',<br />
solint='inf',solnorm=T,minblperant=4, bandtype='B', fillgaps=17,<br />
gaintable=asdm+'.bpphase.gcal')<br />
</source><br />
<br />
You will see some error messages in the terminal, these are just related to the flagged channels. We set fillgaps=17 to interpolate across the smaller regions of flagged channels (mesospheric features and birdies).<br />
<br />
<figure id="Bandpass.ampspw0.png"><br />
[[Image:Bandpass.ampspw0.png|thumb|<caption>Bandpass amplitude solution plots.</caption>]]<br />
</figure><br />
<figure id="Bandpass.phasespw0.png"><br />
[[Image:Bandpass.phasespw0.png|thumb|<caption>Bandpass phase solution plots.</caption>]]<br />
</figure><br />
<br />
'''A few words about solint and combine:'''<br />
<br />
In {{bandpass}}, the use of '''solint='inf'''' (as in "infinite") will derive a bandpass<br />
solution for each 3C279 scan, '''unless''' '''combine='scan'''' (which is the default). Here we set combine=' ' explicitly so that it does not combine the scans into one bandpass. Likewise, field boundaries are only crossed if combine='field', and spw boundaries are only crossed if combine='spw'. In some cases it can be helpful to combine fields if you suffer from lack of S/N, but it is never a good idea to combine spws. <br />
<br />
Now inspect the phase and amplitude solutions. You are looking for excursions from smooth fits, or particularly noisy solutions compared to the others. <br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
for spw in [0,1,2,3]:<br />
plotbandpass(asdm+'.bandpass.bcal',xaxis='freq',yaxis='amp', spw=spw,<br />
antenna='1~8', subplot=42, figfile=asdm+'.bandpass.amp', showatm=T,<br />
interactive=True)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
for spw in [0,1,2,3]:<br />
plotbandpass(asdm+'.bandpass.bcal',xaxis='freq',yaxis='phase',spw=spw,<br />
antenna='1~8',subplot=42,figfile=asdm+'.bandpass.phs', showatm=T,<br />
interactive=True)<br />
</source><br />
<br />
The values of phase on DV06 are very close to zero because it was used as the reference antenna.<br />
<br />
==Gain Calibration==<br />
<br />
Now that we have a bandpass solution to apply we can solve for the antenna-based phase and amplitude gain calibration. Since the phase changes on a much shorter timescale than the amplitude, we will solve for them separately. In particular, if the phase changes significantly over a scan time, the amplitude would be decorrelated, if the un-corrected phase were averaged over this timescale. Note that we re-solve for the gain solutions of the bandpass calibrator, so we can derive new solutions that are corrected for the bandpass shape. Since the bandpass calibrator will not be used again, this is not strictly necessary, but is useful to check its calibrated flux density for example. <br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.intphase.gcal')<br />
gaincal(vis=asdm+'.ms',caltable=asdm+'.intphase.gcal',<br />
field='0,1,3,4',spw='0~3:40~3800',refant='DV06',<br />
calmode='p',solint='int',minsnr=2.0,minblperant=4,<br />
gaintable=[asdm+'.bandpass.bcal'])<br />
</source><br />
<br />
Here '''solint='int' ''' coupled with '''calmode='p' ''' will derive a single phase solution for each 10 second integration. Note that the bandpass table is applied on-the-fly before solving for the phase solutions, however the bandpass is NOT applied to the data permanently until applycal is run later on. <br />
<br />
Although '''solint='int' ''' (i.e. the integration time of 10 seconds) is the best choice to apply before solving for the amplitude solutions, it is not a good idea to use this to apply to the target. This is because the phase-scatter within a scan can dominate the interpolation between calibrator scans. Instead, we also solve for the phase on the scan time, '''solint='inf' ''' (but '''combine=' ' ''', since we want one solution per scan) for application to the target later on. Unlike the bandpass task, for {{gaincal}}, the default of the combine parameter is '''combine=' ' '''. <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.scanphase.gcal')<br />
gaincal(vis=asdm+'.ms',caltable=asdm+'.scanphase.gcal',<br />
field='0,1,3,4',spw='0~3:40~3800',refant='DV06',<br />
calmode='p',solint='inf',minsnr=2.0,minblperant=4,<br />
gaintable=[asdm+'.bandpass.bcal'])<br />
</source><br />
<br />
Alternatively, instead of making a separate phase solution for application to the target, one can also run {{smoothcal}} to smooth the solutions derived on the integration time. <br />
<br />
Next we apply the bandpass and '''solint='int' ''' phase-only calibration solutions on-the-fly to derive amplitude solutions. Here the use of '''solint='inf' ''', but '''combine=' ' ''' will result in one solution per scan interval. <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.amp.gcal')<br />
gaincal(vis=asdm+'.ms',caltable=asdm+'.amp.gcal',<br />
field='0,1,3,4',spw='0~3:40~3800',refant='DV06',<br />
calmode='ap',solint='inf',minsnr=2.0,minblperant=4,<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal'])<br />
</source><br />
<br />
Now carefully inspect all these solutions looking for discrepant solutions. If you see any, you will need to flag them and rerun the calibration tasks above. <br />
<br />
We make plots in X and Y separately for clarity. The colors are showing the spectral windows.<br />
<figure id="X3c1_wvrtsys.intphase_X.png"><br />
[[Image:X3c1_wvrtsys.intphase_X.png|thumb|<caption>Phase solutions for the X polarization for every integration time of the first dataset.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.intphase.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',iteration='antenna',subplot=421,<br />
plotrange=[0,0,-180,180],poln='X',figfile=asdm+'.intphase_X.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.intphase.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',iteration='antenna',subplot=421,<br />
plotrange=[0,0,-180,180],poln='Y',figfile=asdm+'.intphase_Y.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<figure id="X3c1_wvrtsys.scanphase_X.png"><br />
[[Image:X3c1_wvrtsys.scanphase_X.png|thumb|<caption>Phase solutions for the X polarization for each scan of the first dataset.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.scanphase.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',iteration='antenna',subplot=421,<br />
plotrange=[0,0,-180,180],poln='X',figfile=asdm+'.scanphase_X.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.scanphase.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',iteration='antenna',subplot=421,<br />
plotrange=[0,0,-180,180],poln='Y',figfile=asdm+'.scanphase_Y.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Since we have taken out the phase as best we can by applying the '''solint='int' ''' phase-only solution, this plot will give a good idea of the residual phase error. If you see scatter of more than a few degrees here, you should consider going back and looking for more data to flag, particularly bad timeranges etc. <br />
<br />
<figure id="X3c1_wvrtsys.amp_phase.png"><br />
[[Image:X3c1_wvrtsys.amp_phase.png|thumb|<caption>Residual phase after applying intphase.gcal for both correlations in the first dataset.</caption>]]<br />
</figure><br />
<figure id="X3c1_wvrtsys.amp_X.png"><br />
[[Image:X3c1_wvrtsys.amp_X.png|thumb|<caption>Amplitude solutions on a scan interval for correlation X in the first dataset.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.amp.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',plotrange=[0,0,-1,1],<br />
iteration='antenna',subplot=421,figfile=asdm+'.amp_phase.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
These are very small, as they should be. Now look at the amplitude solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.amp.gcal',xaxis='time',yaxis='amp',antenna='1~8', <br />
iteration='antenna',subplot=421,spw='',poln='X',<br />
plotrange=[0,0,0.0,0.3],figfile=asdm+'.amp_X.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.amp.gcal',xaxis='time',yaxis='amp',antenna='1~8', <br />
iteration='antenna',subplot=421,spw='',poln='Y',<br />
plotrange=[0,0,0.0,0.3],figfile=asdm+'.amp_Y.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
==Flux Calibration==<br />
<br />
Next we use the flux calibrator (whose flux density was set in {{setjy}} above) to derive the flux density of the other calibrators. Note that the flux table REPLACES the amp.gcal in terms of future application of the calibration to the data, i.e. the flux table contains both the amp.gcal and flux scaling. Unlike the gain calibration steps, this is not an incremental table.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.flux.cal')<br />
fluxscale(vis=asdm+'.ms',caltable=asdm+'.amp.gcal',<br />
fluxtable=asdm+'.flux.cal',reference='1',refspwmap=[0,1,3,3],<br />
listfile=asdm+'.fluxscale.txt')<br />
</source><br />
<br />
Its a good idea to record the derived fluxscale values using the listfile option. The values can also be viewed in the Log Messages window.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Found reference field(s): Titan<br />
Found transfer field(s): 3c279 J1147-382=QSO J1037-295=QSO<br />
Spw=2 will be referenced to spw=3<br />
Flux density for 3c279 in SpW=0 (freq=3.56498e+11 Hz) is: 10.537 +/- 0.0183518 (SNR = 574.169, N = 16)<br />
Flux density for 3c279 in SpW=1 (freq=3.57734e+11 Hz) is: 10.6933 +/- 0.0264134 (SNR = 404.842, N = 16)<br />
Flux density for 3c279 in SpW=2 (freq=3.46034e+11 Hz) (ref SpW=3) is: 10.251 +/- 0.0477949 (SNR = 214.479, N = 14)<br />
Flux density for 3c279 in SpW=3 (freq=3.43956e+11 Hz) is: 9.91798 +/- 0.020167 (SNR = 491.791, N = 16)<br />
Flux density for J1147-382=QSO in SpW=0 (freq=3.56498e+11 Hz) is: 1.03399 +/- 0.0167344 (SNR = 61.7887, N = 16)<br />
Flux density for J1147-382=QSO in SpW=1 (freq=3.57734e+11 Hz) is: 0.844817 +/- 0.0191013 (SNR = 44.2283, N = 16)<br />
Flux density for J1147-382=QSO in SpW=2 (freq=3.46034e+11 Hz) (ref SpW=3) is: 0.987193 +/- 0.024391 (SNR = 40.4737, N = 14)<br />
Flux density for J1147-382=QSO in SpW=3 (freq=3.43956e+11 Hz) is: 1.28859 +/- 0.0194364 (SNR = 66.298, N = 16)<br />
Flux density for J1037-295=QSO in SpW=0 (freq=3.56498e+11 Hz) is: 0.968281 +/- 0.00895224 (SNR = 108.161, N = 16)<br />
Flux density for J1037-295=QSO in SpW=1 (freq=3.57734e+11 Hz) is: 0.75916 +/- 0.015366 (SNR = 49.4053, N = 16)<br />
Flux density for J1037-295=QSO in SpW=2 (freq=3.46034e+11 Hz) (ref SpW=3) is: 0.948551 +/- 0.0165421 (SNR = 57.3416, N = 14)<br />
Flux density for J1037-295=QSO in SpW=3 (freq=3.43956e+11 Hz) is: 1.21905 +/- 0.0139967 (SNR = 87.0956, N = 16)<br />
Fitted spectrum for 3c279 with fitorder=1: Flux density = 10.2962 +/- 0.0450319 (freq=351.002 GHz) spidx=1.70757 +/- 0.245737<br />
Fitted spectrum for J1147-382=QSO with fitorder=1: Flux density = 1.06853 +/- 0.0709817 (freq=351.002 GHz) spidx=-6.77353 +/- 3.71867<br />
Fitted spectrum for J1037-295=QSO with fitorder=1: Flux density = 1.01822 +/- 0.0654586 (freq=351.002 GHz) spidx=-6.28977 +/- 3.71453<br />
Storing result in X7ef_wvrtsys.flux.cal<br />
Writing solutions to table: X7ef_wvrtsys.flux.cal<br />
</pre><br />
<br />
<figure id="x3c1_wvrtsys.flux_X.png"><br />
[[Image:x3c1_wvrtsys.flux_X.png|thumb|<caption>Absolute flux calibration solutions for correlation X for the first dataset.</caption>]]<br />
</figure><br />
<br />
<div class="noprint" style="float:none; border:0px solid blue;background-color:#F6CEF5;padding:2px;"><br />
If you used the updated (Butler-JPL-Horizons 2012) flux density standard when you ran {{setjy}} earlier in this tutorial, the derived flux values for the calibrators will be slightly different. For example, when averaged over the 3 measurement sets, 3c279 in spectral window 0 has a flux of 10.77 Jy using the 2010 standard and 10.63 Jy using the 2012 standard; as a second example, J1147-382 in SPW 3 has an average flux of 1.13 Jy (2010 standard) and 1.15 Jy (2012 standard). <br />
</div><br />
<br />
Now look at the flux solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.flux.cal',xaxis='time',yaxis='amp',antenna='1~8', <br />
iteration='antenna',subplot=421,spw='',poln='X',<br />
plotrange=[0,0,0.0,0.3],figfile=asdm+'.flux_X.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.flux.cal',xaxis='time',yaxis='amp',antenna='1~8', <br />
iteration='antenna',subplot=421,spw='',poln='Y',<br />
plotrange=[0,0,0.0,0.3],figfile=asdm+'.flux_Y.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
==Apply Calibration and Inspect==<br />
<br />
Now we can use the {{flagmanager}} if we want to restore any of the spectral flagging we did prior to bandpass calibration. <br />
In this case, we choose to restore the flags of the emission lines on Titan, because we are interested in seeing how<br />
strong they are compared to the continuum. However, we leave the strong ozone line and mesospheric CO line flagged on all <br />
sources, because we want to get the most accurate continuum flux density for the science target. <br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
flagmanager(vis=asdm+'.ms',mode='restore',versionname=asdm+'.before_emissionflags')<br />
</source><br />
<br />
Next we apply the calibration solutions to each source individually, using the '''gainfield''' parameter to specify which calibrator's solutions should be applied from each of the '''gaintable''' calibration tables. <br />
<br />
First, we do 3C279 (the bandpass calibrator), applying all 3 of its solutions to itself (that's why gainfield contains three zeros):<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='0',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['0','0','0'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
Next, we do Titan (the absolute flux calibrator) using the bandpass solution from 3C279:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='1',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['0','1','1'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
For the secondary phase calibrator, we apply the phase and flux solutions from the primary phase calibrator. This will allow us to check how well the phase transfer to the science target (TW Hya) has worked:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='3',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.scanphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','linear','linear'],<br />
gainfield=['0','4','4'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
Next is the Primary phase calibrator:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='4',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['0','4','4'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
Finally, for the Science Target TW Hya, we apply the phase solutions from both the primary and secondary phase calibrators:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='2',<br />
interp=['nearest','linear','linear'],<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.scanphase.gcal',asdm+'.flux.cal'],<br />
gainfield=['0','3,4','3,4'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
Now we can check the results of applying the calibration solutions.<br />
<br />
<figure id="Corrected_vs_time_1.png"><br />
[[Image:Corrected_vs_time_1.png|thumb|<caption>The calibrated data for the first dataset (amplitude vs. time).</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw',ydatacolumn='corrected')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
In amplitude, it looks good but there are some noisy points toward the end of the first scheduling block, but it mostly only affects the secondary phase calibrator (green). In phase, we expect all the points to cluster about zero. The large scatter in phase on the secondary phase calibrator is readily apparent: <br />
<br />
<figure id="Corrected_phase_vs_time_1.png"><br />
[[Image:Corrected_phase_vs_time_1.png|thumb|<caption>The calibrated data on the calibrators for the first dataset (phase vs. time).</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='time',yaxis='phase',field='0,1,3,4',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw',ydatacolumn='corrected')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Let's check whether the situation improves when we apply this calibrator's solutions to itself rather than transferring the solutions from the primary phase calibrator (which is 17 degrees away, and observed at a different time). <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='3',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['0','3','3'],flagbackup=T, calwt=T)<br />
</source><br />
<br />
<figure id="Corrected_vs_time_1_field3.png"><br />
[[Image:Corrected_vs_time_1_field3.png|thumb|<caption>The calibrated data for the first dataset (amplitude vs. time), but now with field 3, the secondary phase calibrator, calibrated with itself.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw',ydatacolumn='corrected')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<figure id="Corrected_phase_vs_time_1_field3.png"><br />
[[Image:Corrected_phase_vs_time_1_field3.png|thumb|<caption>The calibrated data from the first dataset (phase vs. time), but now with field 3, the secondary phase calibrator, calibrated with itself.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='time',yaxis='phase',field='0,1,3,4',<br />
avgchannel='3840', coloraxis='field',iteraxis='spw',<br />
ydatacolumn='corrected')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Indeed, the secondary calibrator looks better now in amplitude and phase. This is an indication that the calibration transfer is not working well in this timerange. Because the effect is not catastrophic and we know we can self-calibrate on TW Hya later, we will let this go for now. Or, if you want you can delve deeper into the data and try to solve the mystery... <br />
<br />
In any case, we will re-issue the original {{applycal}} so that it is this calibration that our subsequent {{split}} will use. This will allow us to check the effect of correcting the secondary phase calibrator with the primary phase calibrator later. <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='3',<br />
gaintable=[asdm+'.bandpass.bcal', asdm+'.scanphase.gcal', asdm+'.flux.cal'],<br />
interp=['nearest','linear','linear'],<br />
gainfield=['0','4','4'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
<br />
Let's check the spectral calibration now. First 3C279 and Titan:<br />
<br />
<figure id="X3c1_spw2_corrected_3.4.png"><br />
[[Image:X3c1_spw2_corrected_3.4.png|thumb|<caption>Spectral UV-plots of 3C279 and Titan of spw=2 for the first dataset.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='frequency',yaxis='amp',field='0,1',<br />
avgtime='1e8',avgscan=T,coloraxis='field',ydatacolumn='corrected',<br />
iteraxis='spw',xselfscale=T)<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Flip through the spws. These look good. Next the two phase calibrators:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='frequency',yaxis='amp',field='3,4',<br />
avgtime='1e8',avgscan=T,coloraxis='field',ydatacolumn='corrected',<br />
iteraxis='spw',xselfscale=T)<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Flip through the spws. This also looks good, the secondary phase calibrator is a bit noisier but this is normal. The upswing at the lower frequency end of spw=3 will probably need to be flagged on the science target as well. It corresponds to the edge of an atmospheric feature.<br />
<br />
Now for the exciting part, what does the science target look like...<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='frequency',yaxis='amp',field='2',<br />
avgtime='1e8',avgscan=T,coloraxis='field',ydatacolumn='corrected',<br />
iteraxis='spw',xselfscale=T)<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
We see HCO+(4-3) in spw=0 and CO(3-2) in spw=2 as expected. Because the shape of the <br />
line profiles varies with baseline, you can already tell that the line emission is resolved.<br />
<br />
<figure id="X3c1_CO3_2_uvplot_3.4.png"><br />
[[Image:X3c1_CO3_2_uvplot_3.4.png|thumb|<caption>UV-Plot of the TW Hya CO(3-2) emission from the first dataset.</caption>]]<br />
</figure><br />
<figure id="X3c1_HCOp4_3_uvplot_3.4.png"><br />
[[Image:X3c1_HCOp4_3_uvplot_3.4.png|thumb|<caption>UV-Plot of the TW Hya HCO+(4-3) emission from the first dataset.</caption>]]<br />
</figure><br />
<br />
Now check that the velocity of TWHydra is correct in the LSRK frame, it should be around 2.88 km/s.<br />
* CO 3-2 rest freq 345.79599 GHz<br />
* HCO+ 4-3 rest freq 356.7342 GHz<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='2',xaxis='velocity',yaxis='amp',field='2',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',<br />
restfreq='345.79599GHz', plotrange=[-10,15,0,0],coloraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='0',xaxis='velocity',yaxis='amp',field='2',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',<br />
restfreq='356.7342GHz',plotrange=[-10,15,0,0],coloraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Both lines show up at the expected velocity.<br />
<br />
<br />
==Concatenate the Data==<br />
<br />
Here we will concatenate the three datasets prior to imaging.<br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
os.system('rm -rf Band7multi_april22.ms')<br />
concat(vis=splitdata,concatvis='Band7multi_april22.ms')<br />
</source><br />
<br />
If you like you can run listobs on new combined dataset<br />
<br />
<source lang="python"><br />
# In CASA<br />
listfile = 'Band7multi_april22.listobs.txt'<br />
os.system('rm ' + listfile)<br />
listobs(vis='Band7multi_april22.ms',verbose=F, listfile=listfile)<br />
</source><br />
<br />
<figure id="All_spw2_corrected_3.4.png"><br />
[[Image:All_spw2_corrected_3.4.png|thumb|<caption>Spectral UV-plots of 3C279 and Titan of spw=2 for the combined datasets.</caption>]]<br />
</figure><br />
<br />
You can also examine the spectral uv plots for the combined dataset to see the improvement in S/N: <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='Band7multi_april22.ms',spw='',xaxis='frequency',yaxis='amp',field='0,1',<br />
avgtime='1e8',avgscan=T,coloraxis='field',ydatacolumn='corrected',<br />
iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
<figure id="All_CO3_2_uvplot_3.4.png"><br />
[[Image:All_CO3_2_uvplot_3.4.png|thumb|<caption>UV-Plot of the TW Hya CO(3-2) emission from the combined datasets.</caption>]]<br />
</figure><br />
<br />
...and the CO line profile for the combined dataset: <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='Band7multi_april22.ms',spw='2',xaxis='velocity',yaxis='amp',field='2',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',restfreq='345.79599GHz',<br />
plotrange=[-10,15,0,0],coloraxis='spw')<br />
</source><br />
<br />
==Split Calibrated Data==<br />
<br />
Now we split off the calibrated data for the Science Target as well as the interesting parts of the calibrators for imaging.<br />
<br />
When we {{split}} off the Titan data, a few dozen warnings like the following are written to the log:<br />
<pre><br />
2012-05-15 22:00:35 WARN split::SubMS::copySource() Invalid SOURCE ID in SOURCE table row 20 <br />
</pre><br />
These can be ignored, because they do not indicate any problem that will prevent you from imaging Titan correctly at a single position using all the data in the output ms.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_corrected.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='TWHydra_corrected.ms',<br />
datacolumn='corrected',spw='',field='2')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf J1037_corrected.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='J1037_corrected.ms',<br />
datacolumn='corrected',spw='',field='4')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf J1147_corrected.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='J1147_corrected.ms',<br />
datacolumn='corrected',spw='',field='3')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3C279_CO3_2.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='3C279_CO3_2.ms',<br />
datacolumn='corrected',spw='2:1900~2000',field='0')<br />
</source><br />
<br />
==Optional: Reconcile Titan's Coordinates==<br />
<br />
If you do not care to image Titan, then you can skip this step and simply continue on to the [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_4.5 imaging guide].<br />
<br />
Our earlier treatment of Titan's coordinates using [http://casa.nrao.edu/stable/docs/TaskRef/fixplanets-task.html fixplanets] replaced the zeros written by the ALMA control system with the correct position of the body at the instant of the first observation of that SB. As a result, it has slightly different positions in all three datasets, as seen by listobs:<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='Band7multi_april22.ms',verbose=F)<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
ID Code Name RA Decl Epoch SrcId nRows <br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 70866 <br />
1 none Titan 12:49:25.97588 -02.22.41.3024 J2000 1 4842 <br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 515151 <br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 40797 <br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 171153 <br />
5 none Titan 12:49:26.53729 -02.22.27.1521 J2000 0 4833 <br />
6 none Titan 12:49:26.53059 -02.22.18.7878 J2000 0 4833 <br />
</pre><br />
<br />
If we want to image such moving objects observed across multiple SBs, we need to bring the positions into agreement, otherwise {{clean}} will try to make a mosaic. Task [http://casa.nrao.edu/stable/docs/TaskRef/fixplanets-task.html fixplanets] can be used to do this. Here, we set the direction to the direction of the first dataset as reported by listobs. Note that the RA/Dec format is slightly different from the {{listobs}} output format. Also, we do not<br />
fix the uvw coordinates because they are already more correct now than they would be if we "fixed" them.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fixplanets(vis='Band7multi_april22.ms', field='Titan', direction='J2000 12h49m25.97588 -02d22m41.3024', fixuvw=False)<br />
</source><br />
<br />
Check the header information again to see that the information for Titan has changed for the second<br />
and third datasets. They will appear as fields 5 and 6.<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='Band7multi_april22.ms',verbose=F)<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
ID Code Name RA Decl Epoch SrcId <br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 70866 <br />
1 none Titan 12:49:25.97588 -02.22.41.3024 J2000 1 4842 <br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 515151 <br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 40797 <br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 171153 <br />
5 none Titan 12:49:25.97588 -02.22.41.3024 J2000 0 4833 <br />
6 none Titan 12:49:25.97588 -02.22.41.3024 J2000 0 4833 <br />
</pre><br />
<br />
==Optional: Split Calibrated Titan Data==<br />
<br />
When we {{split}} off the Titan data, a few dozen warnings like the following are written to the log:<br />
<pre><br />
2012-05-15 22:00:35 WARN split::SubMS::copySource() Invalid SOURCE ID in SOURCE table row 20 <br />
</pre><br />
These can be ignored, because they do not indicate any problem that will prevent you from imaging Titan correctly at a single position using all the data in the output ms.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Titan_cont.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='Titan_cont.ms',<br />
datacolumn='corrected',spw='0',field='1')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Titan_CO3_2.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='Titan_CO3_2.ms',<br />
datacolumn='corrected',spw='2',field='1')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Titan_unknown.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='Titan_unknown.ms',<br />
datacolumn='corrected',spw='3',field='1')<br />
</source><br />
<br />
==Continue on to Imaging of the Science Target==<br />
<br />
Now you can continue on to the [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_4.5 imaging guide].<br />
<br />
{{Checked 4.5.2}}</div>Sstierwahttps://casaguides.nrao.edu/index.php?title=TWHydraBand7_Calibration_4.5&diff=19470TWHydraBand7 Calibration 4.52016-05-18T03:57:20Z<p>Sstierwa: </p>
<hr />
<div>[[Category:ALMA]][[Category:Calibration]][[Category:Spectral Line]]<br />
*'''This script assumes that you have downloaded TWHYA_BAND7_UnCalibratedMSAndTablesForReduction.tgz from [[TWHydraBand7#Getting_the_Data]]'''<br />
<br />
*'''An introduction to this data set is available at [[TWHydraBand7]].<br />
<br />
*'''This guide is designed for CASA 4.5.2 If you are using an older version of CASA please see [[TWHydraBand7_Calibration_4.3]].<br />
<br />
==Preparation==<br />
<br />
Once you have downloaded TWHYA_BAND7_UnCalibratedMSAndTablesForReduction.tgz, in a terminal unpack it with<br />
<br />
<source lang="bash"><br />
tar -zxvf TWHYA_BAND7_UnCalibratedMSAndTablesForReduction.tgz<br />
</source><br />
<br />
Please be aware that you will need about 100 GB of free space to do the data reduction. It is a good idea to check that now before you begin. Some of the plots described here require 9 GB of RAM; as little as 4 GB may be sufficient if additional data averaging is used when the plots are generated. When you are satisfied with the available drive space and memory on your machine:<br />
<br />
<source lang="bash"><br />
cd TWHYA_BAND7_UnCalibratedMSAndTablesForReduction<br />
</source><br />
<br />
'''NOTE: the calibration tables included in TWHYA_BAND7_UnCalibratedMSAndTablesForReduction CANNOT be used with CASA 4.5, they should be discarded, or moved out of the working directory.'''<br />
<br />
Then start CASA. <br />
<br />
<source lang="bash"><br />
casapy<br />
</source><br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.5.2. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.5.2'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
==Install Analysis Utilities==<br />
<br />
Analysis Utilities (or analysisUtils for short) is a small set of Python scripts that provide a number of analysis and plotting utilities for ALMA data reduction. This guide uses a few of these utilities. They are very easy to install (just download and untar). See <br />
<br />
http://casaguides.nrao.edu/index.php?title=Analysis_Utilities<br />
<br />
for a full description and download instructions. If you do not wish to do this, see the [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Calibration_for_CASA_3.3 CASA 3.3 version of the guide] for alternative (but slow) plotting options. Analysis Utilities are updated frequently so if its been a while since you installed it, its probably worth doing it again. If you are at an ALMA site or ARC, the analysis utilities are probably already installed and up to date.<br />
<br />
==Fix Titan's coordinates==<br />
<br />
'''Note that in the near future this step will be unnecessary.''' <br />
<br />
It is temporarily necessary to correct the positions of ephemeris objects observed during ALMA Cycle 0, because the control software revisions earlier than 9.0 erroneously write the data with coordinates of 00:00:00.0000 +00.00.00.0000 (J2000). For this dataset, we need to correct the position of the absolute flux calibrator Titan, as we can<br />
see from the first {{listobs}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -f X3c1.ms.listobs')<br />
listobs('X3c1.ms', verbose=T, listfile='X3c1.ms.listobs') <br />
</source><br />
<br />
You can view the listobs output files using command "less" from the CASA prompt.<br />
<br />
<pre style="background-color: #fffacd;"><br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 23625<br />
1 none Titan 00:00:00.00000 +00.00.00.0000 J2000 1 4842<br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 175176<br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 14832<br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 59877<br />
</pre><br />
<br />
To correct Titan's position, we will use the task [http://casa.nrao.edu/stable/docs/TaskRef/fixplanets-task.html fixplanets], which writes the actual coordinates at the instant of the first observation. This step takes a while because we are recalculating the uvw's accordingly.<br />
<source lang="python"><br />
# In CASA<br />
fixplanets(vis='X3c1.ms', field='Titan', fixuvw=True)<br />
</source><br />
<br />
Check the header information again with {{listobs}} to confirm that the information for Titan has changed:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -f X3c1.ms.listobs')<br />
listobs('X3c1.ms', verbose=T, listfile='X3c1.ms.listobs') <br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 23625<br />
1 none Titan 12:49:25.93349 -02.22.41.5638 J2000 1 4842<br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 175176<br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 14832<br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 59877<br />
</pre><br />
<br />
Now fix the other two measurement sets similarly:<br />
<source lang="python"><br />
# In CASA<br />
fixplanets(vis='X5d8.ms', field='Titan', fixuvw=True)<br />
fixplanets(vis='X7ef.ms', field='Titan', fixuvw=True)<br />
</source><br />
<br />
==Observing Log and Priors==<br />
<br />
Below is some information that may not be obvious from the data<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Like at most telescopes, the ALMA operators and astronomers at the site log any significant issues <br />
that were noticed from the online system during the observation. For these Band 7 observations of <br />
TW Hya on April 22, 2011, the only issue of note was that antenna DV04 could not observe at Band 7 <br />
and will need to be flagged. <br />
</pre><br />
<br />
First let's examine the basic properties of the data using {{listobs}}. Among other information we <br />
will be able to deduce what the source ids are and what each source was used for:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
3c279 is the bandpass calibrator (field id=0)<br />
Titan is the absolute flux calibrator (field id=1)<br />
J1147-382 is the secondary phase calibrator (field id=3)<br />
J1037-295 is the primary phase calibrator (field id=4)<br />
</pre><br />
<br />
<source lang="python"><br />
# In CASA<br />
data=['X3c1.ms','X5d8.ms','X7ef.ms']<br />
for vis in data:<br />
os.system('rm '+vis+'.listobs')<br />
listobs(vis, verbose=T, listfile=vis+'.listobs') <br />
</source><br />
<br />
You can view the {{listobs}} output files using command '''less''' from the CASA prompt. <br />
Below we copy select parts of the {{listobs}} output files for reference. <br />
<br />
<pre style="background-color: #fffacd;"><br />
X3c1.ms:<br />
Data records: 278352 Total integration time = 6109.06 seconds<br />
Observed from 22-Apr-2011/00:01:52.9 to 22-Apr-2011/01:43:42.0 (UTC)<br />
<br />
X5d8.ms:<br />
Data records: 278406 Total integration time = 5995.01 seconds<br />
Observed from 22-Apr-2011/01:48:05.8 to 22-Apr-2011/03:28:00.8 (UTC)<br />
<br />
X7ef.ms:<br />
Data records: 255717 Total integration time = 5407.49 seconds<br />
Observed from 22-Apr-2011/03:30:39.7 to 22-Apr-2011/05:00:47.2 (UTC)<br />
<br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 23625<br />
1 none Titan 12:49:25.97588 -02.22.41.3024 J2000 1 4842<br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 175176<br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 14832<br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 59877 <br />
<br />
SpwID #Chans Frame Ch1(MHz) ChanWid(kHz) TotBW(kHz) Corrs<br />
0 4 TOPO 184550 1500000 7500000 I<br />
1 128 TOPO 355740.062 15625 2000000 XX YY<br />
2 1 TOPO 356716.625 1796875 1796875 XX YY<br />
3 128 TOPO 356507.813 15625 2000000 XX YY<br />
4 1 TOPO 357484.375 1796875 1796875 XX YY<br />
5 128 TOPO 346792.187 15625 2000000 XX YY<br />
6 1 TOPO 345784.375 1796875 1796875 XX YY<br />
7 128 TOPO 345182.438 15625 2000000 XX YY<br />
8 1 TOPO 344174.625 1796875 1796875 XX YY<br />
9 128 TOPO 344386.763 15625 2000000 XX YY<br />
10 1 TOPO 343378.95 1796875 1796875 XX YY<br />
11 128 TOPO 346324.263 15625 2000000 XX YY<br />
12 1 TOPO 345316.45 1796875 1796875 XX YY<br />
13 128 TOPO 354402.388 15625 2000000 XX YY<br />
14 1 TOPO 355378.95 1796875 1796875 XX YY<br />
15 128 TOPO 356402.388 15625 2000000 XX YY<br />
16 1 TOPO 357378.95 1796875 1796875 XX YY<br />
17 3840 TOPO 356497.936 122.070312 468750 XX YY<br />
18 1 TOPO 356732.189 468750 468750 XX YY<br />
19 3840 TOPO 357734.314 122.070312 468750 XX YY<br />
20 1 TOPO 357499.939 468750 468750 XX YY<br />
21 3840 TOPO 346034.314 122.070312 468750 XX YY<br />
22 1 TOPO 345799.939 468750 468750 XX YY<br />
23 3840 TOPO 343955.936 122.070312 468750 XX YY<br />
24 1 TOPO 344190.189 468750 468750 XX YY<br />
<br />
Antennas: 9:<br />
Name Station Diam. Long. Lat.<br />
0 DV04 J505 12.0 m -067.45.18.0 -22.53.22.8<br />
1 DV06 T704 12.0 m -067.45.16.2 -22.53.22.1<br />
2 DV07 J510 12.0 m -067.45.17.8 -22.53.23.5<br />
3 DV08 T703 12.0 m -067.45.16.2 -22.53.23.9<br />
4 DV09 N602 12.0 m -067.45.17.4 -22.53.22.3<br />
5 DV10 N606 12.0 m -067.45.17.1 -22.53.23.6<br />
6 PM01 T702 12.0 m -067.45.18.6 -22.53.24.1<br />
7 PM02 T701 12.0 m -067.45.18.8 -22.53.22.2<br />
8 PM03 J504 12.0 m -067.45.17.0 -22.53.23.0<br />
</pre><br />
<br />
Things to Notice from above: <br />
*There are three different data sets acquired close together in time. We will calibrate each dataset independently and then combine the calibrated data prior to imaging. <br />
*Titan appears to have slightly different positions in each dataset because it is a moving body. In fact, at the time of observation, due to temporary data capture issue in the ALMA system, the position was written has (0,0). We have pre-corrected this error using fixplanets. Later in the tutorial, we will run fixplanets again to force all three datasets to have the same fixed position for Titan.<br />
*There are a lot of spectral windows! Don't be alarmed. In ALMA data, <br />
**spw=0 is always reserved for the water vapor radiometry data.<br />
**spw=9, 11, 13, 15 are the wideband (TDM) correlator mode with 128 channels per spw default settings for doing pointing and this is all they are used for in these data.<br />
**Currently Tsys data can only be taken in the wide (TDM) correlator mode with 128 channels per spw, these correspond to spws=1, 3, 5, 7 above. The frequencies of these TDM spws were carefully chosen so the the narrowband FDM spws fall within them.<br />
** The 0.5 GHz, high spectral resolution spws that contain all the real source data (science target and calibrators) are 17, 19, 21, and 23<br />
**For quicklook purposes, the ALMA online system produces a channel averaged spw for each channelized spw, these correspond to spw=2,4,6,8,10,12,14,16,18,20,22,24 and shouldn't be used for anything in post-processing as bandpass calibration etc has not been applied.<br />
<br />
In the portion of the {{listobs}} output that shows the timerange, the final column gives the scan intent. It is important to have a look at this because you can flag and do other operations in CASA using the scan intent as a selection option. Also, these intents will be used in the future for pipeline processing. You will usually want to use them to flag the CALIBRATE_POINTING* and CALIBRATE_ATMOS* (the latter correspond to the hot and cold load measurements used to calculate Tsys) data. This is essential for science or calibration data taken only in TDM (wide bandwidth) mode, i.e. the same mode that the pointing and Tsys data are taken in. For the current data however, that calibration data is recorded in different spws from the useful FDM (narrow bandwidth) data, so we'll be able to separate them by splitting them off at the final step prior to imaging.<br />
<br />
<figure id="Ant_pos.png"><br />
[[Image:Ant_pos.png|thumb|<caption>Antenna locations for the first dataset.</caption>]]<br />
</figure><br />
<br />
Before we move on, its also nice to get an idea where the antennas are with respect to each other. We can use {{plotants}} to plot their positions. It is a good idea to check each file since an antenna may have entered or exited the array between observations.<br />
<source lang="python"><br />
# In CASA<br />
for vis in data:<br />
plotants(vis=vis,figfile=vis+'.plotants.png')<br />
</source><br />
<br />
You can view the output images using any standard image viewer.<br />
<br />
==Create the Tsys and WVR Tables, and Examine ==<br />
<br />
Each ms include tables that contain the Tsys and WVR measurements associated with the visibility data.<br />
We must create calibration tables from these measurements. First we create the WVR calibration tables <br />
by running the task [http://casa.nrao.edu/stable/docs/TaskRef/wvrgcal-task.html wvrgcal]. This task <br />
examines the data for each ms as a whole and creates a calibration<br />
table containing only phase corrections for each antenna and spw. <br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
os.system('rm -rf '+asdm+'.wvr')<br />
wvrgcal(vis=asdm+'.ms', caltable=asdm+'.wvr', segsource=True, toffset=-1)<br />
</source><br />
<br />
Next we create the Tsys tables by running {{gencal}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
os.system('rm -rf '+asdm+'.tsys')<br />
gencal(vis=asdm+'.ms', caltable=asdm+'.tsys', caltype='tsys')<br />
</source><br />
<br />
It is very important that Tsys measurements taken as close in time and elevation as possible to a particular source are applied. To save telescope time, Tsys measurements are sometimes intentionally skipped in the scheduling block for specific sources. So the first step is to establish which sources have their own Tsys measurements and which do not. To do this, you may use the intent parameter of {{listobs}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
listobs(vis=asdm+'.ms', verbose=F, selectdata=True, intent='CALIBRATE_ATMOS*')<br />
</source><br />
<br />
<figure id="X3c1.tsys_vs_time_3.4.png"><br />
[[File:X3c1.tsys_vs_time_3.4.png|thumb|<caption>Tsys vs. time for spw 1 of the X3c1.ms data.</caption>]]<br />
</figure><br />
<figure id="X5d8.tsys_vs_time_3.4.png"><br />
[[File:X5d8.tsys_vs_time_3.4.png|thumb|<caption>Tsys vs. time for spw 1 of the X5d8.ms data.</caption>]]<br />
</figure><br />
<figure id="X7ef.tsys_vs_time_3.4.png"><br />
[[File:X7ef.tsys_vs_time_3.4.png|thumb|<caption>Tsys vs. time for spw 1 of the X7ef.ms data.</caption>]]<br />
</figure><br />
<br />
<pre style="background-color: #fffacd;"><br />
Fields: 4<br />
ID Code Name RA Decl Epoch SrcId nRows <br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 1116 <br />
1 none Titan 12:49:25.97588 -02.22.41.3024 J2000 1 1125 <br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 6795 <br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 6777 <br />
Spectral Windows: (9 unique spectral windows and 2 unique polarization setups)<br />
SpwID #Chans Frame Ch1(MHz) ChanWid(kHz) TotBW(kHz) Corrs <br />
0 4 TOPO 184550 1500000 7500000 I <br />
1 128 TOPO 355740.062 15625 2000000 XX YY <br />
2 1 TOPO 356716.625 1796875 1796875 XX YY <br />
3 128 TOPO 356507.813 15625 2000000 XX YY <br />
4 1 TOPO 357484.375 1796875 1796875 XX YY <br />
5 128 TOPO 346792.187 15625 2000000 XX YY <br />
6 1 TOPO 345784.375 1796875 1796875 XX YY <br />
7 128 TOPO 345182.438 15625 2000000 XX YY <br />
8 1 TOPO 344174.625 1796875 1796875 XX YY <br />
</pre><br />
<br />
Because field '3' (the secondary phase calibrator) does not appear in the list, it has no tsys. Since the secondary phase calibrator is close on the sky to the primary phase calibrator and observed near in time, we will transfer the Tsys from the primary to the secondary phase calibrator. <br />
Also notice that spws 1,3,5,7 are the only multi-channel spws that contain Tsys data. At present, Tsys measurements can only be obtained with TDM spectral setups (128 channels/dual pol). Because our science target is observed in FDM (3840 channels/dual pol), we will need to interpolate the measurements from TDM to FDM. But first, to inspect the Tsys vs. time, we use {{plotcal}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all = ['X3c1','X5d8','X7ef']<br />
tsysfields=['0','1','2','4']<br />
os.system('mkdir cal_plots; mkdir cal_plots/Tsys_plots') <br />
for asdm in basename_all:<br />
print "Plotting Tsys vs. time for "+asdm<br />
plotcal(caltable=asdm+'.tsys', xaxis='time',yaxis='tsys',<br />
antenna='1~8',plotrange=[0,0,100,500],<br />
iteration='antenna',subplot=421,poln='',spw='1:50~50',<br />
figfile='cal_plots/Tsys_plots/'+asdm+'.tsys_vs_time.png')<br />
if (asdm != basename_all[-1]):<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
To inspect Tsys vs. frequency, we use [[plotbandpass]]. There are many different options for plotbandpass, and we demonstrate some of the most useful ones. The option '''showtsky=T''' will overlay the effective temperature curve from the atmospheric model. This shows us the location of any atmospheric lines which will appear as emission lines in the autocorrelation data (from which the Tsys spectra are derived) from all antennas. In the<br />
example below, we set '''interactive=False''', which will produce many pages of plots as<br />
individual pngs but will only show the final page in the graphics window. To view all the pages we use the image viewer '''eog''' (Eye of GNOME) available on Linux. The alternative is to set '''interactive=True''' and examine the plots in the casa graphics window as they are produced.<br />
<br />
<figure id="X3c1.tsys.field0.DV04.spw1.t1.png"><br />
[[File:X3c1.tsys.field0.DV04.spw1.t1.png|thumb|<caption>Tsys vs. frequency on 3C279 for the X3c1.ms data, spw=1.</caption>]]<br />
</figure><br />
<figure id="X3c1.tsys.field0.DV04.spw3.t1.png"><br />
[[File:X3c1.tsys.field0.DV04.spw3.t1.png|thumb|<caption>Tsys vs. frequency on 3C279 for the X3c1.ms data, spw=3.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
print "Plotting Tsys vs. frequency for "+asdm<br />
for spw in [1,3,5,7]:<br />
for field in ['0','1']:<br />
plotbandpass(caltable=asdm+'.tsys', xaxis='freq',yaxis='amp',<br />
showtsky=T,subplot=42,field=field,<br />
spw=spw, interactive=False, plotrange=[0,0,0,0],<br />
figfile='cal_plots/Tsys_plots/'+asdm+'.tsys.field%s.png'%field,<br />
buildpdf=False)<br />
</source><br />
<br />
In <xr id="X3c1.tsys.field0.DV04.spw1.t1.png"/> and <xr id="X3c1.tsys.field0.DV04.spw3.t1.png"/> we see the effect of atmospheric ozone lines on the Tsys measurements associated with 3C279 in spw 1 and 3.<br />
<br />
For sources that have multiple Tsys measurements (typically the primary phase calibrator and/or the science target) one can use '''overlay="time"''' to overlay all the measurements for that source. This can help to identify any anomalous Tsys scans. As a fraction of the plots produced by this loop, here we show the Tsys recorded on spw=1 for TW Hya from the first dataset.<br />
<br />
<figure id="X3c1.tsys.field2.DV04.spw1.png"><br />
[[File:X3c1.tsys.field2.DV04.spw1.png|thumb|<caption>Tsys vs. freq for field 2, spw 1 of the X3c1.ms data (antennas 0..3).</caption>]]<br />
</figure><br />
<figure id="X3c1.tsys.field2.DV04.spw1.png"><br />
[[File:X3c1.tsys.field2.DV09.spw1.png|thumb|<caption>Tsys vs. freq for field 2, spw 1 of the X3c1.ms data (antennas 4..7).</caption>]]<br />
</figure><br />
<figure id="X3c1.tsys.field2.PM03.spw1.png"><br />
[[File:X3c1.tsys.field2.PM03.spw1.png|thumb|<caption>Tsys vs. freq for field 2, spw 1 of the X3c1.ms data (antenna 8).</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
print "Plotting Tsys vs. frequency for "+asdm<br />
for spw in [1,3,5,7]:<br />
for field in ['2','4']:<br />
plotbandpass(caltable=asdm+'.tsys', xaxis='freq',yaxis='amp',<br />
showtsky=T,subplot=22,field=field,<br />
overlay='time',spw=spw, interactive=False, plotrange=[0,0,0,0],<br />
figfile='cal_plots/Tsys_plots/'+asdm+'.tsys.field%s.png'%field,<br />
buildpdf = False)<br />
</source><br />
<br />
Alternatively, the '''overlay="antenna"''' option will quickly reveal any Antennas with discrepant Tsys values, as they<br />
will be obvious outliers. For FDM projects like this one, using the '''showfdm=True''' option can be helpful, as it<br />
will show where in the TDM bandpass each FDM spw was located. <br />
<figure id="X3c1.tsys.field0.spw1.t1.png"><br />
[[Image:X3c1.tsys.field0.spw1.t1.png|thumb|<caption>Tsys vs Freq for field 0, spw 1 of the X3c1.ms data with all antennas overlaid.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
tsysfields=['0','1','2','4'] <br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
print "Plotting Tsys vs. frequency for "+asdm<br />
for spw in [1,3,5,7]:<br />
for field in tsysfields:<br />
plotbandpass(caltable=asdm+'.tsys', xaxis='freq',yaxis='amp',<br />
showtsky=T,subplot=11,field=field,<br />
overlay='antenna',spw=spw, interactive=False,<br />
figfile='cal_plots/Tsys_plots/'+asdm+'.tsys.field%s.png'%field,<br />
buildpdf=False,showfdm=True)<br />
</source><br />
<br />
<br />
Note that DV04 consistently has a significantly higher Tsys than the rest of the antennas. We already know from the Observation log that<br />
we need to flag that antenna, but had we not had that information, examining this plot would have demonstrated the situation.<br />
<br />
==Apply the Tsys and WVR Tables, and Split ==<br />
<br />
Next we apply the calibrations. For the (4) sources with Tsys measurements, we use the '''field''' and '''gainfield''' parameters of {{applycal}} to apply solutions only to themselves. {{applycal}} has the ability to interpolate gain tables from one spw onto another spw. In this case, we want to interpolate the TDM Tsys values in spws 1,3,5,7 onto the FDM spws 17,19,21,23. We use the '''interp''' parameter to request linear interpolation in the time dimension and spline interpolation in the channel/frequency dimension. To map the solutions for each spw, we use the '''spwmap''' parameter, which requires a list of all spws for each gain table to be applied, or a blank list ([]) which is a shorthand notation to apply the solution for each spw to itself. While applying Tsys, we will also apply the wvr calibration tables; wvr data is usually always present for all sources. Below we first set some definitions so we can loop over the correct parameters:<br />
<br />
<source lang="python"><br />
# In CASA<br />
fdm='17,19,21,23'<br />
nocal='3' # This source had no Tsys measurements associated with it <br />
tsysfields=['0','1','2','4'] <br />
tsysmap = range(25)<br />
tsysmap[17] = 1<br />
tsysmap[19] = 3<br />
tsysmap[21] = 5<br />
tsysmap[23] = 7<br />
for asdm in basename_all:<br />
for field in tsysfields:<br />
applycal(vis=asdm+'.ms', spw=fdm, field=field, gainfield=field,<br />
gaintable=[asdm+'.tsys', asdm+'.wvr'], spwmap=[tsysmap,[]],<br />
interp=['linear,spline','nearest'], flagbackup=F, calwt=T)<br />
</source><br />
<br />
For the sources without Tsys (i.e. field=3), couple them with the best available source with Tsys (i.e. field=4).<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename_all:<br />
applycal(vis=asdm+'.ms', spw=fdm, field=nocal,<br />
gaintable=[asdm+'.tsys', asdm+'.wvr'], spwmap=[tsysmap,[]],<br />
gainfield=['4',nocal], interp=['linear,spline','nearest'],flagbackup=F,<br />
calwt=T)<br />
</source><br />
<br />
Check Tsys application with plotms. First we make plots with '''ydatacolumn='data'''' to look at the raw data. For <br />
simplicity we'll just look at the two strongest sources 3C279 and Titan.<br />
<br />
<figure id="X5d8_wvrtsys_corrected_spw19.png"><br />
[[Image:X5d8_wvrtsys_corrected_spw19.png|thumb|<caption>Spectral plots of 3C279 (black) and Titan (magenta) for spw=19 after Tsys and wvr correction.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X5d8.ms',spw='17,19,21,23',xaxis='frequency',yaxis='amp',field='0,1',<br />
antenna='*&*',avgtime='1e8',avgscan=T,coloraxis='field',iteraxis='spw',<br />
xselfscale=T,ydatacolumn='data')<br />
</source><br />
<br />
<figure id="X5d8_wvrtsys_corrected_spw21.png"><br />
[[Image:X5d8_wvrtsys_corrected_spw21.png|thumb|<caption>Spectral plots of 3C279 (black) and Titan (magenta) for spw=21 after Tsys and wvr correction.</caption>]]<br />
</figure><br />
<br />
'''Note''': the antenna='*&*' is specifying that we only want to see the cross-correlation data (i.e. not the autocorrelations).<br />
<br />
Use the '''green arrows''' on the {{plotms}} display to cycle through the 4 FDM spws. <br />
<br />
Now change '''Data Column''' to '''corrected''' on the "Axes" tab (this is the same as ydatacolumn in the task) and hit '''Plot''' button on the GUI. Flip through again.<br />
<br />
'''Things to notice:'''<br />
* The amplitude scale has changed due to application of Tsys<br />
* spw=17 is clean and flat<br />
* spw=19 shows a strong dip around channel 3000 (channels can be plotted by going to the Axes tab, and changing X Axis to Channel, then hit the Plot button)-- this is an atmospheric ozone absorption feature at 357.6 GHz. In the future, high spectral resolution Tsys measurements may help to remove the shape of the absorption, but until then we will need to flag this part of the spectrum.<br />
* spw=21 Titan shows both a narrow and a broad spectral feature. The broad feature is CO(3-2) and it completely fills the 0.5 GHz band so there are no line-free channels! Titan must be handled carefully when it is used as a calibrator because it contains strong line emission. Indeed, we will not be able to use the absolute flux transfer from this spw for other targets. When possible Titan should be avoided for absolute flux calibration. For these observations, no other suitable absolute flux calibrator was available.<br />
* spw=23 shows another strong line from Titan.<br />
<br />
Beyond these things to notice, the application of Tsys and wvr seem to have gone well. We can now split off only the narrow band FDM spectral windows for further processing.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename_all:<br />
newvis = asdm + '_wvrtsys.ms'<br />
os.system('rm -rf ' + newvis)<br />
split(vis=asdm+'.ms',outputvis=newvis,datacolumn='corrected',spw=fdm)<br />
</source><br />
<br />
'''Note''': After {{split}}, the spectral windows will be renumbered to 0, 1, 2, 3 corresponding to the old spw=17, 19, 21, 23, see {{listobs}} excerpt below.<br />
<br />
<pre style="background-color: #fffacd;"><br />
SpwID #Chans Frame Ch1(MHz) ChanWid(kHz) TotBW(kHz) Corrs <br />
0 3840 TOPO 356497.936 122.070312 468750 XX YY <br />
1 3840 TOPO 357734.314 122.070312 468750 XX YY <br />
2 3840 TOPO 346034.314 122.070312 468750 XX YY <br />
3 3840 TOPO 343955.936 122.070312 468750 XX YY <br />
</pre><br />
<br />
==Initial Inspection and Flagging==<br />
<br />
From here we begin to operate on the *wvrtsys.ms files. <br />
<br />
Before we begin flagging data, we unflag all data in the measurement sets. If this is your first pass through this section of the guide, no data in the measurement sets will be flagged, and you can skip this step. If you are rerunning the flagging commands below, this will reset your flag columns to their original state.<br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
for vis in splitdata:<br />
flagdata(vis=vis, mode='unflag', action='apply', flagbackup=F)<br />
</source><br />
<br />
ALMA data contains both the cross correlation and autocorrelation data. Presently nothing more can be done with the autocorrelation data so we flag it. Additionally, for smaller configurations of the array, and northerly sources one antenna can ''shadow'' another, blocking its view. This data also needs to be flagged. Finally, the observing log told us DV04 was not behaving properly at Band 7 and shouldn't be used so we flag that as well.<br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
for vis in splitdata:<br />
flagdata(vis=vis, mode='manual', autocorr=True, action = 'apply', flagbackup=T)<br />
flagdata(vis=vis, mode='shadow',tolerance=12.0, action='apply', flagbackup=F)<br />
flagdata(vis=vis, mode='manual', antenna='DV04', action='apply', flagbackup=F)<br />
</source><br />
<br />
Next we inspect the data with {{plotms}} for additional issues that need flagging, first looking at amplitude vs. time for each of the three datasets. Use the '''green''' arrows on the plotms gui to cycle through spws. <br />
<br />
<figure id="Tsyswvr_time_spw0_X3x1.png"><br />
[[Image:Tsyswvr_time_spw0_X3x1.png|thumb|<caption>Amplitude as a function of time for X3c1_wvrtsys.ms, spw=0</caption>]]<br />
</figure><br />
<br />
'''Note''': when '''iteraxis''' is invoked in {{plotms}}, unzoom does not always work properly. If you have trouble with this, flip to next page and then back to current one. This usually fixes the problem.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X5d8_wvrtsys.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X7ef_wvrtsys.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw')<br />
</source><br />
<br />
<figure id="Tsyswvr_time_spw2corr_X3x1.png"><br />
[[Image:Tsyswvr_time_spw2corr_X3x1.png|thumb|<caption>Amplitude as a function of time for X3x1_wvrtsys.ms, spw=2 with colorize='corr'.</caption>]]<br />
</figure><br />
<br />
'''Things to Notice:'''<br />
* In spw=2 there are some low points in all three data files. Use the "Mark Regions" box (left of center on bottom row of icons) to draw small box on low points. Then click the magnifying glass icon to the right of center. The output will be sent to the logger window. '''Note''': keep the marked region small or you can overwhelm the buffer. Locate suggests correlation YY on PM03 is the culprit. <br />
<br />
To see this more clearly you can rerun {{plotms}} with '''coloraxis='field'''' switched to '''coloraxis='corr''''<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='2',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='corr')<br />
</source><br />
<br />
To further check, you can exclude PM03 from the plot using '''antenna='!PM03'.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='2',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='corr',antenna='!PM03')<br />
</source><br />
<br />
Having confirmed the problem antenna, we flag it below. <br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
for vis in splitdata:<br />
flagdata(vis=vis, mode='manual', action= 'apply', flagbackup=T,<br />
spw='2',<br />
antenna='PM03',<br />
correlation='YY')<br />
</source><br />
<br />
'''Next we need to inspect the spectral properties of the data to look for issues.'''<br />
<br />
First we look at phase as a function of frequency for a well behaved antenna like DV06. <br />
'''coloraxis='baselines'''' (note this parameter is called '''Colorize''' in the GUI "Display" tab) will show each baseline as a different color. Significant delay errors or baseline errors will show up as phase slopes in these plots. Again you will want to page through the spectral windows.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='',xaxis='frequency',yaxis='phase',field='0',antenna='DV06',<br />
avgtime='1e8',avgscan=T,coloraxis='baseline',iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X5d8_wvrtsys.ms',spw='',xaxis='frequency',yaxis='phase',field='0',antenna='DV06',<br />
avgtime='1e8',avgscan=T,coloraxis='baseline',iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X7ef_wvrtsys.ms',spw='',xaxis='frequency',yaxis='phase',field='0',antenna='DV06',<br />
avgtime='1e8',avgscan=T,coloraxis='baseline',iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
Overall these plots look good with no large delays or baseline errors apparent.<br />
<br />
<figure id="Birdies_spw2_X3x1.png"><br />
[[Image:Birdies_spw2_X3x1.png|thumb|<caption>Phase calibrators (brown and green) and TW Hya (orange) showing both real CO(3-2) emission in TW Hya and weak ''birdie'' spectral features in all three sources for spw=2.</caption>]]<br />
</figure><br />
<br />
With such high spectral resolution data, one often sees occasional "birdies" in the data. These are typically very narrow weak spectral features that are internally generated in the system. Over time as we track down issues the number of birdies should decrease, but you should always check. This is easiest to do by looking at amplitude vs. frequency for sources observed over a long time range (for sensitivity). It is helpful to look at more than one source to verify the nature of the emission. Below we look at both calibrators (brown and green) and TW Hya (orange). If you have enough sensitivity birdies should be seen on all sources, however, be careful not to mistake real line emission for a birdie even on a calibrator - they can be present as we've seen for Titan.<br />
<br />
<figure id="Birdies_spw3_X3x1.png"><br />
[[Image:Birdies_spw3_X3x1.png|thumb|<caption>Phase calibrators (brown and green) and TW Hya (orange) showing only weak birdie spectral features in spw=3.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='',xaxis='channel',yaxis='amp',field='2,3,4',<br />
avgtime='1e8',avgscan=T,coloraxis='field',iteraxis='spw',xselfscale=T,yselfscale=T)<br />
</source><br />
<br />
Do a quick check that other two datasets are the same (they are usually similar if the source of internal resonance hasn't changed in the meantime).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X5d8_wvrtsys.ms',spw='',xaxis='channel',yaxis='amp',field='2,3,4',<br />
avgtime='1e8',avgscan=T,coloraxis='field',iteraxis='spw',xselfscale=T,yselfscale=T)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X7ef_wvrtsys.ms',spw='',xaxis='channel',yaxis='amp',field='2,3,4',<br />
avgtime='1e8',avgscan=T,coloraxis='field',iteraxis='spw',xselfscale=T,yselfscale=T)<br />
</source><br />
<br />
Now you can zoom in on each region to get channels for flagging, or to save time just go ahead and run the flagging command below where this has been done for you.<br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
for vis in splitdata:<br />
flagdata(vis=vis, mode='manual', action='apply', flagbackup=T,<br />
spw='0:1067~1068;1279~1280;2367~2368;3775~3776, 1:1279~1280;2367~2368;3775~3776, 2:1279~1280;3775~3776, 3:831~832;1535~1536;2367~2368;3775~3776;3839~3839')<br />
</source><br />
<br />
Replot in {{plotms}} to check that flagging has been done as anticipated.<br />
<br />
==Flag Calibrator Spectral Features==<br />
<br />
In this section, we will flag spectral features in the calibrators so they do not skew the calibration solutions. First make plots of 3C279 and Titan in channel space to get channels for flagging. <br />
<br />
<figure id="3C279_Titan_spw1.png"><br />
[[Image:3C279_Titan_spw1.png|thumb|<caption>Spectral plots of 3C279 (black) and Titan (magenta) for spw=1 after Tsys and wvr correction.</caption>]]<br />
</figure><br />
<figure id="3c279_meso_freq.png"><br />
[[Image:3c279_meso_freq.png|thumb|<caption>Zoomed spectral plot of 3C279 showing mesospheric absorption of CO(3-2) in frequency space.</caption>]]<br />
</figure><br />
<figure id="3c279_meso_chann.png"><br />
[[Image:3c279_meso_chann.png|thumb|<caption>Zoomed spectral plot of 3C279 showing mesospheric absorption of CO(3-2) in channel space.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='channel',yaxis='amp',field='0,1',<br />
avgtime='1e8',coloraxis='field',iteraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
The figure to the right shows a broad absorption line in spw 1 at channel 3000. This is the ozone absorption line at 357.62982 GHz. However, there is another narrow absorption feature in the spectra (spw 2) that is most easily seen on 3C279 (because it is the strongest calibrator). Let's look at it first in frequency space.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='2:1600~2300',xaxis='frequency',yaxis='amp',<br />
field='0',avgtime='1e8',coloraxis='field')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
The absorption feature lies exactly at the rest frequency for CO 3-2 (345.79599 GHz). Because it is so narrow (< 1 MHz), it must originate from a very low pressure region (i.e. high altitude) in the Earth's atmosphere, otherwise it would be more pressure broadened. Indeed, the first detection of CO in the mesosphere was made over 35 years ago (see, e.g. [http://adsabs.harvard.edu/abs/1976Sci...191.1174W Waters et al. 1976] or [http://adsabs.harvard.edu/abs/1979JGR....84..416G Goldsmith et al. 1979]). Be aware that the line is stronger as you go up the CO ladder (strength ~ J^3 for low J) because the temperature at that altitude (~50km) is about 250 K. In April 2011, the apparent depth of the feature was about 10% in the 2-1 line and 35% in the 3-2 line. However, the depth of the absorption feature is exaggerated due to the way ALMA normalizes the cross-correlation spectra by the autocorrelation spectra prior to storage. While this technique generally leads to a flat bandpass shape, it will accentuate telluric features because they are emission lines in the single dish spectrum (e.g. JCMT observations of mesospheric CO 3-2 can be found in [http://adsabs.harvard.edu/abs/1993MNRAS.264..673P Preston et al. 1993]). Finally, note that large seasonal variations in the line strength have been reported from observations at [http://adsabs.harvard.edu/abs/2003GeoRL..30j..39F Onsala]. <br />
<br />
Now, let's re-plot the line with channel number as the x-axis in order to get the channel range for flagging. <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='2:1600~2300',xaxis='channel',yaxis='amp',<br />
field='0',avgtime='1e8',coloraxis='field')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Now lets look at Titan in more detail.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='channel',yaxis='amp',field='1',<br />
avgtime='1e8',coloraxis='field',iteraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Explicitly back up the flag tables so that flagged regions can be restored later.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
flagmanager(vis=asdm+'.ms',mode='save',versionname=asdm+'.before_calspectralflags')<br />
</source><br />
<br />
<figure id="Titan_spw2.png"><br />
[[Image:Titan_spw2.png|thumb|<caption>Spectral plot of Titan (magenta) for spw=2.</caption>]]<br />
</figure><br />
<br />
Flag absorption features for all sources.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
print "Flagging absorption features in all sources for "+asdm<br />
flagdata(vis=asdm+'.ms', mode='manual', spw='1:2000~3839, 2:1945~1960')<br />
</source><br />
<br />
<figure id="Titan_spw3.png"><br />
[[Image:Titan_spw3.png|thumb|<caption>Spectral plot of Titan (magenta) for spw=3.</caption>]]<br />
</figure><br />
<br />
Now we need to flag emission. The very broad CO(3-2) in spw=2 of Titan will prevent us from using it as a calibrator for this spectral window since there are no line-free channels (we will transfer, phase, amplitude, and absolute flux from another Titan spw below). We do want to flag the narrower Titan line in spw=3.<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
flagmanager(vis=asdm+'.ms',mode='save',versionname=asdm+'.before_emissionflags')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
print "Flagging emission for "+asdm<br />
flagdata(vis=asdm+'.ms', mode='manual', <br />
field='1',<br />
spw='3:1000~3000')<br />
</source><br />
<br />
If you like, check that the right things have been flagged.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='channel',yaxis='amp',field='0,1',<br />
avgtime='1e8',coloraxis='field',iteraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
==Set Up the Flux Calibrator Model==<br />
<br />
Fill the model data column for Titan with a model for the flux density as a function of baseline. The model is a uniformly illuminated disk with the size obtained from the JPL Horizons ephemeris.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
setjy(vis=asdm+'.ms',field='1',usescratch=F,<br />
standard='Butler-JPL-Horizons 2010',scalebychan=F)<br />
</source><br />
<br />
<figure id="Titan amp vs uvdist.png"><br />
[[Image:Titan amp vs uvdist.png|thumb|<caption>Plot of Titan model for each of the 4 spws. We used the Butler-JPL-Horizons 2010 standard to compute this model.</caption>]]<br />
</figure><br />
<br />
After running setjy, it is a good idea to plot the model in order to confirm that it makes sense. In this case, Titan is partially resolved, so we expect the flux density to drop with uv distance, but not so much as to pass through a null. We also expect it to be brighter at higher frequencies since it has a thermal blackbody spectrum.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',field='1',xaxis='uvdist',yaxis='amp',coloraxis='spw',<br />
ydatacolumn='model')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<figure id="twhydra_X3c1_wvrtsys_2012_titan_model.png">[[File:twhydra_X3c1_wvrtsys_2012_titan_model.png|thumb|right|<caption>Titan model produced by 'Butler-JPL-Horizons 2012'.</caption>]]</figure><br />
<br />
<br/><br />
<div class="noprint" style="float:none; border:0px solid blue;background-color:#F6CEF5;padding:2px;"><br />
The setjy invocation, above, uses the flux density standard '''standard='Butler-JPL-Horizons 2010' '''. A more updated standard is also available: '''standard='Butler-JPL-Horizons 2012' '''. <xr id="twhydra_X3c1_wvrtsys_2012_titan_model.png"/> shows the Titan model produced using the updated standard. The motivated reader may wish to rerun {{setjy}} using the updated model. We will highlight later in this tutorial, and in the imaging tutorial that follows, the effects of using the updated model.<br />
</div><br />
<br />
==Bandpass Calibration==<br />
<br />
First we need to check how the amplitude and phase of 3C279 behave as a function of time. In order to set<br />
a fixed scale on the y-axis, we first make a plot of all the data, excluding antenna DV04. (We must specify '''ydatacolumn='data' ''' explicitly here because the default value of '''ydatacolumn''' equals the value used in the previous execution of {{plotms}}. In the previous execution '''ydatacolumn''' was set to '''model'''. See the online help, <tt>help plotms</tt>, for details.)<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',xaxis='time',yaxis='amp',coloraxis='corr',<br />
field='0',avgchannel='3840',ydatacolumn='data')<br />
</source><br />
<br />
<figure id="ThreeScansAmp.png"><br />
[[Image:ThreeScansAmp.png|thumb|<caption>Amplitude variation for three 3C279 scans, spw 0 (for one representative baseline).</caption>]]<br />
</figure><br />
<br />
We see that the uncalibrated amplitudes range between 0.2-0.4, so let's set this as our<br />
scale and examine a representative baseline (DV06-DV07) to see how the amplitude changes with time. <br />
<br />
<source lang="python"><br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for spw in ['0','1','2','3']:<br />
for asdm in basename:<br />
print "Now showing spw %s from %s" % (spw, asdm+'.ms')<br />
plotms(vis=asdm+'.ms',spw=spw,xaxis='time',yaxis='amp',coloraxis='corr',iteraxis='spw',<br />
field='0',avgchannel='3840',antenna='DV06&DV07',plotrange=[0,0,0.2,0.4])<br />
user_check=raw_input('press enter to go to the next plot\n')<br />
</source><br />
<br />
<figure id="ThreeScansPhase.png"><br />
[[Image:ThreeScansPhase.png|thumb|<caption>Phase variation for three 3C279 scans, spw 0 (for one representative baseline).</caption>]]<br />
</figure><br />
<br />
Page through the measurement sets for each spw. This shows significant variations in the amplitude across the three measurement sets.<br />
Now do the same with phase.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for spw in ['0','1','2','3']:<br />
for asdm in basename:<br />
print "Now showing spw %s from %s" % (spw, asdm+'.ms')<br />
plotms(vis=asdm+'.ms',spw=spw,xaxis='time',yaxis='phase',coloraxis='corr',iteraxis='spw',<br />
field='0',avgchannel='3840',antenna='DV06&DV07',plotrange=[0,0,-180,180])<br />
user_check=raw_input('press enter to go to the next plot\n')<br />
</source><br />
<br />
This examination reveals two findings: (1) significant variation in the phase across the three scans, as well as (2) smaller but significant variations within a scan. The first finding suggests that we do not want to combine the scans for bandpass calibration, but instead derive an independent bandpass for each scan. Actually what is more important than a DC offset is if the '''shape''' of the amplitude or phase changes from scan to scan. There isn't enough S/N to tell for sure so we will keep them separate. This situation is often the case, which is why we did not concatenate the three datasets prior to calibration. The second finding suggests that we need to correct the phase vs. time behavior of the bandpass calibrator (3C279; field=0) within each scan, before doing the bandpass. We want to chose a relatively narrow range of channels near the center of the spws so that the bandpass phase slopes (to be corrected with the bandpass calibration itself) do not decorrelate the signal. You need to avoid spectral regions that were completely flagged above.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.bpphase.gcal')<br />
gaincal(vis=asdm+'.ms',caltable=asdm+'.bpphase.gcal',<br />
field='0',spw='0~3:900~1100',refant='DV06',<br />
calmode='p',solint='int',minsnr=2.0,minblperant=4)<br />
</source><br />
<br />
<figure id="X7ef_wvrtsys.bpphase.X.png"><br />
[[Image:X7ef_wvrtsys.bpphase.X.png|thumb|<caption>Phase only solutions for correlation X on the third scan of the bandpass calibrator 3C279.</caption>]]<br />
</figure><br />
<br />
Inspect the phase-only calibration solutions for the bandpass calibrator. Look for any noisy solutions. We do XX and YY separately to reduce confusion in the plot. It will help if you make your plotcal window wide.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.bpphase.gcal',xaxis='time',yaxis='phase',spw='',antenna='1~8', <br />
iteration='antenna',subplot=421,plotrange=[0,0,-180,180],<br />
figfile=asdm+'.bpphase.X.png',poln='X')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
In the plotcal gui you can use the magnifying glass symbol to zoom in on one of the scans to see the phase variations. The colors are the 4 different spws.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.bpphase.gcal',xaxis='time',yaxis='phase',spw='',antenna='1~8', <br />
iteration='antenna',subplot=421,plotrange=[0,0,-180,180],<br />
figfile=asdm+'.bpphase.Y.png',poln='Y')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Next we apply this phase-only correction on the fly while calculating the bandpass solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.bandpass.bcal')<br />
bandpass(vis=asdm+'.ms',caltable=asdm+'.bandpass.bcal',<br />
field='0',spw='',combine='',refant='DV06',<br />
solint='inf',solnorm=T,minblperant=4, bandtype='B', fillgaps=17,<br />
gaintable=asdm+'.bpphase.gcal')<br />
</source><br />
<br />
You will see some error messages in the terminal, these are just related to the flagged channels. We set fillgaps=17 to interpolate across the smaller regions of flagged channels (mesospheric features and birdies).<br />
<br />
<figure id="Bandpass.ampspw0.png"><br />
[[Image:Bandpass.ampspw0.png|thumb|<caption>Bandpass amplitude solution plots.</caption>]]<br />
</figure><br />
<figure id="Bandpass.phasespw0.png"><br />
[[Image:Bandpass.phasespw0.png|thumb|<caption>Bandpass phase solution plots.</caption>]]<br />
</figure><br />
<br />
'''A few words about solint and combine:'''<br />
<br />
In {{bandpass}}, the use of '''solint='inf'''' (as in "infinite") will derive a bandpass<br />
solution for each 3C279 scan, '''unless''' '''combine='scan'''' (which is the default). Here we set combine=' ' explicitly so that it does not combine the scans into one bandpass. Likewise, field boundaries are only crossed if combine='field', and spw boundaries are only crossed if combine='spw'. In some cases it can be helpful to combine fields if you suffer from lack of S/N, but it is never a good idea to combine spws. <br />
<br />
Now inspect the phase and amplitude solutions. You are looking for excursions from smooth fits, or particularly noisy solutions compared to the others. <br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
for spw in [0,1,2,3]:<br />
plotbandpass(asdm+'.bandpass.bcal',xaxis='freq',yaxis='amp', spw=spw,<br />
antenna='1~8', subplot=42, figfile=asdm+'.bandpass.amp', showatm=T,<br />
interactive=True)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
for spw in [0,1,2,3]:<br />
plotbandpass(asdm+'.bandpass.bcal',xaxis='freq',yaxis='phase',spw=spw,<br />
antenna='1~8',subplot=42,figfile=asdm+'.bandpass.phs', showatm=T,<br />
interactive=True)<br />
</source><br />
<br />
The values of phase on DV06 are very close to zero because it was used as the reference antenna.<br />
<br />
==Gain Calibration==<br />
<br />
Now that we have a bandpass solution to apply we can solve for the antenna-based phase and amplitude gain calibration. Since the phase changes on a much shorter timescale than the amplitude, we will solve for them separately. In particular, if the phase changes significantly over a scan time, the amplitude would be decorrelated, if the un-corrected phase were averaged over this timescale. Note that we re-solve for the gain solutions of the bandpass calibrator, so we can derive new solutions that are corrected for the bandpass shape. Since the bandpass calibrator will not be used again, this is not strictly necessary, but is useful to check its calibrated flux density for example. <br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.intphase.gcal')<br />
gaincal(vis=asdm+'.ms',caltable=asdm+'.intphase.gcal',<br />
field='0,1,3,4',spw='0~3:40~3800',refant='DV06',<br />
calmode='p',solint='int',minsnr=2.0,minblperant=4,<br />
gaintable=[asdm+'.bandpass.bcal'])<br />
</source><br />
<br />
Here '''solint='int' ''' coupled with '''calmode='p' ''' will derive a single phase solution for each 10 second integration. Note that the bandpass table is applied on-the-fly before solving for the phase solutions, however the bandpass is NOT applied to the data permanently until applycal is run later on. <br />
<br />
Although '''solint='int' ''' (i.e. the integration time of 10 seconds) is the best choice to apply before solving for the amplitude solutions, it is not a good idea to use this to apply to the target. This is because the phase-scatter within a scan can dominate the interpolation between calibrator scans. Instead, we also solve for the phase on the scan time, '''solint='inf' ''' (but '''combine=' ' ''', since we want one solution per scan) for application to the target later on. Unlike the bandpass task, for {{gaincal}}, the default of the combine parameter is '''combine=' ' '''. <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.scanphase.gcal')<br />
gaincal(vis=asdm+'.ms',caltable=asdm+'.scanphase.gcal',<br />
field='0,1,3,4',spw='0~3:40~3800',refant='DV06',<br />
calmode='p',solint='inf',minsnr=2.0,minblperant=4,<br />
gaintable=[asdm+'.bandpass.bcal'])<br />
</source><br />
<br />
Alternatively, instead of making a separate phase solution for application to the target, one can also run {{smoothcal}} to smooth the solutions derived on the integration time. <br />
<br />
Next we apply the bandpass and '''solint='int' ''' phase-only calibration solutions on-the-fly to derive amplitude solutions. Here the use of '''solint='inf' ''', but '''combine=' ' ''' will result in one solution per scan interval. <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.amp.gcal')<br />
gaincal(vis=asdm+'.ms',caltable=asdm+'.amp.gcal',<br />
field='0,1,3,4',spw='0~3:40~3800',refant='DV06',<br />
calmode='ap',solint='inf',minsnr=2.0,minblperant=4,<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal'])<br />
</source><br />
<br />
Now carefully inspect all these solutions looking for discrepant solutions. If you see any, you will need to flag them and rerun the calibration tasks above. <br />
<br />
We make plots in X and Y separately for clarity. The colors are showing the spectral windows.<br />
<figure id="X3c1_wvrtsys.intphase_X.png"><br />
[[Image:X3c1_wvrtsys.intphase_X.png|thumb|<caption>Phase solutions for the X polarization for every integration time of the first dataset.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.intphase.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',iteration='antenna',subplot=421,<br />
plotrange=[0,0,-180,180],poln='X',figfile=asdm+'.intphase_X.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.intphase.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',iteration='antenna',subplot=421,<br />
plotrange=[0,0,-180,180],poln='Y',figfile=asdm+'.intphase_Y.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<figure id="X3c1_wvrtsys.scanphase_X.png"><br />
[[Image:X3c1_wvrtsys.scanphase_X.png|thumb|<caption>Phase solutions for the X polarization for each scan of the first dataset.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.scanphase.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',iteration='antenna',subplot=421,<br />
plotrange=[0,0,-180,180],poln='X',figfile=asdm+'.scanphase_X.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.scanphase.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',iteration='antenna',subplot=421,<br />
plotrange=[0,0,-180,180],poln='Y',figfile=asdm+'.scanphase_Y.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Since we have taken out the phase as best we can by applying the '''solint='int' ''' phase-only solution, this plot will give a good idea of the residual phase error. If you see scatter of more than a few degrees here, you should consider going back and looking for more data to flag, particularly bad timeranges etc. <br />
<br />
<figure id="X3c1_wvrtsys.amp_phase.png"><br />
[[Image:X3c1_wvrtsys.amp_phase.png|thumb|<caption>Residual phase after applying intphase.gcal for both correlations in the first dataset.</caption>]]<br />
</figure><br />
<figure id="X3c1_wvrtsys.amp_X.png"><br />
[[Image:X3c1_wvrtsys.amp_X.png|thumb|<caption>Amplitude solutions on a scan interval for correlation X in the first dataset.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.amp.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',plotrange=[0,0,-1,1],<br />
iteration='antenna',subplot=421,figfile=asdm+'.amp_phase.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
These are very small, as they should be. Now look at the amplitude solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.amp.gcal',xaxis='time',yaxis='amp',antenna='1~8', <br />
iteration='antenna',subplot=421,spw='',poln='X',<br />
plotrange=[0,0,0.0,0.3],figfile=asdm+'.amp_X.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.amp.gcal',xaxis='time',yaxis='amp',antenna='1~8', <br />
iteration='antenna',subplot=421,spw='',poln='Y',<br />
plotrange=[0,0,0.0,0.3],figfile=asdm+'.amp_Y.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
==Flux Calibration==<br />
<br />
Next we use the flux calibrator (whose flux density was set in {{setjy}} above) to derive the flux density of the other calibrators. Note that the flux table REPLACES the amp.gcal in terms of future application of the calibration to the data, i.e. the flux table contains both the amp.gcal and flux scaling. Unlike the gain calibration steps, this is not an incremental table.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.flux.cal')<br />
fluxscale(vis=asdm+'.ms',caltable=asdm+'.amp.gcal',<br />
fluxtable=asdm+'.flux.cal',reference='1',refspwmap=[0,1,3,3],<br />
listfile=asdm+'.fluxscale.txt')<br />
</source><br />
<br />
Its a good idea to record the derived fluxscale values using the listfile option. The values can also be viewed in the Log Messages window.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Found reference field(s): Titan<br />
Found transfer field(s): 3c279 J1147-382=QSO J1037-295=QSO<br />
Spw=2 will be referenced to spw=3<br />
Flux density for 3c279 in SpW=0 (freq=3.56498e+11 Hz) is: 10.537 +/- 0.0183518 (SNR = 574.169, N = 16)<br />
Flux density for 3c279 in SpW=1 (freq=3.57734e+11 Hz) is: 10.6933 +/- 0.0264134 (SNR = 404.842, N = 16)<br />
Flux density for 3c279 in SpW=2 (freq=3.46034e+11 Hz) (ref SpW=3) is: 10.251 +/- 0.0477949 (SNR = 214.479, N = 14)<br />
Flux density for 3c279 in SpW=3 (freq=3.43956e+11 Hz) is: 9.91798 +/- 0.020167 (SNR = 491.791, N = 16)<br />
Flux density for J1147-382=QSO in SpW=0 (freq=3.56498e+11 Hz) is: 1.03399 +/- 0.0167344 (SNR = 61.7887, N = 16)<br />
Flux density for J1147-382=QSO in SpW=1 (freq=3.57734e+11 Hz) is: 0.844817 +/- 0.0191013 (SNR = 44.2283, N = 16)<br />
Flux density for J1147-382=QSO in SpW=2 (freq=3.46034e+11 Hz) (ref SpW=3) is: 0.987193 +/- 0.024391 (SNR = 40.4737, N = 14)<br />
Flux density for J1147-382=QSO in SpW=3 (freq=3.43956e+11 Hz) is: 1.28859 +/- 0.0194364 (SNR = 66.298, N = 16)<br />
Flux density for J1037-295=QSO in SpW=0 (freq=3.56498e+11 Hz) is: 0.968281 +/- 0.00895224 (SNR = 108.161, N = 16)<br />
Flux density for J1037-295=QSO in SpW=1 (freq=3.57734e+11 Hz) is: 0.75916 +/- 0.015366 (SNR = 49.4053, N = 16)<br />
Flux density for J1037-295=QSO in SpW=2 (freq=3.46034e+11 Hz) (ref SpW=3) is: 0.948551 +/- 0.0165421 (SNR = 57.3416, N = 14)<br />
Flux density for J1037-295=QSO in SpW=3 (freq=3.43956e+11 Hz) is: 1.21905 +/- 0.0139967 (SNR = 87.0956, N = 16)<br />
Fitted spectrum for 3c279 with fitorder=1: Flux density = 10.2962 +/- 0.0450319 (freq=351.002 GHz) spidx=1.70757 +/- 0.245737<br />
Fitted spectrum for J1147-382=QSO with fitorder=1: Flux density = 1.06853 +/- 0.0709817 (freq=351.002 GHz) spidx=-6.77353 +/- 3.71867<br />
Fitted spectrum for J1037-295=QSO with fitorder=1: Flux density = 1.01822 +/- 0.0654586 (freq=351.002 GHz) spidx=-6.28977 +/- 3.71453<br />
Storing result in X7ef_wvrtsys.flux.cal<br />
Writing solutions to table: X7ef_wvrtsys.flux.cal<br />
</pre><br />
<br />
<figure id="x3c1_wvrtsys.flux_X.png"><br />
[[Image:x3c1_wvrtsys.flux_X.png|thumb|<caption>Absolute flux calibration solutions for correlation X for the first dataset.</caption>]]<br />
</figure><br />
<br />
<div class="noprint" style="float:none; border:0px solid blue;background-color:#F6CEF5;padding:2px;"><br />
If you used the updated (Butler-JPL-Horizons 2012) flux density standard when you ran {{setjy}} earlier in this tutorial, the derived flux values for the calibrators will be slightly different. For example, when averaged over the 3 measurement sets, 3c279 in spectral window 0 has a flux of 10.77 Jy using the 2010 standard and 10.63 Jy using the 2012 standard; as a second example, J1147-382 in SPW 3 has an average flux of 1.13 Jy (2010 standard) and 1.15 Jy (2012 standard). <br />
</div><br />
<br />
Now look at the flux solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.flux.cal',xaxis='time',yaxis='amp',antenna='1~8', <br />
iteration='antenna',subplot=421,spw='',poln='X',<br />
plotrange=[0,0,0.0,0.3],figfile=asdm+'.flux_X.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.flux.cal',xaxis='time',yaxis='amp',antenna='1~8', <br />
iteration='antenna',subplot=421,spw='',poln='Y',<br />
plotrange=[0,0,0.0,0.3],figfile=asdm+'.flux_Y.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
==Apply Calibration and Inspect==<br />
<br />
Now we can use the {{flagmanager}} if we want to restore any of the spectral flagging we did prior to bandpass calibration. <br />
In this case, we choose to restore the flags of the emission lines on Titan, because we are interested in seeing how<br />
strong they are compared to the continuum. However, we leave the strong ozone line and mesospheric CO line flagged on all <br />
sources, because we want to get the most accurate continuum flux density for the science target. <br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
flagmanager(vis=asdm+'.ms',mode='restore',versionname=asdm+'.before_emissionflags')<br />
</source><br />
<br />
Next we apply the calibration solutions to each source individually, using the '''gainfield''' parameter to specify which calibrator's solutions should be applied from each of the '''gaintable''' calibration tables. <br />
<br />
First, we do 3C279 (the bandpass calibrator), applying all 3 of its solutions to itself (that's why gainfield contains three zeros):<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='0',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['0','0','0'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
Next, we do Titan (the absolute flux calibrator) using the bandpass solution from 3C279:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='1',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['0','1','1'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
For the secondary phase calibrator, we apply the phase and flux solutions from the primary phase calibrator. This will allow us to check how well the phase transfer to the science target (TW Hya) has worked:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='3',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.scanphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','linear','linear'],<br />
gainfield=['0','4','4'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
Next is the Primary phase calibrator:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='4',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['0','4','4'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
Finally, for the Science Target TW Hya, we apply the phase solutions from both the primary and secondary phase calibrators:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='2',<br />
interp=['nearest','linear','linear'],<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.scanphase.gcal',asdm+'.flux.cal'],<br />
gainfield=['0','3,4','3,4'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
Now we can check the results of applying the calibration solutions.<br />
<br />
<figure id="Corrected_vs_time_1.png"><br />
[[Image:Corrected_vs_time_1.png|thumb|<caption>The calibrated data for the first dataset (amplitude vs. time).</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw',ydatacolumn='corrected')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
In amplitude, it looks good but there are some noisy points toward the end of the first scheduling block, but it mostly only affects the secondary phase calibrator (green). In phase, we expect all the points to cluster about zero. The large scatter in phase on the secondary phase calibrator is readily apparent: <br />
<br />
<figure id="Corrected_phase_vs_time_1.png"><br />
[[Image:Corrected_phase_vs_time_1.png|thumb|<caption>The calibrated data on the calibrators for the first dataset (phase vs. time).</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='time',yaxis='phase',field='0,1,3,4',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw',ydatacolumn='corrected')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Let's check whether the situation improves when we apply this calibrator's solutions to itself rather than transferring the solutions from the primary phase calibrator (which is 17 degrees away, and observed at a different time). <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='3',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['0','3','3'],flagbackup=T, calwt=T)<br />
</source><br />
<br />
<figure id="Corrected_vs_time_1_field3.png"><br />
[[Image:Corrected_vs_time_1_field3.png|thumb|<caption>The calibrated data for the first dataset (amplitude vs. time), but now with field 3, the secondary phase calibrator, calibrated with itself.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw',ydatacolumn='corrected')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<figure id="Corrected_phase_vs_time_1_field3.png"><br />
[[Image:Corrected_phase_vs_time_1_field3.png|thumb|<caption>The calibrated data from the first dataset (phase vs. time), but now with field 3, the secondary phase calibrator, calibrated with itself.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='time',yaxis='phase',field='0,1,3,4',<br />
avgchannel='3840', coloraxis='field',iteraxis='spw',<br />
ydatacolumn='corrected')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Indeed, the secondary calibrator looks better now in amplitude and phase. This is an indication that the calibration transfer is not working well in this timerange. Because the effect is not catastrophic and we know we can self-calibrate on TW Hya later, we will let this go for now. Or, if you want you can delve deeper into the data and try to solve the mystery... <br />
<br />
In any case, we will re-issue the original {{applycal}} so that it is this calibration that our subsequent {{split}} will use. This will allow us to check the effect of correcting the secondary phase calibrator with the primary phase calibrator later. <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='3',<br />
gaintable=[asdm+'.bandpass.bcal', asdm+'.scanphase.gcal', asdm+'.flux.cal'],<br />
interp=['nearest','linear','linear'],<br />
gainfield=['0','4','4'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
<br />
Let's check the spectral calibration now. First 3C279 and Titan:<br />
<br />
<figure id="X3c1_spw2_corrected_3.4.png"><br />
[[Image:X3c1_spw2_corrected_3.4.png|thumb|<caption>Spectral UV-plots of 3C279 and Titan of spw=2 for the first dataset.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='frequency',yaxis='amp',field='0,1',<br />
avgtime='1e8',avgscan=T,coloraxis='field',ydatacolumn='corrected',<br />
iteraxis='spw',xselfscale=T)<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Flip through the spws. These look good. Next the two phase calibrators:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='frequency',yaxis='amp',field='3,4',<br />
avgtime='1e8',avgscan=T,coloraxis='field',ydatacolumn='corrected',<br />
iteraxis='spw',xselfscale=T)<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Flip through the spws. This also looks good, the secondary phase calibrator is a bit noisier but this is normal. The upswing at the lower frequency end of spw=3 will probably need to be flagged on the science target as well. It corresponds to the edge of an atmospheric feature.<br />
<br />
Now for the exciting part, what does the science target look like...<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='frequency',yaxis='amp',field='2',<br />
avgtime='1e8',avgscan=T,coloraxis='field',ydatacolumn='corrected',<br />
iteraxis='spw',xselfscale=T)<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
We see HCO+(4-3) in spw=0 and CO(3-2) in spw=2 as expected. Because the shape of the <br />
line profiles varies with baseline, you can already tell that the line emission is resolved.<br />
<br />
<figure id="X3c1_CO3_2_uvplot_3.4.png"><br />
[[Image:X3c1_CO3_2_uvplot_3.4.png|thumb|<caption>UV-Plot of the TW Hya CO(3-2) emission from the first dataset.</caption>]]<br />
</figure><br />
<figure id="X3c1_HCOp4_3_uvplot_3.4.png"><br />
[[Image:X3c1_HCOp4_3_uvplot_3.4.png|thumb|<caption>UV-Plot of the TW Hya HCO+(4-3) emission from the first dataset.</caption>]]<br />
</figure><br />
<br />
Now check that the velocity of TWHydra is correct in the LSRK frame, it should be around 2.88 km/s.<br />
* CO 3-2 rest freq 345.79599 GHz<br />
* HCO+ 4-3 rest freq 356.7342 GHz<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='2',xaxis='velocity',yaxis='amp',field='2',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',<br />
restfreq='345.79599GHz', plotrange=[-10,15,0,0],coloraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='0',xaxis='velocity',yaxis='amp',field='2',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',<br />
restfreq='356.7342GHz',plotrange=[-10,15,0,0],coloraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Both lines show up at the expected velocity.<br />
<br />
<br />
==Concatenate the Data==<br />
<br />
Here we will concatenate the three datasets prior to imaging.<br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
os.system('rm -rf Band7multi_april22.ms')<br />
concat(vis=splitdata,concatvis='Band7multi_april22.ms')<br />
</source><br />
<br />
If you like you can run listobs on new combined dataset<br />
<br />
<source lang="python"><br />
# In CASA<br />
listfile = 'Band7multi_april22.listobs.txt'<br />
os.system('rm ' + listfile)<br />
listobs(vis='Band7multi_april22.ms',verbose=F, listfile=listfile)<br />
</source><br />
<br />
<figure id="All_spw2_corrected_3.4.png"><br />
[[Image:All_spw2_corrected_3.4.png|thumb|<caption>Spectral UV-plots of 3C279 and Titan of spw=2 for the combined datasets.</caption>]]<br />
</figure><br />
<br />
You can also examine the spectral uv plots for the combined dataset to see the improvement in S/N: <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='Band7multi_april22.ms',spw='',xaxis='frequency',yaxis='amp',field='0,1',<br />
avgtime='1e8',avgscan=T,coloraxis='field',ydatacolumn='corrected',<br />
iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
<figure id="All_CO3_2_uvplot_3.4.png"><br />
[[Image:All_CO3_2_uvplot_3.4.png|thumb|<caption>UV-Plot of the TW Hya CO(3-2) emission from the combined datasets.</caption>]]<br />
</figure><br />
<br />
...and the CO line profile for the combined dataset: <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='Band7multi_april22.ms',spw='2',xaxis='velocity',yaxis='amp',field='2',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',restfreq='345.79599GHz',<br />
plotrange=[-10,15,0,0],coloraxis='spw')<br />
</source><br />
<br />
==Split Calibrated Data==<br />
<br />
Now we split off the calibrated data for the Science Target as well as the interesting parts of the calibrators for imaging.<br />
<br />
When we {{split}} off the Titan data, a few dozen warnings like the following are written to the log:<br />
<pre><br />
2012-05-15 22:00:35 WARN split::SubMS::copySource() Invalid SOURCE ID in SOURCE table row 20 <br />
</pre><br />
These can be ignored, because they do not indicate any problem that will prevent you from imaging Titan correctly at a single position using all the data in the output ms.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_corrected.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='TWHydra_corrected.ms',<br />
datacolumn='corrected',spw='',field='2')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf J1037_corrected.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='J1037_corrected.ms',<br />
datacolumn='corrected',spw='',field='4')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf J1147_corrected.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='J1147_corrected.ms',<br />
datacolumn='corrected',spw='',field='3')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3C279_CO3_2.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='3C279_CO3_2.ms',<br />
datacolumn='corrected',spw='2:1900~2000',field='0')<br />
</source><br />
<br />
==Optional: Reconcile Titan's Coordinates==<br />
<br />
If you do not care to image Titan, then you can skip this step and simply continue on to the [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_4.5 imaging guide].<br />
<br />
Our earlier treatment of Titan's coordinates using [http://casa.nrao.edu/stable/docs/TaskRef/fixplanets-task.html fixplanets] replaced the zeros written by the ALMA control system with the correct position of the body at the instant of the first observation of that SB. As a result, it has slightly different positions in all three datasets, as seen by listobs:<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='Band7multi_april22.ms',verbose=F)<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
ID Code Name RA Decl Epoch SrcId nRows <br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 70866 <br />
1 none Titan 12:49:25.97588 -02.22.41.3024 J2000 1 4842 <br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 515151 <br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 40797 <br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 171153 <br />
5 none Titan 12:49:26.53729 -02.22.27.1521 J2000 0 4833 <br />
6 none Titan 12:49:26.53059 -02.22.18.7878 J2000 0 4833 <br />
</pre><br />
<br />
If we want to image such moving objects observed across multiple SBs, we need to bring the positions into agreement, otherwise {{clean}} will try to make a mosaic. Task [http://casa.nrao.edu/stable/docs/TaskRef/fixplanets-task.html fixplanets] can be used to do this. Here, we set the direction to the direction of the first dataset as reported by listobs. Note that the RA/Dec format is slightly different from the {{listobs}} output format. Also, we do not<br />
fix the uvw coordinates because they are already more correct now than they would be if we "fixed" them.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fixplanets(vis='Band7multi_april22.ms', field='Titan', direction='J2000 12h49m25.97588 -02d22m41.3024', fixuvw=False)<br />
</source><br />
<br />
Check the header information again to see that the information for Titan has changed for the second<br />
and third datasets. They will appear as fields 5 and 6.<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='Band7multi_april22.ms',verbose=F)<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
ID Code Name RA Decl Epoch SrcId <br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 70866 <br />
1 none Titan 12:49:25.97588 -02.22.41.3024 J2000 1 4842 <br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 515151 <br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 40797 <br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 171153 <br />
5 none Titan 12:49:25.97588 -02.22.41.3024 J2000 0 4833 <br />
6 none Titan 12:49:25.97588 -02.22.41.3024 J2000 0 4833 <br />
</pre><br />
<br />
==Optional: Split Calibrated Titan Data==<br />
<br />
When we {{split}} off the Titan data, a few dozen warnings like the following are written to the log:<br />
<pre><br />
2012-05-15 22:00:35 WARN split::SubMS::copySource() Invalid SOURCE ID in SOURCE table row 20 <br />
</pre><br />
These can be ignored, because they do not indicate any problem that will prevent you from imaging Titan correctly at a single position using all the data in the output ms.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Titan_cont.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='Titan_cont.ms',<br />
datacolumn='corrected',spw='0',field='1')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Titan_CO3_2.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='Titan_CO3_2.ms',<br />
datacolumn='corrected',spw='2',field='1')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Titan_unknown.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='Titan_unknown.ms',<br />
datacolumn='corrected',spw='3',field='1')<br />
</source><br />
<br />
==Continue on to Imaging of the Science Target==<br />
<br />
Now you can continue on to the [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_4.5 imaging guide].<br />
<br />
{{Checked 4.5.2}}</div>Sstierwahttps://casaguides.nrao.edu/index.php?title=TWHydraBand7_Calibration_4.5&diff=19469TWHydraBand7 Calibration 4.52016-05-18T03:48:56Z<p>Sstierwa: </p>
<hr />
<div>[[Category:ALMA]][[Category:Calibration]][[Category:Spectral Line]]<br />
*'''This script assumes that you have downloaded TWHYA_BAND7_UnCalibratedMSAndTablesForReduction.tgz from [[TWHydraBand7#Getting_the_Data]]'''<br />
<br />
*'''An introduction to this data set is available at [[TWHydraBand7]].<br />
<br />
*'''This guide is designed for CASA 4.5.2 If you are using an older version of CASA please see [[TWHydraBand7_Calibration_4.3]].<br />
<br />
==Preparation==<br />
<br />
Once you have downloaded TWHYA_BAND7_UnCalibratedMSAndTablesForReduction.tgz, in a terminal unpack it with<br />
<br />
<source lang="bash"><br />
tar -zxvf TWHYA_BAND7_UnCalibratedMSAndTablesForReduction.tgz<br />
</source><br />
<br />
Please be aware that you will need about 100 GB of free space to do the data reduction. It is a good idea to check that now before you begin. Some of the plots described here require 9 GB of RAM; as little as 4 GB may be sufficient if additional data averaging is used when the plots are generated. When you are satisfied with the available drive space and memory on your machine:<br />
<br />
<source lang="bash"><br />
cd TWHYA_BAND7_UnCalibratedMSAndTablesForReduction<br />
</source><br />
<br />
'''NOTE: the calibration tables included in TWHYA_BAND7_UnCalibratedMSAndTablesForReduction CANNOT be used with CASA 4.5, they should be discarded, or moved out of the working directory.'''<br />
<br />
Then start CASA. <br />
<br />
<source lang="bash"><br />
casapy<br />
</source><br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.5.2. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.5.2'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
==Install Analysis Utilities==<br />
<br />
Analysis Utilities (or analysisUtils for short) is a small set of Python scripts that provide a number of analysis and plotting utilities for ALMA data reduction. This guide uses a few of these utilities. They are very easy to install (just download and untar). See <br />
<br />
http://casaguides.nrao.edu/index.php?title=Analysis_Utilities<br />
<br />
for a full description and download instructions. If you do not wish to do this, see the [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Calibration_for_CASA_3.3 CASA 3.3 version of the guide] for alternative (but slow) plotting options. Analysis Utilities are updated frequently so if its been a while since you installed it, its probably worth doing it again. If you are at an ALMA site or ARC, the analysis utilities are probably already installed and up to date.<br />
<br />
==Fix Titan's coordinates==<br />
<br />
'''Note that in the near future this step will be unnecessary.''' <br />
<br />
It is temporarily necessary to correct the positions of ephemeris objects observed during ALMA Cycle 0, because the control software revisions earlier than 9.0 erroneously write the data with coordinates of 00:00:00.0000 +00.00.00.0000 (J2000). For this dataset, we need to correct the position of the absolute flux calibrator Titan, as we can<br />
see from the first {{listobs}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -f X3c1.ms.listobs')<br />
listobs('X3c1.ms', verbose=T, listfile='X3c1.ms.listobs') <br />
</source><br />
<br />
You can view the listobs output files using command "less" from the CASA prompt.<br />
<br />
<pre style="background-color: #fffacd;"><br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 23625<br />
1 none Titan 00:00:00.00000 +00.00.00.0000 J2000 1 4842<br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 175176<br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 14832<br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 59877<br />
</pre><br />
<br />
To correct Titan's position, we will use the task [http://casa.nrao.edu/stable/docs/TaskRef/fixplanets-task.html fixplanets], which writes the actual coordinates at the instant of the first observation. This step takes a while because we are recalculating the uvw's accordingly.<br />
<source lang="python"><br />
# In CASA<br />
fixplanets(vis='X3c1.ms', field='Titan', fixuvw=True)<br />
</source><br />
<br />
Check the header information again with {{listobs}} to confirm that the information for Titan has changed:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -f X3c1.ms.listobs')<br />
listobs('X3c1.ms', verbose=T, listfile='X3c1.ms.listobs') <br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 23625<br />
1 none Titan 12:49:25.93349 -02.22.41.5638 J2000 1 4842<br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 175176<br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 14832<br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 59877<br />
</pre><br />
<br />
Now fix the other two measurement sets similarly:<br />
<source lang="python"><br />
# In CASA<br />
fixplanets(vis='X5d8.ms', field='Titan', fixuvw=True)<br />
fixplanets(vis='X7ef.ms', field='Titan', fixuvw=True)<br />
</source><br />
<br />
==Observing Log and Priors==<br />
<br />
Below is some information that may not be obvious from the data<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Like at most telescopes, the ALMA operators and astronomers at the site log any significant issues <br />
that were noticed from the online system during the observation. For these Band 7 observations of <br />
TW Hya on April 22, 2011, the only issue of note was that antenna DV04 could not observe at Band 7 <br />
and will need to be flagged. <br />
</pre><br />
<br />
First let's examine the basic properties of the data using {{listobs}}. Among other information we <br />
will be able to deduce what the source ids are and what each source was used for:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
3c279 is the bandpass calibrator (field id=0)<br />
Titan is the absolute flux calibrator (field id=1)<br />
J1147-382 is the secondary phase calibrator (field id=3)<br />
J1037-295 is the primary phase calibrator (field id=4)<br />
</pre><br />
<br />
<source lang="python"><br />
# In CASA<br />
data=['X3c1.ms','X5d8.ms','X7ef.ms']<br />
for vis in data:<br />
os.system('rm '+vis+'.listobs')<br />
listobs(vis, verbose=T, listfile=vis+'.listobs') <br />
</source><br />
<br />
You can view the {{listobs}} output files using command '''less''' from the CASA prompt. <br />
Below we copy select parts of the {{listobs}} output files for reference. <br />
<br />
<pre style="background-color: #fffacd;"><br />
X3c1.ms:<br />
Data records: 278352 Total integration time = 6109.06 seconds<br />
Observed from 22-Apr-2011/00:01:52.9 to 22-Apr-2011/01:43:42.0 (UTC)<br />
<br />
X5d8.ms:<br />
Data records: 278406 Total integration time = 5995.01 seconds<br />
Observed from 22-Apr-2011/01:48:05.8 to 22-Apr-2011/03:28:00.8 (UTC)<br />
<br />
X7ef.ms:<br />
Data records: 255717 Total integration time = 5407.49 seconds<br />
Observed from 22-Apr-2011/03:30:39.7 to 22-Apr-2011/05:00:47.2 (UTC)<br />
<br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 23625<br />
1 none Titan 12:49:25.97588 -02.22.41.3024 J2000 1 4842<br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 175176<br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 14832<br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 59877 <br />
<br />
SpwID #Chans Frame Ch1(MHz) ChanWid(kHz) TotBW(kHz) Corrs<br />
0 4 TOPO 184550 1500000 7500000 I<br />
1 128 TOPO 355740.062 15625 2000000 XX YY<br />
2 1 TOPO 356716.625 1796875 1796875 XX YY<br />
3 128 TOPO 356507.813 15625 2000000 XX YY<br />
4 1 TOPO 357484.375 1796875 1796875 XX YY<br />
5 128 TOPO 346792.187 15625 2000000 XX YY<br />
6 1 TOPO 345784.375 1796875 1796875 XX YY<br />
7 128 TOPO 345182.438 15625 2000000 XX YY<br />
8 1 TOPO 344174.625 1796875 1796875 XX YY<br />
9 128 TOPO 344386.763 15625 2000000 XX YY<br />
10 1 TOPO 343378.95 1796875 1796875 XX YY<br />
11 128 TOPO 346324.263 15625 2000000 XX YY<br />
12 1 TOPO 345316.45 1796875 1796875 XX YY<br />
13 128 TOPO 354402.388 15625 2000000 XX YY<br />
14 1 TOPO 355378.95 1796875 1796875 XX YY<br />
15 128 TOPO 356402.388 15625 2000000 XX YY<br />
16 1 TOPO 357378.95 1796875 1796875 XX YY<br />
17 3840 TOPO 356497.936 122.070312 468750 XX YY<br />
18 1 TOPO 356732.189 468750 468750 XX YY<br />
19 3840 TOPO 357734.314 122.070312 468750 XX YY<br />
20 1 TOPO 357499.939 468750 468750 XX YY<br />
21 3840 TOPO 346034.314 122.070312 468750 XX YY<br />
22 1 TOPO 345799.939 468750 468750 XX YY<br />
23 3840 TOPO 343955.936 122.070312 468750 XX YY<br />
24 1 TOPO 344190.189 468750 468750 XX YY<br />
<br />
Antennas: 9:<br />
Name Station Diam. Long. Lat.<br />
0 DV04 J505 12.0 m -067.45.18.0 -22.53.22.8<br />
1 DV06 T704 12.0 m -067.45.16.2 -22.53.22.1<br />
2 DV07 J510 12.0 m -067.45.17.8 -22.53.23.5<br />
3 DV08 T703 12.0 m -067.45.16.2 -22.53.23.9<br />
4 DV09 N602 12.0 m -067.45.17.4 -22.53.22.3<br />
5 DV10 N606 12.0 m -067.45.17.1 -22.53.23.6<br />
6 PM01 T702 12.0 m -067.45.18.6 -22.53.24.1<br />
7 PM02 T701 12.0 m -067.45.18.8 -22.53.22.2<br />
8 PM03 J504 12.0 m -067.45.17.0 -22.53.23.0<br />
</pre><br />
<br />
Things to Notice from above: <br />
*There are three different data sets acquired close together in time. We will calibrate each dataset independently and then combine the calibrated data prior to imaging. <br />
*Titan appears to have slightly different positions in each dataset because it is a moving body. In fact, at the time of observation, due to temporary data capture issue in the ALMA system, the position was written has (0,0). We have pre-corrected this error using fixplanets. Later in the tutorial, we will run fixplanets again to force all three datasets to have the same fixed position for Titan.<br />
*There are a lot of spectral windows! Don't be alarmed. In ALMA data, <br />
**spw=0 is always reserved for the water vapor radiometry data.<br />
**spw=9, 11, 13, 15 are the wideband (TDM) correlator mode with 128 channels per spw default settings for doing pointing and this is all they are used for in these data.<br />
**Currently Tsys data can only be taken in the wide (TDM) correlator mode with 128 channels per spw, these correspond to spws=1, 3, 5, 7 above. The frequencies of these TDM spws were carefully chosen so the the narrowband FDM spws fall within them.<br />
** The 0.5 GHz, high spectral resolution spws that contain all the real source data (science target and calibrators) are 17, 19, 21, and 23<br />
**For quicklook purposes, the ALMA online system produces a channel averaged spw for each channelized spw, these correspond to spw=2,4,6,8,10,12,14,16,18,20,22,24 and shouldn't be used for anything in post-processing as bandpass calibration etc has not been applied.<br />
<br />
In the portion of the {{listobs}} output that shows the timerange, the final column gives the scan intent. It is important to have a look at this because you can flag and do other operations in CASA using the scan intent as a selection option. Also, these intents will be used in the future for pipeline processing. You will usually want to use them to flag the CALIBRATE_POINTING* and CALIBRATE_ATMOS* (the latter correspond to the hot and cold load measurements used to calculate Tsys) data. This is essential for science or calibration data taken only in TDM (wide bandwidth) mode, i.e. the same mode that the pointing and Tsys data are taken in. For the current data however, that calibration data is recorded in different spws from the useful FDM (narrow bandwidth) data, so we'll be able to separate them by splitting them off at the final step prior to imaging.<br />
<br />
<figure id="Ant_pos.png"><br />
[[Image:Ant_pos.png|thumb|<caption>Antenna locations for the first dataset.</caption>]]<br />
</figure><br />
<br />
Before we move on, its also nice to get an idea where the antennas are with respect to each other. We can use {{plotants}} to plot their positions. It is a good idea to check each file since an antenna may have entered or exited the array between observations.<br />
<source lang="python"><br />
# In CASA<br />
for vis in data:<br />
plotants(vis=vis,figfile=vis+'.plotants.png')<br />
</source><br />
<br />
You can view the output images using any standard image viewer.<br />
<br />
==Create the Tsys and WVR Tables, and Examine ==<br />
<br />
Each ms include tables that contain the Tsys and WVR measurements associated with the visibility data.<br />
We must create calibration tables from these measurements. First we create the WVR calibration tables <br />
by running the task [http://casa.nrao.edu/stable/docs/TaskRef/wvrgcal-task.html wvrgcal]. This task <br />
examines the data for each ms as a whole and creates a calibration<br />
table containing only phase corrections for each antenna and spw. <br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
os.system('rm -rf '+asdm+'.wvr')<br />
wvrgcal(vis=asdm+'.ms', caltable=asdm+'.wvr', segsource=True, toffset=-1)<br />
</source><br />
<br />
Next we create the Tsys tables by running {{gencal}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
os.system('rm -rf '+asdm+'.tsys')<br />
gencal(vis=asdm+'.ms', caltable=asdm+'.tsys', caltype='tsys')<br />
</source><br />
<br />
It is very important that Tsys measurements taken as close in time and elevation as possible to a particular source are applied. To save telescope time, Tsys measurements are sometimes intentionally skipped in the scheduling block for specific sources. So the first step is to establish which sources have their own Tsys measurements and which do not. To do this, you may use the intent parameter of {{listobs}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
listobs(vis=asdm+'.ms', verbose=F, selectdata=True, intent='CALIBRATE_ATMOS*')<br />
</source><br />
<br />
<figure id="X3c1.tsys_vs_time_3.4.png"><br />
[[File:X3c1.tsys_vs_time_3.4.png|thumb|<caption>Tsys vs. time for spw 1 of the X3c1.ms data.</caption>]]<br />
</figure><br />
<figure id="X5d8.tsys_vs_time_3.4.png"><br />
[[File:X5d8.tsys_vs_time_3.4.png|thumb|<caption>Tsys vs. time for spw 1 of the X5d8.ms data.</caption>]]<br />
</figure><br />
<figure id="X7ef.tsys_vs_time_3.4.png"><br />
[[File:X7ef.tsys_vs_time_3.4.png|thumb|<caption>Tsys vs. time for spw 1 of the X7ef.ms data.</caption>]]<br />
</figure><br />
<br />
<pre style="background-color: #fffacd;"><br />
Fields: 4<br />
ID Code Name RA Decl Epoch SrcId nRows <br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 1116 <br />
1 none Titan 12:49:25.97588 -02.22.41.3024 J2000 1 1125 <br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 6795 <br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 6777 <br />
Spectral Windows: (9 unique spectral windows and 2 unique polarization setups)<br />
SpwID #Chans Frame Ch1(MHz) ChanWid(kHz) TotBW(kHz) Corrs <br />
0 4 TOPO 184550 1500000 7500000 I <br />
1 128 TOPO 355740.062 15625 2000000 XX YY <br />
2 1 TOPO 356716.625 1796875 1796875 XX YY <br />
3 128 TOPO 356507.813 15625 2000000 XX YY <br />
4 1 TOPO 357484.375 1796875 1796875 XX YY <br />
5 128 TOPO 346792.187 15625 2000000 XX YY <br />
6 1 TOPO 345784.375 1796875 1796875 XX YY <br />
7 128 TOPO 345182.438 15625 2000000 XX YY <br />
8 1 TOPO 344174.625 1796875 1796875 XX YY <br />
</pre><br />
<br />
Because field '3' (the secondary phase calibrator) does not appear in the list, it has no tsys. Since the secondary phase calibrator is close on the sky to the primary phase calibrator and observed near in time, we will transfer the Tsys from the primary to the secondary phase calibrator. <br />
Also notice that spws 1,3,5,7 are the only multi-channel spws that contain Tsys data. At present, Tsys measurements can only be obtained with TDM spectral setups (128 channels/dual pol). Because our science target is observed in FDM (3840 channels/dual pol), we will need to interpolate the measurements from TDM to FDM. But first, to inspect the Tsys vs. time, we use {{plotcal}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all = ['X3c1','X5d8','X7ef']<br />
tsysfields=['0','1','2','4']<br />
os.system('mkdir cal_plots; mkdir cal_plots/Tsys_plots') <br />
for asdm in basename_all:<br />
print "Plotting Tsys vs. time for "+asdm<br />
plotcal(caltable=asdm+'.tsys', xaxis='time',yaxis='tsys',<br />
antenna='1~8',plotrange=[0,0,100,500],<br />
iteration='antenna',subplot=421,poln='',spw='1:50~50',<br />
figfile='cal_plots/Tsys_plots/'+asdm+'.tsys_vs_time.png')<br />
if (asdm != basename_all[-1]):<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
To inspect Tsys vs. frequency, we use [[plotbandpass]]. There are many different options for plotbandpass, and we demonstrate some of the most useful ones. The option '''showtsky=T''' will overlay the effective temperature curve from the atmospheric model. This shows us the location of any atmospheric lines which will appear as emission lines in the autocorrelation data (from which the Tsys spectra are derived) from all antennas. In the<br />
example below, we set '''interactive=False''', which will produce many pages of plots as<br />
individual pngs but will only show the final page in the graphics window. To view all the pages we use the image viewer '''eog''' (Eye of GNOME) available on Linux. The alternative is to set '''interactive=True''' and examine the plots in the casa graphics window as they are produced.<br />
<br />
<figure id="X3c1.tsys.field0.DV04.spw1.t1.png"><br />
[[File:X3c1.tsys.field0.DV04.spw1.t1.png|thumb|<caption>Tsys vs. frequency on 3C279 for the X3c1.ms data, spw=1.</caption>]]<br />
</figure><br />
<figure id="X3c1.tsys.field0.DV04.spw3.t1.png"><br />
[[File:X3c1.tsys.field0.DV04.spw3.t1.png|thumb|<caption>Tsys vs. frequency on 3C279 for the X3c1.ms data, spw=3.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
print "Plotting Tsys vs. frequency for "+asdm<br />
for spw in [1,3,5,7]:<br />
for field in ['0','1']:<br />
plotbandpass(caltable=asdm+'.tsys', xaxis='freq',yaxis='amp',<br />
showtsky=T,subplot=42,field=field,<br />
spw=spw, interactive=False, plotrange=[0,0,0,0],<br />
figfile='cal_plots/Tsys_plots/'+asdm+'.tsys.field%s.png'%field,<br />
buildpdf=False)<br />
</source><br />
<br />
In <xr id="X3c1.tsys.field0.DV04.spw1.t1.png"/> and <xr id="X3c1.tsys.field0.DV04.spw3.t1.png"/> we see the effect of atmospheric ozone lines on the Tsys measurements associated with 3C279 in spw 1 and 3.<br />
<br />
For sources that have multiple Tsys measurements (typically the primary phase calibrator and/or the science target) one can use '''overlay="time"''' to overlay all the measurements for that source. This can help to identify any anomalous Tsys scans. As a fraction of the plots produced by this loop, here we show the Tsys recorded on spw=1 for TW Hya from the first dataset.<br />
<br />
<figure id="X3c1.tsys.field2.DV04.spw1.png"><br />
[[File:X3c1.tsys.field2.DV04.spw1.png|thumb|<caption>Tsys vs. freq for field 2, spw 1 of the X3c1.ms data (antennas 0..3).</caption>]]<br />
</figure><br />
<figure id="X3c1.tsys.field2.DV04.spw1.png"><br />
[[File:X3c1.tsys.field2.DV09.spw1.png|thumb|<caption>Tsys vs. freq for field 2, spw 1 of the X3c1.ms data (antennas 4..7).</caption>]]<br />
</figure><br />
<figure id="X3c1.tsys.field2.PM03.spw1.png"><br />
[[File:X3c1.tsys.field2.PM03.spw1.png|thumb|<caption>Tsys vs. freq for field 2, spw 1 of the X3c1.ms data (antenna 8).</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
print "Plotting Tsys vs. frequency for "+asdm<br />
for spw in [1,3,5,7]:<br />
for field in ['2','4']:<br />
plotbandpass(caltable=asdm+'.tsys', xaxis='freq',yaxis='amp',<br />
showtsky=T,subplot=22,field=field,<br />
overlay='time',spw=spw, interactive=False, plotrange=[0,0,0,0],<br />
figfile='cal_plots/Tsys_plots/'+asdm+'.tsys.field%s.png'%field,<br />
buildpdf = False)<br />
</source><br />
<br />
Alternatively, the '''overlay="antenna"''' option will quickly reveal any Antennas with discrepant Tsys values, as they<br />
will be obvious outliers. For FDM projects like this one, using the '''showfdm=True''' option can be helpful, as it<br />
will show where in the TDM bandpass each FDM spw was located. <br />
<figure id="X3c1.tsys.field0.spw1.t1.png"><br />
[[Image:X3c1.tsys.field0.spw1.t1.png|thumb|<caption>Tsys vs Freq for field 0, spw 1 of the X3c1.ms data with all antennas overlaid.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
tsysfields=['0','1','2','4'] <br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
print "Plotting Tsys vs. frequency for "+asdm<br />
for spw in [1,3,5,7]:<br />
for field in tsysfields:<br />
plotbandpass(caltable=asdm+'.tsys', xaxis='freq',yaxis='amp',<br />
showtsky=T,subplot=11,field=field,<br />
overlay='antenna',spw=spw, interactive=False,<br />
figfile='cal_plots/Tsys_plots/'+asdm+'.tsys.field%s.png'%field,<br />
buildpdf=False,showfdm=True)<br />
</source><br />
<br />
<br />
Note that DV04 consistently has a significantly higher Tsys than the rest of the antennas. We already know from the Observation log that<br />
we need to flag that antenna, but had we not had that information, examining this plot would have demonstrated the situation.<br />
<br />
==Apply the Tsys and WVR Tables, and Split ==<br />
<br />
Next we apply the calibrations. For the (4) sources with Tsys measurements, we use the '''field''' and '''gainfield''' parameters of {{applycal}} to apply solutions only to themselves. {{applycal}} has the ability to interpolate gain tables from one spw onto another spw. In this case, we want to interpolate the TDM Tsys values in spws 1,3,5,7 onto the FDM spws 17,19,21,23. We use the '''interp''' parameter to request linear interpolation in the time dimension and spline interpolation in the channel/frequency dimension. To map the solutions for each spw, we use the '''spwmap''' parameter, which requires a list of all spws for each gain table to be applied, or a blank list ([]) which is a shorthand notation to apply the solution for each spw to itself. While applying Tsys, we will also apply the wvr calibration tables; wvr data is usually always present for all sources. Below we first set some definitions so we can loop over the correct parameters:<br />
<br />
<source lang="python"><br />
# In CASA<br />
fdm='17,19,21,23'<br />
nocal='3' # This source had no Tsys measurements associated with it <br />
tsysfields=['0','1','2','4'] <br />
tsysmap = range(25)<br />
tsysmap[17] = 1<br />
tsysmap[19] = 3<br />
tsysmap[21] = 5<br />
tsysmap[23] = 7<br />
for asdm in basename_all:<br />
for field in tsysfields:<br />
applycal(vis=asdm+'.ms', spw=fdm, field=field, gainfield=field,<br />
gaintable=[asdm+'.tsys', asdm+'.wvr'], spwmap=[tsysmap,[]],<br />
interp=['linear,spline','nearest'], flagbackup=F, calwt=T)<br />
</source><br />
<br />
For the sources without Tsys (i.e. field=3), couple them with the best available source with Tsys (i.e. field=4).<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename_all:<br />
applycal(vis=asdm+'.ms', spw=fdm, field=nocal,<br />
gaintable=[asdm+'.tsys', asdm+'.wvr'], spwmap=[tsysmap,[]],<br />
gainfield=['4',nocal], interp=['linear,spline','nearest'],flagbackup=F,<br />
calwt=T)<br />
</source><br />
<br />
Check Tsys application with plotms. First we make plots with '''ydatacolumn='data'''' to look at the raw data. For <br />
simplicity we'll just look at the two strongest sources 3C279 and Titan.<br />
<br />
<figure id="X5d8_wvrtsys_corrected_spw19.png"><br />
[[Image:X5d8_wvrtsys_corrected_spw19.png|thumb|<caption>Spectral plots of 3C279 (black) and Titan (magenta) for spw=19 after Tsys and wvr correction.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X5d8.ms',spw='17,19,21,23',xaxis='frequency',yaxis='amp',field='0,1',<br />
antenna='*&*',avgtime='1e8',avgscan=T,coloraxis='field',iteraxis='spw',<br />
xselfscale=T,ydatacolumn='data')<br />
</source><br />
<br />
<figure id="X5d8_wvrtsys_corrected_spw21.png"><br />
[[Image:X5d8_wvrtsys_corrected_spw21.png|thumb|<caption>Spectral plots of 3C279 (black) and Titan (magenta) for spw=21 after Tsys and wvr correction.</caption>]]<br />
</figure><br />
<br />
'''Note''': the antenna='*&*' is specifying that we only want to see the cross-correlation data (i.e. not the autocorrelations).<br />
<br />
Use the '''green arrows''' on the {{plotms}} display to cycle through the 4 FDM spws. <br />
<br />
Now change '''Data Column''' to '''corrected''' on the "Axes" tab (this is the same as ydatacolumn in the task) and hit '''Plot''' button on the GUI. Flip through again.<br />
<br />
'''Things to notice:'''<br />
* The amplitude scale has changed due to application of Tsys<br />
* spw=17 is clean and flat<br />
* spw=19 shows a strong dip around channel 3000 (channels can be plotted by going to the Axes tab, and changing X Axis to Channel, then hit the Plot button)-- this is an atmospheric ozone absorption feature at 357.6 GHz. In the future, high spectral resolution Tsys measurements may help to remove the shape of the absorption, but until then we will need to flag this part of the spectrum.<br />
* spw=21 Titan shows both a narrow and a broad spectral feature. The broad feature is CO(3-2) and it completely fills the 0.5 GHz band so there are no line-free channels! Titan must be handled carefully when it is used as a calibrator because it contains strong line emission. Indeed, we will not be able to use the absolute flux transfer from this spw for other targets. When possible Titan should be avoided for absolute flux calibration. For these observations, no other suitable absolute flux calibrator was available.<br />
* spw=23 shows another strong line from Titan.<br />
<br />
Beyond these things to notice, the application of Tsys and wvr seem to have gone well. We can now split off only the narrow band FDM spectral windows for further processing.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename_all:<br />
newvis = asdm + '_wvrtsys.ms'<br />
os.system('rm -rf ' + newvis)<br />
split(vis=asdm+'.ms',outputvis=newvis,datacolumn='corrected',spw=fdm)<br />
</source><br />
<br />
'''Note''': After {{split}}, the spectral windows will be renumbered to 0, 1, 2, 3 corresponding to the old spw=17, 19, 21, 23, see {{listobs}} excerpt below.<br />
<br />
<pre style="background-color: #fffacd;"><br />
SpwID #Chans Frame Ch1(MHz) ChanWid(kHz) TotBW(kHz) Corrs <br />
0 3840 TOPO 356497.936 122.070312 468750 XX YY <br />
1 3840 TOPO 357734.314 122.070312 468750 XX YY <br />
2 3840 TOPO 346034.314 122.070312 468750 XX YY <br />
3 3840 TOPO 343955.936 122.070312 468750 XX YY <br />
</pre><br />
<br />
==Initial Inspection and Flagging==<br />
<br />
From here we begin to operate on the *wvrtsys.ms files. <br />
<br />
Before we begin flagging data, we unflag all data in the measurement sets. If this is your first pass through this section of the guide, no data in the measurement sets will be flagged, and you can skip this step. If you are rerunning the flagging commands below, this will reset your flag columns to their original state.<br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
for vis in splitdata:<br />
flagdata(vis=vis, mode='unflag', action='apply', flagbackup=F)<br />
</source><br />
<br />
ALMA data contains both the cross correlation and autocorrelation data. Presently nothing more can be done with the autocorrelation data so we flag it. Additionally, for smaller configurations of the array, and northerly sources one antenna can ''shadow'' another, blocking its view. This data also needs to be flagged. Finally, the observing log told us DV04 was not behaving properly at Band 7 and shouldn't be used so we flag that as well.<br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
for vis in splitdata:<br />
flagdata(vis=vis, mode='manual', autocorr=True, action = 'apply', flagbackup=T)<br />
flagdata(vis=vis, mode='shadow',tolerance=12.0, action='apply', flagbackup=F)<br />
flagdata(vis=vis, mode='manual', antenna='DV04', action='apply', flagbackup=F)<br />
</source><br />
<br />
Next we inspect the data with {{plotms}} for additional issues that need flagging, first looking at amplitude vs. time for each of the three datasets. Use the '''green''' arrows on the plotms gui to cycle through spws. <br />
<br />
<figure id="Tsyswvr_time_spw0_X3x1.png"><br />
[[Image:Tsyswvr_time_spw0_X3x1.png|thumb|<caption>Amplitude as a function of time for X3c1_wvrtsys.ms, spw=0</caption>]]<br />
</figure><br />
<br />
'''Note''': when '''iteraxis''' is invoked in {{plotms}}, unzoom does not always work properly. If you have trouble with this, flip to next page and then back to current one. This usually fixes the problem.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X5d8_wvrtsys.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X7ef_wvrtsys.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw')<br />
</source><br />
<br />
<figure id="Tsyswvr_time_spw2corr_X3x1.png"><br />
[[Image:Tsyswvr_time_spw2corr_X3x1.png|thumb|<caption>Amplitude as a function of time for X3x1_wvrtsys.ms, spw=2 with colorize='corr'.</caption>]]<br />
</figure><br />
<br />
'''Things to Notice:'''<br />
* In spw=2 there are some low points in all three data files. Use the "Mark Regions" box (left of center on bottom row of icons) to draw small box on low points. Then click the magnifying glass icon to the right of center. The output will be sent to the logger window. '''Note''': keep the marked region small or you can overwhelm the buffer. Locate suggests correlation YY on PM03 is the culprit. <br />
<br />
To see this more clearly you can rerun {{plotms}} with '''coloraxis='field'''' switched to '''coloraxis='corr''''<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='2',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='corr')<br />
</source><br />
<br />
To further check, you can exclude PM03 from the plot using '''antenna='!PM03'.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='2',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='corr',antenna='!PM03')<br />
</source><br />
<br />
Having confirmed the problem antenna, we flag it below. <br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
for vis in splitdata:<br />
flagdata(vis=vis, mode='manual', action= 'apply', flagbackup=T,<br />
spw='2',<br />
antenna='PM03',<br />
correlation='YY')<br />
</source><br />
<br />
'''Next we need to inspect the spectral properties of the data to look for issues.'''<br />
<br />
First we look at phase as a function of frequency for a well behaved antenna like DV06. <br />
'''coloraxis='baselines'''' (note this parameter is called '''Colorize''' in the GUI "Display" tab) will show each baseline as a different color. Significant delay errors or baseline errors will show up as phase slopes in these plots. Again you will want to page through the spectral windows.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='',xaxis='frequency',yaxis='phase',field='0',antenna='DV06',<br />
avgtime='1e8',avgscan=T,coloraxis='baseline',iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X5d8_wvrtsys.ms',spw='',xaxis='frequency',yaxis='phase',field='0',antenna='DV06',<br />
avgtime='1e8',avgscan=T,coloraxis='baseline',iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X7ef_wvrtsys.ms',spw='',xaxis='frequency',yaxis='phase',field='0',antenna='DV06',<br />
avgtime='1e8',avgscan=T,coloraxis='baseline',iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
Overall these plots look good with no large delays or baseline errors apparent.<br />
<br />
<figure id="Birdies_spw2_X3x1.png"><br />
[[Image:Birdies_spw2_X3x1.png|thumb|<caption>Phase calibrators (brown and green) and TW Hya (orange) showing both real CO(3-2) emission in TW Hya and weak ''birdie'' spectral features in all three sources for spw=2.</caption>]]<br />
</figure><br />
<br />
With such high spectral resolution data, one often sees occasional "birdies" in the data. These are typically very narrow weak spectral features that are internally generated in the system. Over time as we track down issues the number of birdies should decrease, but you should always check. This is easiest to do by looking at amplitude vs. frequency for sources observed over a long time range (for sensitivity). It is helpful to look at more than one source to verify the nature of the emission. Below we look at both calibrators (brown and green) and TW Hya (orange). If you have enough sensitivity birdies should be seen on all sources, however, be careful not to mistake real line emission for a birdie even on a calibrator - they can be present as we've seen for Titan.<br />
<br />
<figure id="Birdies_spw3_X3x1.png"><br />
[[Image:Birdies_spw3_X3x1.png|thumb|<caption>Phase calibrators (brown and green) and TW Hya (orange) showing only weak birdie spectral features in spw=3.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='',xaxis='channel',yaxis='amp',field='2,3,4',<br />
avgtime='1e8',avgscan=T,coloraxis='field',iteraxis='spw',xselfscale=T,yselfscale=T)<br />
</source><br />
<br />
Do a quick check that other two datasets are the same (they are usually similar if the source of internal resonance hasn't changed in the meantime).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X5d8_wvrtsys.ms',spw='',xaxis='channel',yaxis='amp',field='2,3,4',<br />
avgtime='1e8',avgscan=T,coloraxis='field',iteraxis='spw',xselfscale=T,yselfscale=T)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X7ef_wvrtsys.ms',spw='',xaxis='channel',yaxis='amp',field='2,3,4',<br />
avgtime='1e8',avgscan=T,coloraxis='field',iteraxis='spw',xselfscale=T,yselfscale=T)<br />
</source><br />
<br />
Now you can zoom in on each region to get channels for flagging, or to save time just go ahead and run the flagging command below where this has been done for you.<br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
for vis in splitdata:<br />
flagdata(vis=vis, mode='manual', action='apply', flagbackup=T,<br />
spw='0:1067~1068;1279~1280;2367~2368;3775~3776, 1:1279~1280;2367~2368;3775~3776, 2:1279~1280;3775~3776, 3:831~832;1535~1536;2367~2368;3775~3776;3839~3839')<br />
</source><br />
<br />
Replot in {{plotms}} to check that flagging has been done as anticipated.<br />
<br />
==Flag Calibrator Spectral Features==<br />
<br />
In this section, we will flag spectral features in the calibrators so they do not skew the calibration solutions. First make plots of 3C279 and Titan in channel space to get channels for flagging. <br />
<br />
<figure id="3C279_Titan_spw1.png"><br />
[[Image:3C279_Titan_spw1.png|thumb|<caption>Spectral plots of 3C279 (black) and Titan (magenta) for spw=1 after Tsys and wvr correction.</caption>]]<br />
</figure><br />
<figure id="3c279_meso_freq.png"><br />
[[Image:3c279_meso_freq.png|thumb|<caption>Zoomed spectral plot of 3C279 showing mesospheric absorption of CO(3-2) in frequency space.</caption>]]<br />
</figure><br />
<figure id="3c279_meso_chann.png"><br />
[[Image:3c279_meso_chann.png|thumb|<caption>Zoomed spectral plot of 3C279 showing mesospheric absorption of CO(3-2) in channel space.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='channel',yaxis='amp',field='0,1',<br />
avgtime='1e8',coloraxis='field',iteraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
The figure to the right shows a broad absorption line in spw 1 at channel 3000. This is the ozone absorption line at 357.62982 GHz. However, there is another narrow absorption feature in the spectra (spw 2) that is most easily seen on 3C279 (because it is the strongest calibrator). Let's look at it first in frequency space.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='2:1600~2300',xaxis='frequency',yaxis='amp',<br />
field='0',avgtime='1e8',coloraxis='field')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
The absorption feature lies exactly at the rest frequency for CO 3-2 (345.79599 GHz). Because it is so narrow (< 1 MHz), it must originate from a very low pressure region (i.e. high altitude) in the Earth's atmosphere, otherwise it would be more pressure broadened. Indeed, the first detection of CO in the mesosphere was made over 35 years ago (see, e.g. [http://adsabs.harvard.edu/abs/1976Sci...191.1174W Waters et al. 1976] or [http://adsabs.harvard.edu/abs/1979JGR....84..416G Goldsmith et al. 1979]). Be aware that the line is stronger as you go up the CO ladder (strength ~ J^3 for low J) because the temperature at that altitude (~50km) is about 250 K. In April 2011, the apparent depth of the feature was about 10% in the 2-1 line and 35% in the 3-2 line. However, the depth of the absorption feature is exaggerated due to the way ALMA normalizes the cross-correlation spectra by the autocorrelation spectra prior to storage. While this technique generally leads to a flat bandpass shape, it will accentuate telluric features because they are emission lines in the single dish spectrum (e.g. JCMT observations of mesospheric CO 3-2 can be found in [http://adsabs.harvard.edu/abs/1993MNRAS.264..673P Preston et al. 1993]). Finally, note that large seasonal variations in the line strength have been reported from observations at [http://adsabs.harvard.edu/abs/2003GeoRL..30j..39F Onsala]. <br />
<br />
Now, let's re-plot the line with channel number as the x-axis in order to get the channel range for flagging. <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='2:1600~2300',xaxis='channel',yaxis='amp',<br />
field='0',avgtime='1e8',coloraxis='field')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Now lets look at Titan in more detail.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='channel',yaxis='amp',field='1',<br />
avgtime='1e8',coloraxis='field',iteraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Explicitly back up the flag tables so that flagged regions can be restored later.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
flagmanager(vis=asdm+'.ms',mode='save',versionname=asdm+'.before_calspectralflags')<br />
</source><br />
<br />
<figure id="Titan_spw2.png"><br />
[[Image:Titan_spw2.png|thumb|<caption>Spectral plot of Titan (magenta) for spw=2.</caption>]]<br />
</figure><br />
<br />
Flag absorption features for all sources.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
print "Flagging absorption features in all sources for "+asdm<br />
flagdata(vis=asdm+'.ms', mode='manual', spw='1:2000~3839, 2:1945~1960')<br />
</source><br />
<br />
<figure id="Titan_spw3.png"><br />
[[Image:Titan_spw3.png|thumb|<caption>Spectral plot of Titan (magenta) for spw=3.</caption>]]<br />
</figure><br />
<br />
Now we need to flag emission. The very broad CO(3-2) in spw=2 of Titan will prevent us from using it as a calibrator for this spectral window since there are no line-free channels (we will transfer, phase, amplitude, and absolute flux from another Titan spw below). We do want to flag the narrower Titan line in spw=3.<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
flagmanager(vis=asdm+'.ms',mode='save',versionname=asdm+'.before_emissionflags')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
print "Flagging emission for "+asdm<br />
flagdata(vis=asdm+'.ms', mode='manual', <br />
field='1',<br />
spw='3:1000~3000')<br />
</source><br />
<br />
If you like, check that the right things have been flagged.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='channel',yaxis='amp',field='0,1',<br />
avgtime='1e8',coloraxis='field',iteraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
==Set Up the Flux Calibrator Model==<br />
<br />
Fill the model data column for Titan with a model for the flux density as a function of baseline. The model is a uniformly illuminated disk with the size obtained from the JPL Horizons ephemeris.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
setjy(vis=asdm+'.ms',field='1',usescratch=F,<br />
standard='Butler-JPL-Horizons 2010',scalebychan=F)<br />
</source><br />
<br />
<figure id="Titan amp vs uvdist.png"><br />
[[Image:Titan amp vs uvdist.png|thumb|<caption>Plot of Titan model for each of the 4 spws. We used the Butler-JPL-Horizons 2010 standard to compute this model.</caption>]]<br />
</figure><br />
<br />
After running setjy, it is a good idea to plot the model in order to confirm that it makes sense. In this case, Titan is partially resolved, so we expect the flux density to drop with uv distance, but not so much as to pass through a null. We also expect it to be brighter at higher frequencies since it has a thermal blackbody spectrum.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',field='1',xaxis='uvdist',yaxis='amp',coloraxis='spw',<br />
ydatacolumn='model')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<figure id="twhydra_X3c1_wvrtsys_2012_titan_model.png">[[File:twhydra_X3c1_wvrtsys_2012_titan_model.png|thumb|right|<caption>Titan model produced by 'Butler-JPL-Horizons 2012'.</caption>]]</figure><br />
<br />
<br/><br />
<div class="noprint" style="float:none; border:0px solid blue;background-color:#F6CEF5;padding:2px;"><br />
The setjy invocation, above, uses the flux density standard '''standard='Butler-JPL-Horizons 2010' '''. A more updated standard is also available: '''standard='Butler-JPL-Horizons 2012' '''. <xr id="twhydra_X3c1_wvrtsys_2012_titan_model.png"/> shows the Titan model produced using the updated standard. The motivated reader may wish to rerun {{setjy}} using the updated model. We will highlight later in this tutorial, and in the imaging tutorial that follows, the effects of using the updated model.<br />
</div><br />
<br />
==Bandpass Calibration==<br />
<br />
First we need to check how the amplitude and phase of 3C279 behave as a function of time. In order to set<br />
a fixed scale on the y-axis, we first make a plot of all the data, excluding antenna DV04. (We must specify '''ydatacolumn='data' ''' explicitly here because the default value of '''ydatacolumn''' equals the value used in the previous execution of {{plotms}}. In the previous execution '''ydatacolumn''' was set to '''model'''. See the online help, <tt>help plotms</tt>, for details.)<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',xaxis='time',yaxis='amp',coloraxis='corr',<br />
field='0',avgchannel='3840',ydatacolumn='data')<br />
</source><br />
<br />
<figure id="ThreeScansAmp.png"><br />
[[Image:ThreeScansAmp.png|thumb|<caption>Amplitude variation for three 3C279 scans, spw 0 (for one representative baseline).</caption>]]<br />
</figure><br />
<br />
We see that the uncalibrated amplitudes range between 0.2-0.4, so let's set this as our<br />
scale and examine a representative baseline (DV06-DV07) to see how the amplitude changes with time. <br />
<br />
<source lang="python"><br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for spw in ['0','1','2','3']:<br />
for asdm in basename:<br />
print "Now showing spw %s from %s" % (spw, asdm+'.ms')<br />
plotms(vis=asdm+'.ms',spw=spw,xaxis='time',yaxis='amp',coloraxis='corr',iteraxis='spw',<br />
field='0',avgchannel='3840',antenna='DV06&DV07',plotrange=[0,0,0.2,0.4])<br />
user_check=raw_input('press enter to go to the next plot\n')<br />
</source><br />
<br />
<figure id="ThreeScansPhase.png"><br />
[[Image:ThreeScansPhase.png|thumb|<caption>Phase variation for three 3C279 scans, spw 0 (for one representative baseline).</caption>]]<br />
</figure><br />
<br />
Page through the measurement sets for each spw. This shows significant variations in the amplitude across the three measurement sets.<br />
Now do the same with phase.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for spw in ['0','1','2','3']:<br />
for asdm in basename:<br />
print "Now showing spw %s from %s" % (spw, asdm+'.ms')<br />
plotms(vis=asdm+'.ms',spw=spw,xaxis='time',yaxis='phase',coloraxis='corr',iteraxis='spw',<br />
field='0',avgchannel='3840',antenna='DV06&DV07',plotrange=[0,0,-180,180])<br />
user_check=raw_input('press enter to go to the next plot\n')<br />
</source><br />
<br />
This examination reveals two findings: (1) significant variation in the phase across the three scans, as well as (2) smaller but significant variations within a scan. The first finding suggests that we do not want to combine the scans for bandpass calibration, but instead derive an independent bandpass for each scan. Actually what is more important than a DC offset is if the '''shape''' of the amplitude or phase changes from scan to scan. There isn't enough S/N to tell for sure so we will keep them separate. This situation is often the case, which is why we did not concatenate the three datasets prior to calibration. The second finding suggests that we need to correct the phase vs. time behavior of the bandpass calibrator (3C279; field=0) within each scan, before doing the bandpass. We want to chose a relatively narrow range of channels near the center of the spws so that the bandpass phase slopes (to be corrected with the bandpass calibration itself) do not decorrelate the signal. You need to avoid spectral regions that were completely flagged above.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.bpphase.gcal')<br />
gaincal(vis=asdm+'.ms',caltable=asdm+'.bpphase.gcal',<br />
field='0',spw='0~3:900~1100',refant='DV06',<br />
calmode='p',solint='int',minsnr=2.0,minblperant=4)<br />
</source><br />
<br />
<figure id="X7ef_wvrtsys.bpphase.X.png"><br />
[[Image:X7ef_wvrtsys.bpphase.X.png|thumb|<caption>Phase only solutions for correlation X on the third scan of the bandpass calibrator 3C279.</caption>]]<br />
</figure><br />
<br />
Inspect the phase-only calibration solutions for the bandpass calibrator. Look for any noisy solutions. We do XX and YY separately to reduce confusion in the plot. It will help if you make your plotcal window wide.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.bpphase.gcal',xaxis='time',yaxis='phase',spw='',antenna='1~8', <br />
iteration='antenna',subplot=421,plotrange=[0,0,-180,180],<br />
figfile=asdm+'.bpphase.X.png',poln='X')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
In the plotcal gui you can use the magnifying glass symbol to zoom in on one of the scans to see the phase variations. The colors are the 4 different spws.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.bpphase.gcal',xaxis='time',yaxis='phase',spw='',antenna='1~8', <br />
iteration='antenna',subplot=421,plotrange=[0,0,-180,180],<br />
figfile=asdm+'.bpphase.Y.png',poln='Y')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Next we apply this phase-only correction on the fly while calculating the bandpass solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.bandpass.bcal')<br />
bandpass(vis=asdm+'.ms',caltable=asdm+'.bandpass.bcal',<br />
field='0',spw='',combine='',refant='DV06',<br />
solint='inf',solnorm=T,minblperant=4, bandtype='B', fillgaps=17,<br />
gaintable=asdm+'.bpphase.gcal')<br />
</source><br />
<br />
You will see some error messages in the terminal, these are just related to the flagged channels. We set fillgaps=17 to interpolate across the smaller regions of flagged channels (mesospheric features and birdies).<br />
<br />
<figure id="Bandpass.ampspw0.png"><br />
[[Image:Bandpass.ampspw0.png|thumb|<caption>Bandpass amplitude solution plots.</caption>]]<br />
</figure><br />
<figure id="Bandpass.phasespw0.png"><br />
[[Image:Bandpass.phasespw0.png|thumb|<caption>Bandpass phase solution plots.</caption>]]<br />
</figure><br />
<br />
'''A few words about solint and combine:'''<br />
<br />
In {{bandpass}}, the use of '''solint='inf'''' (as in "infinite") will derive a bandpass<br />
solution for each 3C279 scan, '''unless''' '''combine='scan'''' (which is the default). Here we set combine=' ' explicitly so that it does not combine the scans into one bandpass. Likewise, field boundaries are only crossed if combine='field', and spw boundaries are only crossed if combine='spw'. In some cases it can be helpful to combine fields if you suffer from lack of S/N, but it is never a good idea to combine spws. <br />
<br />
Now inspect the phase and amplitude solutions. You are looking for excursions from smooth fits, or particularly noisy solutions compared to the others. <br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
for spw in [0,1,2,3]:<br />
plotbandpass(asdm+'.bandpass.bcal',xaxis='freq',yaxis='amp', spw=spw,<br />
antenna='1~8', subplot=42, figfile=asdm+'.bandpass.amp', showatm=T,<br />
interactive=True)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
for spw in [0,1,2,3]:<br />
plotbandpass(asdm+'.bandpass.bcal',xaxis='freq',yaxis='phase',spw=spw,<br />
antenna='1~8',subplot=42,figfile=asdm+'.bandpass.phs', showatm=T,<br />
interactive=True)<br />
</source><br />
<br />
The values of phase on DV06 are very close to zero because it was used as the reference antenna.<br />
<br />
==Gain Calibration==<br />
<br />
Now that we have a bandpass solution to apply we can solve for the antenna-based phase and amplitude gain calibration. Since the phase changes on a much shorter timescale than the amplitude, we will solve for them separately. In particular, if the phase changes significantly over a scan time, the amplitude would be decorrelated, if the un-corrected phase were averaged over this timescale. Note that we re-solve for the gain solutions of the bandpass calibrator, so we can derive new solutions that are corrected for the bandpass shape. Since the bandpass calibrator will not be used again, this is not strictly necessary, but is useful to check its calibrated flux density for example. <br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.intphase.gcal')<br />
gaincal(vis=asdm+'.ms',caltable=asdm+'.intphase.gcal',<br />
field='0,1,3,4',spw='0~3:40~3800',refant='DV06',<br />
calmode='p',solint='int',minsnr=2.0,minblperant=4,<br />
gaintable=[asdm+'.bandpass.bcal'])<br />
</source><br />
<br />
Here '''solint='int' ''' coupled with '''calmode='p' ''' will derive a single phase solution for each 10 second integration. Note that the bandpass table is applied on-the-fly before solving for the phase solutions, however the bandpass is NOT applied to the data permanently until applycal is run later on. <br />
<br />
Although '''solint='int' ''' (i.e. the integration time of 10 seconds) is the best choice to apply before solving for the amplitude solutions, it is not a good idea to use this to apply to the target. This is because the phase-scatter within a scan can dominate the interpolation between calibrator scans. Instead, we also solve for the phase on the scan time, '''solint='inf' ''' (but '''combine=' ' ''', since we want one solution per scan) for application to the target later on. Unlike the bandpass task, for {{gaincal}}, the default of the combine parameter is '''combine=' ' '''. <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.scanphase.gcal')<br />
gaincal(vis=asdm+'.ms',caltable=asdm+'.scanphase.gcal',<br />
field='0,1,3,4',spw='0~3:40~3800',refant='DV06',<br />
calmode='p',solint='inf',minsnr=2.0,minblperant=4,<br />
gaintable=[asdm+'.bandpass.bcal'])<br />
</source><br />
<br />
Alternatively, instead of making a separate phase solution for application to the target, one can also run {{smoothcal}} to smooth the solutions derived on the integration time. <br />
<br />
Next we apply the bandpass and '''solint='int' ''' phase-only calibration solutions on-the-fly to derive amplitude solutions. Here the use of '''solint='inf' ''', but '''combine=' ' ''' will result in one solution per scan interval. <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.amp.gcal')<br />
gaincal(vis=asdm+'.ms',caltable=asdm+'.amp.gcal',<br />
field='0,1,3,4',spw='0~3:40~3800',refant='DV06',<br />
calmode='ap',solint='inf',minsnr=2.0,minblperant=4,<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal'])<br />
</source><br />
<br />
Now carefully inspect all these solutions looking for discrepant solutions. If you see any, you will need to flag them and rerun the calibration tasks above. <br />
<br />
We make plots in X and Y separately for clarity. The colors are showing the spectral windows.<br />
<figure id="X3c1_wvrtsys.intphase_X.png"><br />
[[Image:X3c1_wvrtsys.intphase_X.png|thumb|<caption>Phase solutions for the X polarization for every integration time of the first dataset.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.intphase.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',iteration='antenna',subplot=421,<br />
plotrange=[0,0,-180,180],poln='X',figfile=asdm+'.intphase_X.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.intphase.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',iteration='antenna',subplot=421,<br />
plotrange=[0,0,-180,180],poln='Y',figfile=asdm+'.intphase_Y.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<figure id="X3c1_wvrtsys.scanphase_X.png"><br />
[[Image:X3c1_wvrtsys.scanphase_X.png|thumb|<caption>Phase solutions for the X polarization for each scan of the first dataset.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.scanphase.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',iteration='antenna',subplot=421,<br />
plotrange=[0,0,-180,180],poln='X',figfile=asdm+'.scanphase_X.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.scanphase.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',iteration='antenna',subplot=421,<br />
plotrange=[0,0,-180,180],poln='Y',figfile=asdm+'.scanphase_Y.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Since we have taken out the phase as best we can by applying the '''solint='int' ''' phase-only solution, this plot will give a good idea of the residual phase error. If you see scatter of more than a few degrees here, you should consider going back and looking for more data to flag, particularly bad timeranges etc. <br />
<br />
<figure id="X3c1_wvrtsys.amp_phase.png"><br />
[[Image:X3c1_wvrtsys.amp_phase.png|thumb|<caption>Residual phase after applying intphase.gcal for both correlations in the first dataset.</caption>]]<br />
</figure><br />
<figure id="X3c1_wvrtsys.amp_X.png"><br />
[[Image:X3c1_wvrtsys.amp_X.png|thumb|<caption>Amplitude solutions on a scan interval for correlation X in the first dataset.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.amp.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',plotrange=[0,0,-1,1],<br />
iteration='antenna',subplot=421,figfile=asdm+'.amp_phase.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
These are very small, as they should be. Now look at the amplitude solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.amp.gcal',xaxis='time',yaxis='amp',antenna='1~8', <br />
iteration='antenna',subplot=421,spw='',poln='X',<br />
plotrange=[0,0,0.0,0.3],figfile=asdm+'.amp_X.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.amp.gcal',xaxis='time',yaxis='amp',antenna='1~8', <br />
iteration='antenna',subplot=421,spw='',poln='Y',<br />
plotrange=[0,0,0.0,0.3],figfile=asdm+'.amp_Y.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
==Flux Calibration==<br />
<br />
Next we use the flux calibrator (whose flux density was set in {{setjy}} above) to derive the flux density of the other calibrators. Note that the flux table REPLACES the amp.gcal in terms of future application of the calibration to the data, i.e. the flux table contains both the amp.gcal and flux scaling. Unlike the gain calibration steps, this is not an incremental table.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.flux.cal')<br />
fluxscale(vis=asdm+'.ms',caltable=asdm+'.amp.gcal',<br />
fluxtable=asdm+'.flux.cal',reference='1',refspwmap=[0,1,3,3],<br />
listfile=asdm+'.fluxscale.txt')<br />
</source><br />
<br />
Its a good idea to record the derived fluxscale values using the listfile option. The values can also be viewed in the Log Messages window.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Found reference field(s): Titan<br />
Found transfer field(s): 3c279 J1147-382=QSO J1037-295=QSO<br />
Spw=2 will be referenced to spw=3<br />
Flux density for 3c279 in SpW=0 (freq=3.56498e+11 Hz) is: 10.537 +/- 0.0183518 (SNR = 574.169, N = 16)<br />
Flux density for 3c279 in SpW=1 (freq=3.57734e+11 Hz) is: 10.6933 +/- 0.0264134 (SNR = 404.842, N = 16)<br />
Flux density for 3c279 in SpW=2 (freq=3.46034e+11 Hz) (ref SpW=3) is: 10.251 +/- 0.0477949 (SNR = 214.479, N = 14)<br />
Flux density for 3c279 in SpW=3 (freq=3.43956e+11 Hz) is: 9.91798 +/- 0.020167 (SNR = 491.791, N = 16)<br />
Flux density for J1147-382=QSO in SpW=0 (freq=3.56498e+11 Hz) is: 1.03399 +/- 0.0167344 (SNR = 61.7887, N = 16)<br />
Flux density for J1147-382=QSO in SpW=1 (freq=3.57734e+11 Hz) is: 0.844817 +/- 0.0191013 (SNR = 44.2283, N = 16)<br />
Flux density for J1147-382=QSO in SpW=2 (freq=3.46034e+11 Hz) (ref SpW=3) is: 0.987193 +/- 0.024391 (SNR = 40.4737, N = 14)<br />
Flux density for J1147-382=QSO in SpW=3 (freq=3.43956e+11 Hz) is: 1.28859 +/- 0.0194364 (SNR = 66.298, N = 16)<br />
Flux density for J1037-295=QSO in SpW=0 (freq=3.56498e+11 Hz) is: 0.968281 +/- 0.00895224 (SNR = 108.161, N = 16)<br />
Flux density for J1037-295=QSO in SpW=1 (freq=3.57734e+11 Hz) is: 0.75916 +/- 0.015366 (SNR = 49.4053, N = 16)<br />
Flux density for J1037-295=QSO in SpW=2 (freq=3.46034e+11 Hz) (ref SpW=3) is: 0.948551 +/- 0.0165421 (SNR = 57.3416, N = 14)<br />
Flux density for J1037-295=QSO in SpW=3 (freq=3.43956e+11 Hz) is: 1.21905 +/- 0.0139967 (SNR = 87.0956, N = 16)<br />
Fitted spectrum for 3c279 with fitorder=1: Flux density = 10.2962 +/- 0.0450319 (freq=351.002 GHz) spidx=1.70757 +/- 0.245737<br />
Fitted spectrum for J1147-382=QSO with fitorder=1: Flux density = 1.06853 +/- 0.0709817 (freq=351.002 GHz) spidx=-6.77353 +/- 3.71867<br />
Fitted spectrum for J1037-295=QSO with fitorder=1: Flux density = 1.01822 +/- 0.0654586 (freq=351.002 GHz) spidx=-6.28977 +/- 3.71453<br />
Storing result in X7ef_wvrtsys.flux.cal<br />
Writing solutions to table: X7ef_wvrtsys.flux.cal<br />
</pre><br />
<br />
<figure id="x3c1_wvrtsys.flux_X.png"><br />
[[Image:x3c1_wvrtsys.flux_X.png|thumb|<caption>Absolute flux calibration solutions for correlation X for the first dataset.</caption>]]<br />
</figure><br />
<br />
<div class="noprint" style="float:none; border:0px solid blue;background-color:#F6CEF5;padding:2px;"><br />
If you used the updated (Butler-JPL-Horizons 2012) flux density standard when you ran {{setjy}} earlier in this tutorial, the derived flux values for the calibrators will be slightly different. For example, when averaged over the 3 measurement sets, 3c279 in spectral window 0 has a flux of 10.77 Jy using the 2010 standard and 10.63 Jy using the 2012 standard; as a second example, J1147-382 in SPW 3 has an average flux of 1.13 Jy (2010 standard) and 1.15 Jy (2012 standard). <br />
</div><br />
<br />
Now look at the flux solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.flux.cal',xaxis='time',yaxis='amp',antenna='1~8', <br />
iteration='antenna',subplot=421,spw='',poln='X',<br />
plotrange=[0,0,0.0,0.3],figfile=asdm+'.flux_X.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.flux.cal',xaxis='time',yaxis='amp',antenna='1~8', <br />
iteration='antenna',subplot=421,spw='',poln='Y',<br />
plotrange=[0,0,0.0,0.3],figfile=asdm+'.flux_Y.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
==Apply Calibration and Inspect==<br />
<br />
Now we can use the {{flagmanager}} if we want to restore any of the spectral flagging we did prior to bandpass calibration. <br />
In this case, we choose to restore the flags of the emission lines on Titan, because we are interested in seeing how<br />
strong they are compared to the continuum. However, we leave the strong ozone line and mesospheric CO line flagged on all <br />
sources, because we want to get the most accurate continuum flux density for the science target. <br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
flagmanager(vis=asdm+'.ms',mode='restore',versionname=asdm+'.before_emissionflags')<br />
</source><br />
<br />
Next we apply the calibration solutions to each source individually, using the '''gainfield''' parameter to specify which calibrator's solutions should be applied from each of the '''gaintable''' calibration tables. <br />
<br />
First, we do 3C279 (the bandpass calibrator), applying all 3 of its solutions to itself (that's why gainfield contains three zeros):<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='0',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['0','0','0'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
Next, we do Titan (the absolute flux calibrator) using the bandpass solution from 3C279:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='1',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['0','1','1'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
For the secondary phase calibrator, we apply the phase and flux solutions from the primary phase calibrator. This will allow us to check how well the phase transfer to the science target (TW Hya) has worked:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='3',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.scanphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','linear','linear'],<br />
gainfield=['0','4','4'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
Next is the Primary phase calibrator:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='4',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['0','4','4'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
Finally, for the Science Target TW Hya, we apply the phase solutions from both the primary and secondary phase calibrators:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='2',<br />
interp=['nearest','linear','linear'],<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.scanphase.gcal',asdm+'.flux.cal'],<br />
gainfield=['0','3,4','3,4'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
Now we can check the results of applying the calibration solutions.<br />
<br />
<figure id="Corrected_vs_time_1.png"><br />
[[Image:Corrected_vs_time_1.png|thumb|<caption>The calibrated data for the first dataset (amplitude vs. time).</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw',ydatacolumn='corrected')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
In amplitude, it looks good but there are some noisy points toward the end of the first scheduling block, but it mostly only affects the secondary phase calibrator (green). In phase, we expect all the points to cluster about zero. The large scatter in phase on the secondary phase calibrator is readily apparent: <br />
<br />
<figure id="Corrected_phase_vs_time_1.png"><br />
[[Image:Corrected_phase_vs_time_1.png|thumb|<caption>The calibrated data on the calibrators for the first dataset (phase vs. time).</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='time',yaxis='phase',field='0,1,3,4',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw',ydatacolumn='corrected')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Let's check whether the situation improves when we apply this calibrator's solutions to itself rather than transferring the solutions from the primary phase calibrator (which is 17 degrees away, and observed at a different time). <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='3',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['0','3','3'],flagbackup=T, calwt=T)<br />
</source><br />
<br />
<figure id="Corrected_vs_time_1_field3.png"><br />
[[Image:Corrected_vs_time_1_field3.png|thumb|<caption>The calibrated data for the first dataset (amplitude vs. time), but now with field 3, the secondary phase calibrator, calibrated with itself.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw',ydatacolumn='corrected')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<figure id="Corrected_phase_vs_time_1_field3.png"><br />
[[Image:Corrected_phase_vs_time_1_field3.png|thumb|<caption>The calibrated data from the first dataset (phase vs. time), but now with field 3, the secondary phase calibrator, calibrated with itself.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='time',yaxis='phase',field='0,1,3,4',<br />
avgchannel='3840', coloraxis='field',iteraxis='spw',<br />
ydatacolumn='corrected')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Indeed, the secondary calibrator looks better now in amplitude and phase. This is an indication that the calibration transfer is not working well in this timerange. Because the effect is not catastrophic and we know we can self-calibrate on TW Hya later, we will let this go for now. Or, if you want you can delve deeper into the data and try to solve the mystery... <br />
<br />
In any case, we will re-issue the original {{applycal}} so that it is this calibration that our subsequent {{split}} will use. This will allow us to check the effect of correcting the secondary phase calibrator with the primary phase calibrator later. <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='3',<br />
gaintable=[asdm+'.bandpass.bcal', asdm+'.scanphase.gcal', asdm+'.flux.cal'],<br />
interp=['nearest','linear','linear'],<br />
gainfield=['0','4','4'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
<br />
Let's check the spectral calibration now. First 3C279 and Titan:<br />
<br />
<figure id="X3c1_spw2_corrected_3.4.png"><br />
[[Image:X3c1_spw2_corrected_3.4.png|thumb|<caption>Spectral UV-plots of 3C279 and Titan of spw=2 for the first dataset.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='frequency',yaxis='amp',field='0,1',<br />
avgtime='1e8',avgscan=T,coloraxis='field',ydatacolumn='corrected',<br />
iteraxis='spw',xselfscale=T)<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Flip through the spws. These look good. Next the two phase calibrators:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='frequency',yaxis='amp',field='3,4',<br />
avgtime='1e8',avgscan=T,coloraxis='field',ydatacolumn='corrected',<br />
iteraxis='spw',xselfscale=T)<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Flip through the spws. This also looks good, the secondary phase calibrator is a bit noisier but this is normal. The upswing at the lower frequency end of spw=3 will probably need to be flagged on the science target as well. It corresponds to the edge of an atmospheric feature.<br />
<br />
Now for the exciting part, what does the science target look like...<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='frequency',yaxis='amp',field='2',<br />
avgtime='1e8',avgscan=T,coloraxis='field',ydatacolumn='corrected',<br />
iteraxis='spw',xselfscale=T)<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
We see HCO+(4-3) in spw=0 and CO(3-2) in spw=2 as expected. Because the shape of the <br />
line profiles varies with baseline, you can already tell that the line emission is resolved.<br />
<br />
<figure id="X3c1_CO3_2_uvplot_3.4.png"><br />
[[Image:X3c1_CO3_2_uvplot_3.4.png|thumb|<caption>UV-Plot of the TW Hya CO(3-2) emission from the first dataset.</caption>]]<br />
</figure><br />
<figure id="X3c1_HCOp4_3_uvplot_3.4.png"><br />
[[Image:X3c1_HCOp4_3_uvplot_3.4.png|thumb|<caption>UV-Plot of the TW Hya HCO+(4-3) emission from the first dataset.</caption>]]<br />
</figure><br />
<br />
Now check that the velocity of TWHydra is correct in the LSRK frame, it should be around 2.88 km/s.<br />
* CO 3-2 rest freq 345.79599 GHz<br />
* HCO+ 4-3 rest freq 356.7342 GHz<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='2',xaxis='velocity',yaxis='amp',field='2',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',<br />
restfreq='345.79599GHz', plotrange=[-10,15,0,0],coloraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='0',xaxis='velocity',yaxis='amp',field='2',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',<br />
restfreq='356.7342GHz',plotrange=[-10,15,0,0],coloraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Both lines show up at the expected velocity.<br />
<br />
<br />
==Concatenate the Data==<br />
<br />
Here we will concatenate the three datasets prior to imaging.<br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
os.system('rm -rf Band7multi_april22.ms')<br />
concat(vis=splitdata,concatvis='Band7multi_april22.ms')<br />
</source><br />
<br />
If you like you can run listobs on new combined dataset<br />
<br />
<source lang="python"><br />
# In CASA<br />
listfile = 'Band7multi_april22.listobs.txt'<br />
os.system('rm ' + listfile)<br />
listobs(vis='Band7multi_april22.ms',verbose=F, listfile=listfile)<br />
</source><br />
<br />
<figure id="All_spw2_corrected_3.4.png"><br />
[[Image:All_spw2_corrected_3.4.png|thumb|<caption>Spectral UV-plots of 3C279 and Titan of spw=2 for the combined datasets.</caption>]]<br />
</figure><br />
<br />
You can also examine the spectral uv plots for the combined dataset to see the improvement in S/N: <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='Band7multi_april22.ms',spw='',xaxis='frequency',yaxis='amp',field='0,1',<br />
avgtime='1e8',avgscan=T,coloraxis='field',ydatacolumn='corrected',<br />
iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
<figure id="All_CO3_2_uvplot_3.4.png"><br />
[[Image:All_CO3_2_uvplot_3.4.png|thumb|<caption>UV-Plot of the TW Hya CO(3-2) emission from the combined datasets.</caption>]]<br />
</figure><br />
<br />
...and the CO line profile for the combined dataset: <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='Band7multi_april22.ms',spw='2',xaxis='velocity',yaxis='amp',field='2',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',restfreq='345.79599GHz',<br />
plotrange=[-10,15,0,0],coloraxis='spw')<br />
</source><br />
<br />
==Split Calibrated Data==<br />
<br />
Now we split off the calibrated data for the Science Target as well as the interesting parts of the calibrators for imaging.<br />
<br />
When we {{split}} off the Titan data, a few dozen warnings like the following are written to the log:<br />
<pre><br />
2012-05-15 22:00:35 WARN split::SubMS::copySource() Invalid SOURCE ID in SOURCE table row 20 <br />
</pre><br />
These can be ignored, because they do not indicate any problem that will prevent you from imaging Titan correctly at a single position using all the data in the output ms.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_corrected.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='TWHydra_corrected.ms',<br />
datacolumn='corrected',spw='',field='2')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf J1037_corrected.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='J1037_corrected.ms',<br />
datacolumn='corrected',spw='',field='4')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf J1147_corrected.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='J1147_corrected.ms',<br />
datacolumn='corrected',spw='',field='3')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3C279_CO3_2.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='3C279_CO3_2.ms',<br />
datacolumn='corrected',spw='2:1900~2000',field='0')<br />
</source><br />
<br />
==Optional: Reconcile Titan's Coordinates==<br />
<br />
If you do not care to image Titan, then you can skip this step and simply continue on to the [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_4.5 imaging guide].<br />
<br />
Our earlier treatment of Titan's coordinates using [http://casa.nrao.edu/stable/docs/TaskRef/fixplanets-task.html fixplanets] replaced the zeros written by the ALMA control system with the correct position of the body at the instant of the first observation of that SB. As a result, it has slightly different positions in all three datasets, as seen by listobs:<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='Band7multi_april22.ms',verbose=F)<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
ID Code Name RA Decl Epoch SrcId nRows <br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 70866 <br />
1 none Titan 12:49:25.97588 -02.22.41.3024 J2000 1 4842 <br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 515151 <br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 40797 <br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 171153 <br />
5 none Titan 12:49:26.53729 -02.22.27.1521 J2000 0 4833 <br />
6 none Titan 12:49:26.53059 -02.22.18.7878 J2000 0 4833 <br />
</pre><br />
<br />
If we want to image such moving objects observed across multiple SBs, we need to bring the positions into agreement, otherwise {{clean}} will try to make a mosaic. Task [http://casa.nrao.edu/stable/docs/TaskRef/fixplanets-task.html fixplanets] can be used to do this. Here, we set the direction to the direction of the first dataset as reported by listobs. Note that the RA/Dec format is slightly different from the {{listobs}} output format. Also, we do not<br />
fix the uvw coordinates because they are already more correct now than they would be if we "fixed" them.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fixplanets(vis='Band7multi_april22.ms', field='Titan', direction='J2000 12h49m25.97588 -02d22m41.3024', fixuvw=False)<br />
</source><br />
<br />
Check the header information again to see that the information for Titan has changed for the second<br />
and third datasets. They will appear as fields 5 and 6.<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='Band7multi_april22.ms',verbose=F)<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
ID Code Name RA Decl Epoch SrcId <br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 70866 <br />
1 none Titan 12:49:25.97588 -02.22.41.3024 J2000 1 4842 <br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 515151 <br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 40797 <br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 171153 <br />
5 none Titan 12:49:25.97588 -02.22.41.3024 J2000 0 4833 <br />
6 none Titan 12:49:25.97588 -02.22.41.3024 J2000 0 4833 <br />
</pre><br />
<br />
==Optional: Split Calibrated Titan Data==<br />
<br />
When we {{split}} off the Titan data, a few dozen warnings like the following are written to the log:<br />
<pre><br />
2012-05-15 22:00:35 WARN split::SubMS::copySource() Invalid SOURCE ID in SOURCE table row 20 <br />
</pre><br />
These can be ignored, because they do not indicate any problem that will prevent you from imaging Titan correctly at a single position using all the data in the output ms.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Titan_cont.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='Titan_cont.ms',<br />
datacolumn='corrected',spw='0',field='1')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Titan_CO3_2.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='Titan_CO3_2.ms',<br />
datacolumn='corrected',spw='2',field='1')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Titan_unknown.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='Titan_unknown.ms',<br />
datacolumn='corrected',spw='3',field='1')<br />
</source><br />
<br />
==Continue on to Imaging of the Science Target==<br />
<br />
Now you can continue on to the [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_4.5 imaging guide].<br />
<br />
{{Checked 4.5.0}}</div>Sstierwahttps://casaguides.nrao.edu/index.php?title=TWHydraBand7_Calibration_4.5&diff=19468TWHydraBand7 Calibration 4.52016-05-18T03:38:06Z<p>Sstierwa: </p>
<hr />
<div>[[Category:ALMA]][[Category:Calibration]][[Category:Spectral Line]]<br />
*'''This script assumes that you have downloaded TWHYA_BAND7_UnCalibratedMSAndTablesForReduction.tgz from [[TWHydraBand7#Getting_the_Data]]'''<br />
<br />
*'''An introduction to this data set is available at [[TWHydraBand7]].<br />
<br />
*'''This guide is designed for CASA 4.5.2 If you are using an older version of CASA please see [[TWHydraBand7_Calibration_4.3]].<br />
<br />
==Preparation==<br />
<br />
Once you have downloaded TWHYA_BAND7_UnCalibratedMSAndTablesForReduction.tgz, in a terminal unpack it with<br />
<br />
<source lang="bash"><br />
tar -zxvf TWHYA_BAND7_UnCalibratedMSAndTablesForReduction.tgz<br />
</source><br />
<br />
Please be aware that you will need about 100 GB of free space to do the data reduction. It is a good idea to check that now before you begin. Some of the plots described here require 9 GB of RAM; as little as 4 GB may be sufficient if additional data averaging is used when the plots are generated. When you are satisfied with the available drive space and memory on your machine:<br />
<br />
<source lang="bash"><br />
cd TWHYA_BAND7_UnCalibratedMSAndTablesForReduction<br />
</source><br />
<br />
'''NOTE: the calibration tables included in TWHYA_BAND7_UnCalibratedMSAndTablesForReduction CANNOT be used with CASA 4.5, they should be discarded, or moved out of the working directory.'''<br />
<br />
Then start CASA. <br />
<br />
<source lang="bash"><br />
casapy<br />
</source><br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.5. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.5.0'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
==Install Analysis Utilities==<br />
<br />
Analysis Utilities (or analysisUtils for short) is a small set of Python scripts that provide a number of analysis and plotting utilities for ALMA data reduction. This guide uses a few of these utilities. They are very easy to install (just download and untar). See <br />
<br />
http://casaguides.nrao.edu/index.php?title=Analysis_Utilities<br />
<br />
for a full description and download instructions. If you do not wish to do this, see the [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Calibration_for_CASA_3.3 CASA 3.3 version of the guide] for alternative (but slow) plotting options. Analysis Utilities are updated frequently so if its been a while since you installed it, its probably worth doing it again. If you are at an ALMA site or ARC, the analysis utilities are probably already installed and up to date.<br />
<br />
==Fix Titan's coordinates==<br />
<br />
'''Note that in the near future this step will be unnecessary.''' <br />
<br />
It is temporarily necessary to correct the positions of ephemeris objects observed during ALMA Cycle 0, because the control software revisions earlier than 9.0 erroneously write the data with coordinates of 00:00:00.0000 +00.00.00.0000 (J2000). For this dataset, we need to correct the position of the absolute flux calibrator Titan, as we can<br />
see from the first {{listobs}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -f X3c1.ms.listobs')<br />
listobs('X3c1.ms', verbose=T, listfile='X3c1.ms.listobs') <br />
</source><br />
<br />
You can view the listobs output files using command "less" from the CASA prompt.<br />
<br />
<pre style="background-color: #fffacd;"><br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 23625<br />
1 none Titan 00:00:00.00000 +00.00.00.0000 J2000 1 4842<br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 175176<br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 14832<br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 59877<br />
</pre><br />
<br />
To correct Titan's position, we will use the task [http://casa.nrao.edu/stable/docs/TaskRef/fixplanets-task.html fixplanets], which writes the actual coordinates at the instant of the first observation. This step takes a while because we are recalculating the uvw's accordingly.<br />
<source lang="python"><br />
# In CASA<br />
fixplanets(vis='X3c1.ms', field='Titan', fixuvw=True)<br />
</source><br />
<br />
Check the header information again with {{listobs}} to confirm that the information for Titan has changed:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -f X3c1.ms.listobs')<br />
listobs('X3c1.ms', verbose=T, listfile='X3c1.ms.listobs') <br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 23625<br />
1 none Titan 12:49:25.93349 -02.22.41.5638 J2000 1 4842<br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 175176<br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 14832<br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 59877<br />
</pre><br />
<br />
Now fix the other two measurement sets similarly:<br />
<source lang="python"><br />
# In CASA<br />
fixplanets(vis='X5d8.ms', field='Titan', fixuvw=True)<br />
fixplanets(vis='X7ef.ms', field='Titan', fixuvw=True)<br />
</source><br />
<br />
==Observing Log and Priors==<br />
<br />
Below is some information that may not be obvious from the data<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Like at most telescopes, the ALMA operators and astronomers at the site log any significant issues <br />
that were noticed from the online system during the observation. For these Band 7 observations of <br />
TW Hya on April 22, 2011, the only issue of note was that antenna DV04 could not observe at Band 7 <br />
and will need to be flagged. <br />
</pre><br />
<br />
First let's examine the basic properties of the data using {{listobs}}. Among other information we <br />
will be able to deduce what the source ids are and what each source was used for:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
3c279 is the bandpass calibrator (field id=0)<br />
Titan is the absolute flux calibrator (field id=1)<br />
J1147-382 is the secondary phase calibrator (field id=3)<br />
J1037-295 is the primary phase calibrator (field id=4)<br />
</pre><br />
<br />
<source lang="python"><br />
# In CASA<br />
data=['X3c1.ms','X5d8.ms','X7ef.ms']<br />
for vis in data:<br />
os.system('rm '+vis+'.listobs')<br />
listobs(vis, verbose=T, listfile=vis+'.listobs') <br />
</source><br />
<br />
You can view the {{listobs}} output files using command '''less''' from the CASA prompt. <br />
Below we copy select parts of the {{listobs}} output files for reference. <br />
<br />
<pre style="background-color: #fffacd;"><br />
X3c1.ms:<br />
Data records: 278352 Total integration time = 6109.06 seconds<br />
Observed from 22-Apr-2011/00:01:52.9 to 22-Apr-2011/01:43:42.0 (UTC)<br />
<br />
X5d8.ms:<br />
Data records: 278406 Total integration time = 5995.01 seconds<br />
Observed from 22-Apr-2011/01:48:05.8 to 22-Apr-2011/03:28:00.8 (UTC)<br />
<br />
X7ef.ms:<br />
Data records: 255717 Total integration time = 5407.49 seconds<br />
Observed from 22-Apr-2011/03:30:39.7 to 22-Apr-2011/05:00:47.2 (UTC)<br />
<br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 23625<br />
1 none Titan 12:49:25.97588 -02.22.41.3024 J2000 1 4842<br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 175176<br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 14832<br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 59877 <br />
<br />
SpwID #Chans Frame Ch1(MHz) ChanWid(kHz) TotBW(kHz) Corrs<br />
0 4 TOPO 184550 1500000 7500000 I<br />
1 128 TOPO 355740.062 15625 2000000 XX YY<br />
2 1 TOPO 356716.625 1796875 1796875 XX YY<br />
3 128 TOPO 356507.813 15625 2000000 XX YY<br />
4 1 TOPO 357484.375 1796875 1796875 XX YY<br />
5 128 TOPO 346792.187 15625 2000000 XX YY<br />
6 1 TOPO 345784.375 1796875 1796875 XX YY<br />
7 128 TOPO 345182.438 15625 2000000 XX YY<br />
8 1 TOPO 344174.625 1796875 1796875 XX YY<br />
9 128 TOPO 344386.763 15625 2000000 XX YY<br />
10 1 TOPO 343378.95 1796875 1796875 XX YY<br />
11 128 TOPO 346324.263 15625 2000000 XX YY<br />
12 1 TOPO 345316.45 1796875 1796875 XX YY<br />
13 128 TOPO 354402.388 15625 2000000 XX YY<br />
14 1 TOPO 355378.95 1796875 1796875 XX YY<br />
15 128 TOPO 356402.388 15625 2000000 XX YY<br />
16 1 TOPO 357378.95 1796875 1796875 XX YY<br />
17 3840 TOPO 356497.936 122.070312 468750 XX YY<br />
18 1 TOPO 356732.189 468750 468750 XX YY<br />
19 3840 TOPO 357734.314 122.070312 468750 XX YY<br />
20 1 TOPO 357499.939 468750 468750 XX YY<br />
21 3840 TOPO 346034.314 122.070312 468750 XX YY<br />
22 1 TOPO 345799.939 468750 468750 XX YY<br />
23 3840 TOPO 343955.936 122.070312 468750 XX YY<br />
24 1 TOPO 344190.189 468750 468750 XX YY<br />
<br />
Antennas: 9:<br />
Name Station Diam. Long. Lat.<br />
0 DV04 J505 12.0 m -067.45.18.0 -22.53.22.8<br />
1 DV06 T704 12.0 m -067.45.16.2 -22.53.22.1<br />
2 DV07 J510 12.0 m -067.45.17.8 -22.53.23.5<br />
3 DV08 T703 12.0 m -067.45.16.2 -22.53.23.9<br />
4 DV09 N602 12.0 m -067.45.17.4 -22.53.22.3<br />
5 DV10 N606 12.0 m -067.45.17.1 -22.53.23.6<br />
6 PM01 T702 12.0 m -067.45.18.6 -22.53.24.1<br />
7 PM02 T701 12.0 m -067.45.18.8 -22.53.22.2<br />
8 PM03 J504 12.0 m -067.45.17.0 -22.53.23.0<br />
</pre><br />
<br />
Things to Notice from above: <br />
*There are three different data sets acquired close together in time. We will calibrate each dataset independently and then combine the calibrated data prior to imaging. <br />
*Titan appears to have slightly different positions in each dataset because it is a moving body. In fact, at the time of observation, due to temporary data capture issue in the ALMA system, the position was written has (0,0). We have pre-corrected this error using fixplanets. Later in the tutorial, we will run fixplanets again to force all three datasets to have the same fixed position for Titan.<br />
*There are a lot of spectral windows! Don't be alarmed. In ALMA data, <br />
**spw=0 is always reserved for the water vapor radiometry data.<br />
**spw=9, 11, 13, 15 are the wideband (TDM) correlator mode with 128 channels per spw default settings for doing pointing and this is all they are used for in these data.<br />
**Currently Tsys data can only be taken in the wide (TDM) correlator mode with 128 channels per spw, these correspond to spws=1, 3, 5, 7 above. The frequencies of these TDM spws were carefully chosen so the the narrowband FDM spws fall within them.<br />
** The 0.5 GHz, high spectral resolution spws that contain all the real source data (science target and calibrators) are 17, 19, 21, and 23<br />
**For quicklook purposes, the ALMA online system produces a channel averaged spw for each channelized spw, these correspond to spw=2,4,6,8,10,12,14,16,18,20,22,24 and shouldn't be used for anything in post-processing as bandpass calibration etc has not been applied.<br />
<br />
In the portion of the {{listobs}} output that shows the timerange, the final column gives the scan intent. It is important to have a look at this because you can flag and do other operations in CASA using the scan intent as a selection option. Also, these intents will be used in the future for pipeline processing. You will usually want to use them to flag the CALIBRATE_POINTING* and CALIBRATE_ATMOS* (the latter correspond to the hot and cold load measurements used to calculate Tsys) data. This is essential for science or calibration data taken only in TDM (wide bandwidth) mode, i.e. the same mode that the pointing and Tsys data are taken in. For the current data however, that calibration data is recorded in different spws from the useful FDM (narrow bandwidth) data, so we'll be able to separate them by splitting them off at the final step prior to imaging.<br />
<br />
<figure id="Ant_pos.png"><br />
[[Image:Ant_pos.png|thumb|<caption>Antenna locations for the first dataset.</caption>]]<br />
</figure><br />
<br />
Before we move on, its also nice to get an idea where the antennas are with respect to each other. We can use {{plotants}} to plot their positions. It is a good idea to check each file since an antenna may have entered or exited the array between observations.<br />
<source lang="python"><br />
# In CASA<br />
for vis in data:<br />
plotants(vis=vis,figfile=vis+'.plotants.png')<br />
</source><br />
<br />
You can view the output images using any standard image viewer.<br />
<br />
==Create the Tsys and WVR Tables, and Examine ==<br />
<br />
Each ms include tables that contain the Tsys and WVR measurements associated with the visibility data.<br />
We must create calibration tables from these measurements. First we create the WVR calibration tables <br />
by running the task [http://casa.nrao.edu/stable/docs/TaskRef/wvrgcal-task.html wvrgcal]. This task <br />
examines the data for each ms as a whole and creates a calibration<br />
table containing only phase corrections for each antenna and spw. <br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
os.system('rm -rf '+asdm+'.wvr')<br />
wvrgcal(vis=asdm+'.ms', caltable=asdm+'.wvr', segsource=True, toffset=-1)<br />
</source><br />
<br />
Next we create the Tsys tables by running {{gencal}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
os.system('rm -rf '+asdm+'.tsys')<br />
gencal(vis=asdm+'.ms', caltable=asdm+'.tsys', caltype='tsys')<br />
</source><br />
<br />
It is very important that Tsys measurements taken as close in time and elevation as possible to a particular source are applied. To save telescope time, Tsys measurements are sometimes intentionally skipped in the scheduling block for specific sources. So the first step is to establish which sources have their own Tsys measurements and which do not. To do this, you may use the intent parameter of {{listobs}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
listobs(vis=asdm+'.ms', verbose=F, selectdata=True, intent='CALIBRATE_ATMOS*')<br />
</source><br />
<br />
<figure id="X3c1.tsys_vs_time_3.4.png"><br />
[[File:X3c1.tsys_vs_time_3.4.png|thumb|<caption>Tsys vs. time for spw 1 of the X3c1.ms data.</caption>]]<br />
</figure><br />
<figure id="X5d8.tsys_vs_time_3.4.png"><br />
[[File:X5d8.tsys_vs_time_3.4.png|thumb|<caption>Tsys vs. time for spw 1 of the X5d8.ms data.</caption>]]<br />
</figure><br />
<figure id="X7ef.tsys_vs_time_3.4.png"><br />
[[File:X7ef.tsys_vs_time_3.4.png|thumb|<caption>Tsys vs. time for spw 1 of the X7ef.ms data.</caption>]]<br />
</figure><br />
<br />
<pre style="background-color: #fffacd;"><br />
Fields: 4<br />
ID Code Name RA Decl Epoch SrcId nRows <br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 1116 <br />
1 none Titan 12:49:25.97588 -02.22.41.3024 J2000 1 1125 <br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 6795 <br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 6777 <br />
Spectral Windows: (9 unique spectral windows and 2 unique polarization setups)<br />
SpwID #Chans Frame Ch1(MHz) ChanWid(kHz) TotBW(kHz) Corrs <br />
0 4 TOPO 184550 1500000 7500000 I <br />
1 128 TOPO 355740.062 15625 2000000 XX YY <br />
2 1 TOPO 356716.625 1796875 1796875 XX YY <br />
3 128 TOPO 356507.813 15625 2000000 XX YY <br />
4 1 TOPO 357484.375 1796875 1796875 XX YY <br />
5 128 TOPO 346792.187 15625 2000000 XX YY <br />
6 1 TOPO 345784.375 1796875 1796875 XX YY <br />
7 128 TOPO 345182.438 15625 2000000 XX YY <br />
8 1 TOPO 344174.625 1796875 1796875 XX YY <br />
</pre><br />
<br />
Because field '3' (the secondary phase calibrator) does not appear in the list, it has no tsys. Since the secondary phase calibrator is close on the sky to the primary phase calibrator and observed near in time, we will transfer the Tsys from the primary to the secondary phase calibrator. <br />
Also notice that spws 1,3,5,7 are the only multi-channel spws that contain Tsys data. At present, Tsys measurements can only be obtained with TDM spectral setups (128 channels/dual pol). Because our science target is observed in FDM (3840 channels/dual pol), we will need to interpolate the measurements from TDM to FDM. But first, to inspect the Tsys vs. time, we use {{plotcal}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all = ['X3c1','X5d8','X7ef']<br />
tsysfields=['0','1','2','4']<br />
os.system('mkdir cal_plots; mkdir cal_plots/Tsys_plots') <br />
for asdm in basename_all:<br />
print "Plotting Tsys vs. time for "+asdm<br />
plotcal(caltable=asdm+'.tsys', xaxis='time',yaxis='tsys',<br />
antenna='1~8',plotrange=[0,0,100,500],<br />
iteration='antenna',subplot=421,poln='',spw='1:50~50',<br />
figfile='cal_plots/Tsys_plots/'+asdm+'.tsys_vs_time.png')<br />
if (asdm != basename_all[-1]):<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
To inspect Tsys vs. frequency, we use [[plotbandpass]]. There are many different options for plotbandpass, and we demonstrate some of the most useful ones. The option '''showtsky=T''' will overlay the effective temperature curve from the atmospheric model. This shows us the location of any atmospheric lines which will appear as emission lines in the autocorrelation data (from which the Tsys spectra are derived) from all antennas. In the<br />
example below, we set '''interactive=False''', which will produce many pages of plots as<br />
individual pngs but will only show the final page in the graphics window. To view all the pages we use the image viewer '''eog''' (Eye of GNOME) available on Linux. The alternative is to set '''interactive=True''' and examine the plots in the casa graphics window as they are produced.<br />
<br />
<figure id="X3c1.tsys.field0.DV04.spw1.t1.png"><br />
[[File:X3c1.tsys.field0.DV04.spw1.t1.png|thumb|<caption>Tsys vs. frequency on 3C279 for the X3c1.ms data, spw=1.</caption>]]<br />
</figure><br />
<figure id="X3c1.tsys.field0.DV04.spw3.t1.png"><br />
[[File:X3c1.tsys.field0.DV04.spw3.t1.png|thumb|<caption>Tsys vs. frequency on 3C279 for the X3c1.ms data, spw=3.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
print "Plotting Tsys vs. frequency for "+asdm<br />
for spw in [1,3,5,7]:<br />
for field in ['0','1']:<br />
plotbandpass(caltable=asdm+'.tsys', xaxis='freq',yaxis='amp',<br />
showtsky=T,subplot=42,field=field,<br />
spw=spw, interactive=False, plotrange=[0,0,0,0],<br />
figfile='cal_plots/Tsys_plots/'+asdm+'.tsys.field%s.png'%field,<br />
buildpdf=False)<br />
</source><br />
<br />
In <xr id="X3c1.tsys.field0.DV04.spw1.t1.png"/> and <xr id="X3c1.tsys.field0.DV04.spw3.t1.png"/> we see the effect of atmospheric ozone lines on the Tsys measurements associated with 3C279 in spw 1 and 3.<br />
<br />
For sources that have multiple Tsys measurements (typically the primary phase calibrator and/or the science target) one can use '''overlay="time"''' to overlay all the measurements for that source. This can help to identify any anomalous Tsys scans. As a fraction of the plots produced by this loop, here we show the Tsys recorded on spw=1 for TW Hya from the first dataset.<br />
<br />
<figure id="X3c1.tsys.field2.DV04.spw1.png"><br />
[[File:X3c1.tsys.field2.DV04.spw1.png|thumb|<caption>Tsys vs. freq for field 2, spw 1 of the X3c1.ms data (antennas 0..3).</caption>]]<br />
</figure><br />
<figure id="X3c1.tsys.field2.DV04.spw1.png"><br />
[[File:X3c1.tsys.field2.DV09.spw1.png|thumb|<caption>Tsys vs. freq for field 2, spw 1 of the X3c1.ms data (antennas 4..7).</caption>]]<br />
</figure><br />
<figure id="X3c1.tsys.field2.PM03.spw1.png"><br />
[[File:X3c1.tsys.field2.PM03.spw1.png|thumb|<caption>Tsys vs. freq for field 2, spw 1 of the X3c1.ms data (antenna 8).</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
print "Plotting Tsys vs. frequency for "+asdm<br />
for spw in [1,3,5,7]:<br />
for field in ['2','4']:<br />
plotbandpass(caltable=asdm+'.tsys', xaxis='freq',yaxis='amp',<br />
showtsky=T,subplot=22,field=field,<br />
overlay='time',spw=spw, interactive=False, plotrange=[0,0,0,0],<br />
figfile='cal_plots/Tsys_plots/'+asdm+'.tsys.field%s.png'%field,<br />
buildpdf = False)<br />
</source><br />
<br />
Alternatively, the '''overlay="antenna"''' option will quickly reveal any Antennas with discrepant Tsys values, as they<br />
will be obvious outliers. For FDM projects like this one, using the '''showfdm=True''' option can be helpful, as it<br />
will show where in the TDM bandpass each FDM spw was located. <br />
<figure id="X3c1.tsys.field0.spw1.t1.png"><br />
[[Image:X3c1.tsys.field0.spw1.t1.png|thumb|<caption>Tsys vs Freq for field 0, spw 1 of the X3c1.ms data with all antennas overlaid.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
tsysfields=['0','1','2','4'] <br />
basename_all = ['X3c1','X5d8','X7ef']<br />
for asdm in basename_all:<br />
print "Plotting Tsys vs. frequency for "+asdm<br />
for spw in [1,3,5,7]:<br />
for field in tsysfields:<br />
plotbandpass(caltable=asdm+'.tsys', xaxis='freq',yaxis='amp',<br />
showtsky=T,subplot=11,field=field,<br />
overlay='antenna',spw=spw, interactive=False,<br />
figfile='cal_plots/Tsys_plots/'+asdm+'.tsys.field%s.png'%field,<br />
buildpdf=False,showfdm=True)<br />
</source><br />
<br />
<br />
Note that DV04 consistently has a significantly higher Tsys than the rest of the antennas. We already know from the Observation log that<br />
we need to flag that antenna, but had we not had that information, examining this plot would have demonstrated the situation.<br />
<br />
==Apply the Tsys and WVR Tables, and Split ==<br />
<br />
Next we apply the calibrations. For the (4) sources with Tsys measurements, we use the '''field''' and '''gainfield''' parameters of {{applycal}} to apply solutions only to themselves. {{applycal}} has the ability to interpolate gain tables from one spw onto another spw. In this case, we want to interpolate the TDM Tsys values in spws 1,3,5,7 onto the FDM spws 17,19,21,23. We use the '''interp''' parameter to request linear interpolation in the time dimension and spline interpolation in the channel/frequency dimension. To map the solutions for each spw, we use the '''spwmap''' parameter, which requires a list of all spws for each gain table to be applied, or a blank list ([]) which is a shorthand notation to apply the solution for each spw to itself. While applying Tsys, we will also apply the wvr calibration tables; wvr data is usually always present for all sources. Below we first set some definitions so we can loop over the correct parameters:<br />
<br />
<source lang="python"><br />
# In CASA<br />
fdm='17,19,21,23'<br />
nocal='3' # This source had no Tsys measurements associated with it <br />
tsysfields=['0','1','2','4'] <br />
tsysmap = range(25)<br />
tsysmap[17] = 1<br />
tsysmap[19] = 3<br />
tsysmap[21] = 5<br />
tsysmap[23] = 7<br />
for asdm in basename_all:<br />
for field in tsysfields:<br />
applycal(vis=asdm+'.ms', spw=fdm, field=field, gainfield=field,<br />
gaintable=[asdm+'.tsys', asdm+'.wvr'], spwmap=[tsysmap,[]],<br />
interp=['linear,spline','nearest'], flagbackup=F, calwt=T)<br />
</source><br />
<br />
For the sources without Tsys (i.e. field=3), couple them with the best available source with Tsys (i.e. field=4).<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename_all:<br />
applycal(vis=asdm+'.ms', spw=fdm, field=nocal,<br />
gaintable=[asdm+'.tsys', asdm+'.wvr'], spwmap=[tsysmap,[]],<br />
gainfield=['4',nocal], interp=['linear,spline','nearest'],flagbackup=F,<br />
calwt=T)<br />
</source><br />
<br />
Check Tsys application with plotms. First we make plots with '''ydatacolumn='data'''' to look at the raw data. For <br />
simplicity we'll just look at the two strongest sources 3C279 and Titan.<br />
<br />
<figure id="X5d8_wvrtsys_corrected_spw19.png"><br />
[[Image:X5d8_wvrtsys_corrected_spw19.png|thumb|<caption>Spectral plots of 3C279 (black) and Titan (magenta) for spw=19 after Tsys and wvr correction.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X5d8.ms',spw='17,19,21,23',xaxis='frequency',yaxis='amp',field='0,1',<br />
antenna='*&*',avgtime='1e8',avgscan=T,coloraxis='field',iteraxis='spw',<br />
xselfscale=T,ydatacolumn='data')<br />
</source><br />
<br />
<figure id="X5d8_wvrtsys_corrected_spw21.png"><br />
[[Image:X5d8_wvrtsys_corrected_spw21.png|thumb|<caption>Spectral plots of 3C279 (black) and Titan (magenta) for spw=21 after Tsys and wvr correction.</caption>]]<br />
</figure><br />
<br />
'''Note''': the antenna='*&*' is specifying that we only want to see the cross-correlation data (i.e. not the autocorrelations).<br />
<br />
Use the '''green arrows''' on the {{plotms}} display to cycle through the 4 FDM spws. <br />
<br />
Now change '''Data Column''' to '''corrected''' on the "Axes" tab (this is the same as ydatacolumn in the task) and hit '''Plot''' button on the GUI. Flip through again.<br />
<br />
'''Things to notice:'''<br />
* The amplitude scale has changed due to application of Tsys<br />
* spw=17 is clean and flat<br />
* spw=19 shows a strong dip around channel 3000 (channels can be plotted by going to the Axes tab, and changing X Axis to Channel, then hit the Plot button)-- this is an atmospheric ozone absorption feature at 357.6 GHz. In the future, high spectral resolution Tsys measurements may help to remove the shape of the absorption, but until then we will need to flag this part of the spectrum.<br />
* spw=21 Titan shows both a narrow and a broad spectral feature. The broad feature is CO(3-2) and it completely fills the 0.5 GHz band so there are no line-free channels! Titan must be handled carefully when it is used as a calibrator because it contains strong line emission. Indeed, we will not be able to use the absolute flux transfer from this spw for other targets. When possible Titan should be avoided for absolute flux calibration. For these observations, no other suitable absolute flux calibrator was available.<br />
* spw=23 shows another strong line from Titan.<br />
<br />
Beyond these things to notice, the application of Tsys and wvr seem to have gone well. We can now split off only the narrow band FDM spectral windows for further processing.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename_all:<br />
newvis = asdm + '_wvrtsys.ms'<br />
os.system('rm -rf ' + newvis)<br />
split(vis=asdm+'.ms',outputvis=newvis,datacolumn='corrected',spw=fdm)<br />
</source><br />
<br />
'''Note''': After {{split}}, the spectral windows will be renumbered to 0, 1, 2, 3 corresponding to the old spw=17, 19, 21, 23, see {{listobs}} excerpt below.<br />
<br />
<pre style="background-color: #fffacd;"><br />
SpwID #Chans Frame Ch1(MHz) ChanWid(kHz) TotBW(kHz) Corrs <br />
0 3840 TOPO 356497.936 122.070312 468750 XX YY <br />
1 3840 TOPO 357734.314 122.070312 468750 XX YY <br />
2 3840 TOPO 346034.314 122.070312 468750 XX YY <br />
3 3840 TOPO 343955.936 122.070312 468750 XX YY <br />
</pre><br />
<br />
==Initial Inspection and Flagging==<br />
<br />
From here we begin to operate on the *wvrtsys.ms files. <br />
<br />
Before we begin flagging data, we unflag all data in the measurement sets. If this is your first pass through this section of the guide, no data in the measurement sets will be flagged, and you can skip this step. If you are rerunning the flagging commands below, this will reset your flag columns to their original state.<br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
for vis in splitdata:<br />
flagdata(vis=vis, mode='unflag', action='apply', flagbackup=F)<br />
</source><br />
<br />
ALMA data contains both the cross correlation and autocorrelation data. Presently nothing more can be done with the autocorrelation data so we flag it. Additionally, for smaller configurations of the array, and northerly sources one antenna can ''shadow'' another, blocking its view. This data also needs to be flagged. Finally, the observing log told us DV04 was not behaving properly at Band 7 and shouldn't be used so we flag that as well.<br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
for vis in splitdata:<br />
flagdata(vis=vis, mode='manual', autocorr=True, action = 'apply', flagbackup=T)<br />
flagdata(vis=vis, mode='shadow',tolerance=12.0, action='apply', flagbackup=F)<br />
flagdata(vis=vis, mode='manual', antenna='DV04', action='apply', flagbackup=F)<br />
</source><br />
<br />
Next we inspect the data with {{plotms}} for additional issues that need flagging, first looking at amplitude vs. time for each of the three datasets. Use the '''green''' arrows on the plotms gui to cycle through spws. <br />
<br />
<figure id="Tsyswvr_time_spw0_X3x1.png"><br />
[[Image:Tsyswvr_time_spw0_X3x1.png|thumb|<caption>Amplitude as a function of time for X3c1_wvrtsys.ms, spw=0</caption>]]<br />
</figure><br />
<br />
'''Note''': when '''iteraxis''' is invoked in {{plotms}}, unzoom does not always work properly. If you have trouble with this, flip to next page and then back to current one. This usually fixes the problem.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X5d8_wvrtsys.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X7ef_wvrtsys.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw')<br />
</source><br />
<br />
<figure id="Tsyswvr_time_spw2corr_X3x1.png"><br />
[[Image:Tsyswvr_time_spw2corr_X3x1.png|thumb|<caption>Amplitude as a function of time for X3x1_wvrtsys.ms, spw=2 with colorize='corr'.</caption>]]<br />
</figure><br />
<br />
'''Things to Notice:'''<br />
* In spw=2 there are some low points in all three data files. Use the "Mark Regions" box (left of center on bottom row of icons) to draw small box on low points. Then click the magnifying glass icon to the right of center. The output will be sent to the logger window. '''Note''': keep the marked region small or you can overwhelm the buffer. Locate suggests correlation YY on PM03 is the culprit. <br />
<br />
To see this more clearly you can rerun {{plotms}} with '''coloraxis='field'''' switched to '''coloraxis='corr''''<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='2',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='corr')<br />
</source><br />
<br />
To further check, you can exclude PM03 from the plot using '''antenna='!PM03'.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='2',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='corr',antenna='!PM03')<br />
</source><br />
<br />
Having confirmed the problem antenna, we flag it below. <br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
for vis in splitdata:<br />
flagdata(vis=vis, mode='manual', action= 'apply', flagbackup=T,<br />
spw='2',<br />
antenna='PM03',<br />
correlation='YY')<br />
</source><br />
<br />
'''Next we need to inspect the spectral properties of the data to look for issues.'''<br />
<br />
First we look at phase as a function of frequency for a well behaved antenna like DV06. <br />
'''coloraxis='baselines'''' (note this parameter is called '''Colorize''' in the GUI "Display" tab) will show each baseline as a different color. Significant delay errors or baseline errors will show up as phase slopes in these plots. Again you will want to page through the spectral windows.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='',xaxis='frequency',yaxis='phase',field='0',antenna='DV06',<br />
avgtime='1e8',avgscan=T,coloraxis='baseline',iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X5d8_wvrtsys.ms',spw='',xaxis='frequency',yaxis='phase',field='0',antenna='DV06',<br />
avgtime='1e8',avgscan=T,coloraxis='baseline',iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X7ef_wvrtsys.ms',spw='',xaxis='frequency',yaxis='phase',field='0',antenna='DV06',<br />
avgtime='1e8',avgscan=T,coloraxis='baseline',iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
Overall these plots look good with no large delays or baseline errors apparent.<br />
<br />
<figure id="Birdies_spw2_X3x1.png"><br />
[[Image:Birdies_spw2_X3x1.png|thumb|<caption>Phase calibrators (brown and green) and TW Hya (orange) showing both real CO(3-2) emission in TW Hya and weak ''birdie'' spectral features in all three sources for spw=2.</caption>]]<br />
</figure><br />
<br />
With such high spectral resolution data, one often sees occasional "birdies" in the data. These are typically very narrow weak spectral features that are internally generated in the system. Over time as we track down issues the number of birdies should decrease, but you should always check. This is easiest to do by looking at amplitude vs. frequency for sources observed over a long time range (for sensitivity). It is helpful to look at more than one source to verify the nature of the emission. Below we look at both calibrators (brown and green) and TW Hya (orange). If you have enough sensitivity birdies should be seen on all sources, however, be careful not to mistake real line emission for a birdie even on a calibrator - they can be present as we've seen for Titan.<br />
<br />
<figure id="Birdies_spw3_X3x1.png"><br />
[[Image:Birdies_spw3_X3x1.png|thumb|<caption>Phase calibrators (brown and green) and TW Hya (orange) showing only weak birdie spectral features in spw=3.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',spw='',xaxis='channel',yaxis='amp',field='2,3,4',<br />
avgtime='1e8',avgscan=T,coloraxis='field',iteraxis='spw',xselfscale=T,yselfscale=T)<br />
</source><br />
<br />
Do a quick check that other two datasets are the same (they are usually similar if the source of internal resonance hasn't changed in the meantime).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X5d8_wvrtsys.ms',spw='',xaxis='channel',yaxis='amp',field='2,3,4',<br />
avgtime='1e8',avgscan=T,coloraxis='field',iteraxis='spw',xselfscale=T,yselfscale=T)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X7ef_wvrtsys.ms',spw='',xaxis='channel',yaxis='amp',field='2,3,4',<br />
avgtime='1e8',avgscan=T,coloraxis='field',iteraxis='spw',xselfscale=T,yselfscale=T)<br />
</source><br />
<br />
Now you can zoom in on each region to get channels for flagging, or to save time just go ahead and run the flagging command below where this has been done for you.<br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
for vis in splitdata:<br />
flagdata(vis=vis, mode='manual', action='apply', flagbackup=T,<br />
spw='0:1067~1068;1279~1280;2367~2368;3775~3776, 1:1279~1280;2367~2368;3775~3776, 2:1279~1280;3775~3776, 3:831~832;1535~1536;2367~2368;3775~3776;3839~3839')<br />
</source><br />
<br />
Replot in {{plotms}} to check that flagging has been done as anticipated.<br />
<br />
==Flag Calibrator Spectral Features==<br />
<br />
In this section, we will flag spectral features in the calibrators so they do not skew the calibration solutions. First make plots of 3C279 and Titan in channel space to get channels for flagging. <br />
<br />
<figure id="3C279_Titan_spw1.png"><br />
[[Image:3C279_Titan_spw1.png|thumb|<caption>Spectral plots of 3C279 (black) and Titan (magenta) for spw=1 after Tsys and wvr correction.</caption>]]<br />
</figure><br />
<figure id="3c279_meso_freq.png"><br />
[[Image:3c279_meso_freq.png|thumb|<caption>Zoomed spectral plot of 3C279 showing mesospheric absorption of CO(3-2) in frequency space.</caption>]]<br />
</figure><br />
<figure id="3c279_meso_chann.png"><br />
[[Image:3c279_meso_chann.png|thumb|<caption>Zoomed spectral plot of 3C279 showing mesospheric absorption of CO(3-2) in channel space.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='channel',yaxis='amp',field='0,1',<br />
avgtime='1e8',coloraxis='field',iteraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
The figure to the right shows a broad absorption line in spw 1 at channel 3000. This is the ozone absorption line at 357.62982 GHz. However, there is another narrow absorption feature in the spectra (spw 2) that is most easily seen on 3C279 (because it is the strongest calibrator). Let's look at it first in frequency space.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='2:1600~2300',xaxis='frequency',yaxis='amp',<br />
field='0',avgtime='1e8',coloraxis='field')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
The absorption feature lies exactly at the rest frequency for CO 3-2 (345.79599 GHz). Because it is so narrow (< 1 MHz), it must originate from a very low pressure region (i.e. high altitude) in the Earth's atmosphere, otherwise it would be more pressure broadened. Indeed, the first detection of CO in the mesosphere was made over 35 years ago (see, e.g. [http://adsabs.harvard.edu/abs/1976Sci...191.1174W Waters et al. 1976] or [http://adsabs.harvard.edu/abs/1979JGR....84..416G Goldsmith et al. 1979]). Be aware that the line is stronger as you go up the CO ladder (strength ~ J^3 for low J) because the temperature at that altitude (~50km) is about 250 K. In April 2011, the apparent depth of the feature was about 10% in the 2-1 line and 35% in the 3-2 line. However, the depth of the absorption feature is exaggerated due to the way ALMA normalizes the cross-correlation spectra by the autocorrelation spectra prior to storage. While this technique generally leads to a flat bandpass shape, it will accentuate telluric features because they are emission lines in the single dish spectrum (e.g. JCMT observations of mesospheric CO 3-2 can be found in [http://adsabs.harvard.edu/abs/1993MNRAS.264..673P Preston et al. 1993]). Finally, note that large seasonal variations in the line strength have been reported from observations at [http://adsabs.harvard.edu/abs/2003GeoRL..30j..39F Onsala]. <br />
<br />
Now, let's re-plot the line with channel number as the x-axis in order to get the channel range for flagging. <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='2:1600~2300',xaxis='channel',yaxis='amp',<br />
field='0',avgtime='1e8',coloraxis='field')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Now lets look at Titan in more detail.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='channel',yaxis='amp',field='1',<br />
avgtime='1e8',coloraxis='field',iteraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Explicitly back up the flag tables so that flagged regions can be restored later.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
flagmanager(vis=asdm+'.ms',mode='save',versionname=asdm+'.before_calspectralflags')<br />
</source><br />
<br />
<figure id="Titan_spw2.png"><br />
[[Image:Titan_spw2.png|thumb|<caption>Spectral plot of Titan (magenta) for spw=2.</caption>]]<br />
</figure><br />
<br />
Flag absorption features for all sources.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
print "Flagging absorption features in all sources for "+asdm<br />
flagdata(vis=asdm+'.ms', mode='manual', spw='1:2000~3839, 2:1945~1960')<br />
</source><br />
<br />
<figure id="Titan_spw3.png"><br />
[[Image:Titan_spw3.png|thumb|<caption>Spectral plot of Titan (magenta) for spw=3.</caption>]]<br />
</figure><br />
<br />
Now we need to flag emission. The very broad CO(3-2) in spw=2 of Titan will prevent us from using it as a calibrator for this spectral window since there are no line-free channels (we will transfer, phase, amplitude, and absolute flux from another Titan spw below). We do want to flag the narrower Titan line in spw=3.<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
flagmanager(vis=asdm+'.ms',mode='save',versionname=asdm+'.before_emissionflags')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
print "Flagging emission for "+asdm<br />
flagdata(vis=asdm+'.ms', mode='manual', <br />
field='1',<br />
spw='3:1000~3000')<br />
</source><br />
<br />
If you like, check that the right things have been flagged.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='channel',yaxis='amp',field='0,1',<br />
avgtime='1e8',coloraxis='field',iteraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
==Set Up the Flux Calibrator Model==<br />
<br />
Fill the model data column for Titan with a model for the flux density as a function of baseline. The model is a uniformly illuminated disk with the size obtained from the JPL Horizons ephemeris.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
setjy(vis=asdm+'.ms',field='1',usescratch=F,<br />
standard='Butler-JPL-Horizons 2010',scalebychan=F)<br />
</source><br />
<br />
<figure id="Titan amp vs uvdist.png"><br />
[[Image:Titan amp vs uvdist.png|thumb|<caption>Plot of Titan model for each of the 4 spws. We used the Butler-JPL-Horizons 2010 standard to compute this model.</caption>]]<br />
</figure><br />
<br />
After running setjy, it is a good idea to plot the model in order to confirm that it makes sense. In this case, Titan is partially resolved, so we expect the flux density to drop with uv distance, but not so much as to pass through a null. We also expect it to be brighter at higher frequencies since it has a thermal blackbody spectrum.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',field='1',xaxis='uvdist',yaxis='amp',coloraxis='spw',<br />
ydatacolumn='model')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<figure id="twhydra_X3c1_wvrtsys_2012_titan_model.png">[[File:twhydra_X3c1_wvrtsys_2012_titan_model.png|thumb|right|<caption>Titan model produced by 'Butler-JPL-Horizons 2012'.</caption>]]</figure><br />
<br />
<br/><br />
<div class="noprint" style="float:none; border:0px solid blue;background-color:#F6CEF5;padding:2px;"><br />
The setjy invocation, above, uses the flux density standard '''standard='Butler-JPL-Horizons 2010' '''. A more updated standard is also available: '''standard='Butler-JPL-Horizons 2012' '''. <xr id="twhydra_X3c1_wvrtsys_2012_titan_model.png"/> shows the Titan model produced using the updated standard. The motivated reader may wish to rerun {{setjy}} using the updated model. We will highlight later in this tutorial, and in the imaging tutorial that follows, the effects of using the updated model.<br />
</div><br />
<br />
==Bandpass Calibration==<br />
<br />
First we need to check how the amplitude and phase of 3C279 behave as a function of time. In order to set<br />
a fixed scale on the y-axis, we first make a plot of all the data, excluding antenna DV04. (We must specify '''ydatacolumn='data' ''' explicitly here because the default value of '''ydatacolumn''' equals the value used in the previous execution of {{plotms}}. In the previous execution '''ydatacolumn''' was set to '''model'''. See the online help, <tt>help plotms</tt>, for details.)<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='X3c1_wvrtsys.ms',xaxis='time',yaxis='amp',coloraxis='corr',<br />
field='0',avgchannel='3840',ydatacolumn='data')<br />
</source><br />
<br />
<figure id="ThreeScansAmp.png"><br />
[[Image:ThreeScansAmp.png|thumb|<caption>Amplitude variation for three 3C279 scans, spw 0 (for one representative baseline).</caption>]]<br />
</figure><br />
<br />
We see that the uncalibrated amplitudes range between 0.2-0.4, so let's set this as our<br />
scale and examine a representative baseline (DV06-DV07) to see how the amplitude changes with time. <br />
<br />
<source lang="python"><br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for spw in ['0','1','2','3']:<br />
for asdm in basename:<br />
print "Now showing spw %s from %s" % (spw, asdm+'.ms')<br />
plotms(vis=asdm+'.ms',spw=spw,xaxis='time',yaxis='amp',coloraxis='corr',iteraxis='spw',<br />
field='0',avgchannel='3840',antenna='DV06&DV07',plotrange=[0,0,0.2,0.4])<br />
user_check=raw_input('press enter to go to the next plot\n')<br />
</source><br />
<br />
<figure id="ThreeScansPhase.png"><br />
[[Image:ThreeScansPhase.png|thumb|<caption>Phase variation for three 3C279 scans, spw 0 (for one representative baseline).</caption>]]<br />
</figure><br />
<br />
Page through the measurement sets for each spw. This shows significant variations in the amplitude across the three measurement sets.<br />
Now do the same with phase.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for spw in ['0','1','2','3']:<br />
for asdm in basename:<br />
print "Now showing spw %s from %s" % (spw, asdm+'.ms')<br />
plotms(vis=asdm+'.ms',spw=spw,xaxis='time',yaxis='phase',coloraxis='corr',iteraxis='spw',<br />
field='0',avgchannel='3840',antenna='DV06&DV07',plotrange=[0,0,-180,180])<br />
user_check=raw_input('press enter to go to the next plot\n')<br />
</source><br />
<br />
This examination reveals two findings: (1) significant variation in the phase across the three scans, as well as (2) smaller but significant variations within a scan. The first finding suggests that we do not want to combine the scans for bandpass calibration, but instead derive an independent bandpass for each scan. Actually what is more important than a DC offset is if the '''shape''' of the amplitude or phase changes from scan to scan. There isn't enough S/N to tell for sure so we will keep them separate. This situation is often the case, which is why we did not concatenate the three datasets prior to calibration. The second finding suggests that we need to correct the phase vs. time behavior of the bandpass calibrator (3C279; field=0) within each scan, before doing the bandpass. We want to chose a relatively narrow range of channels near the center of the spws so that the bandpass phase slopes (to be corrected with the bandpass calibration itself) do not decorrelate the signal. You need to avoid spectral regions that were completely flagged above.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.bpphase.gcal')<br />
gaincal(vis=asdm+'.ms',caltable=asdm+'.bpphase.gcal',<br />
field='0',spw='0~3:900~1100',refant='DV06',<br />
calmode='p',solint='int',minsnr=2.0,minblperant=4)<br />
</source><br />
<br />
<figure id="X7ef_wvrtsys.bpphase.X.png"><br />
[[Image:X7ef_wvrtsys.bpphase.X.png|thumb|<caption>Phase only solutions for correlation X on the third scan of the bandpass calibrator 3C279.</caption>]]<br />
</figure><br />
<br />
Inspect the phase-only calibration solutions for the bandpass calibrator. Look for any noisy solutions. We do XX and YY separately to reduce confusion in the plot. It will help if you make your plotcal window wide.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.bpphase.gcal',xaxis='time',yaxis='phase',spw='',antenna='1~8', <br />
iteration='antenna',subplot=421,plotrange=[0,0,-180,180],<br />
figfile=asdm+'.bpphase.X.png',poln='X')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
In the plotcal gui you can use the magnifying glass symbol to zoom in on one of the scans to see the phase variations. The colors are the 4 different spws.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.bpphase.gcal',xaxis='time',yaxis='phase',spw='',antenna='1~8', <br />
iteration='antenna',subplot=421,plotrange=[0,0,-180,180],<br />
figfile=asdm+'.bpphase.Y.png',poln='Y')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Next we apply this phase-only correction on the fly while calculating the bandpass solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.bandpass.bcal')<br />
bandpass(vis=asdm+'.ms',caltable=asdm+'.bandpass.bcal',<br />
field='0',spw='',combine='',refant='DV06',<br />
solint='inf',solnorm=T,minblperant=4, bandtype='B', fillgaps=17,<br />
gaintable=asdm+'.bpphase.gcal')<br />
</source><br />
<br />
You will see some error messages in the terminal, these are just related to the flagged channels. We set fillgaps=17 to interpolate across the smaller regions of flagged channels (mesospheric features and birdies).<br />
<br />
<figure id="Bandpass.ampspw0.png"><br />
[[Image:Bandpass.ampspw0.png|thumb|<caption>Bandpass amplitude solution plots.</caption>]]<br />
</figure><br />
<figure id="Bandpass.phasespw0.png"><br />
[[Image:Bandpass.phasespw0.png|thumb|<caption>Bandpass phase solution plots.</caption>]]<br />
</figure><br />
<br />
'''A few words about solint and combine:'''<br />
<br />
In {{bandpass}}, the use of '''solint='inf'''' (as in "infinite") will derive a bandpass<br />
solution for each 3C279 scan, '''unless''' '''combine='scan'''' (which is the default). Here we set combine=' ' explicitly so that it does not combine the scans into one bandpass. Likewise, field boundaries are only crossed if combine='field', and spw boundaries are only crossed if combine='spw'. In some cases it can be helpful to combine fields if you suffer from lack of S/N, but it is never a good idea to combine spws. <br />
<br />
Now inspect the phase and amplitude solutions. You are looking for excursions from smooth fits, or particularly noisy solutions compared to the others. <br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
for spw in [0,1,2,3]:<br />
plotbandpass(asdm+'.bandpass.bcal',xaxis='freq',yaxis='amp', spw=spw,<br />
antenna='1~8', subplot=42, figfile=asdm+'.bandpass.amp', showatm=T,<br />
interactive=True)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
for spw in [0,1,2,3]:<br />
plotbandpass(asdm+'.bandpass.bcal',xaxis='freq',yaxis='phase',spw=spw,<br />
antenna='1~8',subplot=42,figfile=asdm+'.bandpass.phs', showatm=T,<br />
interactive=True)<br />
</source><br />
<br />
The values of phase on DV06 are very close to zero because it was used as the reference antenna.<br />
<br />
==Gain Calibration==<br />
<br />
Now that we have a bandpass solution to apply we can solve for the antenna-based phase and amplitude gain calibration. Since the phase changes on a much shorter timescale than the amplitude, we will solve for them separately. In particular, if the phase changes significantly over a scan time, the amplitude would be decorrelated, if the un-corrected phase were averaged over this timescale. Note that we re-solve for the gain solutions of the bandpass calibrator, so we can derive new solutions that are corrected for the bandpass shape. Since the bandpass calibrator will not be used again, this is not strictly necessary, but is useful to check its calibrated flux density for example. <br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.intphase.gcal')<br />
gaincal(vis=asdm+'.ms',caltable=asdm+'.intphase.gcal',<br />
field='0,1,3,4',spw='0~3:40~3800',refant='DV06',<br />
calmode='p',solint='int',minsnr=2.0,minblperant=4,<br />
gaintable=[asdm+'.bandpass.bcal'])<br />
</source><br />
<br />
Here '''solint='int' ''' coupled with '''calmode='p' ''' will derive a single phase solution for each 10 second integration. Note that the bandpass table is applied on-the-fly before solving for the phase solutions, however the bandpass is NOT applied to the data permanently until applycal is run later on. <br />
<br />
Although '''solint='int' ''' (i.e. the integration time of 10 seconds) is the best choice to apply before solving for the amplitude solutions, it is not a good idea to use this to apply to the target. This is because the phase-scatter within a scan can dominate the interpolation between calibrator scans. Instead, we also solve for the phase on the scan time, '''solint='inf' ''' (but '''combine=' ' ''', since we want one solution per scan) for application to the target later on. Unlike the bandpass task, for {{gaincal}}, the default of the combine parameter is '''combine=' ' '''. <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.scanphase.gcal')<br />
gaincal(vis=asdm+'.ms',caltable=asdm+'.scanphase.gcal',<br />
field='0,1,3,4',spw='0~3:40~3800',refant='DV06',<br />
calmode='p',solint='inf',minsnr=2.0,minblperant=4,<br />
gaintable=[asdm+'.bandpass.bcal'])<br />
</source><br />
<br />
Alternatively, instead of making a separate phase solution for application to the target, one can also run {{smoothcal}} to smooth the solutions derived on the integration time. <br />
<br />
Next we apply the bandpass and '''solint='int' ''' phase-only calibration solutions on-the-fly to derive amplitude solutions. Here the use of '''solint='inf' ''', but '''combine=' ' ''' will result in one solution per scan interval. <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.amp.gcal')<br />
gaincal(vis=asdm+'.ms',caltable=asdm+'.amp.gcal',<br />
field='0,1,3,4',spw='0~3:40~3800',refant='DV06',<br />
calmode='ap',solint='inf',minsnr=2.0,minblperant=4,<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal'])<br />
</source><br />
<br />
Now carefully inspect all these solutions looking for discrepant solutions. If you see any, you will need to flag them and rerun the calibration tasks above. <br />
<br />
We make plots in X and Y separately for clarity. The colors are showing the spectral windows.<br />
<figure id="X3c1_wvrtsys.intphase_X.png"><br />
[[Image:X3c1_wvrtsys.intphase_X.png|thumb|<caption>Phase solutions for the X polarization for every integration time of the first dataset.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.intphase.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',iteration='antenna',subplot=421,<br />
plotrange=[0,0,-180,180],poln='X',figfile=asdm+'.intphase_X.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.intphase.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',iteration='antenna',subplot=421,<br />
plotrange=[0,0,-180,180],poln='Y',figfile=asdm+'.intphase_Y.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<figure id="X3c1_wvrtsys.scanphase_X.png"><br />
[[Image:X3c1_wvrtsys.scanphase_X.png|thumb|<caption>Phase solutions for the X polarization for each scan of the first dataset.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.scanphase.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',iteration='antenna',subplot=421,<br />
plotrange=[0,0,-180,180],poln='X',figfile=asdm+'.scanphase_X.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.scanphase.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',iteration='antenna',subplot=421,<br />
plotrange=[0,0,-180,180],poln='Y',figfile=asdm+'.scanphase_Y.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Since we have taken out the phase as best we can by applying the '''solint='int' ''' phase-only solution, this plot will give a good idea of the residual phase error. If you see scatter of more than a few degrees here, you should consider going back and looking for more data to flag, particularly bad timeranges etc. <br />
<br />
<figure id="X3c1_wvrtsys.amp_phase.png"><br />
[[Image:X3c1_wvrtsys.amp_phase.png|thumb|<caption>Residual phase after applying intphase.gcal for both correlations in the first dataset.</caption>]]<br />
</figure><br />
<figure id="X3c1_wvrtsys.amp_X.png"><br />
[[Image:X3c1_wvrtsys.amp_X.png|thumb|<caption>Amplitude solutions on a scan interval for correlation X in the first dataset.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.amp.gcal',xaxis='time',yaxis='phase',antenna='1~8', <br />
spw='',field='0,1,3,4',plotrange=[0,0,-1,1],<br />
iteration='antenna',subplot=421,figfile=asdm+'.amp_phase.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
These are very small, as they should be. Now look at the amplitude solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.amp.gcal',xaxis='time',yaxis='amp',antenna='1~8', <br />
iteration='antenna',subplot=421,spw='',poln='X',<br />
plotrange=[0,0,0.0,0.3],figfile=asdm+'.amp_X.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.amp.gcal',xaxis='time',yaxis='amp',antenna='1~8', <br />
iteration='antenna',subplot=421,spw='',poln='Y',<br />
plotrange=[0,0,0.0,0.3],figfile=asdm+'.amp_Y.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
==Flux Calibration==<br />
<br />
Next we use the flux calibrator (whose flux density was set in {{setjy}} above) to derive the flux density of the other calibrators. Note that the flux table REPLACES the amp.gcal in terms of future application of the calibration to the data, i.e. the flux table contains both the amp.gcal and flux scaling. Unlike the gain calibration steps, this is not an incremental table.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
os.system('rm -rf ' + asdm + '.flux.cal')<br />
fluxscale(vis=asdm+'.ms',caltable=asdm+'.amp.gcal',<br />
fluxtable=asdm+'.flux.cal',reference='1',refspwmap=[0,1,3,3],<br />
listfile=asdm+'.fluxscale.txt')<br />
</source><br />
<br />
Its a good idea to record the derived fluxscale values using the listfile option. The values can also be viewed in the Log Messages window.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Found reference field(s): Titan<br />
Found transfer field(s): 3c279 J1147-382=QSO J1037-295=QSO<br />
Spw=2 will be referenced to spw=3<br />
Flux density for 3c279 in SpW=0 (freq=3.56498e+11 Hz) is: 10.537 +/- 0.0183518 (SNR = 574.169, N = 16)<br />
Flux density for 3c279 in SpW=1 (freq=3.57734e+11 Hz) is: 10.6933 +/- 0.0264134 (SNR = 404.842, N = 16)<br />
Flux density for 3c279 in SpW=2 (freq=3.46034e+11 Hz) (ref SpW=3) is: 10.251 +/- 0.0477949 (SNR = 214.479, N = 14)<br />
Flux density for 3c279 in SpW=3 (freq=3.43956e+11 Hz) is: 9.91798 +/- 0.020167 (SNR = 491.791, N = 16)<br />
Flux density for J1147-382=QSO in SpW=0 (freq=3.56498e+11 Hz) is: 1.03399 +/- 0.0167344 (SNR = 61.7887, N = 16)<br />
Flux density for J1147-382=QSO in SpW=1 (freq=3.57734e+11 Hz) is: 0.844817 +/- 0.0191013 (SNR = 44.2283, N = 16)<br />
Flux density for J1147-382=QSO in SpW=2 (freq=3.46034e+11 Hz) (ref SpW=3) is: 0.987193 +/- 0.024391 (SNR = 40.4737, N = 14)<br />
Flux density for J1147-382=QSO in SpW=3 (freq=3.43956e+11 Hz) is: 1.28859 +/- 0.0194364 (SNR = 66.298, N = 16)<br />
Flux density for J1037-295=QSO in SpW=0 (freq=3.56498e+11 Hz) is: 0.968281 +/- 0.00895224 (SNR = 108.161, N = 16)<br />
Flux density for J1037-295=QSO in SpW=1 (freq=3.57734e+11 Hz) is: 0.75916 +/- 0.015366 (SNR = 49.4053, N = 16)<br />
Flux density for J1037-295=QSO in SpW=2 (freq=3.46034e+11 Hz) (ref SpW=3) is: 0.948551 +/- 0.0165421 (SNR = 57.3416, N = 14)<br />
Flux density for J1037-295=QSO in SpW=3 (freq=3.43956e+11 Hz) is: 1.21905 +/- 0.0139967 (SNR = 87.0956, N = 16)<br />
Fitted spectrum for 3c279 with fitorder=1: Flux density = 10.2962 +/- 0.0450319 (freq=351.002 GHz) spidx=1.70757 +/- 0.245737<br />
Fitted spectrum for J1147-382=QSO with fitorder=1: Flux density = 1.06853 +/- 0.0709817 (freq=351.002 GHz) spidx=-6.77353 +/- 3.71867<br />
Fitted spectrum for J1037-295=QSO with fitorder=1: Flux density = 1.01822 +/- 0.0654586 (freq=351.002 GHz) spidx=-6.28977 +/- 3.71453<br />
Storing result in X7ef_wvrtsys.flux.cal<br />
Writing solutions to table: X7ef_wvrtsys.flux.cal<br />
</pre><br />
<br />
<figure id="x3c1_wvrtsys.flux_X.png"><br />
[[Image:x3c1_wvrtsys.flux_X.png|thumb|<caption>Absolute flux calibration solutions for correlation X for the first dataset.</caption>]]<br />
</figure><br />
<br />
<div class="noprint" style="float:none; border:0px solid blue;background-color:#F6CEF5;padding:2px;"><br />
If you used the updated (Butler-JPL-Horizons 2012) flux density standard when you ran {{setjy}} earlier in this tutorial, the derived flux values for the calibrators will be slightly different. For example, when averaged over the 3 measurement sets, 3c279 in spectral window 0 has a flux of 10.77 Jy using the 2010 standard and 10.63 Jy using the 2012 standard; as a second example, J1147-382 in SPW 3 has an average flux of 1.13 Jy (2010 standard) and 1.15 Jy (2012 standard). <br />
</div><br />
<br />
Now look at the flux solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.flux.cal',xaxis='time',yaxis='amp',antenna='1~8', <br />
iteration='antenna',subplot=421,spw='',poln='X',<br />
plotrange=[0,0,0.0,0.3],figfile=asdm+'.flux_X.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotcal(caltable=asdm+'.flux.cal',xaxis='time',yaxis='amp',antenna='1~8', <br />
iteration='antenna',subplot=421,spw='',poln='Y',<br />
plotrange=[0,0,0.0,0.3],figfile=asdm+'.flux_Y.png')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
==Apply Calibration and Inspect==<br />
<br />
Now we can use the {{flagmanager}} if we want to restore any of the spectral flagging we did prior to bandpass calibration. <br />
In this case, we choose to restore the flags of the emission lines on Titan, because we are interested in seeing how<br />
strong they are compared to the continuum. However, we leave the strong ozone line and mesospheric CO line flagged on all <br />
sources, because we want to get the most accurate continuum flux density for the science target. <br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=["X3c1_wvrtsys","X5d8_wvrtsys","X7ef_wvrtsys"]<br />
for asdm in basename:<br />
flagmanager(vis=asdm+'.ms',mode='restore',versionname=asdm+'.before_emissionflags')<br />
</source><br />
<br />
Next we apply the calibration solutions to each source individually, using the '''gainfield''' parameter to specify which calibrator's solutions should be applied from each of the '''gaintable''' calibration tables. <br />
<br />
First, we do 3C279 (the bandpass calibrator), applying all 3 of its solutions to itself (that's why gainfield contains three zeros):<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='0',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['0','0','0'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
Next, we do Titan (the absolute flux calibrator) using the bandpass solution from 3C279:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='1',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['0','1','1'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
For the secondary phase calibrator, we apply the phase and flux solutions from the primary phase calibrator. This will allow us to check how well the phase transfer to the science target (TW Hya) has worked:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='3',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.scanphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','linear','linear'],<br />
gainfield=['0','4','4'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
Next is the Primary phase calibrator:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='4',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['0','4','4'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
Finally, for the Science Target TW Hya, we apply the phase solutions from both the primary and secondary phase calibrators:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='2',<br />
interp=['nearest','linear','linear'],<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.scanphase.gcal',asdm+'.flux.cal'],<br />
gainfield=['0','3,4','3,4'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
Now we can check the results of applying the calibration solutions.<br />
<br />
<figure id="Corrected_vs_time_1.png"><br />
[[Image:Corrected_vs_time_1.png|thumb|<caption>The calibrated data for the first dataset (amplitude vs. time).</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw',ydatacolumn='corrected')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
In amplitude, it looks good but there are some noisy points toward the end of the first scheduling block, but it mostly only affects the secondary phase calibrator (green). In phase, we expect all the points to cluster about zero. The large scatter in phase on the secondary phase calibrator is readily apparent: <br />
<br />
<figure id="Corrected_phase_vs_time_1.png"><br />
[[Image:Corrected_phase_vs_time_1.png|thumb|<caption>The calibrated data on the calibrators for the first dataset (phase vs. time).</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='time',yaxis='phase',field='0,1,3,4',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw',ydatacolumn='corrected')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Let's check whether the situation improves when we apply this calibrator's solutions to itself rather than transferring the solutions from the primary phase calibrator (which is 17 degrees away, and observed at a different time). <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='3',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['0','3','3'],flagbackup=T, calwt=T)<br />
</source><br />
<br />
<figure id="Corrected_vs_time_1_field3.png"><br />
[[Image:Corrected_vs_time_1_field3.png|thumb|<caption>The calibrated data for the first dataset (amplitude vs. time), but now with field 3, the secondary phase calibrator, calibrated with itself.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',iteraxis='spw',ydatacolumn='corrected')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<figure id="Corrected_phase_vs_time_1_field3.png"><br />
[[Image:Corrected_phase_vs_time_1_field3.png|thumb|<caption>The calibrated data from the first dataset (phase vs. time), but now with field 3, the secondary phase calibrator, calibrated with itself.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='time',yaxis='phase',field='0,1,3,4',<br />
avgchannel='3840', coloraxis='field',iteraxis='spw',<br />
ydatacolumn='corrected')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Indeed, the secondary calibrator looks better now in amplitude and phase. This is an indication that the calibration transfer is not working well in this timerange. Because the effect is not catastrophic and we know we can self-calibrate on TW Hya later, we will let this go for now. Or, if you want you can delve deeper into the data and try to solve the mystery... <br />
<br />
In any case, we will re-issue the original {{applycal}} so that it is this calibration that our subsequent {{split}} will use. This will allow us to check the effect of correcting the secondary phase calibrator with the primary phase calibrator later. <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
applycal(vis=asdm+'.ms',field='3',<br />
gaintable=[asdm+'.bandpass.bcal', asdm+'.scanphase.gcal', asdm+'.flux.cal'],<br />
interp=['nearest','linear','linear'],<br />
gainfield=['0','4','4'], flagbackup=T, calwt=F)<br />
</source><br />
<br />
<br />
Let's check the spectral calibration now. First 3C279 and Titan:<br />
<br />
<figure id="X3c1_spw2_corrected_3.4.png"><br />
[[Image:X3c1_spw2_corrected_3.4.png|thumb|<caption>Spectral UV-plots of 3C279 and Titan of spw=2 for the first dataset.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='frequency',yaxis='amp',field='0,1',<br />
avgtime='1e8',avgscan=T,coloraxis='field',ydatacolumn='corrected',<br />
iteraxis='spw',xselfscale=T)<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Flip through the spws. These look good. Next the two phase calibrators:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='frequency',yaxis='amp',field='3,4',<br />
avgtime='1e8',avgscan=T,coloraxis='field',ydatacolumn='corrected',<br />
iteraxis='spw',xselfscale=T)<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Flip through the spws. This also looks good, the secondary phase calibrator is a bit noisier but this is normal. The upswing at the lower frequency end of spw=3 will probably need to be flagged on the science target as well. It corresponds to the edge of an atmospheric feature.<br />
<br />
Now for the exciting part, what does the science target look like...<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='',xaxis='frequency',yaxis='amp',field='2',<br />
avgtime='1e8',avgscan=T,coloraxis='field',ydatacolumn='corrected',<br />
iteraxis='spw',xselfscale=T)<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
We see HCO+(4-3) in spw=0 and CO(3-2) in spw=2 as expected. Because the shape of the <br />
line profiles varies with baseline, you can already tell that the line emission is resolved.<br />
<br />
<figure id="X3c1_CO3_2_uvplot_3.4.png"><br />
[[Image:X3c1_CO3_2_uvplot_3.4.png|thumb|<caption>UV-Plot of the TW Hya CO(3-2) emission from the first dataset.</caption>]]<br />
</figure><br />
<figure id="X3c1_HCOp4_3_uvplot_3.4.png"><br />
[[Image:X3c1_HCOp4_3_uvplot_3.4.png|thumb|<caption>UV-Plot of the TW Hya HCO+(4-3) emission from the first dataset.</caption>]]<br />
</figure><br />
<br />
Now check that the velocity of TWHydra is correct in the LSRK frame, it should be around 2.88 km/s.<br />
* CO 3-2 rest freq 345.79599 GHz<br />
* HCO+ 4-3 rest freq 356.7342 GHz<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='2',xaxis='velocity',yaxis='amp',field='2',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',<br />
restfreq='345.79599GHz', plotrange=[-10,15,0,0],coloraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename:<br />
plotms(vis=asdm+'.ms',spw='0',xaxis='velocity',yaxis='amp',field='2',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',<br />
restfreq='356.7342GHz',plotrange=[-10,15,0,0],coloraxis='spw')<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
Both lines show up at the expected velocity.<br />
<br />
<br />
==Concatenate the Data==<br />
<br />
Here we will concatenate the three datasets prior to imaging.<br />
<br />
<source lang="python"><br />
# In CASA<br />
splitdata=['X3c1_wvrtsys.ms','X5d8_wvrtsys.ms','X7ef_wvrtsys.ms']<br />
os.system('rm -rf Band7multi_april22.ms')<br />
concat(vis=splitdata,concatvis='Band7multi_april22.ms')<br />
</source><br />
<br />
If you like you can run listobs on new combined dataset<br />
<br />
<source lang="python"><br />
# In CASA<br />
listfile = 'Band7multi_april22.listobs.txt'<br />
os.system('rm ' + listfile)<br />
listobs(vis='Band7multi_april22.ms',verbose=F, listfile=listfile)<br />
</source><br />
<br />
<figure id="All_spw2_corrected_3.4.png"><br />
[[Image:All_spw2_corrected_3.4.png|thumb|<caption>Spectral UV-plots of 3C279 and Titan of spw=2 for the combined datasets.</caption>]]<br />
</figure><br />
<br />
You can also examine the spectral uv plots for the combined dataset to see the improvement in S/N: <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='Band7multi_april22.ms',spw='',xaxis='frequency',yaxis='amp',field='0,1',<br />
avgtime='1e8',avgscan=T,coloraxis='field',ydatacolumn='corrected',<br />
iteraxis='spw',xselfscale=T)<br />
</source><br />
<br />
<figure id="All_CO3_2_uvplot_3.4.png"><br />
[[Image:All_CO3_2_uvplot_3.4.png|thumb|<caption>UV-Plot of the TW Hya CO(3-2) emission from the combined datasets.</caption>]]<br />
</figure><br />
<br />
...and the CO line profile for the combined dataset: <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='Band7multi_april22.ms',spw='2',xaxis='velocity',yaxis='amp',field='2',<br />
avgtime='1e8',avgscan=T,transform=T,freqframe='LSRK',restfreq='345.79599GHz',<br />
plotrange=[-10,15,0,0],coloraxis='spw')<br />
</source><br />
<br />
==Split Calibrated Data==<br />
<br />
Now we split off the calibrated data for the Science Target as well as the interesting parts of the calibrators for imaging.<br />
<br />
When we {{split}} off the Titan data, a few dozen warnings like the following are written to the log:<br />
<pre><br />
2012-05-15 22:00:35 WARN split::SubMS::copySource() Invalid SOURCE ID in SOURCE table row 20 <br />
</pre><br />
These can be ignored, because they do not indicate any problem that will prevent you from imaging Titan correctly at a single position using all the data in the output ms.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf TWHydra_corrected.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='TWHydra_corrected.ms',<br />
datacolumn='corrected',spw='',field='2')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf J1037_corrected.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='J1037_corrected.ms',<br />
datacolumn='corrected',spw='',field='4')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf J1147_corrected.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='J1147_corrected.ms',<br />
datacolumn='corrected',spw='',field='3')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3C279_CO3_2.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='3C279_CO3_2.ms',<br />
datacolumn='corrected',spw='2:1900~2000',field='0')<br />
</source><br />
<br />
==Optional: Reconcile Titan's Coordinates==<br />
<br />
If you do not care to image Titan, then you can skip this step and simply continue on to the [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_4.5 imaging guide].<br />
<br />
Our earlier treatment of Titan's coordinates using [http://casa.nrao.edu/stable/docs/TaskRef/fixplanets-task.html fixplanets] replaced the zeros written by the ALMA control system with the correct position of the body at the instant of the first observation of that SB. As a result, it has slightly different positions in all three datasets, as seen by listobs:<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='Band7multi_april22.ms',verbose=F)<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
ID Code Name RA Decl Epoch SrcId nRows <br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 70866 <br />
1 none Titan 12:49:25.97588 -02.22.41.3024 J2000 1 4842 <br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 515151 <br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 40797 <br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 171153 <br />
5 none Titan 12:49:26.53729 -02.22.27.1521 J2000 0 4833 <br />
6 none Titan 12:49:26.53059 -02.22.18.7878 J2000 0 4833 <br />
</pre><br />
<br />
If we want to image such moving objects observed across multiple SBs, we need to bring the positions into agreement, otherwise {{clean}} will try to make a mosaic. Task [http://casa.nrao.edu/stable/docs/TaskRef/fixplanets-task.html fixplanets] can be used to do this. Here, we set the direction to the direction of the first dataset as reported by listobs. Note that the RA/Dec format is slightly different from the {{listobs}} output format. Also, we do not<br />
fix the uvw coordinates because they are already more correct now than they would be if we "fixed" them.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fixplanets(vis='Band7multi_april22.ms', field='Titan', direction='J2000 12h49m25.97588 -02d22m41.3024', fixuvw=False)<br />
</source><br />
<br />
Check the header information again to see that the information for Titan has changed for the second<br />
and third datasets. They will appear as fields 5 and 6.<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='Band7multi_april22.ms',verbose=F)<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
ID Code Name RA Decl Epoch SrcId <br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 70866 <br />
1 none Titan 12:49:25.97588 -02.22.41.3024 J2000 1 4842 <br />
2 none TW Hya 11:01:51.84498 -34.42.17.1609 J2000 2 515151 <br />
3 none J1147-382=QSO 11:47:01.38151 -38.12.11.1179 J2000 3 40797 <br />
4 none J1037-295=QSO 10:37:16.08989 -29.34.02.9888 J2000 4 171153 <br />
5 none Titan 12:49:25.97588 -02.22.41.3024 J2000 0 4833 <br />
6 none Titan 12:49:25.97588 -02.22.41.3024 J2000 0 4833 <br />
</pre><br />
<br />
==Optional: Split Calibrated Titan Data==<br />
<br />
When we {{split}} off the Titan data, a few dozen warnings like the following are written to the log:<br />
<pre><br />
2012-05-15 22:00:35 WARN split::SubMS::copySource() Invalid SOURCE ID in SOURCE table row 20 <br />
</pre><br />
These can be ignored, because they do not indicate any problem that will prevent you from imaging Titan correctly at a single position using all the data in the output ms.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Titan_cont.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='Titan_cont.ms',<br />
datacolumn='corrected',spw='0',field='1')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Titan_CO3_2.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='Titan_CO3_2.ms',<br />
datacolumn='corrected',spw='2',field='1')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Titan_unknown.ms')<br />
split(vis='Band7multi_april22.ms',outputvis='Titan_unknown.ms',<br />
datacolumn='corrected',spw='3',field='1')<br />
</source><br />
<br />
==Continue on to Imaging of the Science Target==<br />
<br />
Now you can continue on to the [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_4.5 imaging guide].<br />
<br />
{{Checked 4.5.0}}</div>Sstierwa