4. Exporting visibilities¶
-
uvplot.io.export_uvtable(uvtable_filename, tb, vis='', split_args=None, split=None, channel='all', dualpol=True, fmt='%10.6e', datacolumn='CORRECTED_DATA', keep_tmp_ms=False, verbose=True)¶ Export visibilities from an MS Table to a uvtable. Requires execution inside CASA.
Currently the only uvtable format supported is ASCII.
Typicall call signature:
export_uvtable('uvtable_new.txt', tb, channel='all', split=split, split_args={'vis': 'sample.ms', 'datacolumn': 'DATA', 'spw':'0,1'}, verbose=True)
- Parameters
uvtable_filename (str) – Filename of the output uvtable, e.g. “uvtable.txt”
tb (CASA
tbobject) – As tb parameter you must pass the tb object that is defined in the CASA shell. Since tb cannot be accessed outside CASA, export_uvtable(‘uvtable.txt’, tb, …) can be executed only inside CASA.vis (str, optional) – MS Table filename, e.g. mstable.ms
split_args (dict, optional) – Default is None. If provided, perform a split before exporting the uvtable. The split_args dictionary is passed to the CASA::split task. The CASA::split task must be provided in input as split.
split (optional) – CASA split task
channel (str, optional) – If ‘all’, all channels are exported; if ‘first’ only the first channel of each spectral window (spw) is exported. Number of channels in each spw must be equal, otherwise you will get a CASA error, e.g.:
RuntimeError: ArrayColumn::getColumn cannot be done for column DATA; the array shapes vary: Table array conformance errorDefault is ‘all’.dualpol (bool, optional) – If the MS Table contains dual polarisation data. Default is True.
fmt (str, optional) – Format of the output ASCII uvtable.
datacolumn (str, optional) – Data column to be extracted, e.g. “DATA”, “CORRECTED_DATA”, “MODEL_DATA”.
keep_tmp_ms (bool, optional) – If True, keeps the temporary outputvis created by the split command.
verbose (bool, optional) – If True, print informative messages. Default: True
Note
By default, all the spws and all the channels of the
visMS table are exported. To export only the first channel in each spw, set channel=’first’.To export only some spws provide split_args, e.g.:
split_args = {'vis': 'input.ms', 'outputvis': 'input_tmp.ms', spw: '1,2'}
Flagged data can be removed from the .ms by providing
splitand thesplit_argsdictionary, e.g.:split_args = {'vis': 'input.ms', 'outputvis': 'input_tmp.ms', 'keepflags': False}
If you try exporting visibilites from an MS table with spws with different number of channels, you will get a CASA error (see requirement for the
channelparameter above). To avoid that, you can either use the CASAsplittask to create a new MS table with only spws with same number of channels. Alternatively (or additionally) you can channel average all the spws to the same number of channels.Example
From within CASA, to extract all the visibilities from an MS table:
export_uvtable('uvtable.txt', tb, vis='sample.ms', channel='all')
where
tbis the CASA tb object (to inspect it typetbin the CASA shell). For more information ontbsee https://casa.nrao.edu/docs/CasaRef/table-Module.htmlFrom within CASA, to extract the visibilities in spectral windows 0 and 2 use the
split_argsparameter and the CASAsplittask:export_uvtable('uvtable.txt', tb, channel='all', split=split, split_args={'vis': 'sample.ms' , 'datacolumn': 'DATA', 'spw':'0,2'})
To perform these operations without running CASA interactively:
casa --nologger --nogui -c "from uvplot import export_uvtable; export_uvtable(...)"
ensuring that the strings are inside the ‘..’ characters and not the “…” one.