Warning, /graphics/kst-plot/devel-docs/fits_datasource.txt is written in an unsupported language. File is not indexed.

0001 FITS Datasource Design 
0002 ============================
0003 Revision History
0004 ----------------------------
0005 
0006 2006 05 29 : Ted K.  More details about FITS helper library
0007 2006 05 04 : Ted K.  Added info about WCS
0008 2006 05 03 : Ted K.  Initial proposal
0009 ----------------------------
0010 
0011 This is a proposal for a new general FITS datasource (called fitsfile).  There
0012 are some auxillary issues that also need to be dealt with in the healpix and
0013 LFIIO datasources.
0014 
0015 
0016 Utility library
0017 --------------------------------------------------------------------
0018 
0019 The cfitsio library has low level functions to access the FITS file.  It
0020 would be convenient to have a library of higher level functions that could be
0021 called from all datasources that deal with FITS files.  Examples of
0022 possible functions would be:  fetch all keys, build combined fieldlist from
0023 all extensions, build matrixlist from all extensions, etc.
0024 
0025 In order to be really useful, this utility library needs to be accessible from
0026 the understands_*, fieldList_* and matrixList_* functions.  I'm not sure of
0027 the best place to put such a library in the buildsystem- maybe
0028 kst/src/datasources/libfitsfile/ ?
0029 
0030 Proposed Functions:
0031 
0032 1.  fitsNHDU( fitsfile *fp )
0033     Returns the number of HDU's in the FITS file.
0034     
0035 2.  fitsDim( fitsfile *fp, int HDU )
0036     Returns the dimensions of the image or table contained in the 
0037     current HDU.  In the case of binary tables with "wide" columns (each
0038     column entry is a vector), the column entries will be "unrolled" 
0039     and the returned number of rows will reflect this new size.
0040     
0041 3.  fitsKeys( fitsfile *fp, int HDU )
0042     Returns a list of FITS keys.  This list will contain any keywords in the
0043     file header, and then the keys contained in the specified HDU.
0044     
0045 4.  fitsNames( fitsfile *fp, int HDU )
0046     Returns a QStringList of the names of all columns in the HDU (if the HDU
0047     contains a table), or the label of the image.
0048     
0049 5.  fitsUnits( fitsfile *fp, int HDU )
0050     Returns a QStringList of the units of all columns in the HDU (if the HDU
0051     contains a table), or the units of the image.
0052     
0053 6.  fitsFields( fitsfile *fp, int HDU )
0054     Returns a fieldlist for the current HDU.  Some datasources may wish to
0055     construct their own fieldlist using the information returned from
0056     fitsNames and fitsUnits.
0057     
0058 7.  fitsMatrices( fitsfile *fp, int HDU )
0059     Returns a matrixlist for the current HDU.  Some datasources may wish to
0060     construct their own fieldlist using the information returned from
0061     fitsNames and fitsUnits.
0062 
0063 
0064 Overview of the fitsfile datasource
0065 --------------------------------------------------------------------
0066 
0067 The overall behaviour of the datasource will be to offer up all data in the
0068 FITS file as both vectors and matrices.  The datasource will scan through
0069 the current extension (HDU) in the FITS file and build up a list of 
0070 available fields.  The current HDU will default to the first one, and be 
0071 selectable from the config dialog.  The INDEX field length will be determined
0072 based on the size of the current HDU.
0073 
0074 A.  Vector List.  The datasource would call a function in libfitsfile to build
0075 the fieldlist for the current HDU.  For an image extension, it will read the
0076 units and add 2 fields to the fieldlist that represent the pixel index (row
0077 major) and the flat-packed pixel values from the image.  For a table
0078 extension, it will read the names and units of the columns and combine them
0079 to create a field name to add to the fieldlist.
0080 
0081 B.  Matrix List.  The datasource would call a function in libfitsfile to build
0082 the matrixlist for the current HDU.  For an image extension, it will read the
0083 units and add a field to the matrixlist which represents the rectangular 
0084 image data.  For a table extension, it will read the names and units of all 
0085 columns and combine them to create a field name to add to the matrixlist.  So 
0086 for a table extension, the corresponding matrix field has the same dimensions 
0087 as the table.
0088 
0089 C.  Dealing with corrupt or "poorly created" files.  Unfortunately, not all
0090 FITS files "in the wild" are of the same quality.  Sometimes files become
0091 truncated or the software creating the file has made a mistake.  In my
0092 experience, a more robust way of handling these issues is to use the very low
0093 level functions of cfitsio to read the file.  This makes it easier to handle
0094 errors with a subset of the data in the file, while keeping any data that is
0095 good. The higher level functions tend to just give up if they encounter a
0096 problem.
0097 
0098 D.  Configuration.  The initial config widget will be very simple, and allow
0099 the user to choose which HDU to use in the file.
0100 
0101 E.  Command line.  The command line switches -x, -y, and -z will determine how
0102 the fitsfile datasource returns data to be plotted.  If the -z option is not
0103 specified, all further actions pertain to the first HDU.  If the -z option is 
0104 specified alone, the value will be taken as the HDU to plot as an image.  If
0105 the -x and -y options are specified, then their values correspond to the
0106 columns of the fieldlist to use.  If no -x is specified, data is plotted
0107 versus the INDEX field for the selected HDU.
0108 
0109 
0110 WCS Extensions
0111 --------------------------------------------------------------------
0112 The WCS system provides a way of specifying the coordinates of each pixel
0113 value in a FITS image.  This can be done by specifying mapping parameters, or
0114 even by specifying every pixel's coordinates in a binary table extension. 
0115 This is great, but what can we do with this information?  The best we can do
0116 at this point is maybe support some limited types of coordinate mappings
0117 (rectangular ones).  Full support of WCS projections will not be possible
0118 with kst until we have a complete 3D display framework.
0119 
0120 Note that WCS is implemented as an external library.  It is small and GPL'd,
0121 so it may be easier to just include the files we wish within the fitsfile
0122 datasource.  This can be discussed more later.
0123 
0124 
0125 Healpix, LFIIO, and Miscellaneous
0126 --------------------------------------------------------------------
0127 
0128 A.  The healpix datasource needs to support the use case of reading the pixel
0129 values straight out of the binary table as vectors.  I will do this by adding
0130 some additional fields to the fieldlist that have the form "(RAW) <field
0131 name>", so that the user knows what they are getting.
0132 
0133 B.  The LFIIO datasource needs to support interleaved data in tables.  My hope
0134 is that it can make use of some of the existing utility functions in
0135 libfitsfile. For example, it could call the function to read all keys and then
0136 check if there are special keys to indicate that the file is an LFIIO fits
0137 file.  Then it could call another function to build the fieldlist and simply
0138 add/remove a couple fields to deal with the interleaving.  So basically LFIIO
0139 would support all the functionality of the fitsfile datasource (through the
0140 use of libfitsfile), with some "extra" functionality built on top.
0141 
0142 C.  Notes:  Need to properly handle null pixel values in images.
0143 
0144 
0145 
0146