{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "name": "visibilities_import_export.ipynb", "provenance": [], "collapsed_sections": [], "toc_visible": true } }, "cells": [ { "cell_type": "markdown", "metadata": { "id": "mucRwpac0ECv" }, "source": [ "# Visibilities Import Export \n", "\n", "\n", "To use CASA to process your data, you first will need to get it into a form that is understood by the package. These are \"MeasurementSets\" for synthesis and single dish data, which is the purpose of this chapter. Importing images, or \"image tables\" as understood by CASA, is explained [here](image_analysis.ipynb#Image-Import/Export).\n", "\n", "There are a number of tasks used to fill telescope-specific data and to import/export standard formats. These are:\n", "\n", "- **importasdm** --- import of ALMA data in ASDM format\n", "- **importuvfits** --- import visibility data in UVFITS format\n", "- **importfitsidi** --- import visibility data in the FITS-IDI format\n", "- **importvla** --- import data from VLA that is in export format\n", "- **importmiriad** --- import data from MIRIAD visibilities\n", "- **importatca** --- import ATCA data that is in the RPFITS (archive) format\n", "- **importgmrt** --- import GMRT data\n", "- **importasap** --- convert ASAP (ATNF Spectral Analysis Package) into a CASA visibility data format\n", "- **importnro** --- import NRO 45m data \n", "- **exportasdm** --- convert a CASA MS into an ASDM\n", "- **exportuvfits** --- export a CASA MS in UVFITS format\n", "\n", "\n", "\n", "***\n", "\n", "\n", "\n" ] }, { "cell_type": "markdown", "metadata": { "id": "Sf8a4cr90ECx" }, "source": [ "## UV Data Import \n", "\n", "Converting Telescope UV Data to a MeasurementSet\n", "\n", "There are a number of tasks available to bring data in various forms into CASA as a MeasurementSet:\n", "\n", "- ALMA and VLA Science Data Model format via **importasdm** and **importevla**\n", "- historic VLA Archive format data via **importvla**\n", "- ATCA Data via **importatca**\n", "- MIRIAD Data from various telescopes via **importmiriad**\n", "- GMRT Data via **importgmrt**\n", "- UVFITS format can be imported into and exported from CASA (**importuvfits**, **importfitsidi**, and **exportuvfits**)\n", "\n", "\n", "*ALMA and VLA Filling of Science Data Model (ASDM) data*\n", "\n", "The ALMA and JVLA projects have agreed upon a common archival science data model (ASDM; sometimes also called SDM) format, and have jointly developed the software to fill this data into CASA. In the ASDM format, the bulk of the data is contained in large binary data format (BDF) tables, with the meta-data and ancillary information in XML tables. This is structured as a directory, like the MS, and was designed to be similar to the MS to facilitate conversion.\n", "\n", "The content of an ASDM can be listed with the task **asdmsummary**:\n", "\n", "```\n", "#asdmsummary :: Summarized description of an ASDM dataset.\n", "asdm = '' #Name of input ASDM directory\n", "```\n", "\n", "with an output that contains the list and positions of the antennas, followed by the metadata of each scan like observation time, source name, frequency and polarization setup:\n", "\n", "```python\n", "Input ASDM dataset : TDEM0008.sb3373760.eb3580330.55661.22790537037\n", "========================================================================================\n", "ASDM dataset :TDEM0008.sb3373760.eb3580330.55661.22790537037\n", "========================================================================================\n", "\n", "Exec Block : ExecBlock_0\n", "Telescope : JVLA\n", "Configuration name : B\n", "Observer name : Dr. Juergen Ott\n", "The exec block started on 2011-04-10T05:28:13.200000000 and ended on 2011-04-10T10:27:12.300000256\n", "\n", "27 antennas have been used in this exec block.\n", " Id Name Make Station Diameter X Y Z\n", " Antenna_0 ea01 UNDEFINED W36 25 -1606841.96 -5042279.689 3551913.017\n", " Antenna_1 ea02 UNDEFINED E20 25 -1599340.8 -5043150.965 3554065.219\n", " Antenna_2 ea03 UNDEFINED E36 25 -1596127.728 -5045193.751 3552652.421\n", " Antenna_3 ea04 UNDEFINED W28 25 -1604865.649 -5042190.04 3552962.365\n", " Antenna_4 ea05 UNDEFINED W08 25 -1601614.091 -5042001.653 3554652.509\n", " Antenna_5 ea06 UNDEFINED N24 25 -1600930.06 -5040316.397 3557330.397\n", " Antenna_6 ea07 UNDEFINED E32 25 -1597053.116 -5044604.687 3553058.987\n", " Antenna_7 ea08 UNDEFINED N28 25 -1600863.684 -5039885.318 3557965.319\n", " Antenna_8 ea09 UNDEFINED E24 25 -1598663.09 -5043581.392 3553767.029\n", " Antenna_9 ea10 UNDEFINED N32 25 -1600781.039 -5039347.456 3558761.542\n", " Antenna_10 ea11 UNDEFINED E04 25 -1601068.79 -5042051.91 3554824.835\n", " Antenna_11 ea12 UNDEFINED E08 25 -1600801.926 -5042219.366 3554706.448\n", " Antenna_12 ea14 UNDEFINED W12 25 -1602044.903 -5042025.824 3554427.832\n", " Antenna_13 ea15 UNDEFINED W24 25 -1604008.742 -5042135.828 3553403.707\n", " Antenna_14 ea16 UNDEFINED N12 25 -1601110.052 -5041488.079 3555597.439\n", " Antenna_15 ea17 UNDEFINED W32 25 -1605808.656 -5042230.082 3552459.202\n", " Antenna_16 ea18 UNDEFINED N16 25 -1601061.961 -5041175.88 3556058.022\n", " Antenna_17 ea19 UNDEFINED W04 25 -1601315.893 -5041985.32 3554808.305\n", " Antenna_18 ea20 UNDEFINED N36 25 -1600690.606 -5038758.734 3559632.061\n", " Antenna_19 ea21 UNDEFINED E12 25 -1600416.51 -5042462.45 3554536.041\n", " Antenna_20 ea22 UNDEFINED N04 25 -1601173.979 -5041902.658 3554987.518\n", " Antenna_21 ea23 UNDEFINED E16 25 -1599926.104 -5042772.967 3554319.789\n", " Antenna_22 ea24 UNDEFINED W16 25 -1602592.854 -5042054.997 3554140.7\n", " Antenna_23 ea25 UNDEFINED N20 25 -1601004.709 -5040802.809 3556610.133\n", " Antenna_24 ea26 UNDEFINED W20 25 -1603249.685 -5042091.404 3553797.803\n", " Antenna_25 ea27 UNDEFINED E28 25 -1597899.903 -5044068.676 3553432.445\n", " Antenna_26 ea28 UNDEFINED N08 25 -1601147.94 -5041733.837 3555235.956\n", "\n", "Number of scans in this exec Block : 234\n", "\n", "scan #1 from 2011-04-10T05:28:13.200000000 to 2011-04-10T05:33:35.500000256\n", " Intents : OBSERVE_TARGET\n", " Sources : 1331+305=3C286\n", " Subscan #1 from 2011-04-10T05:28:13.200000000 to 2011-04-10T05:33:35.500000256\n", " Intent : UNSPECIFIED\n", " Number of integrations : 322\n", "\n", " Binary data in uid:///evla/bdf/1302413292901\n", " Number of integrations : 322\n", " Time sampling : INTEGRATION\n", " Correlation Mode : CROSS_AND_AUTO\n", " Spectral resolution type : FULL_RESOLUTION\n", " Atmospheric phase correction : AP_UNCORRECTED\n", " SpectralWindow_0 : numChan = 256, frame = TOPO,\n", " firstChan = 8484000000, chandWidth = 125000 x Polarization_0 : corr = RR,LL\n", "\n", "scan #2 from 2011-04-10T05:33:35.500000256 to 2011-04-10T05:35:35.200000000\n", " Intents : OBSERVE_TARGET\n", " Sources : 1331+305=3C286\n", " Subscan #1 from 2011-04-10T05:33:35.500000256 to 2011-04-10T05:35:35.200000000\n", " Intent : UNSPECIFIED\n", " Number of integrations : 119\n", "\n", " Binary data in uid:///evla/bdf/1302413293280\n", " Number of integrations : 119\n", " Time sampling : INTEGRATION\n", " Correlation Mode : CROSS_AND_AUTO\n", " Spectral resolution type : FULL_RESOLUTION\n", " Atmospheric phase correction : AP_UNCORRECTED\n", " SpectralWindow_0 : numChan = 256, frame = TOPO,\n", " firstChan = 8484000000, chandWidth = 125000 x Polarization_0 : corr = RR,LL\n", "\n", "scan #3 from 2011-04-10T05:35:35.200000000 to 2011-04-10T05:36:34.999999488\n", " Intents : OBSERVE_TARGET\n", " Sources : 1331+305=3C286\n", " Subscan #1 from 2011-04-10T05:35:35.200000000 to 2011-04-10T05:36:34.999999488\n", "...\n", "```\n", "\n", "The **importasdm** task will fill SDM format data from ALMA and the JVLA into a CASA visibility data set (MS). All SDM formats from version 2 to the current version can be filled by **importasdm**. \n", "\n", "The default inputs of **importasdm** are:\n", "\n", "```\n", "# importasdm -- Convert an ALMA Science Data Model observation into a\n", "# CASA visibility file (MS)\n", "asdm = '' # Name of input asdm directory (on\n", " # disk)\n", "vis = '' # Root name of the MS to be created.\n", " # Note the .ms is NOT added\n", "createmms = False # Create a multi-MS output\n", "corr_mode = 'all' # specifies the correlation mode to be\n", " # considered on input. A quoted string\n", " # containing a sequence of ao, co,\n", " # ac,or all separated by whitespaces\n", " # is expected\n", "srt = 'all' # specifies the spectral resolution\n", " # type to be considered on input. A\n", " # quoted string containing a sequence\n", " # of fr, ca, bw, or all separated by\n", " # whitespaces is expected\n", "time_sampling = 'all' # specifies the time sampling\n", " # (INTEGRATION and/or SUBINTEGRATION)\n", " # to be considered on input. A quoted\n", " # string containing a sequence of i,\n", " # si, or all separated by whitespaces\n", " # is expected\n", "ocorr_mode = 'ca' # output data for correlation mode\n", " # AUTO_ONLY (ao) or CROSS_ONLY (co) or\n", " # CROSS_AND_AUTO (ca)\n", "compression = False # Flag for turning on data compression\n", "lazy = False # Make the MS DATA column read the ASDM\n", " # Binary data directly (faster import,\n", " # smaller MS)\n", "asis = '' # Creates verbatim copies of the\n", " # ASDMtables in the ouput MeasurementSet.\n", " # Value given must be a string\n", " # of table names separated by spaces;\n", " # A * wildcard is allowed.\n", "wvr_corrected_data = 'no' # Specifies which values are considerd\n", " # in the SDM binary data to fill the\n", " # DATA column in the MAIN table of the\n", " # MS; yes for corrected, no for \n", " # uncorrected, both for corrected and \n", " # uncorrected (resulting in two MSs) \n", "scans = '' # Processes only the specified scans.\n", " # A scan specification consists of an \n", " # exec block index followed by the :\n", " # character, followed by a comma\n", " # separated list of scan indexes or\n", " # scan index ranges.\n", " # (e.g. 0:1;1:2~6,8;2:,3:24~30), \n", "ignore_time = False # All the rows of the tables Feed,\n", " # History, Pointing, Source, SysCal,\n", " # CalDevice, SysPower, and Weather are\n", " # processed independently of the time\n", " # range of the selected exec\n", " # block / scan.\n", "process_syspower = True # Process the SysPower table? \n", "process_caldevice = True # Process the CalDevice table? \n", "process_pointing = True # Process the Pointing table? \n", "process_flags = True # Create online flags in the FLAG_CMD\n", " # sub-table? \n", " tbuff = 0.0 # Time padding buffer (seconds)\n", " applyflags = False # Apply the flags to the MS.\n", " savecmds = False # Save flag commands to an ASCII file\n", " outfile = '' # Name of ASCII file to save flag\n", " # commands\n", "flagbackup = True # Back up flag column before applying\n", " # flags.\n", "verbose = False # Output lots of information while the\n", " # filler is working\n", "overwrite = False # Over write an existing MS(s)\n", "bdfflags = False # Set the MS FLAG column according to\n", " # the ASDM _binary_ flags\n", "with_pointing_correction = False # Add (ASDM::Pointing::encoder -\n", " # ASDM::Pointing::pointingDirection)\n", " # to the value to be written in\n", " # MS::Pointing::direction\n", "convert_ephem2geo = True # if True, convert any attached\n", " # ephemerides to the GEO reference\n", " # frame (time-spacing not changed)\n", "polyephem_tabtimestep = 0.0 # Timestep (days) for the tabulation \n", " # of polynomial ephemerides. \n", " # A value <= 0 disables tabulation. \n", "```\n", "\n", "If *scans* is set, then **importasdm** processes only the scans specified in the option's value. This value is a semicolon separated list of scan specifications. A scan specification consists of an exec block index followed by the character ':' followed by a comma separated list of scan indexes or scan index ranges. A scan index is relative to the exec block it belongs to. Scan indexes are 1-based while exec blocks are 0-based. The expressions\n", "\n", "```\n", " \"0:1\"\n", " \"2:2~6\"\n", " \"0:1,1:2~6,8;2:,3:24~30\"\n", " \"1,2\"\n", " \"3:\"\n", "```\n", "\n", "are all valid values for the [selection](visibility_data_selection.ipynb). The \\\"3:\\\" selector will be interpreted as 'all the scans of the exec block 3'. A scan index or a scan index range not preceded by an exec block index will be interpreted as 'all the scans with such indexes in all the exec blocks'. By default all the scans are considered.\n", "\n", "When *process_flags=True* the task will create online flags based on the Flag.xml, Antenna.xml and SpectralWindow.xml files and copy them to the *FLAG_CMD* sub-table of the MS. The flags will NOT be applied unless the parameter *applyflags* is set to *True*. Optionally, the flags can also be saved to an external ASCII file if savecmds is set to *True*. The flags can later be applied to the MS using task **flagdata** in *list* mode.\n", "\n", "When *bdfflags=True* the task will apply online flags contained in the ASDM BDF data by calling the executable bdflags2MS which the user can also do from the OS prompt. This is recommended for ALMA data.\n", "\n", "The option *createmms* prepares the output file for [parallel processing](parallel-processing.ipynb) and creates a [multi-MS](parallel-processing.ipynb#the-multi-ms).\n", "\n", " \n", "\n", "**Specifics on importing Janksy VLA data with importasdm**\n", "\n", "As of CASA 5.4, the task importevla is no longer available to import JVLA data, but a lot of its functionality is replaced by importasdm. However, several additional steps are required to duplicate the behaviour of importevla when using importasdm, involving a difference in default parameters and the fact that some of the on-the-go flagging cannot be performed by importasdm.\n", "\n", "To mimic the behaviour of importevla, change the following parameters in **importasdm** from their default settings:\n", "\n", "- *ocorr_mode = \\'co\\'* to import cross-correlations only (discarding auto-correlations)* *\n", "- *with_pointing_correction = True* to add pointing corrections* *\n", "- *process_flags = True* (default) to read in the online flags, then *applyflags = True* to apply the online flags and/or *savecmd = True* to save flag commands to an ascii table.\n", "- For ephemeris objects: convert_ephem2geo = False\n", "\n", "While online flags can thus be created by leaving the parameter *process_flags = True* by default, additional flagging steps need to be performed after **importasdm** to flag zero values and shadowing of antennas:\n", "\n", "- **Shadow flags:** use task **flagdata**, with *mode = \\'shadow\\'* (and optionally *reason = \\'shadow\\'*). The parameters *tolerance* and *addantenna* can be specified in flagdata in the same way they were used in importevla. * *\n", "- **Zero clipping flags:** use task **flagdata**, with ***mode = \\'clip\\',*** *correlation = \\'ABS_ALL\\',* and *clipzeros = True* (and optionally *reason = \\'clip\\'*)*.* Note that the non-default case in importevla where *flagpol = False c*an be replicated by setting *correlation=\\\"ABS_RR, ABS_LL\\\".*\n", "\n", "Like **importasdm**, the task **flagdata** can also save the flagging commands to an ascii table by setting *savepars = True.* To NOT apply the flags (*applyflags=False* in importevla) add *action=\\'calculate\\'* to flagdata. You may also chose to add a reason using the cmdreason argument, e.g. *cmdreason=\\\"CLIP_ZERO_ALL\\\".*\n", "\n", "