IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 30, 2010, 1:33:47 PM (16 years ago)
Author:
eugene
Message:

some API re-work to support psphotForced and detection efficiency measurements; better visualization; CR masking (optional); better source size analysis; some motion towards stack photometry

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot/src/psphotEfficiency.c

    r26894 r27532  
    44                    PM_MODEL_STATUS_BADARGS | PM_MODEL_STATUS_LIMITS) // Mask to apply to models
    55
    6 //#define TESTING
    7 
    8 
    9 # if 0
     6# define TESTING 0
    107
    118// Calculate the limiting magnitude for an image
     
    1916                     float *covarFactor,// Covariance factor
    2017                     const pmReadout *ro,     // Readout of interest
    21                      const pmPSF *psf,        // Point-spread function
     18                     pmPSF *psf,              // Point-spread function
    2219                     float thresh,            // Threshold for source identification
    2320                     float smoothSigma,       // Gaussian smoothing sigma
     
    152149}
    153150
    154 # endif
    155 
    156151bool psphotEfficiency (pmConfig *config, const pmFPAview *view)
    157152{
     
    178173bool psphotEfficiencyReadout(pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe)
    179174{
    180 # if 0
    181175    bool status = true;
    182176
     
    206200
    207201    // Collect recipe information
    208     float fwhmMajor = psMetadataLookupF32(NULL, recipe, "FWHM_MAJ"); // PSF size in x
    209     float fwhmMinor = psMetadataLookupF32(NULL, recipe, "FWHM_MIN"); // PSF size in y
     202    float smoothNsigma = psMetadataLookupF32(&status, recipe, "PEAKS_SMOOTH_NSIGMA"); // Smoothing limit
     203    psAssert (status && isfinite(smoothNsigma), "Unable to find PEAKS_SMOOTH_NSIGMA in recipe (or invalid value)");
     204
     205    float thresh = psMetadataLookupF32(&status, recipe, "PEAKS_NSIGMA_LIMIT_2");
     206    psAssert (status && isfinite(thresh), "Unable to find PEAKS_NSIGMA_LIMIT_2 in recipe (or invalid value)");
     207
     208    psVector *magOffsets = psMetadataLookupVector(&status, recipe, "EFF.MAG"); // Magnitude offsets
     209    psAssert (status, "Unable to find EFF.MAG F32 vector in recipe");
     210    psAssert (magOffsets->type.type == PS_TYPE_F32, "Unable to find EFF.MAG F32 vector in recipe");
     211
     212    int numSources = psMetadataLookupS32(&status, recipe, "EFF.NUM"); // Number of sources for each bin
     213    psAssert (status && (numSources > 0), "Unable to find EFF.NUM in recipe (or invalid value)");
     214
     215    float minGauss = psMetadataLookupF32(&status, recipe, "PEAKS_MIN_GAUSS"); // Minimum valid fraction of kernel
     216    psAssert (status && isfinite(minGauss), "PEAKS_MIN_GAUSS is not set in recipe (or invalid)");
     217
     218    // find the PSF size information (why is this not part of the psf structure?)
     219    float fwhmMajor = psMetadataLookupF32(NULL, readout->analysis, "FWHM_MAJ"); // PSF size in x
     220    float fwhmMinor = psMetadataLookupF32(NULL, readout->analysis, "FWHM_MIN"); // PSF size in y
    210221    if (!isfinite(fwhmMajor) || !isfinite(fwhmMinor) || fwhmMajor == 0.0 || fwhmMinor == 0.0) {
    211         psError(PSPHOT_ERR_CONFIG, false, "Unable to find FWHM_MAJ and FWHM_MIN in recipe");
    212         return false;
    213     }
    214     float smoothNsigma = psMetadataLookupF32(NULL, recipe, "PEAKS_SMOOTH_NSIGMA"); // Smoothing limit
    215     if (!isfinite(smoothNsigma)) {
    216         psError(PSPHOT_ERR_CONFIG, false, "Unable to find PEAKS_SMOOTH_NSIGMA in recipe");
    217         return false;
    218     }
    219     float thresh = psMetadataLookupF32(NULL, recipe, "PEAKS_NSIGMA_LIMIT_2");
    220     if (!isfinite(thresh)) {
    221         psError(PSPHOT_ERR_CONFIG, false, "Unable to find PEAKS_NSIGMA_LIMIT_2 in recipe");
    222         return false;
    223     }
    224     psVector *magOffsets = psMetadataLookupVector(NULL, recipe, "EFF.MAG"); // Magnitude offsets
    225     if (!magOffsets || magOffsets->type.type != PS_TYPE_F32) {
    226         psError(PSPHOT_ERR_CONFIG, false, "Unable to find EFF.MAG F32 vector in recipe");
    227         return NULL;
    228     }
    229     int numSources = psMetadataLookupS32(NULL, recipe, "EFF.NUM"); // Number of sources for each bin
    230     if (numSources == 0) {
    231         psError(PSPHOT_ERR_CONFIG, false, "Unable to find EFF.NUM in recipe");
    232         return NULL;
    233     }
    234     float minGauss = psMetadataLookupF32(NULL, recipe, "PEAKS_MIN_GAUSS"); // Minimum valid fraction of kernel
    235     if (!isfinite(minGauss)) {
    236         psWarning("PEAKS_MIN_GAUSS is not set in recipe; using default value");
    237         minGauss = 0.5;
     222        psError(PSPHOT_ERR_CONFIG, false, "Unable to find FWHM_MAJ and FWHM_MIN in readout->analysis");
     223        return false;
    238224    }
    239225
     
    246232    // remove all sources, adding noise for subtracted sources
    247233    psphotRemoveAllSources(realSources, recipe);
    248     // psphotAddNoise(readout, realSources, recipe);
    249 
    250 
    251 #if defined(TESTING) && 0
     234
     235#if TESTING
    252236    {
    253237        psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS);
     
    278262    }
    279263
    280 #ifdef TESTING
     264#if TESTING
    281265    psphotSaveImage(NULL, readout->image, "orig_image.fits");
    282266    psphotSaveImage(NULL, readout->variance, "orig_variance.fits");
     
    293277    }
    294278
    295 #ifdef TESTING
     279#if TESTING
    296280    psphotSaveImage(NULL, readout->image, "fake_image.fits");
    297281    psphotSaveImage(NULL, readout->variance, "fake_variance.fits");
     
    408392    psFree(significance);
    409393
    410     if (!psphotFitSourcesLinear(readout, fakeSourcesAll, recipe, psf, true)) {
     394    if (!psphotFitSourcesLinearReadout(recipe, readout, fakeSourcesAll, psf, true)) {
    411395        psError(PS_ERR_UNKNOWN, false, "Unable to perform linear fit on fake sources.");
    412396        psFree(fakeSources);
     
    415399    }
    416400
    417     // Disable aperture corrections; casting away const!
     401    // Disable aperture corrections (save current value)
    418402    pmTrend2D *apTrend = psf->ApTrend;  // Aperture trend
    419     ((pmPSF*)psf)->ApTrend = NULL;
    420 
    421     if (!psphotMagnitudes(config, readout, view, fakeSourcesAll, psf)) {
     403    psf->ApTrend = NULL;
     404
     405    if (!psphotMagnitudesReadout(config, recipe, view, readout, fakeSourcesAll, psf)) {
    422406        psError(PS_ERR_UNKNOWN, false, "Unable to measure magnitudes of fake sources.");
    423407        psFree(fakeSources);
    424408        psFree(count);
    425         ((pmPSF*)psf)->ApTrend = apTrend; // Casting away const!
     409        psf->ApTrend = apTrend; // Casting away const!
    426410        return false;
    427411    }
    428412    psFree(fakeSourcesAll);
    429413
    430     // Re-enable aperture corrections; casting away const!
    431     ((pmPSF*)psf)->ApTrend = apTrend;
     414    // Replace aperture corrections
     415    psf->ApTrend = apTrend;
    432416
    433417    psVector *magDiffMean = psVectorAlloc(numBins, PS_TYPE_F32); // Mean difference in magnitude for each bin
     
    443427        psVectorInit(magMask, 0);
    444428
    445 #ifdef TESTING
     429#if TESTING
    446430        psString name = NULL;
    447431        psStringAppend(&name, "fake_%d.dat", i);
     
    459443            }
    460444
    461 #ifdef TESTING
     445#if TESTING
    462446            fprintf(file, "%f %f %f %f %f %f %f\n", source->peak->xf, source->peak->yf,
    463447                    source->modelPSF->params->data.F32[PM_PAR_XPOS],
     
    495479        }
    496480
    497 #ifdef TESTING
     481#if TESTING
    498482        fclose(file);
    499483#endif
     
    520504    psLogMsg("psphot", PS_LOG_INFO, "Detection efficiency: %lf sec\n", psTimerClear("psphot.fake"));
    521505
    522 # endif
    523 
    524506    return true;
    525507}
Note: See TracChangeset for help on using the changeset viewer.