PyCasa -
A Python binding for CASA MeasurementSets

"PyCasa es su CASA"

 

This Python extension modules enables opening and reading [and writing!] data from/to casa::Tables stored on disk.
Array-valued values (ArrayColumn<T>::getCell() or *Column<T>::get()) are transformed into a Python numarray object for efficiency.

As of Sep. 2007 support for quanta is emerging, starting from version 0.9c!

Note: this software is not part of the CASA project; it links against it

Read on or go to the latest version immediately


External dependencies


 

The code has been tested with and proved to work with

Files

   
An introductionary user manual, submitted by Arno Schoenmakers - thnx!
  PyCasa user manual
   
The c++ source code for pycasa itself. See the README and the makefile in the extracted tree for documentation.
 
  • Version 0.9c, 14-09-2007:
    Highlights:
    • added support for pycasa.table.deepcopy()
      for saving results (see example below)
    • added support for pycasa.table.unlock()
      (for concurrent access)
    • a new sibling: pyquanta.so!
      only elementary yet but adds a lot of convenience constructor and operators. see qtst.py in the tarball
      execute 'gmake CASA=1 pyquanta.so' to build it.
    example:
    		>>> 
    		>>> t  = pycasa.table('3c84.ms') 
    		>>> t2 = t.query('ROWNUMBER()<20')  # select only first 20 rows
    		>>> len(t2)
    		20
    		>>> t2.deepcopy("/tmp/selection")
    		>>> t3 = pycasa.table("/tmp/selection")
    		>>> len(t3)
    		20
    
    		MVTime:
    		>>> import pyquanta
    		>>> 1 = pyquanta.mvtime('now')
    		>>> print t
    		14-Sep-2007/14:07:45
    		>>> t.format(pyquanta.mvtime.formatTypes.MJD) # print in MJD
    		'54357/14:07:45'
    		>>>  t.format(pyquanta.mvtime.formatTypes.FITS) # or in FITS notation
    		'2007-09-14T14:07:45'
    		>>>  t2 = t + '1h23m'  # add 1 hour and 23 minutes to the time
    		>>>  print t2
    		14-Sep-2007/15:09:45
    		>>>  print t + t2
    		12-Jul-2156/05:17:30
    
    		Quanta:
    		>>> ds = pyquanta.quantity('512yd')
    		>>> print ds.get('cm')  # 512 yard in cm
    		46817.3 cm 
    		>>> dt = pyquanta.quantity(3.23e-1, 's') # 0.232 seconds
    		>>> print (ds/dt).get('mm/min') # velocity in mm per minute
    		>>> print ds + '0.3km'   # add an amount of distance, in different unit
    		840.084 yd
    	
  • Version 0.9, 03-10-2006:
    Yes. A large jump in version number

    Justifiable because the module now has full write support!

    From this version on one can assign to:
    • individual cells in a tablecolumn
    • the complete column
    • a (partial) tablerow
    Small example:
    		>>> t = pycasa.table('3c84.ms') 
    		>>> antab = t.keywordSet()['ANTENNA']
    		>>> namecol = antab.getcol('NAME')
    		>>> 
    		>>> namecol[2]        # show what's in cell 2 of column 'NAME'
    		Ef
    		>>> t.update()        # if this succeeds, the table is R/W
    		True
    		>>> namecol[2] = 'Ur' # set name of antenna[2] to 'Ur'
    		>>> 
    		>>> r2 = antab[2]     # get row #2 of the antenna table (returns dict)
    		>>> r2                # display the contents
    		{'NAME':'Ur', 'MOUNT': 'alt-az', 'POSITION':array([...]) ... }
    		>>> r2['MOUNT'] = 'equatorial'
    		>>> antab[2] = r2     # update all values in the row
    		>>> 
    		>>> # create a dict with *some* of the column-names as keys
    		>>> # and values, well, the new values you want to put there
    		>>> newvals = {'FLAG_ROW':True, 'NAME': 'Ef', 'OFFSET':[-1,-2,-3L]}
    		>>> antab[2] = newvals 
    		>>> antab[2]
    		{'NAME':'Ef', ..., 'OFFSET': array([-1.,-2.-3.]), 'FLAG_ROW':1}
    		>>> 
    		>>> # A whole column in one go
    		>>> offsetcol = at.getcol('OFFSET')
    		>>> # create 2D array with shape (3,nrow)
    		>>> # Note: casa does fortran style array-indexing
    		>>> nwoff = numarray.resize(numarray.array([1,2,3]), (3,len(offsetcol)))
    		>>> offsetcol.put( nwoff ) 
    		>>> 
    		>>> # by default data not flushed to disk
    		>>> antab.flush()     # make sure changes are flushed to disk
    		>>> 
    	
  • Version 0.03a, 18-09-2006:
    Minor update to 0.03

    0.03 failed to compile with numarray or Numeric.
    Numpy users shouldn't have to upgrade

    The pycasa module must load the Array API too. Each of the implementations features an 'import_array()' method, however, they do not agree on the signature of that method.
    Numpy: int import_array()
    Numeric/numarray: void import_array()
    Actually, I got too dependant on numpy, which returns an integer telling the success or failure. Now works on all num* implementations again.
  • Version 0.03, 04-09-2006:
    Minor update to 0.02, TableValued keywords are now returned as pycasa.table objects.
    This will make correct access to referenced tables possible since in a reference table (eg you saved a selection of the main table as a separate table) the subtables are not copied across but the reference table keeps, well, err references to the original subtables.
    In order to normalize access to subtables one should do the following:
    		subtable = table.keywordSet()['<NAME-OF-SUBTABLE>']
    	
    eg
    		>>> t = pycasa.table('3c84.ms')
    		>>> antab = t.keywordSet()['ANTENNA']
    		>>> type(antab)
    		<class 'pycasa.table'>
    	
  • Version 0.02, 30-06-2006:
    Added support for retrieving table/column keywords.
    Table-valued keywords not yet returned as pycasa.table object but the string 'casa::Table' to identify that specific keyword is a table.
  • Version 0.01. Initial version providing access to tables and columns and the data therein.
 The patch for numarray 1.5.1
 
Apply this patch as follows
  1. Download numarray 1.5.1 from here and download the patch (Use the "Save link As" to save the patch on your machine)
  2. $>cd somewhere
    $>tar zxvf numarray-1.5.1.tar.gz
  3. $>patch -p0 < numarray-1.5.1-patch
  4. $>cd numarray-1.5.1
  5. $>./configure etc etc
Note: on Solaris systems one needs to use gpatch. Solaris patch does not recognize the patchfileformat.

 

verkouter AT jive DOT nl for comments, requests, remarks, you know what

Marjolein Verkouter/2006