NRAO Home > CASA > CASA Toolkit Reference Manual
table.create - Function

3.2.1 create a new table


Description

Create a new CASA Table.

Most of the time you just need to specify the table’s name and a description of its format.

A table can be shared by multiple processes by using the appropriate locking options. The possible options are:
- auto: let the system take care of locking. At regular time intervals these autolocks are released to give other processes the opportunity to access the table.
- autonoread: as auto, but no read locking is needed. This must be used with care, because it means that reading can be done while the table tool is not synchronized with the table file (as is normally done when a lock is acquired). The function resync can be used to explicitly synchronize the table tool
- user: the user takes care by explicit calls to lock and unlock
- usernoread: as user and the no readlocking behaviour of autonoread.
- permanent: use a permanent lock; the constructor fails when the table is already in use in another process
- permanentwait: as above, but wait until the other process releases its lock
- default: this is the default option. If the given table is already open, the locking option in use is not changed. Otherwise it reverts to auto.
When auto locking is used, it is possible to give a record containing the fields option, interval, and/or maxwait. In this way advanced users have full control over the locking options. In practice this is hardly ever needed.

Arguments





Inputs

tablename

allowed:

string

Default:

tabledesc

description of the table’s format

allowed:

record

Default:

lockoptions

locking to be used

allowed:

record

Default:

default

endianformat

allowed:

string

Default:

memtype

allowed:

string

Default:

nrow

allowed:

int

Default:

0

dminfo

Data Manager information

allowed:

record

Default:

Returns
bool

Example

 
 
 
  # First let’s get sample descriptions of a table and its data managers.  
  import os, shutil  
 
  def get_tabledesc_and_dminfo(tabname="3C273XC1.MS"):  
      made_copy = False  
 
      # Fetch new table if tabname not present  
      if not os.path.isdir(tabname):  
          # Get path to CASA root directory by stripping name from ’$CASAPATH’  
          pathname = os.environ.get("CASAPATH").split()[0]  
 
          # There should be some data here  
          fitsdata = pathname + "/data/demo/3C273XC1.fits"  
          tabname = "3C273XC1.MS"  
 
          ms.fromfits(tabname, fitsdata)  
          ms.close()  
          made_copy = True  
 
      tb.open(tabname)  
      tabdesc = tb.getdesc()  
      dminfo  = tb.getdminfo()  
      print tabname, "has", tb.nrows(), "rows."  
      tb.close()  
 
      # Clean up  
      if made_copy:  
          shutil.rmtree(tabname)  
 
      return tabdesc, dminfo  
 
  tabdesc, dmi = get_tabledesc_and_dminfo()  
  tabdesc  # prints tabdesc  
  dmi      # prints dmi  
 
  # You could alter tabdesc and/or dmi at this point.  
 
  # Unnecessary, but just to show there is nothing up my sleeve...  
  tb.close()  
 
  tb.create("myempty.ms", tabdesc, dminfo=dmi)  
  tb.nrows()     # 0L  
  tb.addrows(5)  # Add the rows _before_ filling the columns.  
  tb.putcol(’ARRAY_ID’, numpy.array([0 for i in range(5)]))  
  tb.putcol(’ANTENNA1’, numpy.array(range(5)))  
  tb.putcol(’ANTENNA2’, numpy.array(range(1,6)))  
  tb.browse()    # Still mostly, but not completely, empty.  
  tb.close()  
 
 
This creates a CASA table using a description of a table and its data managers from an existing MS.  
 

__________________________________________________________________


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