IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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

updates from trunk

Location:
branches/tap_branches
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/tap_branches

  • branches/tap_branches/psphot

  • branches/tap_branches/psphot/src

    • Property svn:ignore
      •  

        old new  
        1919psphotMomentsStudy
        2020psphotPetrosianStudy
         21psphotForced
         22psphotMakePSF
         23psphotStack
  • branches/tap_branches/psphot/src/psphotEfficiency.c

    • Property svn:mergeinfo deleted
    r25890 r27838  
    44                    PM_MODEL_STATUS_BADARGS | PM_MODEL_STATUS_LIMITS) // Mask to apply to models
    55
    6 //#define TESTING
    7 
     6# define TESTING 0
    87
    98// Calculate the limiting magnitude for an image
     
    1716                     float *covarFactor,// Covariance factor
    1817                     const pmReadout *ro,     // Readout of interest
    19                      const pmPSF *psf,        // Point-spread function
     18                     pmPSF *psf,              // Point-spread function
    2019                     float thresh,            // Threshold for source identification
    2120                     float smoothSigma,       // Gaussian smoothing sigma
     
    3332
    3433    psKernel *kernel = psImageSmoothKernel(smoothSigma, smoothNsigma); // Kernel used for smoothing
    35     psKernel *newCovar = psImageCovarianceCalculate(kernel, ro->covariance); // Covariance matrix
     34    *covarFactor = psImageCovarianceCalculateFactor(kernel, ro->covariance);
    3635    psFree(kernel);
    37     *covarFactor = psImageCovarianceFactor(newCovar); // Variance factor
    38     psFree(newCovar);
    3936
    4037    psStats *stats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN); // Statistics for variance
     
    128125    psFree(rng);
    129126
     127    bool oldThreads = pmReadoutFakeThreads(true); // Old threading status
     128
    130129    pmReadout *fakeRO = pmReadoutAlloc(NULL); // Fake readout
    131130    if (!pmReadoutFakeFromVectors(fakeRO, numCols, numRows, xAll, yAll, magAll,
     
    142141    psFree(yAll);
    143142
     143    pmReadoutFakeThreads(oldThreads);
     144
    144145    psBinaryOp(ro->image, ro->image, "+", fakeRO->image);
    145146    psFree(fakeRO);
     
    148149}
    149150
     151bool psphotEfficiency (pmConfig *config, const pmFPAview *view)
     152{
     153    bool status = true;
     154
     155    // select the appropriate recipe information
     156    psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE);
     157    psAssert (recipe, "missing recipe?");
     158
     159    int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
     160    psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     161
     162    // skip the chisq image (optionally?)
     163    int chisqNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.CHISQ.NUM");
     164    if (!status) chisqNum = -1;
     165
     166    // loop over the available readouts
     167    for (int i = 0; i < num; i++) {
     168        if (i == chisqNum) continue; // skip chisq image
     169        if (!psphotEfficiencyReadout (config, view, "PSPHOT.INPUT", i, recipe)) {
     170            psError (PSPHOT_ERR_CONFIG, false, "failed to measure detection efficiency for PSPHOT.INPUT entry %d", i);
     171            return false;
     172        }
     173    }
     174    return true;
     175}
    150176
    151177// Determine detection efficiency
    152 bool psphotEfficiency(pmConfig *config, pmReadout *readout, const pmFPAview *view, const pmPSF *psf,
    153                 psMetadata *recipe, const psArray *realSources)
     178bool psphotEfficiencyReadout(pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe)
    154179{
     180    bool status = true;
     181
     182    psTimerStart("psphot.fake");
     183
     184    // find the currently selected readout
     185    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filename, index); // File of interest
     186    psAssert (file, "missing file?");
     187
     188    pmReadout *readout = pmFPAviewThisReadout(view, file->fpa);
     189    psAssert (readout, "missing readout?");
     190
     191    pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS");
     192    psAssert (detections, "missing detections?");
     193
     194    psArray *realSources = detections->allSources;
     195    psAssert (realSources, "missing sources?");
     196
     197    // XXX do we need to skip this step if we do not have a psf?
     198    pmPSF *psf = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.PSF");
     199    psAssert (psf, "missing psf?");
     200
    155201    PM_ASSERT_READOUT_NON_NULL(readout, false);
    156202    PM_ASSERT_READOUT_IMAGE(readout, false);
    157203    PS_ASSERT_PTR_NON_NULL(psf, false);
    158204    PS_ASSERT_METADATA_NON_NULL(recipe, false);
    159     PS_ASSERT_ARRAY_NON_NULL(realSources, false);
    160 
    161     psTimerStart("psphot.fake");
    162205
    163206    // Collect recipe information
    164     float fwhmMajor = psMetadataLookupF32(NULL, recipe, "FWHM_MAJ"); // PSF size in x
    165     float fwhmMinor = psMetadataLookupF32(NULL, recipe, "FWHM_MIN"); // PSF size in y
     207    float smoothNsigma = psMetadataLookupF32(&status, recipe, "PEAKS_SMOOTH_NSIGMA"); // Smoothing limit
     208    psAssert (status && isfinite(smoothNsigma), "Unable to find PEAKS_SMOOTH_NSIGMA in recipe (or invalid value)");
     209
     210    float thresh = psMetadataLookupF32(&status, recipe, "PEAKS_NSIGMA_LIMIT_2");
     211    psAssert (status && isfinite(thresh), "Unable to find PEAKS_NSIGMA_LIMIT_2 in recipe (or invalid value)");
     212
     213    psVector *magOffsets = psMetadataLookupVector(&status, recipe, "EFF.MAG"); // Magnitude offsets
     214    psAssert (status, "Unable to find EFF.MAG F32 vector in recipe");
     215    psAssert (magOffsets->type.type == PS_TYPE_F32, "Unable to find EFF.MAG F32 vector in recipe");
     216
     217    int numSources = psMetadataLookupS32(&status, recipe, "EFF.NUM"); // Number of sources for each bin
     218    psAssert (status && (numSources > 0), "Unable to find EFF.NUM in recipe (or invalid value)");
     219
     220    float minGauss = psMetadataLookupF32(&status, recipe, "PEAKS_MIN_GAUSS"); // Minimum valid fraction of kernel
     221    psAssert (status && isfinite(minGauss), "PEAKS_MIN_GAUSS is not set in recipe (or invalid)");
     222
     223    // find the PSF size information (why is this not part of the psf structure?)
     224    float fwhmMajor = psMetadataLookupF32(NULL, readout->analysis, "FWHM_MAJ"); // PSF size in x
     225    float fwhmMinor = psMetadataLookupF32(NULL, readout->analysis, "FWHM_MIN"); // PSF size in y
    166226    if (!isfinite(fwhmMajor) || !isfinite(fwhmMinor) || fwhmMajor == 0.0 || fwhmMinor == 0.0) {
    167         psError(PSPHOT_ERR_CONFIG, false, "Unable to find FWHM_MAJ and FWHM_MIN in recipe");
    168         return false;
    169     }
    170     float smoothNsigma = psMetadataLookupF32(NULL, recipe, "PEAKS_SMOOTH_NSIGMA"); // Smoothing limit
    171     if (!isfinite(smoothNsigma)) {
    172         psError(PSPHOT_ERR_CONFIG, false, "Unable to find PEAKS_SMOOTH_NSIGMA in recipe");
    173         return false;
    174     }
    175     float thresh = psMetadataLookupF32(NULL, recipe, "PEAKS_NSIGMA_LIMIT_2");
    176     if (!isfinite(thresh)) {
    177         psError(PSPHOT_ERR_CONFIG, false, "Unable to find PEAKS_NSIGMA_LIMIT_2 in recipe");
    178         return false;
    179     }
    180     psVector *magOffsets = psMetadataLookupVector(NULL, recipe, "EFF.MAG"); // Magnitude offsets
    181     if (!magOffsets || magOffsets->type.type != PS_TYPE_F32) {
    182         psError(PSPHOT_ERR_CONFIG, false, "Unable to find EFF.MAG F32 vector in recipe");
    183         return NULL;
    184     }
    185     int numSources = psMetadataLookupS32(NULL, recipe, "EFF.NUM"); // Number of sources for each bin
    186     if (numSources == 0) {
    187         psError(PSPHOT_ERR_CONFIG, false, "Unable to find EFF.NUM in recipe");
    188         return NULL;
    189     }
    190     float minGauss = psMetadataLookupF32(NULL, recipe, "PEAKS_MIN_GAUSS"); // Minimum valid fraction of kernel
    191     if (!isfinite(minGauss)) {
    192         psWarning("PEAKS_MIN_GAUSS is not set in recipe; using default value");
    193         minGauss = 0.5;
     227        psError(PSPHOT_ERR_CONFIG, false, "Unable to find FWHM_MAJ and FWHM_MIN in readout->analysis");
     228        return false;
    194229    }
    195230
     
    202237    // remove all sources, adding noise for subtracted sources
    203238    psphotRemoveAllSources(realSources, recipe);
    204     //    psphotAddNoise(readout, realSources, recipe);
    205 
    206 
    207 #if defined(TESTING) && 0
     239
     240#if TESTING
    208241    {
    209242        psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS);
     
    234267    }
    235268
    236 #ifdef TESTING
     269#if TESTING
    237270    psphotSaveImage(NULL, readout->image, "orig_image.fits");
    238271    psphotSaveImage(NULL, readout->variance, "orig_variance.fits");
     
    249282    }
    250283
    251 #ifdef TESTING
     284#if TESTING
    252285    psphotSaveImage(NULL, readout->image, "fake_image.fits");
    253286    psphotSaveImage(NULL, readout->variance, "fake_variance.fits");
     
    364397    psFree(significance);
    365398
    366     if (!psphotFitSourcesLinear(readout, fakeSourcesAll, recipe, psf, true)) {
     399    if (!psphotFitSourcesLinearReadout(recipe, readout, fakeSourcesAll, psf, true)) {
    367400        psError(PS_ERR_UNKNOWN, false, "Unable to perform linear fit on fake sources.");
    368401        psFree(fakeSources);
     
    371404    }
    372405
    373     // Disable aperture corrections; casting away const!
     406    // Disable aperture corrections (save current value)
    374407    pmTrend2D *apTrend = psf->ApTrend;  // Aperture trend
    375     ((pmPSF*)psf)->ApTrend = NULL;
    376 
    377     if (!psphotMagnitudes(config, readout, view, fakeSourcesAll, psf)) {
     408    psf->ApTrend = NULL;
     409
     410    if (!psphotMagnitudesReadout(config, recipe, view, readout, fakeSourcesAll, psf)) {
    378411        psError(PS_ERR_UNKNOWN, false, "Unable to measure magnitudes of fake sources.");
    379412        psFree(fakeSources);
    380413        psFree(count);
    381         ((pmPSF*)psf)->ApTrend = apTrend; // Casting away const!
     414        psf->ApTrend = apTrend; // Casting away const!
    382415        return false;
    383416    }
    384417    psFree(fakeSourcesAll);
    385418
    386     // Re-enable aperture corrections; casting away const!
    387     ((pmPSF*)psf)->ApTrend = apTrend;
     419    // Replace aperture corrections
     420    psf->ApTrend = apTrend;
    388421
    389422    psVector *magDiffMean = psVectorAlloc(numBins, PS_TYPE_F32); // Mean difference in magnitude for each bin
     
    399432        psVectorInit(magMask, 0);
    400433
    401 #ifdef TESTING
     434#if TESTING
    402435        psString name = NULL;
    403436        psStringAppend(&name, "fake_%d.dat", i);
     
    415448            }
    416449
    417 #ifdef TESTING
     450#if TESTING
    418451            fprintf(file, "%f %f %f %f %f %f %f\n", source->peak->xf, source->peak->yf,
    419452                    source->modelPSF->params->data.F32[PM_PAR_XPOS],
     
    451484        }
    452485
    453 #ifdef TESTING
     486#if TESTING
    454487        fclose(file);
    455488#endif
     
    476509    psLogMsg("psphot", PS_LOG_INFO, "Detection efficiency: %lf sec\n", psTimerClear("psphot.fake"));
    477510
    478 
    479511    return true;
    480512}
Note: See TracChangeset for help on using the changeset viewer.