IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 8, 2013, 4:41:42 PM (13 years ago)
Author:
eugene
Message:

warping of background model appears to work

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20130419/pswarp/src/pswarpUpdateMetadata.c

    r35527 r35535  
    1010
    1111#include "pswarp.h"
     12#define WCS_NONLIN_TOL 0.001            // Non-linear tolerance for header WCS
    1213
    13 // once the output fpa elements have been built, loop over the fpa and generate stats
    14 // for each readout
    15 bool pswarpUpdateMetadata (pmFPA *output, pmFPA *input, pmFPA *astrom, pmConfig *config)  {
     14// once the output fpa elements have been built, loop over the fpa and generate metadata
     15bool pswarpUpdateMetadata (pmFPA *output, pmFPA *skycell, pmFPA *input, pmFPA *astrom, pmConfig *config, bool fullImage)  {
    1616
    1717    pmFPAview *view = pmFPAviewAlloc(0);
    1818   
     19    // check output astrometry mode
     20    bool bilevelAstrometry = psMetadataLookupBool (NULL, skycell->analysis, "ASTROMETRY.BILEVEL");
     21
    1922    pmChip *chip;
    2023    while ((chip = pmFPAviewNextChip (view, output, 1)) != NULL) {
     
    3942                if (!readout->data_exists) continue;
    4043   
    41                 // Set covariance matrix for output
    42 # if (0)
    43                 psList *covariances = psMetadataLookupPtr(&mdok, output->analysis, PSWARP_ANALYSIS_COVARIANCES); // Covariance matrices
    44                 psAssert(covariances, "Should be there");
    45                 psArray *covars = psListToArray(covariances); // Array of covariance matrices
    46                 psKernel *covar = psImageCovarianceAverage(covars);
    47                 psFree(covars);
    48                 psMetadataRemoveKey(output->analysis, PSWARP_ANALYSIS_COVARIANCES);
     44                if (fullImage) {
     45                    // Set covariance matrix for output
     46                    bool status = false;
     47                    psList *covariances = psMetadataLookupPtr(&status, readout->analysis, PSWARP_ANALYSIS_COVARIANCES); // Covariance matrices
     48                    psAssert(covariances, "Should be there");
     49                    psArray *covars = psListToArray(covariances); // Array of covariance matrices
     50                    psKernel *covar = psImageCovarianceAverage(covars);
     51                    psFree(covars);
     52                    psMetadataRemoveKey(readout->analysis, PSWARP_ANALYSIS_COVARIANCES);
    4953
    50                 // Correct covariance matrix scale for the mean (square root of the) Jacobian
    51                 double jacobian = psMetadataLookupF64(NULL, output->analysis, PSWARP_ANALYSIS_JACOBIAN); // Jacobian
    52                 int goodPixels = psMetadataLookupS32(NULL, output->analysis, PSWARP_ANALYSIS_GOODPIX);   // Good pixels
    53                 jacobian /= goodPixels;
    54                 output->covariance = psImageCovarianceScale(covar, jacobian);
    55                 psFree(covar);
     54                    // Correct covariance matrix scale for the mean (square root of the) Jacobian
     55                    double jacobian = psMetadataLookupF64(NULL, readout->analysis, PSWARP_ANALYSIS_JACOBIAN); // Jacobian
     56                    int goodPixels = psMetadataLookupS32(NULL, readout->analysis, PSWARP_ANALYSIS_GOODPIX);   // Good pixels
     57                    jacobian /= goodPixels;
     58                    readout->covariance = psImageCovarianceScale(covar, jacobian);
     59                    psFree(covar);
    5660
    57                 if (output->variance) {
    58                   psImageCovarianceTransfer(output->variance, output->covariance);
     61                    if (readout->variance) {
     62                        psImageCovarianceTransfer(readout->variance, readout->covariance);
     63                    }
    5964                }
    60 # endif
    6165
    62                 {
    63                   // Add MD5 information for readout
    64                   psString headerName = NULL; ///< Header name for MD5
    65                   psVector *md5 = psImageMD5(readout->image); ///< md5 hash
    66                   psString md5string = psMD5toString(md5); ///< String
    67 
    68                   pmHDU *hdu = pmHDUFromReadout(readout);
    69                   psStringAppend(&headerName, "MD5_%s_%s_%d", chipName, cellName, view->readout);
    70                   psMetadataAddStr(hdu->header, PS_LIST_TAIL, headerName, PS_META_REPLACE, "Image MD5", md5string);
    71                   psFree(md5);
    72                   psFree(md5string);
    73                   psFree(headerName);
    74                 }
     66                // Add MD5 information for readout
     67                psString headerName = NULL; ///< Header name for MD5
     68                psVector *md5 = psImageMD5(readout->image); ///< md5 hash
     69                psString md5string = psMD5toString(md5); ///< String
     70               
     71                pmHDU *hdu = pmHDUFromReadout(readout);
     72                psStringAppend(&headerName, "MD5_%s_%s_%d", chipName, cellName, view->readout);
     73                psMetadataAddStr(hdu->header, PS_LIST_TAIL, headerName, PS_META_REPLACE, "Image MD5", md5string);
     74                psFree(md5);
     75                psFree(md5string);
     76                psFree(headerName);
    7577            }
    7678
    77             psList *inputCells = psMetadataLookupPtr (NULL, cell->analysis, "INPUT.CELLS");
    78             if (!pmConceptsAverageCells(cell, inputCells, NULL, NULL, false)) {
    79                 psError(psErrorCodeLast(), false, "Unable to average cell concepts.");
    80                 psFree(view);
    81                 return false;
     79            if (fullImage) {
     80                psList *inputCells = psMetadataLookupPtr (NULL, cell->analysis, "INPUT.CELLS");
     81                if (!pmConceptsAverageCells(cell, inputCells, NULL, NULL, false)) {
     82                    psError(psErrorCodeLast(), false, "Unable to average cell concepts.");
     83                    psFree(view);
     84                    return false;
     85                }
    8286            }
    8387
     
    8589            psRegion *trimsec = psMetadataLookupPtr(NULL, cell->concepts, "CELL.TRIMSEC"); ///< Trim section
    8690            trimsec->x0 = trimsec->x1 = trimsec->y0 = trimsec->y1 = 0; ///< All pixels
     91        }
    8792
     93        // update astrometry headers
     94        pmHDU *hdu = pmHDUFromChip(chip); ///< HDU for source
     95        if (!hdu || !hdu->header) {
     96            psError(PM_ERR_PROG, false, "Unable to find header for output.");
     97            psFree(view);
     98            return false;
     99        }
     100
     101        if (bilevelAstrometry) {
     102            if (!pmAstromWriteBilevelChip(hdu->header, chip, WCS_NONLIN_TOL)) {
     103                psError(psErrorCodeLast(), false, "Unable to read bilevel chip astrometry for skycell.");
     104                psFree(view);
     105                return false;
     106            }
     107        } else {
     108            // we use a default FPA pixel scale of 1.0
     109            if (!pmAstromWriteWCS(hdu->header, output, chip, WCS_NONLIN_TOL)) {
     110                psError(psErrorCodeLast(), false, "Unable to read WCS astrometry for skycell.");
     111                psFree(view);
     112                return false;
     113            }
    88114        }
    89115    }
     
    93119        return false;
    94120    }
    95 
     121   
    96122    // Update ZP from the astrometry
    97     {
     123    if (fullImage) {
    98124        psMetadataItem *item = psMetadataLookup(output->concepts, "FPA.ZP");
    99125        item->data.F32 = psMetadataLookupF32(NULL, astrom->concepts, "FPA.ZP");
    100126    }
    101127
    102     // need to update the chip and fpa level astrometry appropriately, see
    103     // code in psastro
    104    
    105 # if (0)
    106     if (!pmAstromWriteWCS(hdu->header, outFPA, outChip, WCS_NONLIN_TOL)) {
    107         psError(psErrorCodeLast(), false, "Unable to generate WCS header.");
    108         return false;
     128    // apply the bilevel astrometry elements to the target
     129    if (bilevelAstrometry) {
     130        pmHDU *phu = pmFPAviewThisPHU(view, output); ///< Astrometry PHU
     131        if (!phu->header) {
     132            phu->header = psMetadataAlloc ();
     133        }
     134        if (!pmAstromWriteBilevelMosaic(phu->header, output, WCS_NONLIN_TOL)) {
     135            psError(psErrorCodeLast(), false, "Unable to write bilevel mosaic astrometry for skycell.");
     136            psFree(view);
     137            return false;
     138        }
    109139    }
    110 # endif
    111140
    112141    return true;
Note: See TracChangeset for help on using the changeset viewer.