IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 18, 2012, 5:56:48 AM (14 years ago)
Author:
eugene
Message:

merge changes from trunk

File:
1 edited

Legend:

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

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