Funtools Files, Extensions, and Filters using Bracket Notation

Funtools programs and libraries operate on FITS images and binary tables, as well as on non-FITS arrays and raw event files. The type of file being processed, (or, for a FITS file, the FITS extension to process) is specified by means of IRAF-style bracket notation appended to the Funtools data filename:
  events.fits[EVENTS]                   # open EVENTS extension of a FITS file
  array.file[ARRAY(s1024)]              # open raw array of 1024x1024 shorts
  events.file[EVENTS(x:1024,y:1024...)] # open raw event list
Note that in many Unix shells (e.g., csh and tcsh), filenames must be enclosed in quotes to protect the brackets from shell processing.

Specifying Files and FITS Extensions

All Funtools filenames use IRAF-style bracket notation to specify FITS extensions, image sections, and region and table filters: where:

In order to open a FITS binary table or image extension, it usually is necessary to specifiy either the extension name or the extension number in brackets. The exception to this rule is that, in the absence of an extension name or number, Funtools will try to open either an extension named either EVENTS or STDEVT, if one of these exists. This default behavior supports standard X-ray event list processing (which is what we at SAO/HEAD do, after all).

The file designator can be a standard disk file. In addition, gzip'ed files are suported in Funtools: gzip'ed input files are automatically uncompressed as they are read, and gzip'ed output files are compressed as they are written. NB: if a FITS binary table is written in gzip format, the number of rows in the table will be set incorrectly to -1. Such a file will work with Funtools programs but will not work with other FITS programs such as ds9.

The special keywords "stdin" and "stdout" designate Unix standard input and standard output, respectively. The string "-" (hyphen) will be taken to mean "stdin" if the file is opened for reading and "stdout" if the file is opened for writing.

A file can be an INET socket on the same or another machine using the syntax:

  machine:port
Thus, for example:
  karapet:1428
specifies that I/O should be performed to/from port 1428 on the machine karapet. If no machine name is specified, the default is to use the current machine:
 :1428
This means to open port 1428 on the current machine. Socket support allows you to generate a distributed pipe:
on karapet:       funtask1 in.fits bynars:1428
on bynars:        funtask2 :1428 out.fits
The socket mechanism provides simple parallel processing using process decomposition. Note that parallel processing using data decomposition is supported via the section specifier (see below), and the row# specifier, which is part of Table Filtering.

A file also can be a pointer to existing shared memory using the syntax:

  shm:[id|@key][:size]
A shared memory segment is specified with a shm: prefix, followed by either the shared memory id or the shared memory key (where the latter is prefixed by the '@' character). The size (in bytes) of the shared memory segment can then be appended (preceded by the ':' character). If the size specification is absent, the code will attempt to determine the length automatically. Note that the shared memory segment must exist already.

The specification of FITS ext name, ind number and image section must be done in order, but all sensible defaults are supported:

The ext argument specifies the name of the FITS extension (i.e. the value of the EXTENSION header parameter in a FITS extension), while the index specifies the value of the FITS EXTVER header parameter. When a Funtools data file is opened for reading using FunOpen(), the specified extension is automatically located and is used to initialize the Funtools handle.

Specifying Image Sections

Once a section or image is set up using FunOpen(), the next optional part of a bracket specification can be used to select section information, i.e., to specify the x,y limits of an image section, as well as the blocking factor to apply to that section: where the limit values can be ints or "*" for default. A single "*" can be used instead of val:val, as shown. Note that blocking is applied to the section after it is extracted. In addition to image sections, image centers can be specified: Note that the (float) values for dim, dim1, dim2, xcen, ycen must be specified or else the expression does not make sense!

In all cases, block is optional and defaults to 1. An 's' or 'a' can be appended to signify "sum" or "average" blocking (default is "sum"). Section specifications are given in image coordinates by default. If you wish to specify physical coordinates, add a 'p' as the last character of the section specification, before the closing bracket. For example:


A section can be specified in any Funtools file name. If the operation to be applied to that file is an imaging operation, then the specification will be utilized. If the operation is purely a table operation, then the section specification is ignored.

Do not be confused by:

  foo.fits[2]
  foo.fits[*,2]
The former specifies opening the second extension of the FITS file. The latter specifies application of block 2 to the image section.

Specifying Filters

In addition extensions and image sections, Funtools bracket notation can be used to specify table and region filters. These filters are always placed after the image section information. They can be specified in the same bracket or in a separate bracket immediately following: The topics of table and region filtering is covered in detail in:

Specifying Non-FITS Array Files

In addition to FITS image, Funtools programs and libraries can operate on non-FITS files containing arrays of homogeneous data. To specify an array file, use: where array-spec is of the form: and where [type] is: The dim1 specification is required, but dim2 is optional and defaults to dim1. The skip specification is optional and defaults to 0. The optional endian specification can be 'l' or 'b' and defaults to the endian type for the current machine. If no array specification is included within the ARRAY() operator, then the array specification is taken from the ARRAY environment variable. For example:
  foo.arr[ARRAY(r512)]		# bitpix=-32 dim1=512 dim2=512
  foo.arr[ARRAY(r512.400)]	# bitpix=-32 dim1=512 dim2=400
  foo.arr[ARRAY(r512.400])	# bitpix=-32 dim1=512 dim2=400
  foo.arr[ARRAY(r512.400:2880)]	# bitpix=-32 dim1=512 dim2=400 skip=2880
  foo.arr[ARRAY(r512l)]		# bitpix=-32 dim1=512 dim2=512 endian=little
  setenv ARRAY "r512.400:2880"
  foo.arr[ARRAY()]		# bitpix=-32 dim1=512 dim2=400 skip=2880

Specifying Non-FITS Raw Event Files

In addition to FITS tables, Funtools programs and libraries can operate on non-FITS files containing heterogeneous event records. To specify an event file, use: where event-spec is a string that specified the names, data types, and optional image dimensions for each element of the event record: Data types follow standard conventions for FITS binary tables, but include two extra unsigned types ('U' and 'V'): An optional integer value n can be prefixed to the type to indicate that the element is an array of n values.

Furthermore, image dimensions are attached to the event specification in order to tell Funtools how to bin the events into an image. They follow the conventions for the FITS TLMIN/TLMAX keywords. If the low image dimension is not specified, it defaults to 1. Thus:

both specify that the dimension of this column runs from 1 to 100. Note that it is required that all padding be specified in the record definition. For example, suppose a FITS binary table has the following set of column definitions:
TTYPE1  = 'X                 ' / Label for field
TFORM1  = '1I                ' / Data type for field
TLMIN1  =                    1 / Min. axis value
TLMAX1  =                   10 / Max. axis value
TTYPE2  = 'Y                 ' / Label for field
TFORM2  = '1I                ' / Data type for field
TLMIN2  =                    2 / Min. axis value
TLMAX2  =                   11 / Max. axis value
TTYPE3  = 'PHA               ' / Label for field
TFORM3  = '1I                ' / Data type for field
TTYPE4  = 'PI                ' / Label for field
TFORM4  = '1J                ' / Data type for field
TTYPE5  = 'TIME              ' / Label for field
TFORM5  = '1D                ' / Data type for field 
TTYPE6  = 'DX                ' / Label for field
TFORM6  = '1E                ' / Data type for field
TLMIN6  =                    1 / Min. axis value
TLMAX6  =                   10 / Max. axis value
TTYPE7  = 'DY                ' / Label for field
TFORM7  = '1E                ' / Data type for field
TLMIN7  =                    3 / Min. axis value
TLMAX7  =                   12 / Max. axis value
An raw event file containing these same data would have the event specification: If no event specification is included within the EVENTS() operator, then the event specification is taken from the EVENTS environment variable:
  setenv EVENTS "X:I:10,Y:I:10,PHA:I,PI:J,TIME:D,DX:E:10,DY:E:10"
In addition to knowing the data structure, it is necessary to know the endian ordering of the data, i.e., whether or not the data is in bigendian format, so that we can convert to the native format for this platform. This issue does not arise for FITS Binary Tables because all FITS files use big-endian ordering, regardless of platform. For example, big-endian data produced on a Sun workstation but read on a Linux PC need to be byte-swapped, since PCs use little-endian ordering. To specify an ordering, use the bigendian= or endian= keywords on the command-line or the EVENTS_BIGENDIAN or EVENTS_ENDIAN environment variables. The value of the bigendian variables should be "true" or "false", while the value of the endian variables should be "little" or "big". Thus, for example, for a PC to access data produced by a Sun, use:
  hrc.nepr[EVENTS(),bigendian=true]
or
  hrc.nepr[EVENTS(),endian=big]
or
  setenv EVENTS_BIGENDIAN true
or
  setenv EVENTS_ENDIAN big
If none of these are specified, the data are assumed to follow the format for that platform and no byte-swapping is performed.

Binning FITS Binary Tables and Non-FITS Event Files

If a FITS binary table or a non-FITS raw event file is being binned into an image, it is necessary to specify the two columns to be used for the 2D binning, as well as the dimensions of the image. Funtools first looks for a specifier of the form:
  bincols=([xname[:tlmin[:tlmax:[binsiz]]]],[yname[:tlmin[:tlmax[:binsiz]]]])
in bracket syntax, and uses the column names thus specified. The tlmin, tlmax, and binsiz specifiers determine the image binning dimensions using:
  dim = (tlmax - tlmin)/binsiz     (floating point data)
  dim = (tlmax - tlmin)/binsiz + 1 (integer data)
These tlmin, tlmax, and binsiz specifiers can be omitted if TLMIN, TLMAX, and TDBIN header parameters are present in the FITS binary table header, respectively. If only one parameter is specified, it is assumed to be tlmax, and tlmin defaults to 1. If two parameters are specified, they are assumed to be tlmin and tlmax. For example, to bin an HRC event list columns "VPOS" and "UPOS", use:
  hrc.nepr[bincols=(VPOS,UPOS)]
or
  hrc.nepr[bincols=(VPOS:49152,UPOS:4096)]
Note that you can optionally specify the dimensions of these columns to cover cases where neither TLMAX keywords are defined in the header. If either dimension is specified, then both must be specified.

You can set the FITS_BINCOLS or EVENTS_BINCOLS environment variable as an alternative to adding the "bincols=" specifier to each file name for FITS binary tables and raw event files, respectively. If no binning keywords or environment variables are specified, or if the specified columns are not in the binary table, the Chandra parameters CPREF (or PREFX) are searched for in the FITS binary table header. Failing this, columns named "X" and "Y" are sought. If these are not found, the code looks for columns containing the characters "X" and "Y". Thus, you can bin on "DETX" and "DETX" columns without specifying them, if these are the only column names containing the "X" and "Y" characters.

Finally, when binning events, the data type of the resulting 2D image must be specified. This can be done with the "bitpix=[n]" keyword in the bracket specification. For example:

  events.fits[bincols=(VPOS,UPOS),bitpix=-32]
will create a floating point image binned on columns VPOS and UPOS. If no bitpix keyword is specified, bitpix=32 is assumed. As with bincols values, you also can use the FITS_BITPIX and EVENTS_BITPIX environment variables to set this value for FITS binary tables and raw event files, respectively. Finally, please note that Funtools supports most FITS standards and will add missing support as required by the community. In general, however, we do not support non-standard extensions. For example, we sense the presence of the binary table 'variable length array' proposed extension and we pass it along when copying and filtering files, but we do not process it. We will add support for new standards as they become official.
Index to the Funtools Help Pages
Last updated: April 10, 2002