IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 9721


Ignore:
Timestamp:
Oct 23, 2006, 5:08:59 PM (20 years ago)
Author:
Paul Price
Message:

Updating FPA and HDU section to match implementation: major changes.

File:
1 edited

Legend:

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

    r9712 r9721  
    303303correct, the function shall return \code{true}.
    304304
     305\subsubsection{Levels}
     306
     307The level within an FPA hierarchy may be specified by an enumerated
     308type:
     309\begin{datatype}
     310typedef enum {
     311    PM_FPA_LEVEL_NONE,                  ///< No particular level specified
     312    PM_FPA_LEVEL_FPA,                   ///< Level corresponds to an FPA
     313    PM_FPA_LEVEL_CHIP,                  ///< Level corresponds to a Chip
     314    PM_FPA_LEVEL_CELL,                  ///< Level corresponds to a Cell
     315    PM_FPA_LEVEL_READOUT                ///< Level corresponds to a Readout
     316} pmFPALevel;
     317\end{datatype}
     318
     319The following functions are provided to convert between the enumerated type
     320and string representation of the level:
     321\begin{prototype}
     322const char *pmFPALevelToName(pmFPALevel level ///< Level enum
     323                            );
     324pmFPALevel pmFPALevelFromName(const char *name ///< Level name
     325                             );
     326\end{prototype}
     327
     328The string representations are \code{FPA}, \code{CHIP}, \code{CELL}
     329and \code{READOUT} (case insensitive).
     330
     331\subsubsection{Flags}
     332
     333The following functions are provided to set and check the \code{file_exists}
     334and \code{data_exists} status flags within the FPA hierarchy:
     335\begin{prototype}
     336bool pmFPASetFileStatus(pmFPA *fpa,     ///< FPA for which to set status
     337                        bool status     ///< Status to set
     338                       );
     339bool pmChipSetFileStatus(pmChip *chip,  ///< Chip for which to set status
     340                         bool status    ///< Status to set
     341                        );
     342bool pmCellSetFileStatus(pmCell *cell,  ///< Cell for which to set status
     343                         bool status    ///< Status to set
     344                        );
     345bool pmFPACheckFileStatus(const pmFPA *fpa ///< FPA for which to check status
     346                         );
     347bool pmChipCheckFileStatus(const pmChip *chip ///< Chip for which to check status
     348                          );
     349bool pmCellCheckFileStatus(const pmCell *cell ///< Cell for which to check status
     350                          );
     351bool pmFPASetDataStatus(pmFPA *fpa,     ///< FPA for which to set status
     352                        bool status     ///< Status to set
     353                       );
     354bool pmChipSetDataStatus(pmChip *chip,  ///< Chip for which to set status
     355                         bool status    ///< Status to set
     356                        );
     357bool pmCellSetDataStatus(pmCell *cell,  ///< Cell for which to set status
     358                         bool status    ///< Status to set
     359                        );
     360\end{prototype}
     361
     362The following functions set the \code{process} flag within the FPA
     363hierarchy, either selecting a component for processing, or excluding
     364it from processing:
     365\begin{prototype}
     366bool pmFPASelectChip(pmFPA *fpa,        ///< FPA containing the chip of interest
     367                     int chipNum,       ///< Chip number to select
     368                     bool exclusive     ///< Process this chip exclusive of the others?
     369                    );
     370bool pmChipSelectCell(pmChip *chip,     ///< Chip containing the cell of interest
     371                      int cellNum,      ///< Cell number to select
     372                      bool exclusive    ///< Process this cell exclusive of the others?
     373                     );
     374int pmFPAExcludeChip(pmFPA *fpa,        ///< FPA containing the chip of interest
     375                     int chipNum        ///< Chip number to exclude
     376                    );
     377int pmChipExcludeCell(pmChip *chip,     ///< Chip containing the chip of interest
     378                      int cellNum       ///< Cell number to exclude
     379                     );
     380\end{prototype}
     381
     382The \code{Select} functions, set the specified component to be the
     383only component (at that level) to be processed if \code{exclusive} is
     384\code{true}.  A negative value for the component number is valid, and
     385if \code{exclusive} is \code{true}, de-selects all components at the
     386appropriate level.
     387
     388
     389\subsubsection{Finding a component by name}
     390
     391A component may be found by its symbolic name (the concepts
     392\code{CHIP.NAME} or \code{CELL.NAME}, as appropriate).  The following
     393functions return the index of the component that matches the provided
     394name, or -1 if none was found:
     395
     396\begin{prototype}
     397int pmFPAFindChip(const pmFPA *fpa,     ///< FPA in which to find the chip
     398                  const char *name      ///< Name of the chip
     399                 );
     400int pmChipFindCell(const pmChip *chip,  // Chip in which to find the cell
     401                   const char *name     // Name of the cell
     402                  );
     403\end{prototype}
     404
    305405
    306406\subsection{Header Data Units}
     
    507607
    508608
    509 
    510609%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    511610%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    512611%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    513612
    514 
    515 
    516 
    517 
    518 
    519 \subsection{Detector Coordinate Transformations}
    520 
    521 \tbd{The implementation of this section may change slightly if the
    522 coordinate transformations in the focal plane hierarchy are pushed
    523 into the metadata --- the math shouldn't change, just how the values
    524 are accessed.}
    525 
    526 \begin{figure}
    527 \psfig{file=pics/CameraLayout,width=5.5in}
    528 \caption{Camera Pixel Layout\label{CameraLayout}}
    529 \end{figure}
    530 
    531 These container levels also include in their definition the
    532 information needed to transform the coordinates in one of the levels
    533 to the coordinate system relevant at the higher levels.
    534 
    535 The data structures define the basic coordinate relationships between
    536 all of these data elements.  A set of offsets for each level in the
    537 data hierarchy specifies the location of the particular set of pixels
    538 in the next level of the hierarchy.  This is illustrated in
    539 Figure~\ref{CameraLayout}.  These offsets may be used to define the
    540 complete camera layout in the approximating assumption that all pixels
    541 in the camera are laid out on a single linear pixel grid.  This
    542 approximate is sufficient for many basic operations.  For more detail,
    543 the precise astrometric relationship between each level of the
    544 hierarchy may also be made available in the metadata of the data
    545 structures.
    546 
    547 In practice, a single readout from a detector may represent only a
    548 subset of the complete set of pixels addressed by the {\it cell}.  The
    549 readout may also have binning applied in both of the two dimensions.
    550 There may also be overscan and pre-scan regions in the set of pixels.
    551 Finally, the readout direction is not always the same for all detector
    552 amplifiers.  As shown in Figure~\ref{CameraLayout}, these different
    553 concepts are represented in the data hierarchy.  The coordinate of the
    554 origin of the data grid for one level of the hierarchy in the grid of
    555 the containing hierarchy is defined for each data level.  For example,
    556 the origin of the coordinates for a single chip are located in the
    557 camera grid at \code{pmChip.cell0,row0}.  The \code{pmReadout} data
    558 level has additional information to specify the details of the readout
    559 process.  The elements \code{pmReadout.colBins,rowBins} specify the
    560 binning factor in the two dimensions, while the sign indicates the
    561 parity of the specific readout (readout direction).  Note that the
    562 value of \code{pmReadout.col0,row0} must be assigned in such a way
    563 that it represents the coordinate of the origin pixel in the actual
    564 image: the overscan or pre-scan pixels must be accounted for.  Putting
    565 all of these element together, we can see that the pixel coordinates
    566 in the camera grid may be determined from the pixel coordinates in the
    567 image grid from the following relationship:
    568 
    569 \begin{verbatim}
    570 pmFPA(cell,row) = pmChip.cell0,row0 + pmCell.cell0,row0 + pmReadout.cell0,row0 +
    571                   pmReadout.cellParity,rowParity * pmReadout.cellBins,rowBins *
    572                   psImage.data(cell,row)
    573 \end{verbatim}
    574 
    575 \subsection{Input/Output of a Focal Plane Hierarchy}
    576 
    577 Data sources and output targets may be specified in the Camera
    578 Configuration file.  These targets may consist of explicitly named
    579 files, or they may define rules by which the names are constructed,
    580 using other information available to the configuration system.  The
    581 following function provides a mechanism with which the name rules are
    582 selected and interpretted
    583 \begin{prototype}
    584 char *pmConfigNameFromRule (char *rule, psMetadata *camera, *psMetadata *arguments, psMetadata *header);
    585 \end{prototype}
    586 
    587 The \code{rule} defines a name in the \code{camera} metadata.  The
    588 rule defines the output value of a new name.  The rule may include
    589 elements which are looked up from the camera configuration
    590 information, the supplied command-line arguments, or the header of the
    591 current file.  The following lookups rules are define:
    592 \begin{verbatim}
    593 {CELL.NAME} : pmCell.concepts:CELL.NAME
    594 {CHIP.NAME} : pmChip.concepts:CHIP.NAME
    595 {EXTNAME}   : value of EXTNAME in header
    596 {INPUT}     : value of INPUT from camera config
    597 {OUTPUT}    : value of OUTPUT from camera config
    598 \end{verbatim}
    599 
    600 
    601 We specify two functions to construct a focal plane hierarchy from a
    602 camera configuration and read from a FITS file.  These two operations
    603 are decoupled so that the big investment of memory from the read only
    604 occurs when it is necessary.
    605 
    606 \begin{prototype}
    607 pmFPA *pmFPAConstruct(const psMetadata *camera);
    608 bool pmFPADatabase(pmFPA *fpa, psDB *db);
    609 bool pmFPARead(pmFPA *fpa, psFits *fits);
    610 bool pmFPAWrite(psFits *fits, pmFPA *fpa);
    611 \end{prototype}
    612 
    613 \code{pmFPAConstruct} shall construct a focal plane hierarchy from a
    614 \code{camera} configuration.  The resultant \code{pmFPA} and its
    615 lower-down components shall be ready for to read a FITS file into it
    616 by setting \code{filename} and \code{extname} in the \code{file}
    617 pointers at the appropriate levels.
    618 
    619 \code{pmFPADatabase} shall set the \code{database} of the \code{file}
    620 pointers within the hierarchy to the supplied \code{db}.
    621 
    622 \code{pmFPARead} shall read a \code{fits} file (the contents of which
    623 are described by the previous \code{camera} configuration) into an
    624 extant \code{fpa}, for those components which don't already
    625 \code{exist} and are marked to be \code{process}ed.  This involves
    626 reading the headers and pixels into the \code{pmFile}, ingesting all
    627 the concepts for that level, and making subimages for the
    628 \code{readout->image} (from \code{CELL.TRIMSEC}) and
    629 \code{readout->bias} (from \code{CELL.BIASSEC}).
    630 
    631 \code{pmFPAWrite} shall write those elements focal plane hierarchy
    632 (\code{fpa}) that \code{exist} and are marked to be \code{process}ed
    633 to the specified \code{fits} file, returning \code{true} upon success
    634 and \code{false} otherwise.  If the provided \code{fits} file is
    635 \code{NULL}, the information within the \code{pmFile *image}
    636 components is used for the output.  The \code{fpa} should contain
    637 sufficient information with which to write the FITS images.
    638 
    639 \tbd{Following the reworking of the focal plane hierarchy in April
    640 2006, much of this document needs to be updated.  I'm including the below
    641 before I forget them --- PAP.}
    642 
    643 \begin{prototype}
    644 bool pmReadoutReadNext(pmReadout *readout, psFits *fits, int z, int numRows);
    645 bool pmCellRead(pmCell *cell, psFits *fits, psDB *db);
    646 bool pmChipRead(pmChip *chip, psFits *fits, psDB *db);
    647 bool pmFPARead(pmFPA *fpa, psFits *fits, psDB *db);
    648 \end{prototype}
    649 
    650 \tbd{Explanation here.}
    651 
    652 Here's a demonstration of the use of \code{pmReadoutReadNext}:
    653 \begin{verbatim}
    654     pmReadout *readout = pmReadoutAlloc(cell);
    655     for (int z = 0; pmReadoutReadNext(readout, inFile, z, 100); z++) {
    656         do {
    657             somethingWithTheReadout(readout);
    658         } while (pmReadoutReadNext(readout, inFile, z, 2048));
    659     }
    660     psFree(readout);
    661 \end{verbatim}
    662 
    663 
    664 \subsubsection{Mask and weight input/output}
    665 
    666 We carry mask and weight images, since these are useful for downstream
    667 processing.  A mask value of zero for a pixel shall indicate that the
    668 pixel is not suspect.  The weight images shall be the variance (the
    669 square of the standard deviation).
    670 
    671 We desire to access the mask and weight images without specifying a
    672 particular file name.  We introduce the \code{SUPPLEMENTARY} metadata
    673 entry in the camera configuration file, which allows identification of
    674 the location for the mask and weight images, based on the value of
    675 some of the ``concepts'':
    676 
    677 \begin{verbatim}
    678 # How to get the supplementary stuff: mask and weight
    679 SUPPLEMENTARY   METADATA
    680         MASK.SOURCE     STR     FILE                    # Source type for mask: EXT | FILE
    681         MASK.NAME       STR     {FPA.NAME}_mask.fits    # Name for mask extension or filename
    682         WEIGHT.SOURCE   STR     EXT                     # Source type for weight: EXT | FILE
    683         WEIGHT.NAME     STR     {CELL.NAME}_weight.fits # Name for weight extension or filename
    684 END
    685 \end{verbatim}
    686 
    687 How the mask (or weight) image is stored is specified by the
    688 \code{MASK.SOURCE} (or \code{WEIGHT.SOURCE}) keyword.  The images may
    689 be stored either in the same file as the pixels with a different
    690 extension name (\code{EXT}), or they may be stored in a different file
    691 with the same extension name (\code{FILE}).  The name of the file or
    692 extension is specified by the \code{MASK.NAME} (or \code{WEIGHT.NAME})
    693 keyword, with strings within curly brackets interpreted as concepts
    694 that must be evaluated and replaced.
    695 
    696 \begin{prototype}
    697 pmFPAReadMask(pmFPA *fpa, psFits *fits);
    698 pmFPAWriteMask(psFits *fits, pmFPA *fpa);
    699 pmFPAReadWeight(pmFPA *fpa, psFits *fits);
    700 pmFPAWriteWeight(psFits *fits, pmFPA *fpa);
    701 \end{prototype}
    702 
    703 \code{pmFPAReadMask} and \code{pmFPAReadWeight} are very similar to
    704 \code{pmFPARead}, except that they shall read the \code{mask} and
    705 \code{weight} elements (respectively) of the \code{pmReadout}s
    706 comprising the \code{fpa}.
    707 
    708 \code{pmFPAWriteMask} and \code{pmFPAWriteWeight} is very similar to
    709 \code{pmFPAWrite}, but it shall write the \code{mask} and
    710 \code{weight} elements (respectively) of the \code{pmReadout}s
    711 comprising the \code{fpa}.
    712 
    713 We also provide functions to generate the mask and weight images:
    714 \begin{prototype}
    715 bool pmCellDetectorMask(pmCell *cell);
    716 bool pmCellDetectorWeight(pmCell *cell);
    717 \end{prototype}
    718 
    719 \code{pmCellPhotonMask} shall set the mask pixels based on the
    720 \code{CELL.SATURATION} and \code{CELL.BAD} concepts.
    721 \code{pmCellPhotonWeight} shall set the weight image based on the
    722 photon statistics using the \code{CELL.GAIN} and \code{CELL.READNOISE}
    723 concepts.
    724 
    725 \subsection{Iteration}
    726 
    727 Often we will desire to perform a function on all cells in the focal
    728 plane, or all chips, etc.  Since this is a common operation, we
    729 provide an iterator that performs the mind numbing part:
    730 
     613\subsection{FPA Construction}
     614
     615The following function creates the FPA hierarchy on the basis of the
     616camera configuration.  The \code{FPA} entry in the camera
     617configuration specifies the chips (each of type \code{STR}) with their
     618component cells listed as the corresponding values (whitespace
     619separated).  The FPA hierarchy is created devoid of any input/output
     620sources (i.e., HDUs).
     621\begin{prototype}
     622pmFPA *pmFPAConstruct(const psMetadata *camera ///< The camera configuration
     623                     );
     624\end{prototype}
     625
     626Input/output sources may be specified within the hierarchy by
     627providing information that allows the position of the new HDU to be
     628determined (not only the level, but which component of that level);
     629this may be done in two ways.  The first is through a \code{pmFPAview}
     630that corresponds to the HDU position; this is appropriate when
     631creating an output file of known format.  The second is by providing
     632the primary header of an input file, from which the HDU position(s)
     633can be inferred (using the \code{FILE} information within the camera
     634format configuration); this is useful for adding input sources.  In
     635both cases, the camera format configuration is required in order to
     636describe how the FPA is laid out in terms of disk files.
     637
     638\begin{prototype}
     639bool pmFPAAddSourceFromView(pmFPA *fpa,   ///< The FPA
     640                            const pmFPAview *phuView, ///< The view, corresponding to the PHU
     641                            const psMetadata *format ///< Format of file
     642                           );
     643pmFPAview *pmFPAAddSourceFromHeader(pmFPA *fpa, ///< The FPA
     644                                    psMetadata *phu, ///< Primary header of file
     645                                    const psMetadata *format ///< Format of file
     646                                   );
     647\end{prototype}
     648
     649As an aid to development, we have a function that prints to a file
     650stream a representation of the FPA, including its headers and
     651concepts, if desired.
     652
     653\begin{prototype}
     654void pmFPAPrint(FILE *fd,               ///< File descriptor to which to print
     655                const pmFPA *fpa,       ///< FPA to print
     656                bool header,            ///< Print headers?
     657                bool concepts           ///< Print concepts?
     658               );
     659\end{prototype}
     660
     661
     662\subsection{FPA Reading and Writing}
     663
     664\subsubsection{Reading headers}
     665
     666The following functions read the headers, if the HDU is at the
     667appropriate level.  The functions return \code{true} if they
     668successfully read the header, or if the header had already been read.
     669The functions do not iterate to lower levels.
     670\begin{prototype}
     671bool pmFPAReadHeader(pmFPA *fpa,        ///< FPA for which to read header
     672                     psFits *fits       ///< FITS file handle
     673                    );
     674bool pmChipReadHeader(pmChip *chip,     ///< Chip for which to read header
     675                      psFits *fits      ///< FITS file handle
     676                     );
     677bool pmCellReadHeader(pmCell *cell,     ///< Cell for which to read header
     678                      psFits *fits      ///< FITS file handle
     679                     );
     680\end{prototype}
     681
     682\subsubsection{Reading pixels}
     683
     684The following functions iterate over the component cells, reading the
     685pixels, converting them to \code{F32}, allocating readouts, and
     686ingesting concepts:
     687\begin{prototype}
     688bool pmCellRead(pmCell *cell,           // Cell to read into
     689                psFits *fits,           // FITS file from which to read
     690                psDB *db                // Database handle, for "concepts" ingest
     691               );
     692bool pmChipRead(pmChip *chip,           // Chip to read into
     693                psFits *fits,           // FITS file from which to read
     694                psDB *db                // Database handle, for "concepts" ingest
     695               );
     696bool pmFPARead(pmFPA *fpa,              // FPA to read into
     697               psFits *fits,            // FITS file from which to read
     698               psDB *db                 // Database handle, for "concepts" ingest
     699              );
     700\end{prototype}
     701
     702The following functions perform the same as the above functions, but
     703read the pixels into the \code{mask} or \code{weight} elements of the
     704readout.
     705\begin{prototype}
     706bool pmCellReadMask(pmCell *cell,           // Cell to read into
     707                    psFits *fits,           // FITS file from which to read
     708                    psDB *db                // Database handle, for "concepts" ingest
     709                   );
     710bool pmChipReadMask(pmChip *chip,           // Chip to read into
     711                    psFits *fits,           // FITS file from which to read
     712                    psDB *db                // Database handle, for "concepts" ingest
     713                   );
     714bool pmFPAReadMask(pmFPA *fpa,              // FPA to read into
     715                   psFits *fits,            // FITS file from which to read
     716                   psDB *db                 // Database handle, for "concepts" ingest
     717                  );
     718bool pmCellReadWeight(pmCell *cell,           // Cell to read into
     719                      psFits *fits,           // FITS file from which to read
     720                      psDB *db                // Database handle, for "concepts" ingest
     721                     );
     722bool pmChipReadWeight(pmChip *chip,           // Chip to read into
     723                      psFits *fits,           // FITS file from which to read
     724                      psDB *db                // Database handle, for "concepts" ingest
     725                     );
     726bool pmFPAReadWeight(pmFPA *fpa,              // FPA to read into
     727                     psFits *fits,            // FITS file from which to read
     728                     psDB *db                 // Database handle, for "concepts" ingest
     729                    );
     730\end{prototype}
     731
     732
     733The above functions all read the pixels, at least a cell at a time.
     734The following function reads the pixels for a readout incrementally.
     735Multiple calls to this function moves through a readout within a cell
     736incrementally.  It is required to pass the readout previously acquired
     737(or a newly-allocated one) in order to preserve state information
     738(where the read is at).  Only a maximum of \code{numRows} rows are
     739read at a time.  Returns \code{true} if pixels are read, and
     740\code{false} otherwise.  To facilitate looping, no error is generated
     741for reading a plane that doesn't exist.  Note that this function
     742doesn't put pixels in the HDU.  It is therefore \textbf{not
     743compatible} with \code{pmCellWrite}, \code{pmChipWrite}, and
     744\code{pmFPAWrite} (or any function that uses or creates an HDU, for
     745that matter).  \code{pmReadoutWriteNext} should be used to write the
     746data that's read by this function.  This function is intended for
     747reading in many readouts into memory at once (e.g., for stacking)
     748where the input is not written out.
     749\begin{prototype}
     750bool pmReadoutReadNext(pmReadout *readout, // Readout into which to read
     751                       psFits *fits,    // FITS file from which to read
     752                       int z,           // Readout number/plane; zero-offset indexing
     753                       int numRows      // The number of rows to read
     754                      );
     755\end{prototype}
     756
     757\subsubsection{Writing pixels and headers}
     758
     759The following functions write the appropriate hierarchy level to a
     760FITS file, if one exists at that level.  The function generates
     761CELL.TRIMSEC, CELL.BIASSEC and the HDU pixels if required (see
     762\code{pmHDUGenerate}).  A blank (i.e., image-less header) is written
     763only if specifically requested.  The function writes the concepts to
     764the various locations, and then the HDU to the FITS file.  This
     765function should be called at the beginning of the output cell loop
     766with \code{blank=true} in order to produce the correct file structure.
     767\begin{prototype}
     768bool pmCellWrite(pmCell *cell,          ///<  Cell to write
     769                 psFits *fits,          ///<  FITS file to which to write
     770                 psDB *db,              ///<  Database handle for "concepts" update
     771                 bool blank             ///<  Write a blank PHU?
     772                );
     773bool pmChipWrite(pmChip *chip,          ///<  Chip to write
     774                 psFits *fits,          ///<  FITS file to which to write
     775                 psDB *db,              ///<  Database handle for "concepts" update
     776                 bool blank,            ///<  Write a blank PHU?
     777                 bool recurse           ///<  Recurse to lower levels?
     778                );
     779bool pmFPAWrite(pmFPA *fpa,             ///<  FPA to write
     780                psFits *fits,           ///<  FITS file to which to write
     781                psDB *db,               ///<  Database handle for "concepts" update
     782                bool blank,             ///<  Write a blank PHU?
     783                bool recurse            ///<  Recurse to lower levels?
     784               );
     785\end{prototype}
     786
     787
     788The following function is the companion to \code{pmReadoutReadNext},
     789as it writes a readout to a FITS file, perhaps incrementally (if it
     790has been read in using \code{pmReadoutReadNext}).  It relies on the
     791FITS header to specify how many image planes there are, and the width
     792and height.
     793\begin{prototype}
     794bool pmReadoutWriteNext(pmReadout *readout, ///< Readout to write
     795                        psFits *fits,   ///<  FITS file to which to write
     796                        int z           ///<  Image plane to write
     797                       );
     798\end{prototype}
     799
     800
     801\subsubsection{HDU Generation}
     802
     803The write functions for the FPA hierarchy use \code{pmHDUWrite}, which
     804assumes that the images in the readouts are subimages of the pixels in
     805the HDU structure.  If this is not the case, the HDU pixels can be
     806generated using some simple assumptions.
     807
     808The following function generate an HDU (with \code{CELL.TRIMSEC},
     809\code{CELL.BIASSEC} and pixels) for a cell with pixels.  They splice
     810the images and overscans together without regard for \code{CELL.X0}
     811and \code{CELL.Y0} (for a proper mosaic, see \code{pmFPAMosaic}),
     812though they should respect \code{CELL.READDIR} (so that the bias and
     813trim sections match properly).  A warning may be generated (by the
     814concept write functions) after running these functions if the bias and
     815trim sections are specified in the camera format by default values
     816rather than in the header.  Failure of these functions is often due to
     817a bad camera format file.
     818\begin{prototype}
     819bool pmHDUGenerateForCell(pmCell *cell  ///< The cell for which to generate an HDU
     820                         );
     821bool pmHDUGenerateForChip(pmChip *chip  ///< The chip for which to generate an HDU
     822                         );
     823bool pmHDUGenerateForFPA(pmFPA *fpa     ///< The fpa for which to generate an HDU
     824                        );
     825\end{prototype}
     826
     827These functions are primarily intended for private use (by the write
     828functions) within the Modules, but may be used by the user if desired.
     829
     830\subsection{Masks and Weights}
     831
     832Pixel mask values are defined with the following enumerated type:
    731833\begin{datatype}
    732 typedef bool (*pmFPAIterateFunc)(pmFPA *fpa, pmChip *chip, pmCell *cell);
     834typedef enum {
     835    PM_MASK_CLEAR   = 0x00,   ///< The pixel is not masked
     836    PM_MASK_TRAP    = 0x01,   ///< The pixel is a charge trap.
     837    PM_MASK_BADCOL  = 0x02,   ///< The pixel is a bad column.
     838    PM_MASK_SAT     = 0x04,   ///< The pixel is saturated.
     839    PM_MASK_BAD     = 0x08,   ///< The pixel is low
     840    PM_MASK_FLAT    = 0x10,   ///< The pixel is non-positive in the flat-field.
     841    PM_MASK_MARK    = 0x20,   ///< The pixel is marked as temporarily ignored
     842    PM_MASK_EXT1    = 0x40,   ///< This mask value is not used
     843    PM_MASK_EXT2    = 0x80,   ///< This mask value is not used
     844} pmMaskValue;
    733845\end{datatype}
    734 \begin{prototype}
    735 bool pmFPAIterateChips(pmFPA *fpa, pmFPAIterateFunc func);
    736 bool pmFPAIterateCells(pmFPA *fpa, pmFPAIterateFunc func);
    737 \end{prototype}
    738 
    739 \code{pmFPAIterateChips} shall iterate through all chips (that
    740 \code{exist} and are marked to be \code{process}ed) in the \code{fpa},
    741 calling the iterator function, \code{func}, for each (with
    742 \code{cell=NULL}).  \code{pmFPAIterateCells} shall iterate through all
    743 cells (that \code{exist} and are marked to be \code{process}ed) in all
    744 chips (that \code{exist} and are marked to be \code{process}ed),
    745 calling the iterator function for each.
    746 
    747 
    748 \subsection{Selecting elements of the hierarchy for processing}
    749 
    750 \begin{prototype}
    751 bool pmFPASelectChip(pmFPA *fpa, int chipNum);
    752 int pmFPAExcludeChip(pmFPA *fpa, int chipNum);
    753 \end{prototype}
    754 
    755 These functions are provided to set the \code{process} booleans within
    756 an \code{fpa} so that only certain chips within the FITS file are read
    757 in.
    758 
    759 \code{pmFPASelectChip} shall set \code{valid} to \code{true} for the
    760 specified chip number (\code{chipNum}), and all other chips shall have
    761 \code{valid} set to \code{false}.  In the event that the specified
    762 chip number does not exist within the \code{fpa}, the function shall
    763 return \code{false}.
    764 
    765 \code{pmFPAExcludeChip} shall set \code{valid} to \code{false} only
    766 for the specified chip number (\code{chipNum}).  In the event that the
    767 specified chip number does not exist within the \code{fpa}, the
    768 function shall generate a warning, and perform no action.  The
    769 function shall return the number of chips within the \code{fpa} that
    770 have \code{valid} set to \code{true}.
    771 
    772 \tbd{Provide a richer set of functions: select by extension, extname,
    773 cell, options to invalidate all / validate all, etc}
    774 
    775 
    776 \subsection{Mosaicking}
    777 
    778 \begin{prototype}
    779 bool pmFPAMorph(pmFPA *toFPA, pmFPA *fromFPA, bool positionDependent, int chipNum, int cellNum);
    780 \end{prototype}
    781 \code{pmFPAMorph} shall morph the \code{fromFPA} focal plane hierarchy
    782 to the \code{toFPA} focal plane hierarchy.  This allows us to write
    783 the pixels out using a different (though consistent) camera
    784 configuration.  In the event that the \code{toFPA} has different
    785 levels than the \code{fromFPA}, only the chip and cell specified by
    786 \code{chipNum} and \code{cellNum} shall be written; if the levels are
    787 the same, these numbers are ignored.  This function shall break apart
    788 pixel regions or splice them together where required in order to
    789 satisfy the demands of the \code{toFPA}.  How the image and overscan
    790 regions are spliced together depends on the value of
    791 \code{positionDependent}: If \code{positionDependent} is \code{true},
    792 then the overscan regions go to the low end of the spliced image if $i
    793 < N/2$, and to the high end of the spliced image if $i >= N/2$, where
    794 $i$ (zero-offset) is the cell number, and $N$ is the total number of
    795 cells; if \code{positionDependent} is \code{false}, then the overscan
    796 regions all go to the high end of the spliced image.  Care should be
    797 taken to check the \code{CELL.READDIR}, so the orientation of the
    798 overscan regions is known.  If the bias and trim sections are
    799 specified by headers in the \code{toFPA}, these shall be updated
    800 appropriately; otherwise, the function is permitted to fail with a
    801 suitable error message, in which case it shall return \code{false}.
    802 
    803 \tbd{Don't code pmFPAMorph --- it's tricky, and maybe unnecessary.}
    804 
    805 \begin{prototype}
    806 int pmChipMosaic(pmChip *chip, int xBinChip, int yBinChip);
    807 \end{prototype}
    808 
    809 \code{pmChipMosaic} shall mosaic the cells within the provided
    810 \code{chip}.  The mosaicking shall take into account the offsets of
    811 the cells on the chip (\code{CELL.X0,CELL.Y0}), the cell binning
    812 (\code{CELL.XBIN,CELL.YBIN}) and the desired (absolute, i.e., relative
    813 to the physical pixels) binning level (\code{xBinChip,yBinChip}).  The
    814 component cells and readouts shall be replaced with a single cell and
    815 readout containing the mosaic.  \code{file} pointers within the
    816 hierarchy and the concepts shall be updated.
    817 
     846
     847\tbd{It would be nice to have a system of registering symbolic names
     848for mask values at run time.}
     849
     850The following functions use the readout image and certain concepts to
     851provide the mask and weight values.  There are two cases.  The first
     852is that of ``setting'' the mask/weight, where the mask/weight that
     853produced is temporary --- it is not added to the HDU.  This is
     854intended for when the user is iterating using pmReadoutReadNext, in
     855which case the HDU can't be generated.  The second case is that of
     856``generating'' the mask/weight, where the mask/weight that is produced
     857is suitable for output (complete with HDU entry); this is intended for
     858most operations.
     859
     860In both cases, the mask is formed by identifying pixels are saturated
     861(at or above \code{CELL.SATURATION}) or bad (at or below
     862\code{CELL.BAD}); while the weights (actually variances) are
     863calculated using photon statistics from the cell gain
     864(\code{CELL.GAIN}) and read noise (\code{CELL.READNOISE})
     865
     866\begin{prototype}
     867bool pmReadoutSetMask(pmReadout *readout ///< Readout for which to set mask
     868                     );
     869bool pmReadoutSetWeight(pmReadout *readout ///< Readout for which to set weight
     870                       );
     871bool pmReadoutGenerateMask(pmReadout *readout ///< Readout for which to generate mask
     872                          );
     873bool pmReadoutGenerateWeight(pmReadout *readout ///< Readout for which to generate weight
     874                            );
     875\end{prototype}
     876
     877The following functions are intended for convenience, generating a
     878mask and weight map for a readout or cell:
     879\begin{prototype}
     880bool pmReadoutGenerateMaskWeight(pmReadout *readout ///< Readout for which to generate mask and weights
     881                                );
     882bool pmCellGenerateMaskWeight(pmCell *cell ///< Cell for which to generate mask and weights
     883                             );
     884\end{prototype}
     885
     886
     887\subsection{Copying: Converting between formats}
     888
     889The following functions copy components of an FPA hierarchy to a
     890different representation of the same camera These functions are useful
     891for converting between different representations of the same camera.
     892For example, between Megacam "RAW" (one amp per extension) and Megacam
     893"SPLICED" formats (two amps = 1 chip per extension, spliced together).
     894Components are spliced together as necessary.
     895
     896\begin{prototype}
     897bool pmFPACopy(pmFPA *target,           ///< The target FPA
     898               const pmFPA *source      ///< The source FPA, to be copied
     899              );
     900bool pmChipCopy(pmChip *target,         ///< The target chip
     901                const pmChip *source    ///< The source chip, to be copied
     902               );
     903bool pmCellCopy(pmCell *target,         ///< The target cell
     904                const pmCell *source    ///< The source cell, to be copied
     905               );
     906\end{prototype}
     907
     908The following functions are similar, except that the pixels are not
     909copied (although images of sufficient size are allocated in the
     910target), and the \code{CELL.XBIN} and \code{CELL.YBIN} are changed
     911according to the provided binning factors.  These functions are
     912intended for binning a camera, where the user will do the binning.
     913
     914\begin{prototype}
     915bool pmFPACopyStructure(pmFPA *target,   ///< The target FPA
     916                        const pmFPA *source, ///< The source FPA, to be copied
     917                        int xBin, int yBin ///< Binning factors in x and y
     918                       );
     919bool pmChipCopyStructure(pmChip *target, ///< The target chip
     920                         const pmChip *source, ///< The source chip, to be copied
     921                         int xBin, int yBin ///< Binning factors in x and y
     922                        );
     923bool pmCellCopyStructure(pmCell *target, ///< The target cell
     924                         const pmCell *source, ///< The source cell, to be copied
     925                         int xBin, int yBin ///< Binning factors in x and y
     926                        );
     927\end{prototype}
     928
     929
     930\subsection{Mosaicking: Converting between cameras}
     931
     932The following functions mosaic cells within the appropriate hierarchy
     933component into a single cell within the target (which must have only a
     934single cell).  These functions are therefore useful for converting to
     935a different camera, which is generally a false representation of the
     936physical camera; in this manner, one can obtain an image of the chip
     937or FPA on the sky.  Cells are placed on the chip according to the
     938\code{CELL.X0} and \code{CELL.Y0} offsets.  The mosaicking is done so
     939as to avoid performing a deep copy of the pixels, if possible.
     940
     941\begin{prototype}
     942bool pmChipMosaic(pmChip *target,       // Target chip --- may contain only a single cell
     943                  const pmChip *source  // Source chip whose cells will be mosaicked
     944                 );
     945bool pmFPAMosaic(pmFPA *target,         // Target FPA --- may contain only a single chip with a single cell
     946                 const pmFPA *source    // FPA whose chips and cells will be mosaicked
     947                );
     948\end{prototype}
     949
     950
     951\subsection{FPA Files}
     952
     953\tbd{EAM to provide from the following files:
     954pmFPAfileDefine.h
     955pmFPAfileFitsIO.h
     956pmFPAfile.h
     957pmFPAfileIO.h
     958pmFPA_MANAPLOT.h
     959pmFPA_JPEG.h
     960}
    818961
    819962%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    820963
    821964\section{Astrometry}
     965
     966\tbd{EAM needs to update this section.}
    822967
    823968Astrometry is a basic functionality required for the IPP that will be
     
    8601005We require structures to contain each of the above transformations as
    8611006well as the pixel data.
    862 
    863 \subsection{Position Finding}
    864 
    865 We require functions to return the structure containing given
    866 coordinates.  For example, we want the chip that corresponds to the
    867 focal plane coordinates $(p,q) = (-1.234,+5.678)$.  These routines
    868 handle the one-to-many problem --- i.e., for one given focal plane
    869 coordinate, there are many chips that this coordinate may be
    870 correspond to; these functions will select the correct one.
    871 %
    872 \begin{verbatim}
    873 pmCell *pmCellInFPA (const psPlane *coord, const pmFPA *fpa);
    874 pmChip *pmChipInFPA (const psPlane *coord, const pmFPA *fpa);
    875 pmCell *pmCellInChip(const psPlane *coord, const pmChip *chip);
    876 \end{verbatim}
    877 
    878 \subsection{Conversion Functions}
    879 
    880 We require functions to convert between the various coordinate frames
    881 (Section~\ref{sec:coordinateFrames}).  The hierarchy of the coordinate
    882 frames and the transformations between each are shown in
    883 Figure~\ref{fig:coco}.  The functions that employ the transformations
    884 are shown in Figure~\ref{fig:cocoFunc}.  In addition to
    885 transformations between each adjoining coordinate frame in the
    886 hierarchy, we also require higher-level functions to convert between
    887 the Cell and Sky coordinate frames; these will simply perform the
    888 intermediate steps.
    889 
    890 \begin{figure}
    891 \psfig{file=../pslib/pics/coordinateFrames,height=7in,angle=-90}
    892 \caption{The coordinate systems in the \PS{} IPP, and the relation
    893 between each by transformations contained in the appropriate
    894 structures.}
    895 \label{fig:coco}
    896 \end{figure}
    897 
    898 \begin{figure}
    899 \psfig{file=../pslib/pics/coordinateConv,height=7in,angle=-90}
    900 \caption{Conversion between coordinate systems by PSLib.}
    901 \label{fig:cocoFunc}
    902 \end{figure}
    903 
    904 We specify the following functions to convert between coordinates in
    905 one type of frame to another type of frame.  The first group consist
    906 of unambiguous transformations: from the coordinates in a low-level
    907 frame to the coordinates in the containing higher-level frame, of
    908 which only one exists.  In all of these functions, the output
    909 coordinate structure may be \code{NULL} or may be supplied by the
    910 calling function.  In the former case, the structure must be
    911 allocated; in the latter case, the supplied structure must be used.
    912 
    913 \begin{verbatim}
    914 psPlane *pmCoordCellToChip (psPlane *out, const psPlane *in, const pmCell *cell);
    915 % astrometry comes from cell (no need for parent)
    916 \end{verbatim}
    917 which converts coordindates \code{in} on the specified \code{cell} to
    918 the coordinates on the parent chip.
    919 
    920 \begin{verbatim}
    921 psPlane *pmCoordChipToFPA (psPlane *out, const psPlane *in, const pmChip *chip);
    922 % astrometry comes from chip (no need for parent)
    923 \end{verbatim}
    924 which converts the coordinates \code{in} on the specified \code{chip}
    925 to the coordinates on the parent FPA.
    926 
    927 \begin{verbatim}
    928 psPlane *pmCoordFPAToTP(psPlane *out, const psPlane *in, float color, float mag, const pmFPA *fpa);
    929 % astrometry comes from FPA (no need for parent)
    930 \end{verbatim}
    931 which converts coordinates \code{in} on the specified focal plane
    932 \code{fpa} to tangent plane coordinates, applying the appropriate
    933 distortion terms.  The \code{color} and magnitude (\code{mag}) of the
    934 source is necessary in order to perform the distortion between the
    935 focal plane and the tangent plane.
    936 
    937 \begin{verbatim}
    938 psSphere *pmCoordTPToSky(psSphere *out, const psPlane *in, const psProjection *projection);
    939 \end{verbatim}
    940 which converts the tangent plane coordinates \code{in} to (RA,Dec) on
    941 the sky, using the specified \code{projection}.
    942 
    943 % astrometry comes from cell
    944 \begin{verbatim}
    945 psPlane *pmCoordCellToFPA(psPlane *out, const psPlane *in, const pmCell *cell);
    946 \end{verbatim}
    947 which performs the single-step conversion between Cell coordinates
    948 \code{in} and FPA coordinates.
    949 
    950 % astrometry comes from cell,chip,fpa (PARENT IS NEEDED HERE)
    951 \begin{verbatim}
    952 psSphere *pmCoordCellToSky(psSphere *out, const psPlane *in, float color, float mag, const pmCell *cell);
    953 \end{verbatim}
    954 which converts coordinates on the specified cell to (RA,Dec).  This
    955 transformation must be performed using the intermediate stage
    956 transformations of Cell to Chip, Chip to FPA, FPA to Tangent Plane,
    957 Tangent Plane to Sky.  The information needed for each of these
    958 transformations is available in the \code{.parent} elements of
    959 \code{pmCell} and \code{pmChip}, and the \code{pmFPA.projection}.  The
    960 \code{color} and magnitude (\code{mag}) of the source is necessary in
    961 order to perform the distortion between the focal plane and the
    962 tangent plane.
    963 
    964 % astrometry comes from cell (no need for parent)
    965 \begin{verbatim}
    966 psSphere *pmCoordCellToSkyQuick(psSphere *out, const psPlane *in, const pmCell *cell);
    967 \end{verbatim}
    968 which uses the 'quick-and-dirty' transformation to convert coordinates
    969 on the specified cell to (RA,Dec).  This transformation should use the
    970 locally linear transformation specified by the element
    971 \code{pmCell.toTP}.  Although the accuracy of this transformation
    972 is lower than the complete transformation above, the calculation is
    973 substantially faster as it only involves linear transformations.
    974 
    975 The following functions convert from high-level frames to the
    976 coordinates of contained lower-level frames. 
    977 
    978 \begin{verbatim}
    979 psPlane *pmCoordSkyToTP(psPlane *out, const psSphere *in, const psProjection *projection);
    980 \end{verbatim}
    981 which converts (RA,Dec) coordinates \code{in} to tangent plane coords
    982 using the specified \code{projection}.
    983 
    984 \begin{verbatim}
    985 psPlane *pmCoordTPToFPA(psPlane *out, const psPlane *in, float color, float mag, const pmFPA *fpa);
    986 \end{verbatim}
    987 which converts the tangent plane coordinates \code{in} to focal plane
    988 coordinates.  The \code{color} and magnitude (\code{mag}) of the
    989 source is necessary in order to perform the distortion between the
    990 focal plane and the tangent plane.
    991 
    992 \begin{verbatim}
    993 psPlane *pmCoordFPAToChip (psPlane *out, const psPlane *in, const pmChip *chip);
    994 \end{verbatim}
    995 which converts the specified FPA coordinates \code{in} to the
    996 coordinates on the given Chip.  The specified chip need not contain
    997 the input coordinate.  To find the chip which contains a particular
    998 coordinate, the function \code{pmChipInFPA}, defined above, should be
    999 used.
    1000 
    1001 \begin{verbatim}
    1002 psPlane *pmCoordChipToCell (psPlane *out, const psPlane *in, const pmCell *cell);
    1003 \end{verbatim}
    1004 which converts the specified Chip coordinate \code{in} to the
    1005 coordinate on the given Cell.  The specified Cell need not contain the
    1006 input coordinate.  To find the cell which contains a particular
    1007 coordinate, the function \code{pmCellInChip}, defined above, should be
    1008 used.
    1009 
    1010 \begin{verbatim}
    1011 psPlane *pmCoordSkyToCell(psPlane *out, const psSphere *in, float color, float mag, pmCell *cell);
    1012 \end{verbatim}
    1013 which directly converts (RA,Dec) \code{in} to coordinates on the
    1014 specified cell.  The specified cell need not contain the input
    1015 coordinates.  The \code{color} and magnitude (\code{mag}) of the
    1016 source is necessary in order to perform the distortion between the
    1017 focal plane and the tangent plane.
    1018 
    1019 \begin{verbatim}
    1020 psPlane *pmCoordSkyToCellQuick(psPlane *out, const psSphere *in, pmCell *cell);
    1021 \end{verbatim}
    1022 which directly converts (RA,Dec) \code{in} to coordinates on the
    1023 specified cell.  The specified cell need not contain the input
    1024 coordinates.  This transformation should use the locally linear
    1025 transformation specified by the element \code{pmCell.toTP}.
    1026 Although the accuracy of this transformation is lower than the
    1027 complete transformation above, the calculation is substantially faster
    1028 as it only involves linear transformations.
    1029 
    1030 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    10311007
    10321008\subsection{FITS World Coordinate System}
Note: See TracChangeset for help on using the changeset viewer.