My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
Description  
Description of libpyrap and bindings to casacore libraries.
Featured
Updated Apr 22, 2010 by gervandi...@gmail.com

Introduction

pyrap is the python binding to the radio-astronomical casacore package.

It consists of 2 parts:

  • libpyrap is a small library containing generic converters of casacore types (like Array and Record) and other data types (scalars, STL containers) to/from python types. It is described in AIPS++ note 259. It uses Boost.Python as its foundation.

  • The bindings to casacore libraries. The bindings to several libraries have been realized. They are listed below.

libpyrap

As described in AIPS++ note 259, casacore Array objects are stored in Fortran order. During the conversion to numpy array objects, the array axes are reversed to get C-ordering in python. Although numpy supports Fortran order, that support is only superficial. When, for example, adding 0 to a Fortran array the result is in C-order. It means that a possibly expensive transpose operation is done. See for example the following python code:

from numpy import *
a=array([[1,2,3],[4,5,6]],order='FORTRAN')
a.strides
Out[5]: (8, 16)
b=a+0
b.strides
Out[7]: (24, 8)        # transposed!!

libpyrap can be used by other packages needing a python binding.

pyrap.quanta

Quanta are numbers or vectors of numbers with physical units.
It can create compound units (like m/s) and convert between units.

This binding is different from the glish binding to quanta. In the python binding each quantum is a proper python object, while in glish each quantum resides in the server only.

pyrap.measures

Measures are quanta with a reference frame. The frame tells how, when, and where it was measured.
It can convert between reference frames (e.g. J2000 to apparent direction).
Several measure types exist. Some important are:

  • Epoch (time)
  • Position (on earth)
  • Direction (in sky)
  • Frequency

pyrap.functionals

A binding to the casacore Functionals library supporting N-dimensional arbitrary functions.

pyrap.fitting

A binding to the casacore Fitting library supporting linear and non-linear fitting using the Levenberg-Marquardt method.

pyrap.tables

This binding is a superset of the glish binding and Harro Verkouter's pycasa binding (http://www.jive.nl/~verkout/pycasa.html). Note that Harro's pycasa does not reverse the Array axes and requires some array resizing to get things right. All glish functions (as described on http://www.astron.nl/aips++/docs/user/Utility/node454.html#table) are available in python with the same function and argument names. It is useful to remark that put functionality is fully supported; for example, a non-contiguous numpy array slice is handled correctly.

It has full support of the tableindex, tableiter, tablerow, and the new tablecolumn classes. Furthermore some extra functionality is available to make it really pythonic.

  • Inspired by Harro's pycasa, an object tablecolumn has been added to make accessing a column easier. It has all the get and put functions found in the table object. Furthermore it supports the python get/setitem idiom using start,stop,step. For example:
  • t=table("mytable",readonly=False)   # open an existing table for update
    tc=tablecolumn(t,'COLNAME');        # create object
    mylist=tc[0:10:2];                  # get row 0,2,4,6,8 and return in a list
    tc[0:10:2]=3;                       # put 3 in these rows
    t.close()
Closing the table is not really needed, as the destructor automatically closes the table(and flushes written data if needed).
A la python it is possible to give negative values for start and stop (thus counting from the end) and for step (thus reversed order).
  • tablerow also got the set/getitem idiom described above.
  • tableindex got the indexing operator. For example
  • tix=tableindex(t,'COLNAME')           # form an index on the given column(s)
    rows=tix[key]                         # find all rows containing the key value
  • Iterating using the tableiter is very easy and can be done like:
  • for tab in tableiter(t,'COLNAME'):
Each step in the iteration gives a table object representing a subset of the original table in which the values in the given iteration column(s) are the same. Such a table object references the rows in the original table, thus writing to this subset changes the original table.

The glish-python differences are reflected in the versatile Table Query Language (see http://www.astron.nl/aips++/docs/notes/199/199.html). TaQL can have different styles, so it can be used in Glish mode or in Python mode. By default pyrap uses the Python mode. Apart from using 0-base and C-order, this mode also uses a non-inclusive stop value in array indexing (a la python indexing). TaQL does not support negative start,stop,step values though. For example:

t1=t.query("ANTENNA1 in [0:6:2]")

selects ANTENNA1 0, 2 and 4 (NOT 6 as end is exclusive). Just like the table iterator, it creates a table object which references the rows in the original table. All table functionality is available on this subset.

pyrap.images

A binding the the casacore Images module, the module handling astronomical images. It can:

  • open an image in casa, HDF5, FITS, or MIRIAD format
  • open an image as an expression of images
  • create an image in casa or HDF5 format
  • take a subset of an image
  • convert an image to FITS
  • get/put data or mask


Sign in to add a comment
Powered by Google Project Hosting