funfiles(7)
π FunFiles β Funtools Data Files π
okay bestie, welcome to funfiles(7) from SAORD Documentation. This is the manual page for FunFiles, aka Funtools Data Files. It's giving data-file-format lore, and we're gonna get through it together. π«Ά
β¨ NAME β¨
FunFiles β Funtools Data Files
πΈ SYNOPSIS πΈ
okay so this document describes the data file formats (FITS, array, raw events) as well as the file types (gzip, socket, etc.) supported by Funtools. periodt. π
π DESCRIPTION π
Funtools supports FITS images and binary tables, and binary files containing array (homogeneous) data or event (heterogeneous) data. IRAF-style brackets are appended to the filename to specify various kinds of information needed to characterize these data:
file[extβͺindβͺARRAY()βͺEVENTS(),section][filters]
or
file[extβͺindβͺARRAY()βͺEVENTS(),section,filters]
where:
fileis the Funtools file nameextis the FITS extension nameindis the FITS extension numberARRAY()is an array specificationEVENTS()is an event specificationsectionis the image section specificationfiltersare spatial region and table (row) filters
π Supported Data Formats π
Funtools programs (and the underlying libraries) support the following data file formats:
- FITS images (and image extensions)
- FITS binary tables
- binary files containing an array of homogeneous data
- binary files containing events, i.e. records of heterogeneous data
- column-based text files, which are documented here
- non-disk files and lists of files
Information needed to identify and characterize the event or image data can be specified on the command line using IRAF-style bracket notation appended to the filename:
foo.fits # open FITS default extension
image.fits[3] # open FITS extension #3
events.fits[EVENTS] # open EVENTS extension
array.file[ARRAY(s1024)] # open 1024x1024 short array
events.file[EVENTS(x:1024,y:1024...)] # open non-FITS 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.
bestie, if you don't quote those brackets, the shell will snatch them and you'll be sad. π
π₯ FITS Images and Binary Tables π₯
When FunOpen() opens a FITS file without a bracket specifier, the default behavior is to look for a valid image in the primary HDU. In the absence of a primary image, Funtools will try to open an extension named either EVENTS or STDEVT, if one of these exists. This default behavior supports both FITS image processing and standard X-ray event list processing (which, after all, is what we at SAO/HEAD do).
In order to open a FITS binary table or image extension explicitly, it is necessary to specify either the extension name or the extension number in brackets:
foo.fits[1] # open extension #1: the primary HDU
foo.fits[3] # open extension #3 of a FITS file
foo.fits[GTI] # open GTI extension of a FITS file
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. Following FITS conventions, extension numbers start at 1.
When a FITS data file is opened for reading using FunOpen(), the specified extension is automatically located and is used to initialize the Funtools internal data structures.
π¦ 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 such an event file, use:
file[EVENTS(event-spec)]file[EVENTS()]
where event-spec is a string that specified the names, data types, and optional image dimensions for each element of the event record:
[name]:[n][type]:[(lodim:)hidim]
Data types follow standard conventions for FITS binary tables, but include two extra unsigned types ('U' and 'V'):
B-- unsigned 8-bit charI-- signed 16-bit intJ-- signed 32-bit intK-- signed 64-bit intE-- 32-bit floatD-- 64-bit floatU-- unsigned 16-bit intV-- unsigned 32-bit int
An optional integer value n can be prefixed to the type to indicate that the element is an array of n values. For example:
foo.fits[EVENTS(x:I,y:I,status:4J)]
defines x and y as 16-bit ints and status as an array of 4 32-bit ints.
Furthermore, image dimensions can be 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:
RAWX:J:1:100RAWX:J:100
both specify that the dimension of this column runs from 1 to 100.
NB: it is required that all padding be specified in the record definition. Thus, when writing out whole C structs instead of individual record elements, great care must be taken to include the compiler-added padding in the event definition. no cap, this one bites people. π
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:
EVENTS(X:I:10,Y:I:2:11,PHA:I,PI:J,TIME:D,DX:E:10,DY:E:3:12)
If no event specification string 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. But for non-FITS data, big-endian data produced on a Sun workstation but read on a Linux PC needs 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".
For example, a PC can access data produced by a Sun using:
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.
π Non-FITS Array Files π
In addition to FITS images, Funtools programs and libraries can operate on non-FITS files containing arrays of homogeneous data. To specify an array file, use:
file[ARRAY(array-spec)]file[ARRAY()]
where array-spec is of the form:
[type][dim1][.dim2][:skip][endian]
and where [type] is:
b(8-bit unsigned char)s(16-bit short int)u(16-bit unsigned short int)i(32-bit int)r,f(32-bit float)d(64-bit float)
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 Image Sections π
Once a data file (and possibly, a FITS extension) has been specified, the next (optional) part of a bracket specification can be used to select image 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. This information can be added to any file specification but only is used by Funtools image processing routines.
The format of the image section specification is one of the following:
file[xy0:xy1,block]file[x0:x1,y0:y1,block]file[x0:x1,*,block]file[*,y0:y1,block]file[*,block]
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 specified by the lo and hi x,y limits, image sections using center positions can be specified:
file[dim1@xcen,dim2@ycen]file[xdim2@xcen@ycen]file[dim1@xcen,dim2@ycen,block]file[dim@xcen@ycen,block]
Note that the (float) values fordim,dim1,dim2,xcen,ycenmust 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:
file[-8:-7,-8:-7p]file[-8:-7,-8:-7,2p]
A section can be specified in any Funtools file name, bestie. If the operation being done on that file is an imaging operation, then the section spec gets used. But if the operation is purely a table operation? Then the section spec is justβ¦ ignored. It's giving background extra. π
Do NOT get confused by these two, I'm begging:
foo.fits[2]
foo.fits[*,2]
The first one opens the second extension of the FITS file. The second one applies block 2 to the image section. Totally different vibes, okay? π«Ά
Quick note: the section specification has to come after any FITS ext name or ind number β but don't stress, all the sensible defaults are supported:
file[ext]file[ext,index]file[index]file[ext,section]file[ext,index,section]file[index,section]file[section]
π Binning FITS Binary Tables and Non-FITS Event Files π
So if you wanna bin a FITS binary table (or a non-FITS raw event file) into a 2D image β think using the funimage program β you have to tell it which two columns to bin on, plus the dimensions of the image. Funtools first goes looking for a specifier shaped like this:
bincols=([xnam[:tlmin[:tlmax:[binsiz]]]],[ynam[:tlmin[:tlmax[:binsiz]]]])
β¦inside the bracket syntax, and uses whatever column names you put in there. The tlmin, tlmax, and binsiz specifiers decide the image binning dimensions like this:
dim = (tlmax - tlmin)/binsiz (floating point data)
dim = (tlmax - tlmin)/binsiz + 1 (integer data)
You can skip those tlmin, tlmax, and binsiz specifiers if the TLMIN, TLMAX, and TDBIN header parameters are already sitting in the FITS binary table header, respectively. β¨ If you only give one parameter, it's assumed to be tlmax, and tlmin defaults to 1. If you give two parameters, they're assumed to be tlmin and tlmax. That's it, that's the rule. π
For example, to bin an HRC event list on the columns "VPOS" and "UPOS", use:
hrc.nepr[bincols=(VPOS,UPOS)]
or
hrc.nepr[bincols=(VPOS:49152,UPOS:4096)]
Heads up: you can optionally specify the dimensions of these columns, which is a lifesaver for cases where neither TLMAX keyword is defined in the header. But β and this is the catch β if you specify either dimension, you have to specify both. No half measures, babe. π€
You can set the FITS_BINCOLS or EVENTS_BINCOLS environment variable as an alternative to adding the "bincols=" specifier to every single file name, for FITS binary tables and raw event files respectively. Now, if there are no binning keywords or environment variables specified, or if the columns you named just aren't in the binary table, the Chandra parameters CPREF (or PREFX) get searched for in the FITS binary table header. And if that fails, it goes hunting for columns literally named "X" and "Y". Still nothing? Then the code looks for columns containing the characters "X" and "Y". So bestie, you can bin on "DETX" and "DETX" columns without even specifying them β as long as those are the only column names containing the "X" and "Y" characters. Iconic, honestly. π
Ordinarily, every event or row contributes one count to an image pixel during the 2D binning process. So if five events all sit at the same (x,y) position, that pixel's image value will be five. But you can specify a variable contribution for each event using the vcol=[colname] filter spec:
vcol=[colname]
The vcol colname is a column holding a numeric value in each event row, and that value becomes the contribution of that event to its image pixel. Let's say you've got an event file looking like this:
x:e:4 y:e:4 v:e
------ ------ ----
1 1 1.0
2 2 2.0
3 3 3.0
4 4 0.0
1 1 1.0
2 2 2.0
3 3 3.0
4 4 4.0
Two events have an x,y value of (1,1), so normally a 2D image would have a value of 2 in the (1,1) pixel. But if you specify the v column as the value column:
foo.fits'[vcol=v]'
β¦then each pixel holds the additive sum of the associated (x,y) column values from the v column. So like, image pixel (1,1) will contain 1. + 1. = 2, image pixel (2,2) will contain (2 + 2) = 4, etc. Math but make it β¨aestheticβ¨.
An important variation on this: using a value column to specify the contribution an event makes to an image pixel, but when that value column holds the reciprocal of the event contribution. For that case, prefix the column name with a / (divide sign), like so:
foo.fits'[vcol=/v]'
Now every image pixel value is the sum of the reciprocals of the value column. A zero in the value column results in NaN (not a number) β no cap, it just breaks. So in the example above, image pixel (1.1) will contain 1/1 + 1/1 = 2, image pixel (2,2) will contain (1/2 + 1/2) = 1, etc. And image pixel (4,4) will contain (1/0 + 1/4) = NaN. π
You can set the FITS_VCOL or EVENTS_VCOL environment variable as an alternative to adding the "vcol=" specifier to each file name, for FITS binary tables and raw event files respectively.
Finally, when binning events, you must specify the data type of the resulting 2D image. Do that 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. And just like with bincols values, you can also use the FITS_BITPIX and EVENTS_BITPIX environment variables to set this value for FITS binary tables and raw event files, respectively. π
The funimage program also lets you create a 1D image projection along any column of a table, by using the bincols=[column] filter specification and specifying a single column. For example, this command projects a 1D image along the chipx column of a table:
funimage ev.fits'[bincols=chipx]' im.fits
Peep funimage for more info about creating 1D and 2D images. π¦
And lastly β please note that Funtools supports most FITS standards. We'll add missing support as the community requires it. But in general? 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. New standards get support as they become official. Periodt. π
πΈ Table and Spatial Region Filters πΈ
Okay so, on top of extensions and image sections, Funtools bracket notation can also be used to specify table and spatial region filters. These filters always get placed after the image section information, and you can put them in the same bracket or in a separate bracket immediately following:
file[ext|ind|ARRAY()|EVENTS(),section][filters]file[ext|ind|ARRAY()|EVENTS(),section,filters]
where:
fileis the Funtools file nameARRAY()is an array specificationEVENTS()is an event list specificationextis the FITS extension nameindis the FITS extension numbersectionis the image section to extractfiltersare spatial region and table (row) filters to apply
The topics of table and region filtering are covered in detail in:
- Table Filtering
- Spatial Region Filtering
π Disk Files and Other Supported File Types π
The specified file is usually just a regular ordinary disk file, ngl. But also, gzip'ed files are supported in Funtools: gzip'ed input files get automatically uncompressed as they're read, and gzip'ed output files get compressed as they're written. NB: if a FITS binary table is written in gzip format, the number of rows in the table will be set to -1. Such a file will work with Funtools programs, but it will not work with other FITS programs such as ds9. So, y'knowβ¦ be aware. π
The special keywords "stdin" and "stdout" designate Unix standard input and standard output, respectively. And 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. The multitasker of file names, honestly. π«Ά
A file can also be an INET socket on the same machine or another one, using this syntax:
machine:port
So 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
β¦which means open port 1428 on the current machine. Socket support lets you generate a distributed pipe:
on karapet: funtask1 in.fits bynars:1428
on bynars: funtask2 :1428 out.fits
The socket mechanism thus supports simple parallel processing using process decomposition. And note that parallel processing using data decomposition is supported via the section specifier (see below), plus the row# specifier, which is part of Table Filtering. Slay. π₯
A file can also be a pointer to shared memory, using this syntax:
shm:[id|@key][:size]
A shared memory segment gets 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. π§
If the open mode contains the string "w+", then the memory segment will be created if it doesn't exist. (It will also be released and deleted when the file is closed.) But in the case where a memory segment is being created, the length of the segment is required. Don't forget it!
A file can also be a Unix piped command (i.e. a program to run) using this syntax:
"pipe: command arg1 ... argn"
The output from the command has to be a valid FITS file. And it's important to use quotes to protect spaces so that command arguments get passed correctly. A silly example:
fundisp "pipe: funtable 'foo.fits[cir 512 512 .1]' stdout"
This seemed like a good idea at the time ... π
β Lists of Files β
Funtools will also process a list of files as a single file, using this syntax:
"list: file1 file2 ... filen"
The files in the list are separated by whitespace. Any of the above file types can be used. For example, if two files, foo1.fits and foo2.fits, are part of the same observation, they can be processed as a single file (using their own filters):
Okay so here's the actual tea, bestie β this is what it looks like when you actually run it: π
fundisp "list: foo1.fits[cir(512,512,10)] foo2.fits[cir(511,511,10)]"
X Y PHA PI TIME DX DY
-------- -------- -------- -------- --------------------- -------- --------
512 512 6 7 79493997.45854475 578 574
512 512 8 9 79494575.58943175 579 573
512 512 5 6 79493631.03866175 578 575
512 512 5 5 79493290.86521725 578 575
512 512 8 9 79493432.00990875 579 573
511 511 5 5 79488631.09462625 580 575
511 511 10 11 79488780.60006675 580 573
511 511 4 4 79494562.35474326 580 575
511 511 6 6 79488203.01561825 580 575
511 511 6 6 79488017.99730176 580 575
511 511 4 4 79494332.45355175 580 575
511 511 9 10 79492685.94014275 581 574
511 511 5 5 79487708.71298325 580 575
511 511 8 9 79493719.00160225 581 573
Look at those columns pop off. π The X, the Y, the PHA, the PI, the TIME, the DX, the DY β all lined up, all serving. Periodt.
And again, because this is the part where people get humbled: it is important to avoid spaces in the filters, because the list separator also is whitespace. The way that whitespace is doing double duty?? It's giving chaos. π
So if you need whitespace to survive inside a filter, enclose the file specification in quotes:
fundisp "list: 'foo1.fits[cir 512 512 .1]' foo2.fits[cir(511,511,.1)]"
See how foo1.fits got wrapped in single quotes inside the double quotes? That's the whole trick, bestie. Nested quotes, no cap. π«Ά
π SEE ALSO π
Like, go read funtools(7) for a whole list of Funtools help pages β it's the master doc, the mothership, the main character of this entire saga. π
And that's the whole page, bestie!! This little legend is version 1.4.5, dated April 14, 2011, and it lives under the name funfiles(7). Iconic. Historic. Ate. πβ¨π
π¦ where this page comes from
- debian bookworm: libfuntools-dev 1.4.8-1 Β· GPL
- debian trixie: libfuntools-dev 1.4.8-1.1+b2 Β· GPL
- ubuntu jammy: libfuntools-dev 1.4.8-1 Β· GPL
- ubuntu noble: libfuntools-dev 1.4.8-1.1build2 Β· GPL
- ubuntu questing: libfuntools-dev 1.4.8-2
- ubuntu resolute: libfuntools-dev 1.4.8-2build1 Β· GPL
- ubuntu stonking: libfuntools-dev 1.4.8-2build1 Β· GPL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms