IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 3, 2010, 8:50:52 AM (16 years ago)
Author:
eugene
Message:

updates from trunk

Location:
branches/simtest_nebulous_branches
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/simtest_nebulous_branches

  • branches/simtest_nebulous_branches/ppStack/src

    • Property svn:ignore
      •  

        old new  
        1010stamp-h1
        1111ppStackVersionDefinitions.h
         12ppStackErrorCodes.c
         13ppStackErrorCodes.h
  • branches/simtest_nebulous_branches/ppStack/src/ppStackPrepare.c

    r23573 r27840  
    2626    float zpRadius = psMetadataLookupS32(&mdok, recipe, "PHOT.RADIUS"); // Radius for PHOT measurement
    2727    if (!mdok) {
    28         psError(PS_ERR_UNKNOWN, true, "Unable to find PHOT.RADIUS in recipe");
     28        psError(PPSTACK_ERR_CONFIG, true, "Unable to find PHOT.RADIUS in recipe");
    2929        return false;
    3030    }
    3131    float zpSigma = psMetadataLookupF32(&mdok, recipe, "PHOT.SIGMA"); // Gaussian sigma for photometry
    3232    if (!mdok) {
    33         psError(PS_ERR_UNKNOWN, true, "Unable to find PHOT.SIGMA in recipe");
     33        psError(PPSTACK_ERR_CONFIG, true, "Unable to find PHOT.SIGMA in recipe");
    3434        return false;
    3535    }
    3636    float zpFrac = psMetadataLookupF32(&mdok, recipe, "PHOT.FRAC"); // Fraction of good pixels for photometry
    3737    if (!mdok) {
    38         psError(PS_ERR_UNKNOWN, true, "Unable to find PHOT.FRAC in recipe");
     38        psError(PPSTACK_ERR_CONFIG, true, "Unable to find PHOT.FRAC in recipe");
    3939        return false;
    4040    }
     
    4242    psString maskValStr = psMetadataLookupStr(&mdok, recipe, "MASK.VAL"); // Name of bits to mask going in
    4343    if (!mdok || !maskValStr) {
    44         psError(PS_ERR_UNKNOWN, false, "Unable to find MASK.VAL in recipe");
     44        psError(PPSTACK_ERR_CONFIG, false, "Unable to find MASK.VAL in recipe");
    4545        return false;
    4646    }
     
    5353    psStats *stats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV); // Statistics
    5454    if (!psImageBackground(stats, NULL, image, mask, maskVal, rng)) {
    55         psError(PS_ERR_UNKNOWN, false, "Unable to measure background for image");
     55        psError(PPSTACK_ERR_DATA, false, "Unable to measure background for image");
    5656        psFree(stats);
    5757        psFree(rng);
     
    126126    options->inputMask = psVectorAlloc(num, PS_TYPE_VECTOR_MASK); // Mask for inputs
    127127    psVectorInit(options->inputMask, 0);
     128    options->exposures = psVectorAlloc(options->num, PS_TYPE_F32);
     129    psVectorInit(options->exposures, NAN);
    128130
    129131    pmFPAfileActivate(config->files, false, NULL);
     
    134136    }
    135137
    136     psMetadataIterator *fileIter = psMetadataIteratorAlloc(config->files, PS_LIST_HEAD, "^PPSTACK.INPUT$");
    137     psMetadataItem *fileItem; // Item from iteration
    138138    psArray *psfs = psArrayAlloc(num); // PSFs for PSF envelope
    139139    int numCols = 0, numRows = 0;   // Size of image
    140     int index = 0;                  // Index for file
    141     while ((fileItem = psMetadataGetAndIncrement(fileIter))) {
    142         assert(fileItem->type == PS_DATA_UNKNOWN);
    143         pmFPAfile *inputFile = fileItem->data.V; // An input file
     140    options->sumExposure = 0.0;
     141    for (int i = 0; i < num; i++) {
     142        pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PPSTACK.INPUT", i); // File of interest
     143        pmCell *cell = pmFPAviewThisCell(view, file->fpa); // Cell of interest
     144
     145        options->exposures->data.F32[i] = psMetadataLookupF32(NULL, cell->concepts, "CELL.EXPOSURE");
     146        options->sumExposure += options->exposures->data.F32[i];
    144147
    145148        // Get list of PSFs, to determine target PSF
    146149        if (options->convolve) {
    147             pmChip *chip = pmFPAviewThisChip(view, inputFile->fpa); // The chip: holds the PSF
     150            pmChip *chip = pmFPAviewThisChip(view, file->fpa); // The chip: holds the PSF
    148151            pmPSF *psf = psMetadataLookupPtr(NULL, chip->analysis, "PSPHOT.PSF"); // PSF
    149152            if (!psf) {
    150                 psError(PS_ERR_UNKNOWN, false, "Unable to find PSF.");
    151                 psFree(view);
    152                 psFree(fileIter);
     153                psError(PPSTACK_ERR_PROG, false, "Unable to find PSF.");
     154                psFree(view);
    153155                psFree(psfs);
    154156                return false;
    155157            }
    156             psfs->data[index] = psMemIncrRefCounter(psf);
     158            psfs->data[i] = psMemIncrRefCounter(psf);
    157159            psMetadataRemoveKey(chip->analysis, "PSPHOT.PSF");
    158160
    159             pmCell *cell = pmFPAviewThisCell(view, inputFile->fpa); // Cell of interest
     161            pmCell *cell = pmFPAviewThisCell(view, file->fpa); // Cell of interest
    160162            pmHDU *hdu = pmHDUFromCell(cell);
    161163            assert(hdu && hdu->header);
     
    163165            int naxis2 = psMetadataLookupS32(NULL, hdu->header, "NAXIS2"); // Number of rows
    164166            if (naxis1 <= 0 || naxis2 <= 0) {
    165                 psError(PS_ERR_UNKNOWN, false, "Unable to determine size of image from PSF.");
    166                 psFree(view);
    167                 psFree(fileIter);
     167                psError(PPSTACK_ERR_PROG, false, "Unable to determine size of image from PSF.");
     168                psFree(view);
    168169                psFree(psfs);
    169170                return false;
     
    176177
    177178
    178         pmReadout *ro = pmFPAviewThisReadout(view, inputFile->fpa); // Readout with sources
    179         psArray *sources = psMetadataLookupPtr(NULL, ro->analysis, "PSPHOT.SOURCES"); // Sources
    180         if (!sources) {
    181             psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find sources in readout.");
    182             return NULL;
    183         }
    184         options->sourceLists->data[index] = psMemIncrRefCounter(sources);
     179        bool redoPhot = psMetadataLookupBool(NULL, recipe, "PHOT");
     180
     181        pmDetections *detections = NULL;
     182        if (options->convolve || options->matchZPs || options->photometry || redoPhot) {
     183            pmReadout *ro = pmFPAviewThisReadout(view, file->fpa); // Readout with sources
     184            detections = psMetadataLookupPtr(NULL, ro->analysis, "PSPHOT.DETECTIONS"); // Sources
     185            if (!detections || !detections->allSources) {
     186                psWarning("No detections found for image %d --- rejecting.", i);
     187                options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i] = PPSTACK_MASK_CAL;
     188                continue;
     189            }
     190            psAssert (detections->allSources, "missing sources?");
     191
     192            options->sourceLists->data[i] = psMemIncrRefCounter(detections->allSources);
     193        }
    185194
    186195        // Re-do photometry if we don't trust the source lists
    187         if (psMetadataLookupBool(NULL, recipe, "PHOT")) {
    188             psTrace("ppStack", 2, "Photometering input %d of %d....\n", index, num);
     196        if (redoPhot) {
     197            psTrace("ppStack", 2, "Photometering input %d of %d....\n", i, num);
    189198            pmFPAfileActivate(config->files, false, NULL);
    190             ppStackFileActivationSingle(config, PPSTACK_FILES_CONVOLVE, true, index);
    191             pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PPSTACK.INPUT", index); // File
     199            ppStackFileActivationSingle(config, PPSTACK_FILES_CONVOLVE, true, i);
     200            if (options->convolve) {
     201                pmFPAfileActivate(config->files, true, "PPSTACK.CONV.KERNEL");
     202            }
     203            pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PPSTACK.INPUT", i); // File
    192204            pmFPAview *photView = ppStackFilesIterateDown(config);
    193205            if (!photView) {
     
    198210            pmReadout *ro = pmFPAviewThisReadout(view, file->fpa); // Readout of interest
    199211
    200             if (!ppStackInputPhotometer(ro, sources, config)) {
    201                 psError(PS_ERR_UNKNOWN, false, "Unable to do photometry on input sources");
     212            if (!ppStackInputPhotometer(ro, detections->allSources, config)) {
     213                psError(psErrorCodeLast(), false, "Unable to do photometry on input sources");
    202214                psFree(view);
    203215                psFree(photView);
     
    213225            ppStackFileActivation(config, PPSTACK_FILES_PREPARE, true);
    214226        }
    215 
    216         index++;
    217     }
    218     psFree(fileIter);
     227    }
     228
     229    psString log = psStringCopy("Input seeing FWHMs:\n"); // Log message
     230    bool havePSFs = false;                                // Do we have any PSFs?
     231    options->inputSeeing = psVectorAlloc(num, PS_TYPE_F32);
     232    psVectorInit(options->inputSeeing, NAN);
     233    for (int i = 0; i < num; i++) {
     234        pmPSF *psf = psfs->data[i];     // PSF for image
     235        if (!psf) {
     236            continue;
     237        }
     238        havePSFs = true;
     239
     240        int xNum = PS_MAX(psf->trendNx, 1), yNum = PS_MAX(psf->trendNy, 1); // Number of realisations
     241        double sumFWHM = 0.0;           // FWHM for image
     242        int numFWHM = 0;                // Number of FWHM measurements
     243        for (int y = 0; y < yNum; y++) {
     244            float yPos = ((float)y + 0.5) / (float)yNum * numRows;
     245            for (int x = 0; x < xNum; x++) {
     246                float xPos = ((float)x + 0.5) / (float)xNum * numCols;
     247                float fwhm = pmPSFtoFWHM(psf, xPos, yPos); // FWHM for image
     248                if (isfinite(fwhm)) {
     249                    sumFWHM += fwhm;
     250                    numFWHM++;
     251                }
     252            }
     253        }
     254        if (numFWHM == 0) {
     255            options->inputSeeing->data.F32[i] = NAN;
     256            options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i] = PPSTACK_MASK_PSF;
     257            psLogMsg("ppStack", PS_LOG_INFO, "Unable to measure PSF FWHM for image %d --- rejected.", i);
     258        } else {
     259            options->inputSeeing->data.F32[i] = sumFWHM / (float)numFWHM;
     260        }
     261
     262        psStringAppend(&log, "Input %d: %f\n", i, options->inputSeeing->data.F32[i]);
     263    }
     264    if (havePSFs) {
     265        psLogMsg("ppStack", PS_LOG_INFO, "%s", log);
     266    }
     267    psFree(log);
    219268
    220269    // Generate target PSF
     
    223272        psFree(psfs);
    224273        if (!options->psf) {
    225             psError(PS_ERR_UNKNOWN, false, "Unable to determine output PSF.");
     274            psError(psErrorCodeLast(), false, "Unable to determine output PSF.");
    226275            psFree(view);
    227276            return false;
     
    229278        psMetadataAddPtr(config->arguments, PS_LIST_TAIL, "PSF.TARGET", PS_DATA_UNKNOWN,
    230279                         "Target PSF for stack", options->psf);
    231 
    232         pmChip *outChip = pmFPAfileThisChip(config->files, view, "PPSTACK.OUTPUT"); // Output chip
     280        options->targetSeeing = pmPSFtoFWHM(options->psf, 0.5 * numCols, 0.5 * numRows); // FWHM for target
     281        psLogMsg("ppStack", PS_LOG_INFO, "Target seeing FWHM: %f\n", options->targetSeeing);
     282
     283        pmChip *outChip = pmFPAfileThisChip(config->files, view, "PPSTACK.TARGET.PSF"); // Output chip
    233284        psMetadataAddPtr(outChip->analysis, PS_LIST_TAIL, "PSPHOT.PSF", PS_DATA_UNKNOWN,
    234285                         "Target PSF", options->psf);
     
    238289    // Zero point calibration
    239290    if (!ppStackSourcesTransparency(options, view, config)) {
    240         psError(PS_ERR_UNKNOWN, false, "Unable to calculate transparency differences");
     291        psError(PPSTACK_ERR_DATA, false, "Unable to calculate transparency differences");
    241292        psFree(view);
    242293        return false;
Note: See TracChangeset for help on using the changeset viewer.