IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 18, 2010, 4:11:53 PM (16 years ago)
Author:
eugene
Message:

merge changes from branches/eam_branches/psphot,psModules.20100506 (finish basic psphotStack)

Location:
trunk/psphot
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot

  • trunk/psphot/src/psphotStackImageLoop.c

    r27848 r28013  
    11# include "psphotStandAlone.h"
    2 
    3 # define ESCAPE(MESSAGE) { \
    4   psError(PSPHOT_ERR_DATA, false, MESSAGE); \
    5   psFree (view); \
    6   return false; \
    7 }
     2#define WCS_NONLIN_TOL 0.001            // Non-linear tolerance for header WCS
     3
     4# define ESCAPE(MESSAGE) {                              \
     5        psError(PSPHOT_ERR_DATA, false, MESSAGE);       \
     6        psFree (view);                                  \
     7        return false;                                   \
     8    }
     9
     10bool GetAstrometryFPA (pmConfig *config, pmFPAview *view);
     11bool SetAstrometryFPA (pmConfig *config, pmFPAview *view, bool bilevelAstrometry);
     12bool GetAstrometryChip (pmConfig *config, pmFPAview *view, bool bilevelAstrometry);
    813
    914bool psphotStackImageLoop (pmConfig *config) {
     
    1419    pmReadout *readout;
    1520
    16     pmFPAfile *input = psMetadataLookupPtr (&status, config->files, "PSPHOT.INPUT");
    17     if (!status) {
     21    pmFPAfile *inputRaw = psMetadataLookupPtr (&status, config->files, "PSPHOT.STACK.INPUT.RAW");
     22    pmFPAfile *inputCnv = psMetadataLookupPtr (&status, config->files, "PSPHOT.STACK.INPUT.CNV");
     23    pmFPAfile *input = inputRaw ? inputRaw : inputCnv;
     24
     25    if (!input) {
    1826        psError(PSPHOT_ERR_PROG, false, "Can't find input data!");
    1927        return false;
     
    2432    // XXX for now, just load the full set of images up front
    2533    if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE ("failed input for fpa in psphot.");
     34
     35    bool bilevelAstrometry = GetAstrometryFPA(config, view);
    2636
    2737    // for psphot, we force data to be read at the chip level
     
    4151                if (! readout->data_exists) { continue; }
    4252
    43 # if (0)               
    44                 // uncomment to generate matched psfs
     53                // PSF matching
    4554                if (!psphotStackMatchPSFs (config, view)) {
    4655                    psError(psErrorCodeLast(), false, "failure in psphotStackMatchPSFs for chip %d, cell %d, readout %d\n", view->chip, view->cell, view->readout);
     
    4857                    return false;
    4958                }
    50 # endif
    5159
    5260                // XXX for now, we assume there is only a single chip in the PHU:
     
    6977            }
    7078        }
     79
     80        GetAstrometryChip(config, view, bilevelAstrometry);
     81
    7182        // save output which is saved at the chip level
    7283        if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE ("failed output for Chip in psphot.");
    7384    }
     85
     86    SetAstrometryFPA(config, view, bilevelAstrometry);
     87   
    7488    // save output which is saved at the fpa level
    7589    if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE ("failed ouput for FPA in psphot.");
     
    87101*/
    88102
     103# define UPDATE_HEADER 0
     104
     105bool GetAstrometryFPA (pmConfig *config, pmFPAview *view) {
     106
     107    bool status = false;
     108
     109    bool foundAstrometry = false;
     110    bool bilevelAstrometry = false;
     111
     112    int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
     113    psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     114
     115    // loop over the available readouts
     116    for (int i = 0; i < num; i++) {
     117
     118        // find the currently selected readout
     119        pmFPAfile *output = pmFPAfileSelectSingle(config->files, "PSPHOT.STACK.OUTPUT.IMAGE", i); // File of interest
     120        psAssert (output, "missing file?");
     121
     122        pmFPAfile *inputRaw = pmFPAfileSelectSingle(config->files, "PSPHOT.STACK.INPUT.RAW", i); // File of interest
     123        pmFPAfile *inputCnv = pmFPAfileSelectSingle(config->files, "PSPHOT.STACK.INPUT.CNV", i); // File of interest
     124        pmFPAfile *input = inputRaw ? inputRaw : inputCnv;
     125        psAssert (input, "missing input file");
     126
     127        // find the FPA phu
     128        pmHDU *phu = pmFPAviewThisPHU(view, input->fpa);
     129        if (!phu) {
     130            psWarning("Unable to read bilevel mosaic astrometry for input FPA entry %d", i);
     131            continue;
     132        }
     133
     134        char *ctype = psMetadataLookupStr(NULL, phu->header, "CTYPE1");
     135        if (!ctype) {
     136            psWarning("Error in WCS keywords for input FPA entry %d", i);
     137            continue;
     138        }
     139
     140        if (!foundAstrometry) {
     141            bilevelAstrometry = !strcmp (&ctype[4], "-DIS");
     142        } else {
     143            if (bilevelAstrometry != !strcmp (&ctype[4], "-DIS")) {
     144                psAbort("astrometry type mis-match");
     145            }
     146        }
     147
     148        if (bilevelAstrometry) {
     149            // update the output structures
     150            if (!pmAstromReadBilevelMosaic(output->fpa, phu->header)) {
     151                psWarning("Unable to read bilevel mosaic astrometry for input FPA.");
     152            }
     153        }
     154    }
     155    return bilevelAstrometry;
     156}
     157
     158bool GetAstrometryChip (pmConfig *config, pmFPAview *view, bool bilevelAstrometry) {
     159
     160    bool status = false;
     161
     162    int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
     163    psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     164
     165    // loop over the available readouts
     166    for (int i = 0; i < num; i++) {
     167
     168        // find the currently selected readout
     169        pmFPAfile *output = pmFPAfileSelectSingle(config->files, "PSPHOT.STACK.OUTPUT.IMAGE", i); // File of interest
     170        psAssert (output, "missing file?");
     171
     172        pmFPAfile *inputRaw = pmFPAfileSelectSingle(config->files, "PSPHOT.STACK.INPUT.RAW", i); // File of interest
     173        pmFPAfile *inputCnv = pmFPAfileSelectSingle(config->files, "PSPHOT.STACK.INPUT.CNV", i); // File of interest
     174        pmFPAfile *input = inputRaw ? inputRaw : inputCnv;
     175        psAssert (input, "missing input file");
     176
     177        // Need to update the output for astrometry.  Read WCS data from the corresponding
     178        // header and save in the output fpa
     179        pmHDU *inHDU = pmFPAviewThisHDU (view, input->fpa);
     180        pmChip *outChip = pmFPAviewThisChip(view, output->fpa); ///< Chip in the output
     181
     182# if (UPDATE_HEADER)
     183        pmHDU *outHDU = pmFPAviewThisHDU (view, output->fpa);
     184        if (!outHDU) {
     185            pmFPAAddSourceFromView(output->fpa, "name", view, output->format);
     186            outHDU = pmFPAviewThisHDU (view, output->fpa);
     187            psAssert (outHDU, "failed to make HDU");
     188        }
     189# endif
     190
     191        if (bilevelAstrometry) {
     192            if (!pmAstromReadBilevelChip (outChip, inHDU->header)) {
     193                psWarning("Unable to read bilevel chip astrometry for input FPA.");
     194                continue;
     195            }
     196# if (UPDATE_HEADER)
     197            if (!pmAstromWriteBilevelChip(outHDU->header, outChip, WCS_NONLIN_TOL)) {
     198                psWarning("Unable to generate WCS header.");
     199                continue;
     200            }
     201# endif
     202        } else {
     203            // we use a default FPA pixel scale of 1.0
     204            if (!pmAstromReadWCS (output->fpa, outChip, inHDU->header, 1.0)) {
     205                psWarning("Unable to read WCS astrometry for input FPA.");
     206                continue;
     207            }
     208# if (UPDATE_HEADER)
     209            if (UPDATE_HEADER && !pmAstromWriteWCS(outHDU->header, output->fpa, outChip, WCS_NONLIN_TOL)) {
     210                psWarning("Unable to generate WCS header.");
     211                continue;
     212            }
     213# endif
     214        }
     215    }
     216
     217    return true;
     218}
     219
     220bool SetAstrometryFPA (pmConfig *config, pmFPAview *view, bool bilevelAstrometry) {
     221
     222    bool status = false;
     223
     224    if (!bilevelAstrometry) return true;
     225
     226    int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
     227    psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     228
     229    // loop over the available readouts
     230    for (int i = 0; i < num; i++) {
     231
     232        // find the currently selected readout
     233        pmFPAfile *output = pmFPAfileSelectSingle(config->files, "PSPHOT.STACK.OUTPUT.IMAGE", i); // File of interest
     234        psAssert (output, "missing file?");
     235
     236# if (UPDATE_HEADER)
     237        pmHDU *PHU = pmFPAviewThisPHU(view, output->fpa);
     238        if (!PHU) {
     239            pmFPAAddSourceFromView(output->fpa, "name", view, output->format);
     240            PHU = pmFPAviewThisPHU (view, output->fpa);
     241            psAssert (PHU, "failed to make PHU");
     242        }
     243
     244        if (!pmAstromWriteBilevelMosaic(PHU->header, output->fpa, WCS_NONLIN_TOL)) {
     245            psWarning("Unable to generate WCS header.");
     246        }
     247# endif
     248    }
     249
     250    return true;
     251}
Note: See TracChangeset for help on using the changeset viewer.