IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 7, 2013, 6:23:04 AM (13 years ago)
Author:
eugene
Message:

cleanup code to be more readable (add pswarpStatsFile structure, pswarpCleanup, move code into pswarpDefineBackground and pswarpLoopBackground

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20130307/pswarp/src/pswarpDefine.c

    r35372 r35373  
    11/** @file pswarpDefine.c
    22 *
    3  *  @brief
    4  *
     3 *  @brief generates the output images
    54 *  @ingroup pswarp
    65 *
     
    1312# include "pswarp.h"
    1413
    15 /**
    16  * loads the skycell metadata
    17  */
    1814bool pswarpDefine (pmConfig *config) {
    1915
     
    132128}
    133129
    134 bool pswarpDefineBackground (pmConfig *config) {
    135 
    136     // load the PSWARP recipe
    137     psMetadata *recipe = psMetadataLookupPtr (NULL, config->recipes, PSWARP_RECIPE);
    138     if (!recipe) {
    139         psError(PSWARP_ERR_CONFIG, true, "Can't find PSWARP recipe!\n");
    140         return false;
    141     }
    142 
    143     // select the input data sources
    144     pmFPAfile *skycell = psMetadataLookupPtr (NULL, config->files, "PSWARP.SKYCELL");
    145     if (!skycell) {
    146         psError(PSWARP_ERR_CONFIG, false, "Can't find skycell data!\n");
    147         return false;
    148     }
    149     pmFPAfile *output = psMetadataLookupPtr(NULL, config->files, "PSWARP.OUTPUT.BKGMODEL");
    150     if (!output) {
    151         psError(PSWARP_ERR_CONFIG, false, "Can't find output data!\n");
    152         return false;
    153     }
    154     pmFPAfile *input = psMetadataLookupPtr(NULL, config->files, "PSWARP.INPUT");
    155     if (!input) {
    156         psError(PSWARP_ERR_CONFIG, false, "Can't find input data!\n");
    157         return false;
    158     }
    159    
    160     // open the full skycell file; no need to defer different depths. only load the header data
    161     pmFPAview *view = pmFPAviewAlloc (0);
    162     pmFPAfileOpen (skycell, view, config);
    163 
    164     // Read header and create target
    165     {
    166         if (!pmFPAReadHeaderSet(skycell->fpa, skycell->fits, config)) {
    167             psError(psErrorCodeLast(), false, "Unable to read headers for skycell.");
    168             psFree(view);
    169             return false;
    170         }
    171         view->chip = 0;
    172         view->cell = 0;
    173         view->readout = 0;
    174         pmCell *source = pmFPAfileThisCell(config->files, view, "PSWARP.SKYCELL"); ///< Source cell
    175         pmHDU *hdu = pmHDUFromCell(source); ///< HDU for source
    176         if (!hdu || !hdu->header) {
    177             psError(PM_ERR_PROG, false, "Unable to find header for sky cell.");
    178             psFree(view);
    179             return false;
    180         }
    181         int numCols = psMetadataLookupS32(NULL, hdu->header, "NAXIS1"); ///< Number of columns
    182         int numRows = psMetadataLookupS32(NULL, hdu->header, "NAXIS2"); ///< Number of rows
    183         if ((numCols == 0) || (numRows == 0)) {
    184             psError(PSWARP_ERR_DATA, false, "skycell has invalid dimensions %d x %d", numCols, numRows);
    185             psFree(view);
    186             return false;
    187         }
    188 
    189         pmCell *target = pmFPAviewThisCell(view, output->fpa); ///< Target cell
    190         pmReadout *readout = pmReadoutAlloc(target); ///< Target readout
    191         readout->image = psImageAlloc(numCols / output->xBin, numRows / output->yBin, PS_TYPE_F32);
    192         psImageInit(readout->image, NAN);
    193         psFree(readout);                // Drop reference
    194 
    195         bool status = false;
    196         psMetadataItemSupplement(&status, target->concepts, source->concepts, "CELL.XBIN");
    197         psMetadataItemSupplement(&status, target->concepts, source->concepts, "CELL.YBIN");
    198 /*      psMetadataAddS32(target->concepts,PS_LIST_TAIL,"CELL.XBIN",PS_META_REPLACE,"",output->xBin); */
    199 /*      psMetadataAddS32(target->concepts,PS_LIST_TAIL,"CELL.YBIN",PS_META_REPLACE,"",output->yBin); */
    200         psMetadataItemSupplement(&status, target->concepts, source->concepts, "CELL.XSIZE");
    201         psMetadataItemSupplement(&status, target->concepts, source->concepts, "CELL.YSIZE");
    202 /*      psMetadataAddS32(target->concepts,PS_LIST_TAIL,"CELL.XSIZE",PS_META_REPLACE,"",numCols / output->xBin); */
    203 /*      psMetadataAddS32(target->concepts,PS_LIST_TAIL,"CELL.YSIZE",PS_META_REPLACE,"",numRows / output->yBin); */
    204         psMetadataItemSupplement(&status, target->concepts, source->concepts, "CELL.XPARITY");
    205         psMetadataItemSupplement(&status, target->concepts, source->concepts, "CELL.YPARITY");
    206         psMetadataItemSupplement(&status, target->concepts, source->concepts, "CELL.X0");
    207         psMetadataItemSupplement(&status, target->concepts, source->concepts, "CELL.Y0");
    208 
    209        
    210     }
    211 
    212     // XXX this is not a sufficient test
    213     view->chip = 0;
    214     view->cell = 0;
    215     view->readout = -1;
    216     pmHDU *phu = pmFPAviewThisPHU(view, skycell->fpa); ///< Skycell PHU
    217     pmHDU *hdu = pmFPAviewThisHDU(view, skycell->fpa); ///< Skycell header
    218 
    219     pmAstromWCS *WCS = pmAstromWCSfromHeader(hdu->header);
    220 
    221     double cd1f = 1.0 * output->xBin;
    222     double cd2f = 1.0 * output->yBin;
    223    
    224     WCS->crpix1 = WCS->crpix1 / cd1f;
    225     WCS->crpix2 = WCS->crpix2 / cd2f;
    226    
    227     WCS->cdelt1 *= cd1f;
    228     WCS->cdelt2 *= cd2f;
    229 
    230     WCS->trans->x->coeff[1][0] *= cd1f;
    231     WCS->trans->x->coeff[0][1] *= cd2f;
    232     WCS->trans->y->coeff[1][0] *= cd1f;
    233     WCS->trans->y->coeff[0][1] *= cd2f;
    234    
    235    
    236     pmAstromWCStoHeader (hdu->header,WCS);
    237 
    238     bool bilevelAstrometry = false;
    239     if (phu) {
    240         char *ctype = psMetadataLookupStr(NULL, phu->header, "CTYPE1");
    241         if (ctype) {
    242             bilevelAstrometry = !strcmp(&ctype[4], "-DIS");
    243         }
    244     }
    245 
    246     // We read from the skycell into the output.  i.e., the output receives the desired astrometry.
    247     pmChip *outputChip = pmFPAviewThisChip(view, output->fpa); ///< Chip in the output
    248     if (bilevelAstrometry) {
    249         if (!pmAstromReadBilevelMosaic(output->fpa, phu->header)) {
    250             psError(psErrorCodeLast(), false, "Unable to read bilevel mosaic astrometry for skycell.");
    251             psFree(view);
    252             return false;
    253         }
    254         if (!pmAstromReadBilevelChip(outputChip, hdu->header)) {
    255             psError(psErrorCodeLast(), false, "Unable to read bilevel chip astrometry for skycell.");
    256             psFree(view);
    257             return false;
    258         }
    259     } else {
    260         // we use a default FPA pixel scale of 1.0
    261       if (!pmAstromReadWCS(output->fpa, outputChip, hdu->header, 1.0)) {
    262             psError(psErrorCodeLast(), false, "Unable to read WCS astrometry for skycell.");
    263             psFree(view);
    264             return false;
    265         }
    266     }
    267 
    268    
    269     view->chip = view->cell = view->readout = -1;
    270     pmFPAAddSourceFromView(output->fpa, view, output->format);
    271 
    272 
    273     psFree (view);
    274     return true;
    275 }
Note: See TracChangeset for help on using the changeset viewer.