1.2.1 ms - Tool

Operations on measurement sets
Requires:

Synopsis

Description

The ms tool provides functions to manipulate the contents of measurement set tables. The functions can be categorised as shown below.

Attaching to a Measurement Set

The simplest and most common way to attach an ms tool to a measurement set is to use the ms.open function which requires that you specify the name of the measurement set table.

The function ms.fromfits converts a UVFITS file to a measurement set table prior to attaching the ms tool to the newly created measurement set. The conversion step may take some time if the FITS file is large. However it only needs to be done once. The measurement set table is not deleted when you close the ms tool, using the close function, or exit CASA. And once the measurement set table is created it is much faster to attach an ms tool to it using the ms.open function.

Getting summary information

The summary function will display, in the logger, an overview of the measurement set. This will include listings of the fields, spectral windows & polarization setups used in the measurement set.

The range function will provide more quantitative information on the minimum, maximum or used values of specified parameters. When using this function you may need to do an initial selection, as described below, depending on whether the parameters you ask for change their shape. A list of parameters accepted by the range function is given in table 1.7 and this table also indicates when an initial selection is necessary.

The lister function provides a concise listing of the data in the measurement set.

The listhistory function lists the contents of the measurement set history table. The history table contains a record of changes made to the measurement set by autoflag, calibrater, imager and other tools.

Selecting data

As described in the ms module documentation a measurement set can contain data with a variety of different shapes. Some of the functions in this tool require the data to be in a fixed shape. Before you can use these functions you need to select a subset of the data in the measurement set where all the data has a fixed shape. There are two functions which can be used to do this. These are the selectinit and command functions.

The select function can be used to further refine which subset of the data will be used by the data access functions. This function allows you to select specific rows in a measurement set using a wide range of criteria.

The select function can only select whole rows in a measurement set. To select specific channels within a row you use the selectchannel function. Similarly to select specific polarizations you should use the selectpolarization function.

Reading and writing data

The getdata function is used to read data from the measurement set into casapy variables. You can select which columns of the measurement set main table you are interested in and only the subset of data specified using the selection functions described above will be retreived. Any frequency averaging (see the selectfrequency function) and polarization conversion (see the selectpolarization function) will be done when you retreive the data. The full power of casapy and other CASA tasks and tools, like plotxy, can then be used for adhoc inspection and calculations involving the data.

If the measurement set was opened for writing then the putdata function can be used to write the data back into the measurement set. When writing data back into the measurement set you cannot change the data shape or the coordinates of the data, only the numerical values. This means that you cannot write data that has been averaged in frequency or converted to different polarizations.

When using the getdata function with a large measurement set you need to be careful to not request too much data. The measurement set is stored on disk but casapy variables are stored in memory. To allow you to access large amounts of data in an ordered way the ms tool provides functions that allow you to iterate through the data in a convienient way.

If you need to step through the data in an orderly fashion, you can use the iteration functions. These allow you to set up an iteration order (iterinit), obtain the first iteration (iterorigin), go to the next iteration (iternext) and end the iteration prematurely (iterend). The iterorigin and iternext function set the currently selected table (as used by getdata and others) to the current iteration. At the end of the iteration, the original selection is restored.

You can iterate through a measurement set you have previously selected using select, but if you use select while iterating, you cannot get back the unselected iteration (without reiterating through the table until the current point).

The writehistory function allows messages to be appended to the measurement set history table should you wish to do so. The listhistory function lists your messages and those created by autoflag, calibrater, imager and other tools.

Conversions to FITS

Just as the fromfits function will convert a UVFITS file to a measurement set the tofits function will convert a measurement set to a UVFITS file. Similarly a single dish measurement set ie., one with a FLOAT_DATA column rather than a DATA column, can be converted to a single dish FITS file using the tosdfits function.

You cannot read a UVFITS file into a measurement set and write it out as a single dish FITS file or vice-versa.

Concatenation

The concatenate function can be used to append the data from one measurement set to the end of another. As all the data is copied this function may take some time if the measurement set to be copied is large. The measurement set needs to be opened for writing for this to work.

Splitting The split function allow you to make a new ms from a subset of the actual ms

Flagging data

The flag and buffer functions all belong together. The idea is to fill a buffer of data (fillbuffer), optionally retrieve it as a record (getbuffer) and display it in some data display tool, do operations like differencing (diffbuffer), clipping (clipbuffer) and manual edits of the displayed data (setbufferflags), and then write the flags back to the MS (writebufferflags), into the appropriate flag level, so you can choose to apply or undo them. The data is untouched by these functions.

Table 1.5: Items recognized by the range, select, getdata and putdata functions. Items marked with a  are only available in interferometric measurement sets. Items marked with a  are only available in interferometric measurement sets that have been processed with calibrator or imager. Items marked with a * do not require all the data in the selected measurement set to have the same shape.






rangeselectgetdataputdatacomment






amplitude+ - + - amplitude of observed data
corrected_amplitude+ - + - amplitude of corrected data
model_amplitude+ - + - amplitude of model data
ratio_amplitude - - + - amplitude of corrected/model
residual_amplitude - - + - amplitude of residual data
obs_residual_amplitude - - + - amplitude of obs residual data
antenna1 *++ - 1st antenna id
antenna2 *++ - 2nd antenna id
antennas * - - - list of antenna names
array_id *+ - -
axis_info - - + - description of data axes
chan_freq + - - - channel frequencies
corr_names + - - - list of polarization strings
corr_types + - - - list of polarization enum values
data - - ++complex observed data
corrected_data - - ++complex corrected data
model_data - - ++complex model data
ratio_data - - + - complex corrected/model
residual_data - - ++complex residual data
obs_residual_data - - ++complex observed residual data
feed1 *++ - 1st feed in correlation
feed2 *++ - 2nd feed in correlation
field_id *++ - field number
fields * - - - list of field names
flag - - ++data flags
flag_row - - ++MS row flags
flag_sum - - + - flag summary
ha - - + - add hour angle to axis_info
ifr_number *++ - 1000*antenna1+antenna2
imaginary+ - + - imag part of observed data
corrected_imaginary+ - + - imag part of corrected data
model_imaginary+ - + - imag part of model data
ratio_imaginary - - + - imag part of corrected/model
residual_imaginary - - + - imag part of residual data
obs_residual_imaginary - - + - imag part of obs residual data
imaging_weight+ - ++weights used for imaging
last - - + - add LAST to axis_info
num_corr + - - - number of polarizations
num_chan + - - - number of freq channels
phase+ - + - phase of observed data
corrected_phase+ - + - phase of corrected data
model_phase+ - + - phase of model data
ratio_phase - - + - phase of corrected/model
residual_phase - - + - phase of residual data
obs_residual_phase - - + - phase of observed residual data
phase_dir + - - - list of phase centers & epoch
real+ - + - real part of observed data
corrected_real+ - + - real part of corrected data
model_real+ - + - real part of model data
ratio_real - - + - real part of corrected/model
residual_real - - + - real part of residual data
obs_residual_real - - + - real part of observed res. data
ref_frequency + - - - reference frequency
rows *+ - - row numbers in original table
scan_number *++ -
sigma * - ++sigma of the data
data_desc_id *++ -
time *++ - MJD time range in seconds
times *+ - - list of MJD timeslots
ut - - + - add UT to axis_info
uvw - - + - uvw vector
u *++ - u coordinate
v *++ - v coordinate
w *++ - w coordinate
uvdist*++ - uv distance
weight* - ++weight of the data






Example:

ms.open("3C273XC1.MS",nomodify=False)  
ms.selectinit(datadescid=0)  
ms.select({’antenna1’:[1,3,5],’uvdist’:[1200.,1900.]})  
rec=ms.getdata(["weight","data"])  
# modify rec[’weight’] and rec[’data’] values as desired  
ms.putdata(rec)  
ms.close()

We open the MS for writing, select an array and spectral window and then select a few antennas and a uv range. We then get out the weight values and the data. We change these values in casapy and then write them back to the measurement set. Finally, we close the ms, causing the values to be written back to disk.

Methods

fromfits Create a measurement set from a uvfits file
nrow Returns the number of rows in the measurement set
iswritable Returns True is the underlying Table is writable
open Attach the ms tool to a measurement set table
close Detach the ms tool from the measurement set table
name Name of the measurement set table the tool is attached to.
tofits Convert a measurement set to a uvfits file
summary (PARTIALLY IMPLEMENTED!!!) Summarize the measurement set
listhistory List history of the measurement set
writehistory Add a row of arbitrary information to the measurement set history table
range Get the range of values in the measurement set
lister List measurement set visibilities
selectinit Initialize the selection of an ms
select Select a subset of the measurement set.
selecttaql Select a subset of the measurement set.
selectchannel Select and average frequency channels
selectpolarizationSelection and convertion of polarizations
getdata Read values from the measurement set.
putdata Write new values into the measurement set
concatenate Concatenate two measurement sets
split make a new ms from a subset of an existing ms
iterinit Initialize for iteration over an ms
iterorigin Set the iterator to the start of the data.
iternext Advance the iterator to the next lot of data
iterend End the iteration and reset the selected table
fillbuffer Fill the internal buffer with data and flags.
diffbuffer Differentiate or difference the internal buffer.
getbuffer Return the internal buffer as a Record for access from the intrepreter.
clipbuffer (NON-FUNCTIONAL???) Clip the internal buffer with specified limits.
setbufferflags Set the flags in the buffer
writebufferflagsWrite the flags in the internal buffer back to the table.
clearbuffer Clear the internal buffer.
continuumsub Continuum fitting and subtraction in uv plane
done Closes the ms tool
msseltoindex Returns ids of the selection used
hanningsmoothHanning smooth the frequency channels to remove Gibbs ringing.
uvsub Subtract model from the corrected visibility data.

Description

The ms tool provides functions to manipulate the contents of measurement set tables. The functions can be categorised as shown below.

Attaching to a Measurement Set

The simplest and most common way to attach an ms tool to a measurement set is to use the ms.open function which requires that you specify the name of the measurement set table.

The function ms.fromfits converts a UVFITS file to a measurement set table prior to attaching the ms tool to the newly created measurement set. The conversion step may take some time if the FITS file is large. However it only needs to be done once. The measurement set table is not deleted when you close the ms tool, using the close function, or exit CASA. And once the measurement set table is created it is much faster to attach an ms tool to it using the ms.open function.

Getting summary information

The summary function will display, in the logger, an overview of the measurement set. This will include listings of the fields, spectral windows & polarization setups used in the measurement set.

The range function will provide more quantitative information on the minimum, maximum or used values of specified parameters. When using this function you may need to do an initial selection, as described below, depending on whether the parameters you ask for change their shape. A list of parameters accepted by the range function is given in table 1.7 and this table also indicates when an initial selection is necessary.

The lister function provides a concise listing of the data in the measurement set.

The listhistory function lists the contents of the measurement set history table. The history table contains a record of changes made to the measurement set by autoflag, calibrater, imager and other tools.

Selecting data

As described in the ms module documentation a measurement set can contain data with a variety of different shapes. Some of the functions in this tool require the data to be in a fixed shape. Before you can use these functions you need to select a subset of the data in the measurement set where all the data has a fixed shape. There are two functions which can be used to do this. These are the selectinit and command functions.

The select function can be used to further refine which subset of the data will be used by the data access functions. This function allows you to select specific rows in a measurement set using a wide range of criteria.

The select function can only select whole rows in a measurement set. To select specific channels within a row you use the selectchannel function. Similarly to select specific polarizations you should use the selectpolarization function.

Reading and writing data

The getdata function is used to read data from the measurement set into casapy variables. You can select which columns of the measurement set main table you are interested in and only the subset of data specified using the selection functions described above will be retreived. Any frequency averaging (see the selectfrequency function) and polarization conversion (see the selectpolarization function) will be done when you retreive the data. The full power of casapy and other CASA tasks and tools, like plotxy, can then be used for adhoc inspection and calculations involving the data.

If the measurement set was opened for writing then the putdata function can be used to write the data back into the measurement set. When writing data back into the measurement set you cannot change the data shape or the coordinates of the data, only the numerical values. This means that you cannot write data that has been averaged in frequency or converted to different polarizations.

When using the getdata function with a large measurement set you need to be careful to not request too much data. The measurement set is stored on disk but casapy variables are stored in memory. To allow you to access large amounts of data in an ordered way the ms tool provides functions that allow you to iterate through the data in a convienient way.

If you need to step through the data in an orderly fashion, you can use the iteration functions. These allow you to set up an iteration order (iterinit), obtain the first iteration (iterorigin), go to the next iteration (iternext) and end the iteration prematurely (iterend). The iterorigin and iternext function set the currently selected table (as used by getdata and others) to the current iteration. At the end of the iteration, the original selection is restored.

You can iterate through a measurement set you have previously selected using select, but if you use select while iterating, you cannot get back the unselected iteration (without reiterating through the table until the current point).

The writehistory function allows messages to be appended to the measurement set history table should you wish to do so. The listhistory function lists your messages and those created by autoflag, calibrater, imager and other tools.

Conversions to FITS

Just as the fromfits function will convert a UVFITS file to a measurement set the tofits function will convert a measurement set to a UVFITS file. Similarly a single dish measurement set ie., one with a FLOAT_DATA column rather than a DATA column, can be converted to a single dish FITS file using the tosdfits function.

You cannot read a UVFITS file into a measurement set and write it out as a single dish FITS file or vice-versa.

Concatenation

The concatenate function can be used to append the data from one measurement set to the end of another. As all the data is copied this function may take some time if the measurement set to be copied is large. The measurement set needs to be opened for writing for this to work.

Splitting The split function allow you to make a new ms from a subset of the actual ms

Flagging data

The flag and buffer functions all belong together. The idea is to fill a buffer of data (fillbuffer), optionally retrieve it as a record (getbuffer) and display it in some data display tool, do operations like differencing (diffbuffer), clipping (clipbuffer) and manual edits of the displayed data (setbufferflags), and then write the flags back to the MS (writebufferflags), into the appropriate flag level, so you can choose to apply or undo them. The data is untouched by these functions.

Table 1.7: Items recognized by the range, select, getdata and putdata functions. Items marked with a  are only available in interferometric measurement sets. Items marked with a  are only available in interferometric measurement sets that have been processed with calibrator or imager. Items marked with a * do not require all the data in the selected measurement set to have the same shape.






rangeselectgetdataputdatacomment






amplitude+ - + - amplitude of observed data
corrected_amplitude+ - + - amplitude of corrected data
model_amplitude+ - + - amplitude of model data
ratio_amplitude - - + - amplitude of corrected/model
residual_amplitude - - + - amplitude of residual data
obs_residual_amplitude - - + - amplitude of obs residual data
antenna1 *++ - 1st antenna id
antenna2 *++ - 2nd antenna id
antennas * - - - list of antenna names
array_id *+ - -
axis_info - - + - description of data axes
chan_freq + - - - channel frequencies
corr_names + - - - list of polarization strings
corr_types + - - - list of polarization enum values
data - - ++complex observed data
corrected_data - - ++complex corrected data
model_data - - ++complex model data
ratio_data - - + - complex corrected/model
residual_data - - ++complex residual data
obs_residual_data - - ++complex observed residual data
feed1 *++ - 1st feed in correlation
feed2 *++ - 2nd feed in correlation
field_id *++ - field number
fields * - - - list of field names
flag - - ++data flags
flag_row - - ++MS row flags
flag_sum - - + - flag summary
ha - - + - add hour angle to axis_info
ifr_number *++ - 1000*antenna1+antenna2
imaginary+ - + - imag part of observed data
corrected_imaginary+ - + - imag part of corrected data
model_imaginary+ - + - imag part of model data
ratio_imaginary - - + - imag part of corrected/model
residual_imaginary - - + - imag part of residual data
obs_residual_imaginary - - + - imag part of obs residual data
imaging_weight+ - ++weights used for imaging
last - - + - add LAST to axis_info
num_corr + - - - number of polarizations
num_chan + - - - number of freq channels
phase+ - + - phase of observed data
corrected_phase+ - + - phase of corrected data
model_phase+ - + - phase of model data
ratio_phase - - + - phase of corrected/model
residual_phase - - + - phase of residual data
obs_residual_phase - - + - phase of observed residual data
phase_dir + - - - list of phase centers & epoch
real+ - + - real part of observed data
corrected_real+ - + - real part of corrected data
model_real+ - + - real part of model data
ratio_real - - + - real part of corrected/model
residual_real - - + - real part of residual data
obs_residual_real - - + - real part of observed res. data
ref_frequency + - - - reference frequency
rows *+ - - row numbers in original table
scan_number *++ -
sigma * - ++sigma of the data
data_desc_id *++ -
time *++ - MJD time range in seconds
times *+ - - list of MJD timeslots
ut - - + - add UT to axis_info
uvw - - +