IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 2504


Ignore:
Timestamp:
Nov 26, 2004, 3:48:49 PM (22 years ago)
Author:
eugene
Message:

added header / camera / config modules

Location:
trunk/doc/modules
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/modules/ChangeLogSDRS.tex

    r2335 r2504  
    1 %%% $Id: ChangeLogSDRS.tex,v 1.6 2004-11-11 04:01:23 price Exp $
     1%%% $Id: ChangeLogSDRS.tex,v 1.7 2004-11-27 01:48:49 eugene Exp $
    22
    33\subsection{Changes from version 00 to version 01}
     
    1818  number of spline pieces if spline fitting is specified.
    1919\item Refined \code{pmReadoutCombine} specification in response to bug 227.
     20\item added details to the functions \code{pmCameraFromHeader}, \code{pmCameraValidateHeaders}, and \code{pmFPAfromHeader}. 
     21
     22\item reorganiztion: placed configuration section up front, camera layout next, etc
     23\item added details about configuration system
     24\item added utility modules \code{pmConfigLoadSite}, \code{pmConfigLoadCamera}, \code{pmConfigLoadRecipe}
     25\item added utility modules \code{pmConfigLookupSTR}, \code{pmConfigLookupS32}, \code{pmConfigLookupF64}, \code{pmConfigLookupRegion},
     26\item added discussion about Coordinate transforms
     27\item added discussion about \code{pmReadoutLoad}
     28\item added module \code{pmSubtractSky}
    2029\end{itemize}
     30
  • trunk/doc/modules/ModulesSDRS.tex

    r2335 r2504  
    1 %%% $Id: ModulesSDRS.tex,v 1.21 2004-11-11 04:01:43 price Exp $
     1%%% $Id: ModulesSDRS.tex,v 1.22 2004-11-27 01:48:49 eugene Exp $
    22\documentclass[panstarrs]{panstarrs}
    33
    44% basic document variables
    5 \title{Pan-STARRS Image Processing Pipeline Modules}
     5\title{Pan-STARRS PS-1 Image Processing Pipeline Modules}
    66\subtitle{Supplementary Design Requirements}
    77\shorttitle{Modules SDRS}
     
    1111\project{Pan-STARRS Image Processing Pipeline}
    1212\organization{Institute for Astronomy}
    13 \version{01}
     13\version{02}
    1414\docnumber{PSDC-430-012}
    1515
     
    3434
    3535\DocumentsInternal
    36 PSCD-130-001  &   PS-1 Design Reference Mission \\ \hline
    37 PSCD-430-004  &   Pan-STARRS IPP C Code Conventions \\ \hline
    38 PSCD-430-005  &   Pan-STARRS IPP SRS \\ \hline
    39 PSCD-430-006  &   Pan-STARRS IPP ADD \\ \hline
    40 PSCD-430-008  &   Pan-STARRS IPP Architecture SDR \\
     36PSCD-230-001  &   PS-1 Design Reference Mission \\ \hline
     37PSDC-430-004  &   Pan-STARRS PS-1 IPP C Code Conventions \\ \hline
     38PSDC-430-005  &   Pan-STARRS PS-1 IPP Software Requirements Specification \\ \hline
     39PSDC-430-006  &   Pan-STARRS PS-1 IPP Algorithm Design Document \\ \hline
     40PSDC-430-011  &   Pan-STARRS PS-1 IPP System/Subsystem Design Description \\ \hline
    4141\DocumentsExternal
    4242Posix Standard & Open Group Based Specifications Issue 6, IEEE Std 1003.1, 2003 \\
     
    5252
    5353This document describes the Pan-STARRS Image Processing Pipeline (IPP)
    54 image processing modules.  The modules use the functionality of the
    55 \PS{} Library (PSLib) to perform more complex tasks.  They will
    56 eventually be tied together, employing a script written in a
    57 high-level language to form a ``processing stage''.  Modules will be
    58 constructed to support each of the required processing stages, and are
    59 listed in this document according to the particular processing stage
    60 for which they will primarily be used.
     54data analysis Modules.  The Modules use the functionality of the
     55Pan-STARRS Library (PSLib) to perform more complex tasks, especially
     56tasks which require assumptions of astronomical analysis or the data
     57organization.  Within the IPP, the Modules are tied together into
     58programs which perform complete data analysis tasks (an ``analysis
     59stage'').  The modules may be tied together within a C framework or
     60using a high-level scripting language.  Bindings of the Modules are
     61made available to the scripting language using the program SWIG.
    6162
    6263In order to preserve name space, globally-visible structures and
    63 functions shall be prefixed with \code{pm}, for ``\PS{} Modules''.
    64 
     64functions shall be prefixed with \code{pm}, for ``Pan-STARRS
     65Modules''.
     66
     67\section{Runtime Configuration Data}
     68
     69PSLib defines a \code{psMetadata} structure which can carry labeled
     70data of arbirtary types.  The associated functions implemented by
     71PSLib consist of tools to manipulate and extract data from
     72\code{psMetadata} collections.  Within PSLib, the \code{psMetadata}
     73stucture is used to carry the data from a FITS header.  In addition,
     74functions are available to fill a \code{psMetadata} collection from a
     75text-based configuration file using a particular syntax, and to fill a
     76\code{psMetadata} collection from a properly formatted XML document. 
     77
     78In the IPP Modules, we use \code{psMetadata} collections to carry
     79run-time configuration data used by the data analysis modules.  Below,
     80in the discussion of the various modules, this configuration
     81information is defined by specifying the name of the data item of
     82interest, the conceptual meaning of that data item, and the allowed
     83values for the data item.  In this section, we discuss top-level
     84concepts related to the configuration information, including the
     85sources of the run-time configuration data and special
     86operations used to extract information from the configuration system.
     87
     88\subsection{Configuration Data Sources}
     89
     90All modules need to load some configuration information defining
     91parameters which may be configured at run-time.  Some module require
     92only a basic amount of information, while others require configuration
     93information defining the camera or details of an analysis (the {\it
     94recipe}).  We define three utility functions to load these files from
     95standard locations, with optional command-line override values.
     96
     97\begin{verbatim}
     98bool pmConfigLoadSite   (psMetadata **site, int *argc, char **argv);
     99bool pmConfigLoadCamera (psMetadata **camera, psMetadata *site, psMetadata *header, int *argc, char **argv);
     100bool pmConfigLoadRecipe (psMetadata **recipe, psMetadata *camera, int *argc, char **argv, char *script);
     101\end{verbatim}
     102
     103\code{pmConfigLoadSite} loads basic configuration information from a
     104general configuration file.  By default, this file has the name
     105\code{~/.ipprc} in the user's home directory.  This file may be
     106overridden on the command line with the optional flag \code{-site
     107(file)}.
     108
     109% eventually, we should define the complete sequence:
     110% $FOO, ~/.foorc, /prefix/config/foorc
     111
     112\code{pmConfigLoadCamera} loads camera configuration information from
     113a file which depends on the camera of interest.  In some cases, the
     114camera may be determined from the header of an image currently in
     115hand.  In other cases, the camera must be specified without reference
     116to a file.  This function attempts to determine the appropriate camera
     117configuration file by examining, in order, the command-line options,
     118the header data, and the site configuration data.  The camera config
     119file may be specified on the command line with the option
     120\code{-camera (file)}.  If this does not exist, the
     121\code{pmConfigLoadCamera} examines the provided header to determine
     122the camera by using the function \code{pmCameraFromHeader} (defined
     123below).  If this fails, the function attempts to determine the camera
     124from the provided site config data, looking for the keyword
     125\code{CAMERA} in the site config data.  The camera name is used to
     126select the camera configuration file, defined in the site
     127configuration file with the keyword \code{CAMERA.name}, where
     128\code{name} is substituted with the name of the camera.
     129
     130\code{pmConfigLoadRecipe} loads the recipe configuration information
     131from a file which depends on the camera of interest and the particular
     132analysis task.  The camera configuration file must define recipe files
     133for each of the analysis tasks of interest.  The function attempts to
     134load the recipe file using the keyword \code{RECIPE.name}, where
     135\code{name} is substituted with the name of the analysis task, for
     136example \code{PHASE2}.  The choice of the recipe file may be
     137overridden on the command line with the option \code{-recipe (file)}.
     138
     139\subsection{Indirect Configuration Data}
     140
     141Some configuration data is not provided directly by the configuration
     142files.  Instead, the configuration system provides a mechanism to
     143define indirect references to configuration data.  Three indirect
     144configuration data sources are currently defined: data from a FITS
     145header, data from the Metadata Database, and data from the Pan-STARRS
     146Status Server.  The configuration data may specify that a certain
     147value is provided by one of these mechanisms. 
     148
     149In order to specify that the configuration data should be derived from
     150a FITS header, the data value is given in the form: \code{HD:KEYWORD},
     151where \code{KEYWORD} specifies the keyword to be used in search the
     152FITS header. 
     153
     154If the data is to be extracted from the Metadata Database, the data
     155value is given in the form: \code{MD:TABLE,FIELD,KEY}.  In this case,
     156\code{TABLE} specifies the Metadata Database table to be used to find
     157the value, \code{FIELD} specifies the field in that table to be used,
     158and \code{KEY} specifies the value of the primary key which gives the
     159value of interest.
     160
     161If the data is to be extracted from the Status Server, the data value
     162is given in the form: \code{SS:PATH}.  In this case, \code{PATH}
     163specifies the Status Server path to the data value of interest. 
     164
     165{\bf \it note that the Metadata Database and Status Server
     166  interactions require us to define the APIs for these interactions.
     167  These two methods are not available until the MD and SS APIs are
     168  defined.}
     169
     170As an example, consider the definition of the data region of an image.
     171This value is frequenty represented in the FITS header with the
     172keyword \code{DATASEC}.  However, in some cameras, this value may not
     173be defined, or another value may be used.  We must be able to flexibly
     174define both the appropriate keyword, or the actual value, if known.
     175These two cases may be written as follows, using the configuration
     176file format parsed by \code{psMetadataParseConfig}:
     177\begin{verbatim}
     178DATA.REGION  STR  [1:100,2:400]
     179DATA.REGION  STR  HD:DATASEC
     180\end{verbatim}
     181In the first case, the data provided in the configuration file is the
     182data of interest.  (\code{[1:100,2:400]}).  In the second case, the
     183three-character code \code{HD:} specifies that the value of interest
     184may be determined by searching for the value associated with the
     185header keyword \code{DATASEC}.
     186
     187We provide utilities functions to extract this type of potentially
     188indirect configuration information.  We provide four functions
     189returning four data types.  The first three return the value from the
     190appropriate location assuming the data type to be \code{char*},
     191\code{psS32}, and \code{psF64}.  The fourth version searches for a
     192string which is passed to the function \code{psRegionFromString}
     193before being returned as a \code{psRegion} pointer.
     194
     195\begin{verbatim}
     196psSTR     pmConfigLookupSTR    (psMetadata *config, psMetadata *header, char *name);
     197psS32     pmConfigLookupS32    (psMetadata *config, psMetadata *header, char *name);
     198psF64     pmConfigLookupF64    (psMetadata *config, psMetadata *header, char *name);
     199psRegion *pmConfigLookupRegion (psMetadata *config, psMetadata *header, char *name);
     200\end{verbatim}
     201
     202\section{Camera Data Organization \& Camera Geometry}
     203
     204We require several utility functions to define the geometry of the
     205detectors in a camera and to specify the organization of the camera
     206data in real FITS images.  The camera data organization is defined in
     207a set of \code{psMetadata} structures, and may be stored on disk in
     208the file format parsed by \code{psMetadataParseConfig}.
     209
     210PSLib defines a hierarchy of data structures related to the
     211organization of the pixels in a camera.  These structures, starting
     212from the top level, follow the sequence \code{psFPA}, \code{psChip},
     213\code{psCell}, \code{psReadout}, \code{psImage}.  Each lower level
     214structure is carried as an array in the higher level.  The containers
     215as defined by PSLib include functions which specify the astrometric
     216relationships between these levels, and provide a single
     217\code{psMetadata} container pointer for each level.  In this section,
     218we define the type of metadata is stored in these metadata containers
     219and how the image headers are parse to define the data hierarchy in
     220memory. 
     221
     222\subsection{Camera Config Data \& the {\tt psFPA}}
     223
     224A relevant collection of metadata is the externally supplied camera
     225definition metadata loaded with the function
     226\code{pmConfigLoadCamera}.  This metadata defines the expected layout
     227of a specific camera along with information detailing how to interpret
     228the headers for an image from that camera.  The camera metadata
     229consists of keyword / value pairs which are relevant to the entire
     230camera, and a set of metadata collections specified for each cell.
     231This top-level metadata is added to the \code{psFPA} with the name
     232'CAMERA.LAYOUT'.  For example:
     233\begin{verbatim}
     234fpa->metadata = psMetadataAdd (fpa->metadata, PS_LIST_TAIL, "CAMERA", PS_META_META, "camera", camera);
     235\end{verbatim}
     236The specific cell-level entries are also placed on the correpsonding
     237\code{psCell} elements.  These entries are added to the metadata with
     238the name 'CELL':
     239\begin{verbatim}
     240cell->metadata = psMetadataAdd (cell->metadata, PS_LIST_TAIL, "CELL", PS_META_META, "cell", cellMD);
     241\end{verbatim}
     242
     243\subsection{FITS File Data Representations}
     244
     245Within the FITS data representation, there are various choices which
     246can and have been made for the placement of the pixels in a data file.
     247In the simplest case, the camera consists of a single chip consisting
     248of a single cell always read with a single readout.  In this case, the
     249image data could be written as part of the primary data unit.  In a
     250more complex case with multiple chips and multiple cells, the data may
     251be organized in various ways.  The data may be distributed into
     252multiple files or in multiple FITS data extensions.  A single camera
     253image may be written as a collection of files for individual chips
     254with separate extensions for each cell (CFH12K.split, GPC).  Another
     255camera may write a single file with multiple extensions for each cell
     256(Megacam.raw), or multiple extensions per chip, which each cell
     257representing portions of the chip image (Megacam.splice, CFHT-IR).
     258
     259In all of these representations, there are only two principal
     260distinctions in how the pixel data is stored.  Either a single data
     261block (a single FITS image) represents only a single cell, or it
     262represents a collection of cells.  This affects the way in which an
     263image is read in, the way the header is associated with a level of the
     264data hierarchy, and the way in which the header keywords are
     265interpretted to define the layout of the pixels in the cell.  We
     266distinguish these two cases as 'cell-based' and 'chip-based' layout.
     267
     268The FITS headers are attached to the \code{psFPA} data hierarchy by
     269adding them to the \code{psMetadata} entries for the appropriate data
     270level.  Each of the data levels \code{psFPA}, \code{psChip}, and
     271\code{psCell} have \code{metadata} elements to store relevant metadata
     272of any type.  A FITS header metadata collection may be added to one of
     273these metadata collections using the metadata name 'HEADER':
     274\begin{verbatim}
     275fpa->metadata = psMetadataAdd (fpa->metadata, PS_LIST_TAIL, "HEADER", PS_META_META, "header", header);
     276\end{verbatim}
     277
     278In 'cell-based' layout, the headers are attached to the corresponding
     279\code{psCell} element.  In 'chip-based' layout, the headers are
     280attached to the \code{psChip} element.  This difference is natural
     281since a 'cell-based' data file has one FITS extension, and therefore
     282one FITS header, for each \code{cell}.  Conversely, in a 'chip-based'
     283data file, there is one extension per chip, and therefore multiple
     284cells for each FITS header, but only one chip for each FITS header. 
     285
     286\subsection{Determine the Camera from the Primary Header}
     287
     288\begin{verbatim}
     289char *pmCameraFromHeader (psFitsHeader *header, psMetadata *rules);
     290\end{verbatim}
     291
     292This function examines a primary header unit (\code{header}) and
     293determines the camera which provided the data.  The rules which
     294identify the camera are defined as a \code{psMetadata} structure
     295containing one element for each known camera.  These are generally to
     296be provided as part of the site configuration information.  The
     297elements of this \code{psMetadata} container are in turn
     298\code{psMetadata} containers consisting of the expected header
     299keywords and their required values.  The function
     300\code{pmCameraFromHeader} tests each of the defined cameras in
     301succession.  For each camera, it searches for each of the given
     302keywords and compares the value with the value expected.  If the
     303keyword does not exist, or if the keyword has the wrong value, the
     304camera is rejected.  The name of first camera which matches the header
     305is returned as an allocated string.  If no match is found, the
     306returned value must be \code{UNKNOWN}.  This condition may be treated
     307by calling functions as either an error or only a warning.  If an
     308error is encountered in parsing the metadata containers, then
     309\code{NULL} is returned.  An example of the metadata keyword / value
     310pairs is given below (note that this uses an undefined metadata config
     311file representation \code{METADATA}):
     312
     313\begin{verbatim}
     314CFH12K.MEF      METADATA
     315  TELESCOP      STR   CFHT
     316  INSTRUME      STR   CFH12K
     317  EXTEND        BOOL  T
     318  NEXTEND       S32   12
     319END
     320
     321CFH12K.SPLIT    METADATA
     322  TELESCOP      STR   CFHT
     323  INSTRUME      STR   CFH12K
     324  EXTEND        BOOL  F
     325END
     326\end{verbatim}
     327
     328\begin{figure}
     329\begin{center}
     330\psfig{file=CameraHierarchy,width=5.0in}
     331\caption{Camera Data and Metadata Hierarchy\label{CameraHierarchy}}
     332\end{center}
     333\end{figure}
     334
     335\subsection{Validate the Header set \& Construct the FPA}
     336
     337\begin{verbatim}
     338bool  pmCameraValidateHeaders (psMetadata *headers, psMetadata *camera);
     339psFPA *pmFPAfromHeader (psMetadata *headers, psMetadata *camera);
     340\end{verbatim}
     341
     342These funtions examine the collection of \code{headers} and compare
     343them with the camera definitions in the metadata structure
     344\code{camera}.  One function (\code{pmFPAfromHeader}) uses the header
     345set and camera definition file to construct a \code{psFPA} with all
     346\code{psChip} and \code{psCell} entries allocated, but without any
     347\code{psReadout} or pixel data.  The other function validates the
     348header set against the camera definition, but does not actually
     349construct the \code{psFPA}. 
     350
     351The camera definition metadata collection defines the relationship
     352between chips, cells, and the FITS extensions.  An example of the data
     353needed by \code{pmCameraValidateHeaders} and \code{pmFPAfromHeader} is
     354given below for several types of cameras in the form of a metadata
     355config file. 
     356
     357\begin{verbatim}
     358MEGACAM.RAW     METADATA   
     359  NCELL         S32    72
     360  CELL.FMT      STR    CELL.%02d
     361  EXT.TYPE      STR    CELL
     362  EXT.KEY       STR    EXTNAME
     363  PHU           STR    FPA
     364  #
     365  #                    EXT.KEY  CHIP 
     366  CELL.00       CELL   amp00    CHIP.00
     367  CELL.01       CELL   amp01    CHIP.00
     368  CELL.02       CELL   amp02    CHIP.01
     369  CELL.03       CELL   amp03    CHIP.01
     370  ...
     371END
     372
     373MEGACAM.SPLICE  METADATA     
     374  NCELL         S32    36
     375  CELL.FMT      STR    CELL.%02d
     376  EXT.TYPE      STR    CHIP
     377  EXT.KEY       STR    EXTNAME
     378  PHU           STR    FPA
     379  #
     380  #                    EXT.KEY  CHIP 
     381  CELL.00       CELL   ccd00    CHIP.00
     382  CELL.01       CELL   ccd00    CHIP.00
     383  CELL.02       CELL   ccd01    CHIP.01
     384  CELL.03       CELL   ccd01    CHIP.01
     385  ...
     386END
     387
     388CFH12K.SPLIT    METADATA
     389  NCELL         S32    12
     390  CELL.FMT      STR    CELL.%02d
     391  EXT.TYPE      STR    CELL
     392  EXT.KEY       STR    EXTNAME
     393  PHU           STR    NONE
     394  #
     395  #                    EXT.KEY  CHIP   
     396  CELL.00       CELL   chip00   CHIP.00
     397  CELL.01       CELL   chip01   CHIP.01
     398  CELL.02       CELL   chip02   CHIP.02
     399  ...
     400END
     401
     402GPC.RAW         METADATA   
     403  NCELL         S32    4096
     404  CELL.FMT      STR    CELL.%04d
     405  EXT.TYPE      STR    CELL
     406  EXT.KEY       STR    EXTNAME
     407  PHU           STR    CHIP
     408  #
     409  #                    EXT.KEY  CHIP 
     410  CELL.0000     CELL   amp00    CHIP.00
     411  CELL.0001     CELL   amp01    CHIP.00
     412  CELL.0002     CELL   amp02    CHIP.00
     413  CELL.0003     CELL   amp03    CHIP.00
     414  ...
     415  CELL.0065     CELL   amp03    CHIP.01
     416  CELL.0066     CELL   amp03    CHIP.01
     417  ...
     418END
     419\end{verbatim}
     420
     421Among the important elements of the camera definition information are:
     422\begin{itemize}
     423\item \code{NCELL} - this defines the possible number of cells from this
     424  camera.
     425\item \code{CELL.FMT} - this defines the format of the \code{CELL.nn}
     426  keywords below in the metadata collection, one for each of the
     427  \code{NCELL} values
     428\item \code{EXT.TYPE} - this defines the lowest data level
     429  corresponding to a single FITS extension: \code{CELL} or
     430  \code{CHIP}.  In some cases, a single extension represents a chip,
     431  and is subdivided into cells by header keywords specifying certain
     432  regions.  In other cases, a single extension represents only the
     433  data from a single amplifier, ie, a cell.  These two cases require
     434  somewhat different handling.
     435\item \code{EXT.KEY} - this entry defines a header keyword which
     436  allows the unique identification of a given header with one of the
     437  cell or chip entries (depending on the value of \code{EXT.TYPE}).
     438\item \code{PHU} - this entry defines the meaning of the FITS file
     439  primary header unit.
     440\end{itemize}
     441In addition to these generic parameters, the camera definition
     442metadata includes an entry for each cell giving specific values
     443required to define that cell. 
     444
     445Both functions \code{pmCameraValidateHeaders} and
     446\code{pmFPAfromHeader} must start with the set of headers and attempt
     447to identify the corresponding cell or chip.  All available cells and
     448chips must be identified, and the cells corresponding to each chip
     449must be tracked.  In the case of \code{pmCameraValidateHeaders}, the
     450function must only verify the headers contain valid extensions,
     451without allocating the correpsonding \code{psFPA}, while
     452\code{pmFPAfromHeader} must also allocate the \code{psFPA}, the
     453contained \code{psChip} arrays, and the correct number of
     454\code{psCell} arrays for each \code{psChip}.
     455
     456These functions also add to the metadata containers for the chips and
     457cells, following the rules discussed above. Each \code{psCell} entry
     458should have the \code{CELL} metadata lines from above attached to the
     459\code{psCell.metadata} element as an additional metadata collection
     460with the name \code{CELL.LAYOUT}.  The complete camera metadata
     461collection (including the cells), are attached to the
     462\code{psFPA.metadata} element with the name \code{CAMERA.LAYOUT}.  The
     463image header data are also attached to metadata entries, at a level
     464which depends on the value of \code{EXT.TYPE} in the camera layout
     465data above.  If the value is \code{CELL}, the header metadata
     466collections are attached to the \code{psCell.metadata} elements with
     467the name \code{HEADER}.  If the value of \code{EXT.TYPE} is chip, the
     468header metadata is attached to the \code{psChip.metadata} element,
     469again with the name \code{HEADER}. 
     470
     471An image file may also have a primary header unit which is not
     472associated with a data block.  This metadata block must also be added
     473to the data heirarchy so successive operations may update the metadata
     474as needed.  The disposition of the primary header unit is defined by
     475the camera layout key \code{PHU}.  If this has a value of \code{NONE},
     476there is no primary header unit, or it should be ignored.  If the
     477value is \code{FPR}, the primary header data is attached to the
     478\code{psFPA.metadata} element with the value PHU.  Alternatively, if
     479it has the value \code{CHIP}, then the primary header metadata is
     480attached to the \code{psChip.metadata} element.
     481
     482\subsection{Coordinate Transforms and Header Data}
     483\tbd{the algorithms for three functions in this section are not
     484  well-defined.  do not code yet}.
     485
     486Astrometric and geometric information about an image from a camera may
     487be represented in a variety of ways.  A crude representation of the
     488pixel geometry is specified in many image headers using the IRAF-style
     489region keywords \code{DATASEC}, \code{DETSEC}, etc.  These keywords
     490are used to define the location of a single image's pixels in the
     491frame of the full mosaic of detectors in the assumption that the
     492mosaic can be represented as a single uniform grid of pixels.  An
     493alternative set of keywords have been used in cases where multiple
     494cells are saved together in a single FITS image extension.  More
     495sophisticated astrometric representations require elements to define
     496projections, scaling, distortion, etc.  Several versions of header
     497keywords have been used to represent these astrometric
     498transformations.  In this section, we define three functions to
     499interpret a collection of image headers and construct the appropriate
     500offset and/or astrometry parameters.
     501
     502\begin{verbatim}
     503bool  pmFPADefineOffsets (psFPA fpa);
     504bool  pmFPADefineWCS (psFPA fpa);
     505bool  pmFPADefineWCSfromOffsets (psFPA fpa);
     506\end{verbatim}
     507
     508The first function takes a \code{psFPA} structure which has been
     509populated with header and camera configuration metadata in the
     510appropriate locations as discussed above.  Using the information in
     511the camera config metadata and the headers, the function sets the
     512values for the elements \code{psChip.col0,row0},
     513\code{psCell.col0,row0}, \code{psReadout.col0,row0},
     514\code{psReadout.colParity,rowParity}, and
     515\code{psReadout.colBinning,rowBinning}.  This information is
     516determined by examining the regions defined by the following names.
     517
     518% how do we handle the CCDSUM keyword case?
     519\begin{verbatim}
     520psCell.metadata:CELL:CCDBIN1 $\rightarrow$ psReadout.colBins
     521psCell.metadata:CELL:CCDBIN2 $\rightarrow$ psReadout.rowBins
     522
     523DETSEC from psCell.metadata:CELL:DETSEC
     524CCDSEC from psCell.metadata:CELL:CCDSEC
     525DATASEC from psCell.metadata:CELL:DATASEC
     526
     527if (DETSEC.x0 > DETSEC.x1) then psReadout.colParity = -1
     528if (DETSEC.y0 > DETSEC.y1) then psReadout.rowParity = -1
     529\end{verbatim}
     530
     531The second function examines the contents of the headers of the chips
     532and cells and constructs the collection of astrometric coordinate
     533transformations..
     534
     535The third function uses the offset information and the basic telescope
     536pointing information to construct a approximate guess at the
     537astrometric coefficients based on the detector geometry.
     538
     539\begin{figure}
     540\begin{center}
     541\psfig{file=CameraLayout,width=5.5in}
     542\caption{Camera Pixel Layout\label{CameraLayout}}
     543\end{center}
     544\end{figure}
     545
     546\begin{figure}
     547\begin{center}
     548\psfig{file=CameraRegionKeywords.ps,width=5.5in}
     549\caption{Camera Region Keyword Definitions\label{CameraRegionKeywords}}
     550\end{center}
     551\end{figure}
     552
     553\subsection{Chip \& Cell from FITS File}
     554\tbd{the algorithm for the function in this section is not
     555  well-defined.  do not code yet}.
     556
     557When loading data from disk, it is may be necessary to use the
     558information in the DATASEC and DETSEC entries to determine which part
     559of the image should be read.  If the data is stored in a chip-based
     560format, then the data for each cell corresponds to only a fraction of
     561the pixels stored in a single image extension.  We specify the
     562following function to perform the correct read of data from a FITS
     563file into the corresponding \code{psCell} entry respecting the
     564boundaries of the cells within chip-based images.
     565
     566\begin{verbatim}
     567psReadout *pmReadoutLoad (psReadout *input, psFits *f, psCell *cell, int plane);
     568\end{verbatim}
    65569
    66570\section{Phase 2}
     
    76580\item Flat-field;
    77581\item Mask bad pixels;
    78 \item \tbd{Subtract the background;}
     582\item Subtract the background;
    79583\item \tbd{Mask cosmic rays;}
    80584\item \tbd{Mask optical defects;}
     
    358862image), the function shall generate an error.
    359863
    360 
    361 
    362 \section{Calibration}
    363 
    364 The calibration module essentially consists of combining multiple
    365 images of a particular type in order to build up signal-to-noise.  For
    366 this, we require a general purpose image combination module.  We
    367 forsee this module as only acting upon data from the same detector,
    368 and so each input image will have the same noise characteristics.
    369 
    370 \begin{verbatim}
    371 typedef struct {
    372     psStats *stats;                     // Statistics to use in combining pixels
    373     unsigned int maskVal,               // Mask pixels where mask & maskVal == 1
    374     float fracHigh;                     // Fraction of high pixels to throw
    375     float fracLow;                      // Fraction of low pixels to throw
    376     int nKeep;                          // Number of pixels to be sure to keep
    377 } pmCombineParams;
    378 
    379 psImage *
    380 pmReadoutCombine(psImage *output,       // Output image, or NULL
    381                  const psList *inputs,  // List of input readouts
    382                  pmCombineParams *params, // Combination parameters
    383                  const psVector *zero,  // Offsets to apply for each image
    384                  const psVector *scale, // Scales to apply for each image
    385                  bool applyZeroScale,   // Are zero and scale for application, or only noise properties?
    386                  float gain,            // Gain in e/ADU
    387                  float readnoise        // Read noise in e
    388                  );
    389 \end{verbatim}
    390 
    391 \code{pmReadoutCombine} combines input images pixel by pixel --- for
    392 each pixel of the output image, a stack of contributing input pixels
    393 is formed and combined.  Several of its input parameters are lists or
    394 vectors, and if these are not all of the same length (or \code{NULL}),
    395 the module shall generate an error and return \code{NULL}.
    396 
    397 If the provided \code{output} is \code{NULL}, then the module shall
    398 allocate a new image of sufficient size for the input images.  If the
    399 \code{output} image is non-\code{NULL} and is not of sufficient size
    400 for the combined image, the module shall generate an error and return
    401 \code{NULL}.
    402 
    403 If the \code{inputs} is \code{NULL}, the module shall generate an
    404 error and return \code{NULL}.  Otherwise, the \code{inputs} shall be a
    405 list of \code{psReadout}s.  The images contained within the
    406 \code{psReadout}s need not all be of the same size, but the module
    407 shall take into account the offsets (\code{col0,row0}) from the corner
    408 of the detector when comparing pixels, so that it is the same
    409 \textit{physical} pixels that are combined.
    410 
    411 The parameters used in the combination, including how the pixels are
    412 to be combined, and how the rejection is performed is contained within
    413 the \code{params}, which may not be \code{NULL} (otherwise the module
    414 shall generate an error and return \code{NULL}).  We choose to use
    415 this structure instead of supplying the values separately in order to
    416 keep down the number of parameters to \code{pmReadoutCombine}; the
    417 \code{psCombineParams} may be recycled for subsequent calls to
    418 \code{pmReadoutCombine} since the values are not dependent upon the
    419 choice of inputs, but merely specify how the combination is to be
    420 performed.
    421 
    422 The particular statistic specified by \code{stats} shall be used to
    423 combine each stack of pixels from the input images.  Only one of the
    424 statistics choices may be specified, otherwise the module shall
    425 generate an error and return \code{NULL}.
    426 
    427 If the \code{maskVal} is non-zero, then pixels in the \code{mask} of
    428 each \code{psReadout} in the \code{inputs} which satisfy the
    429 \code{maskVal} shall not have the corresponding pixels placed in the
    430 stack for combination.
    431 
    432 After masking, but before performing the combination, the highest
    433 \code{fracHigh} fraction and lowest \code{fracLow} fraction of pixels
    434 in the stack are immediately rejected, unless this would leave less
    435 than \code{nKeep} pixels in the stack, in which case no immediate
    436 rejection is performed.
    437 
    438 If the \code{zero} vector is non-\code{NULL} and \code{applyZeroScale}
    439 is \code{true}, then the appropriate values shall be added to the
    440 \code{inputs} before rejection is performed.  If \code{zero} is
    441 non-\code{NULL} and \code{applyZeroScale} is false, then the values
    442 shall only be used in calculating the noise.
    443 
    444 If the \code{scale} vector is non-\code{NULL} and
    445 \code{applyZeroScale} is \code{true}, then the appropriate values
    446 shall multiply the \code{inputs} before rejection is performed.  If
    447 \code{scale} is non-\code{NULL} and \code{applyZeroScale} is false,
    448 then the values shall only be used in calculating the noise.
    449 
    450 The purpose of \code{applyZeroScale} is to allow combination of fringe
    451 frames, where the frames have been deliberately sky-subtracted and
    452 rescaled (to get the fringes amplitudes running from -1 to 1), which
    453 actions should not be undone when combining, but yet it is desirable
    454 to provide the \code{zero} and \code{scale} values so that the correct
    455 noise properties are used in the combination.
    456 
    457 If the \code{gain} and \code{readnoise} are positive and non-negative
    458 (respectively), then these shall be used to provide weights for the
    459 combination using Poisson statistics.
    460 
    461 The \code{inputs, zero} and \code{scale} may be of S16, S32 and F32
    462 types, and must all be of the same type.  The \code{output} shall be
    463 of the same type.
    464 
    465 \section{Camera Configutation Information}
    466 
    467 \tbd{these function are not yet ready for implementation.  The APIs
    468   are fine but the algorithms need to be specified.}
    469 
    470 We require several utility functions to define the general layout of a
    471 camera and to relate the camera definition to the header in a given
    472 camera.  This information may be passed to the modules by using the
    473 configuration files as parse by \code{psMetadataParseConfig}.  These
    474 
    475 \begin{verbatim}
    476 char *pmCameraFromHeader (psFitsHeader *header);
    477 \end{verbatim}
    478 This function examines a primary header unit (\code{header}) and
    479 determines the camera which provided the data.  \tbr{the rules for
    480   performing this analysis probably depend on the keywords such as
    481   INSTRUME and TELESCOP.  Should this function be a script so we can
    482   easily add a new camera or should the rule set be defined by
    483   configuration information?}.
    484 
    485 \begin{verbatim}
    486 bool  pmCameraValidateHeaders (psHash *headers, psMetadata *camera);
    487 \end{verbatim}
    488 This funtion examines the collection of \code{headers} and, based on
    489 the camera definitions in the metadata \code{camera}, determines if
    490 the header set is consistent with the specified camera.
    491 
    492 \begin{verbatim}
    493 psFPA *pmFPAfromHeader (psList *header, psMetadata *camera);
    494 \end{verbatim}
    495 This funtion uses the collection of \code{headers} and the camera
    496 definitions in the metadata \code{camera} to construct a complete
    497 \code{psFPA} structure which represents the data described by the
    498 collection of \code{headers}.  The resulting \code{FPA} has all
    499 possible structure elements defined but no space for pixel data should
    500 be allocated. 
    501 
    502 \section{Revision Change Log}
    503 \input{ChangeLogSDRS.tex}
    504 
    505 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    506 \bibliographystyle{plain}
    507 \bibliography{panstarrs}
    508 
    509 \end{document}
    510 
    511864\subsection{Subtract sky}
    512 
    513 \tbd{This is a simple sky subtraction routine.  A more complicated
    514 routine will be specified in the future, following research into the
    515 best algorithm.}
    516865
    517866Given an input image, a polynomial or spline specifying the order of a
    518867desired fit, a binning factor and statistics to use for the binning,
    519 along with a clipping level, \code{psPhase2SubtractSky} shall fit and
     868along with a clipping level, \code{pmSubtractSky} shall fit and
    520869subtract a model for the background of the image.  The API shall be
    521870the following:
    522871\begin{verbatim}
    523 psReadout *psPhase2SubtractSky(psReadout *in, void *fitSpec, psFit fit, int binFactor, psStats *stats,
    524                                float clipSD);
     872psReadout *pmSubtractSky(psReadout *in, void *fitSpec, psFit fit, int binFactor,
     873                         psStats *stats, float clipSD);
    525874\end{verbatim}
    526875
    527876Note that the input image, \code{in}, shall be subtracted in-place.
    528877The function shall return the subtracted image, and also update the
    529 polynomial, chebyshev or spline specified by \code{fitSpec}, to hold
     878polynomial, Chebyshev or spline specified by \code{fitSpec}, to hold
    530879the coefficients used in the subtraction.
    531880
     
    560909
    561910
     911\section{Calibration}
     912
     913The calibration module essentially consists of combining multiple
     914images of a particular type in order to build up signal-to-noise.  For
     915this, we require a general purpose image combination module.  We
     916forsee this module as only acting upon data from the same detector,
     917and so each input image will have the same noise characteristics.
     918
     919\begin{verbatim}
     920typedef struct {
     921    psStats *stats;                     // Statistics to use in combining pixels
     922    unsigned int maskVal,               // Mask pixels where mask & maskVal == 1
     923    float fracHigh;                     // Fraction of high pixels to throw
     924    float fracLow;                      // Fraction of low pixels to throw
     925    int nKeep;                          // Number of pixels to be sure to keep
     926} pmCombineParams;
     927
     928psImage *
     929pmReadoutCombine(psImage *output,       // Output image, or NULL
     930                 const psList *inputs,  // List of input readouts
     931                 pmCombineParams *params, // Combination parameters
     932                 const psVector *zero,  // Offsets to apply for each image
     933                 const psVector *scale, // Scales to apply for each image
     934                 bool applyZeroScale,   // Are zero and scale for application, or only noise properties?
     935                 float gain,            // Gain in e/ADU
     936                 float readnoise        // Read noise in e
     937                 );
     938\end{verbatim}
     939
     940\code{pmReadoutCombine} combines input images pixel by pixel --- for
     941each pixel of the output image, a stack of contributing input pixels
     942is formed and combined.  Several of its input parameters are lists or
     943vectors, and if these are not all of the same length (or \code{NULL}),
     944the module shall generate an error and return \code{NULL}.
     945
     946If the provided \code{output} is \code{NULL}, then the module shall
     947allocate a new image of sufficient size for the input images.  If the
     948\code{output} image is non-\code{NULL} and is not of sufficient size
     949for the combined image, the module shall generate an error and return
     950\code{NULL}.
     951
     952If the \code{inputs} is \code{NULL}, the module shall generate an
     953error and return \code{NULL}.  Otherwise, the \code{inputs} shall be a
     954list of \code{psReadout}s.  The images contained within the
     955\code{psReadout}s need not all be of the same size, but the module
     956shall take into account the offsets (\code{col0,row0}) from the corner
     957of the detector when comparing pixels, so that it is the same
     958\textit{physical} pixels that are combined.
     959
     960The parameters used in the combination, including how the pixels are
     961to be combined, and how the rejection is performed is contained within
     962the \code{params}, which may not be \code{NULL} (otherwise the module
     963shall generate an error and return \code{NULL}).  We choose to use
     964this structure instead of supplying the values separately in order to
     965keep down the number of parameters to \code{pmReadoutCombine}; the
     966\code{psCombineParams} may be recycled for subsequent calls to
     967\code{pmReadoutCombine} since the values are not dependent upon the
     968choice of inputs, but merely specify how the combination is to be
     969performed.
     970
     971The particular statistic specified by \code{stats} shall be used to
     972combine each stack of pixels from the input images.  Only one of the
     973statistics choices may be specified, otherwise the module shall
     974generate an error and return \code{NULL}.
     975
     976If the \code{maskVal} is non-zero, then pixels in the \code{mask} of
     977each \code{psReadout} in the \code{inputs} which satisfy the
     978\code{maskVal} shall not have the corresponding pixels placed in the
     979stack for combination.
     980
     981After masking, but before performing the combination, the highest
     982\code{fracHigh} fraction and lowest \code{fracLow} fraction of pixels
     983in the stack are immediately rejected, unless this would leave less
     984than \code{nKeep} pixels in the stack, in which case no immediate
     985rejection is performed.
     986
     987If the \code{zero} vector is non-\code{NULL} and \code{applyZeroScale}
     988is \code{true}, then the appropriate values shall be added to the
     989\code{inputs} before rejection is performed.  If \code{zero} is
     990non-\code{NULL} and \code{applyZeroScale} is false, then the values
     991shall only be used in calculating the noise.
     992
     993If the \code{scale} vector is non-\code{NULL} and
     994\code{applyZeroScale} is \code{true}, then the appropriate values
     995shall multiply the \code{inputs} before rejection is performed.  If
     996\code{scale} is non-\code{NULL} and \code{applyZeroScale} is false,
     997then the values shall only be used in calculating the noise.
     998
     999The purpose of \code{applyZeroScale} is to allow combination of fringe
     1000frames, where the frames have been deliberately sky-subtracted and
     1001rescaled (to get the fringes amplitudes running from -1 to 1), which
     1002actions should not be undone when combining, but yet it is desirable
     1003to provide the \code{zero} and \code{scale} values so that the correct
     1004noise properties are used in the combination.
     1005
     1006If the \code{gain} and \code{readnoise} are positive and non-negative
     1007(respectively), then these shall be used to provide weights for the
     1008combination using Poisson statistics.
     1009
     1010The \code{inputs, zero} and \code{scale} may be of S16, S32 and F32
     1011types, and must all be of the same type.  The \code{output} shall be
     1012of the same type.
     1013
     1014\section{Revision Change Log}
     1015\input{ChangeLogSDRS.tex}
     1016
     1017%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     1018\bibliographystyle{plain}
     1019\bibliography{panstarrs}
     1020
     1021\end{document}
     1022
    5621023\subsection{Cosmic rays}
    5631024
     
    7051166\code{in}.
    7061167
    707 
    708 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    709 
    710 \section{Read in an FPA}
    711 
    712 \TBD{This section on reading in an FPA is all TBD and should not be
    713 implemented yet.}
    714 
    715 Of course, before any image manipulation may occur, the image must be
    716 read in.  This involves populating the FPA with structures to
    717 represent the true focal plane.  However, different instruments have
    718 different focal planes, and the images are written to disk in
    719 different ways.  We have proposed a configuration file format which
    720 appears to be able to document the structure of a focal plane and
    721 specify how the IPP can read the required information from the FITS
    722 files \tbd{REFERENCE}.
    723 
    724 Given an open \code{FILE} pointer to a configuration file,
    725 \code{config}, and the name of an FPA image, \code{fpaName},
    726 \code{psFPAGenerate} shall return a \code{psFPA} of the correct
    727 structure, with all the metadata entries read from the nominated FPA
    728 image.  Astrometric information shall be initialised to values
    729 specified by the configuration file.  The API shall be:
    730 
    731 \begin{verbatim}
    732 psFPA *psFPAGenerate(FILE *config, const char *fpaName);
    733 \end{verbatim}
    734 
    735 Once an FPA has been generated, the pixels may all be read in at once,
    736 or the pixels may be read in a chip, cell or readout at a time.  The
    737 corresponding APIs are:
    738 
    739 \begin{verbatim}
    740 psFPA *psFPAReadAll(psFPA *in);
    741 psFPA *psFPAReadChip(psFPA *in, const char *chipName);
    742 psChip *psChipReadCell(psChip *in, const char *cellName);
    743 psCell *psCellReadReadout(psCell *in, const char *readoutName);
    744 \end{verbatim}
    745 
    746 Note that reads of a cell or readout do not act upon an FPA, but
    747 rather a chip and a cell, respectively.  This saves the user from
    748 specifying the name of the FPA, chip, and cell just to get a readout,
    749 since this information is already stored in the generated \code{psFPA}
    750 struct.
    751 
    752 \tbd{Writing the output}
    753 
    754 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Note: See TracChangeset for help on using the changeset viewer.