IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 8, 2010, 1:55:26 PM (16 years ago)
Author:
eugene
Message:

working on psphotStack psf matching

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/psphot.20100506/src/psphotStackMatchPSFsPrepare.c

    r27883 r27884  
    11# include "psphotInternal.h"
     2
     3pmPSF *selectPSF (pmFPAfile *fileSrc, const pmFPAview *view, psphotStackOptions *options, int index);
     4bool determineSeeing (pmPSF *psf, psphotStackOptions *options, int index);
    25
    36// set up the stacking parameters
     
    912    }
    1013
    11     // which image do we want to convolve?  RAW, CNV, AUTO?
    12     // find the currently selected readout
    13     pmFPAfile *fileRaw = pmFPAfileSelectSingle(config->files, "PSPHOT.STACK.INPUT.RAW", index); // File of interest
    14     pmFPAfile *fileCnv = pmFPAfileSelectSingle(config->files, "PSPHOT.STACK.INPUT.CNV", index); // File of interest
    15 
    16     pmFPAfile *fileSrc = NULL;
    17     pmPSF *psf = NULL;
    18 
    19     switch (options->convolveSource) {
    20       case PSPHOT_CNV_SRC_AUTO:
    21         fileSrc = fileCnv ? fileCnv : fileRaw;
    22         break;
    23 
    24       case PSPHOT_CNV_SRC_RAW:
    25         fileSrc = fileRaw;
    26         break;
    27 
    28       case PSPHOT_CNV_SRC_CNV:
    29         fileSrc = fileCnv;
    30         break;
    31 
    32       default:
    33         psAbort("impossible case");
    34     }
     14    pmFPAfile *fileSrc = psphotStackGetConvolveSource(config, options, index);
    3515    if (!fileSrc) {
    36         psError(PSPHOT_ERR_CONFIG, true, "desired convolution source is missing (cnv : %llx, raw : %llx)", (long long) fileCnv, (long long) fileRaw);
     16        psError(PSPHOT_ERR_CONFIG, false, "desired convolution source is missing");
    3717        return false;
    3818    }
    3919
    40     // select the corresponding input psf
    41     {
    42         pmChip *chip = pmFPAviewThisChip(view, fileSrc->fpa); // The chip holds the PSF
    43         pmPSF *psf = psMetadataLookupPtr(NULL, chip->analysis, "PSPHOT.PSF"); // PSF
    44         if (!psf) {
    45             // XXX if we were not supplied a PSF, we should be able to generate one by calling psphot
    46             psError(PSPHOT_ERR_PROG, false, "Unable to find PSF.");
    47             return false;
    48         }
    49         options->psfs->data[index] = psMemIncrRefCounter(psf);
     20    pmPSF *psf = selectPSF (fileSrc, view, options, index);
     21    if (!psf) {
     22        psError(PSPHOT_ERR_PSF, false, "Problem with PSF.");
     23        return false;
     24    }
    5025
    51         // find the image size
    52         pmCell *cell = pmFPAviewThisCell(view, fileSrc->fpa); // Cell of interest
    53         pmHDU *hdu = pmHDUFromCell(cell);
    54         assert(hdu && hdu->header);
    55         int naxis1 = psMetadataLookupS32(NULL, hdu->header, "NAXIS1"); // Number of columns
    56         int naxis2 = psMetadataLookupS32(NULL, hdu->header, "NAXIS2"); // Number of rows
    57         psAssert ((naxis1 > 0) && (naxis2 > 0), "Unable to determine size of image from PSF.");
    58         if (!options->numCols) {
    59             options->numCols = naxis1;
    60         } else {
    61             if (options->numCols != naxis1) {
    62                 psError (PSPHOT_ERR_CONFIG, true, "mismatched sizes (NAXIS1) for input images");
    63                 return false;
    64             }
    65         }
    66         if (!options->numRows) {
    67             options->numRows = naxis2;
    68         } else {
    69             if (options->numRows != naxis2) {
    70                 psError (PSPHOT_ERR_CONFIG, true, "mismatched sizes (NAXIS2) for input images");
    71                 return false;
    72             }
    73         }
    74     }
     26    determineSeeing (psf, options, index);
    7527
    7628    // load the sources (used to find reference sources for the kernel stamps)
    7729    {
    78         pmFPAfile *outputImage = pmFPAfileDefineOutput(config, NULL, "PSPHOT.STACK.OUTPUT.IMAGE");
    79         pmReadout *readout = pmFPAviewThisReadout(view, outputImage->fpa); // Readout with sources
     30        pmFPAfile *inputSrc = pmFPAfileSelectSingle(config->files, "PSPHOT.STACK.SOURCES", index); // File of interest
     31        pmReadout *readout = pmFPAviewThisReadout(view, inputSrc->fpa); // Readout with sources
    8032        pmDetections *detections = psMetadataLookupPtr(NULL, readout->analysis, "PSPHOT.DETECTIONS"); // Sources
    8133        if (!detections || !detections->allSources) {
     
    8840    }
    8941
     42    return true;
     43}
     44
     45// select the corresponding input psf
     46pmPSF *selectPSF (pmFPAfile *fileSrc, const pmFPAview *view, psphotStackOptions *options, int index) {
     47
     48    bool status;
     49
     50    pmChip *chip = pmFPAviewThisChip(view, fileSrc->fpa); // The chip holds the PSF
     51    pmPSF *psf = psMetadataLookupPtr(&status, chip->analysis, "PSPHOT.PSF"); // PSF
     52    if (!psf) {
     53        // XXX if we were not supplied a PSF, we should be able to generate one by calling psphot
     54        psError(PSPHOT_ERR_PROG, true, "Unable to find PSF.");
     55        return NULL;
     56    }
     57    options->psfs->data[index] = psMemIncrRefCounter(psf);
     58
     59    // find the image size
     60    pmCell *cell = pmFPAviewThisCell(view, fileSrc->fpa); // Cell of interest
     61    pmHDU *hdu = pmHDUFromCell(cell);
     62    assert(hdu && hdu->header);
     63    int naxis1 = psMetadataLookupS32(NULL, hdu->header, "NAXIS1"); // Number of columns
     64    int naxis2 = psMetadataLookupS32(NULL, hdu->header, "NAXIS2"); // Number of rows
     65    psAssert ((naxis1 > 0) && (naxis2 > 0), "Unable to determine size of image from PSF.");
     66    if (!options->numCols) {
     67        options->numCols = naxis1;
     68    } else {
     69        if (options->numCols != naxis1) {
     70            psError (PSPHOT_ERR_CONFIG, true, "mismatched sizes (NAXIS1) for input images");
     71            return NULL;
     72        }
     73    }
     74    if (!options->numRows) {
     75        options->numRows = naxis2;
     76    } else {
     77        if (options->numRows != naxis2) {
     78            psError (PSPHOT_ERR_CONFIG, true, "mismatched sizes (NAXIS2) for input images");
     79            return NULL;
     80        }
     81    }
     82    return psf;
     83}
     84
    9085    // determine the input seeing
    91     {
    92         // XXX set this based on the mode (+1 for poly, +0 for map)
    93         float xNum = PS_MAX(psf->trendNx, 1);
    94         float yNum = PS_MAX(psf->trendNy, 1); // Number of realisations
    95         float sumFWHM = 0.0;              // FWHM for image
    96         int numFWHM = 0;                          // Number of FWHM measurements
    97         for (float y = 0; y < yNum; y += 1.0) {
    98             float yPos = options->numRows * ((y + 0.5) / yNum);
    99             for (float x = 0; x < xNum; x++) {
    100                 float xPos = options->numCols * ((x + 0.5) / xNum);
    101                 float fwhm = pmPSFtoFWHM(psf, xPos, yPos); // FWHM for image
    102                 if (isfinite(fwhm)) {
    103                     sumFWHM += fwhm;
    104                     numFWHM++;
    105                 }
     86bool determineSeeing (pmPSF *psf, psphotStackOptions *options, int index) {
     87
     88    // XXX set this based on the mode (+1 for poly, +0 for map)
     89    float xNum = PS_MAX(psf->trendNx, 1);
     90    float yNum = PS_MAX(psf->trendNy, 1); // Number of realisations
     91    float sumFWHM = 0.0;                  // FWHM for image
     92    int numFWHM = 0;                      // Number of FWHM measurements
     93    for (float y = 0; y < yNum; y += 1.0) {
     94        float yPos = options->numRows * ((y + 0.5) / yNum);
     95        for (float x = 0; x < xNum; x++) {
     96            float xPos = options->numCols * ((x + 0.5) / xNum);
     97            float fwhm = pmPSFtoFWHM(psf, xPos, yPos); // FWHM for image
     98            if (isfinite(fwhm)) {
     99                sumFWHM += fwhm;
     100                numFWHM++;
    106101            }
    107102        }
    108         if (numFWHM == 0) {
    109             options->inputSeeing->data.F32[index] = NAN;
    110             options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[index] = 0x02;
    111             psLogMsg("ppStack", PS_LOG_INFO, "Unable to measure PSF FWHM for image %d --- rejected.", index);
    112         } else {
    113             options->inputSeeing->data.F32[index] = sumFWHM / (float)numFWHM;
    114         }
    115         psLogMsg ("psphotStack", PS_LOG_INFO, "Input Seeing for %d: %f\n", index, options->inputSeeing->data.F32[index]);
    116103    }
    117 
     104    if (numFWHM == 0) {
     105        options->inputSeeing->data.F32[index] = NAN;
     106        options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[index] = 0x02;
     107        psLogMsg("ppStack", PS_LOG_INFO, "Unable to measure PSF FWHM for image %d --- rejected.", index);
     108    } else {
     109        options->inputSeeing->data.F32[index] = sumFWHM / (float)numFWHM;
     110    }
     111    psLogMsg ("psphotStack", PS_LOG_INFO, "Input Seeing for %d: %f\n", index, options->inputSeeing->data.F32[index]);
    118112    return true;
    119113}
     114
Note: See TracChangeset for help on using the changeset viewer.