|
|||
NRAO Home > CASA > CASA Toolkit Reference Manual |
|
table.query - Function
3.2.1 Make a table from a query
Description
Make a table from a query applied to the current table. It is possible to specify
column(s) and/or expressions to sort on and to specify the columns to be
contained in the output table. See the example below. A new ”on-the-fly”
table tool is returned. The new (reference) table can be given a name and will
then be written to disk. Note that the resulting table is just a reference to the
original table. One can make a deep copy of the query result using the copy
function (see example).
Arguments
Inputs |
| ||
query |
| Query string
| |
| allowed: | string |
|
| Default: | String |
|
name |
| Name of resulting reference table
| |
| allowed: | string |
|
| Default: |
|
|
sortlist |
| Sort string (one or more expressions separated by
commas)
| |
| allowed: | string |
|
| Default: |
|
|
columns |
| List of column names separated by commas
| |
| allowed: | string |
|
| Default: |
|
|
style |
| How to handle numeric ranges and order axes
| |
| allowed: | string |
|
| Default: |
|
|
table
Example
tb.open("3C273XC1.MS")
subt=tb.query("OBSERVATION_ID==0",
sortlist="ARRAY_ID", columns="TIME, DATA, UVW")
print subt.ncols()
# 23
tb.close()
copyt = subt.copy ("3C273XC1_spw1.MS", True)
subt.close()
copyt.close()
From the original table corresponding to the disk file 3C273XC1.MS, only rows
with OBSERVATION\_ID equal to 0 are selected and sorted by ARRAY\_ID. Only the
columns TIME DATA UVW are written. Thereafter a deep copy of the result is
made. This table query command is equivalent to the Table Query Language
(TaQL) command
SELECT TIME, DATA, UVW
FROM 3C273XC1.MS
WHERE OBSERVATION_ID==0
ORDERBY ARRAY_ID
See http://www.astron.nl/casacore/trunk/casacore/doc/notes/199.html for an explanation of TaQL.
If "style" is not blank, "using style <style> " is prepended to the
query. See
http://www.astron.nl/casacore/trunk/casacore/doc/notes/199.html#x1-50002.2 for
an explanation and list of choices for style. The default (glish) style is
1-based, inclusive end, and Fortran ordering. You may prefer python (0-based,
exclusive end, and C order) style.
tb.open(’any_data’)
tsel = tb.selectrows([0])
print tsel.nrows() # returns 1
tsel = tb.query(’ROWNUMBER()==0’)
print tsel.nrows() # returns 0
tsel = tb.query(’ROWNUMBER()==0’, style=’python’)
print tsel.nrows() # returns 1
tb.close()
Note that style had no effect on the "OBSERVATION_ID==0" query above.
Example
The sortlist argument can be used to sort in ascending or descending
order (or a mix of them) on one or more columns. Default is ascending.
It is also possible to remove duplicate values using the word
NODUPLICATES at the beginning.
E.g.:
sortlist=’TIME desc’
sortlist=’noduplicates ANTENNA1,ANTENNA2’
sortlist=’ANTENNA1 desc, ANTENNA2 asc’
sortlist=’desc ANTENNA1, ANTENNA2, TIME’
__________________________________________________________________
More information about CASA may be found at the
CASA web page
Copyright © 2016 Associated Universities Inc., Washington, D.C.
This code is available under the terms of the GNU General Public Lincense
Home |
Contact Us |
Directories |
Site Map |
Help |
Privacy Policy |
Search