IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 10202


Ignore:
Timestamp:
Nov 26, 2006, 12:37:44 PM (20 years ago)
Author:
eugene
Message:

added option to include weights in 2D parameter fits (PSF_PARAM_WEIGHTS); measure the stats of dSXX,dSYY to better judge psf-like fits

File:
1 edited

Legend:

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

    r10184 r10202  
    2626    }
    2727
     28    float PSF_MIN_DS = psMetadataLookupF32 (&status, recipe, "PSF_MIN_DS");
     29    if (!status) {
     30        PSF_MIN_DS = 0.01;
     31        psWarning("PSF_MIN_DS is not set --- defaulting to %f\n", PSF_MIN_DS);
     32    }
     33
    2834    // supply the measured sky variance for optional constant errors (non-poissonian)
    2935    float SKY_STDEV = psMetadataLookupF32 (&status, recipe, "SKY_STDEV");
     
    3945    }
    4046    pmSourceFitModelInit (15, 0.01, PS_SQR(SKY_STDEV), POISSON_ERRORS);
     47
     48    // use poissonian errors or local-sky errors
     49    bool PSF_PARAM_WEIGHTS = psMetadataLookupBool (&status, recipe, "PSF_PARAM_WEIGHTS");
     50    if (!status) {
     51        PSF_PARAM_WEIGHTS = false;
     52        psWarning("PSF_PARAM_WEIGHTS is not set in the recipe --- defaulting to false.\n");
     53    }
    4154
    4255    // how to model the PSF variations across the field
     
    98111        psMetadataItem *item = psListGetAndIncrement (iter);
    99112        modelName = item->data.V;
    100         models->data[i] = pmPSFtryModel (stars, modelName, RADIUS, POISSON_ERRORS, psfTrendMask);
     113        models->data[i] = pmPSFtryModel (stars, modelName, RADIUS, POISSON_ERRORS, psfTrendMask, PSF_PARAM_WEIGHTS);
    101114    }
    102115
     
    132145    try = models->data[bestN];
    133146
     147    // measure and save the median value of dparams[PM_PAR_SXX],dparams[PM_PAR_SYY]
     148    // these are used by psphotEvalPSF to identify extended sources
     149    psVector *Sx = psVectorAllocEmpty (try->sources->n, PS_TYPE_F32);
     150    psVector *Sy = psVectorAllocEmpty (try->sources->n, PS_TYPE_F32);
     151    psVector *dSx = psVectorAllocEmpty (try->sources->n, PS_TYPE_F32);
     152    psVector *dSy = psVectorAllocEmpty (try->sources->n, PS_TYPE_F32);
     153    psVector *dSN = psVectorAllocEmpty (try->sources->n, PS_TYPE_F32);
     154    for (int i = 0; i < try->sources->n; i++) {
     155        // masked for: bad model fit, outlier in parameters
     156        if (try->mask->data.U8[i] & PSFTRY_MASK_ALL)
     157            continue;
     158
     159        pmSource *source = try->sources->data[i];
     160        Sx->data.F32[Sx->n] = source->modelPSF->params->data.F32[PM_PAR_SXX];
     161        Sy->data.F32[Sy->n] = source->modelPSF->params->data.F32[PM_PAR_SYY];
     162        dSN->data.F32[dSN->n] = source->modelPSF->dparams->data.F32[PM_PAR_I0] / source->modelPSF->params->data.F32[PM_PAR_I0];
     163        dSx->data.F32[dSx->n] = source->modelPSF->dparams->data.F32[PM_PAR_SXX];
     164        dSy->data.F32[dSy->n] = source->modelPSF->dparams->data.F32[PM_PAR_SYY];
     165        Sx->n ++;
     166        Sy->n ++;
     167        dSN->n ++;
     168        dSx->n ++;
     169        dSy->n ++;
     170    }
     171    psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV);
     172
     173    psVectorStats (stats, dSx, NULL, NULL, 0);
     174    float dSxo = stats->sampleMean;
     175    psLogMsg ("psphot.choosePSF", 3, "dSx: mean: %f, median: %f, stdev: %f, npts: %ld", stats->sampleMean, stats->sampleMedian, stats->sampleStdev, dSx->n);
     176
     177    psVectorStats (stats, dSy, NULL, NULL, 0);
     178    float dSyo = stats->sampleMean;
     179    psLogMsg ("psphot.choosePSF", 3, "dSy: mean: %f, median: %f, stdev: %f, npts: %ld", stats->sampleMean, stats->sampleMedian, stats->sampleStdev, dSy->n);
     180
     181    for (int i = 0; i < dSN->n; i++) {
     182        dSx->data.F32[i] = (dSx->data.F32[i] - dSxo) / PS_MAX (PSF_MIN_DS, Sx->data.F32[i]*dSN->data.F32[i]);
     183        dSy->data.F32[i] = (dSy->data.F32[i] - dSyo) / PS_MAX (PSF_MIN_DS, Sy->data.F32[i]*dSN->data.F32[i]);
     184    }
     185
     186    psVectorStats (stats, dSx, NULL, NULL, 0);
     187    float nSx = stats->sampleStdev;
     188    psLogMsg ("psphot.choosePSF", 3, "dSx: mean: %f, median: %f, stdev: %f, npts: %ld", stats->sampleMean, stats->sampleMedian, stats->sampleStdev, dSx->n);
     189    psVectorStats (stats, dSy, NULL, NULL, 0);
     190    float nSy = stats->sampleStdev;
     191    psLogMsg ("psphot.choosePSF", 3, "dSy: mean: %f, median: %f, stdev: %f, npts: %ld", stats->sampleMean, stats->sampleMedian, stats->sampleStdev, dSy->n);
     192
     193    psFree (Sx);
     194    psFree (Sy);
     195    psFree (dSx);
     196    psFree (dSy);
     197    psFree (dSN);
     198    psFree (stats);
     199
     200    psMetadataAddF32 (recipe, PS_LIST_TAIL, "DSX_MEAN", PS_META_REPLACE, "mean offset of dSXX", dSxo);
     201    psMetadataAddF32 (recipe, PS_LIST_TAIL, "DSY_MEAN", PS_META_REPLACE, "mean offset of dSYY", dSyo);
     202    psMetadataAddF32 (recipe, PS_LIST_TAIL, "DSX_STDV", PS_META_REPLACE, "stdev of mean-corrected dSXX", nSx);
     203    psMetadataAddF32 (recipe, PS_LIST_TAIL, "DSY_STDV", PS_META_REPLACE, "stdev of mean-corrected dSYY", nSy);
     204
     205    // unset the PSFSTAR flag for stars not used for PSF model
     206    for (int i = 0; i < try->sources->n; i++) {
     207        pmSource *source = try->sources->data[i];
     208        if (try->mask->data.U8[i]) {
     209            source->mode &= ~PM_SOURCE_MODE_PSFSTAR;
     210        }
     211    }
     212
    134213    // XXX test dump of psf star data and psf-subtracted image
    135214    if (psTraceGetLevel("psphot.psfstars") > 5) {
     
    159238    }
    160239
    161     // unset the PSFSTAR flag for stars not used for PSF model
    162     for (int i = 0; i < try->sources->n; i++) {
    163         pmSource *source = try->sources->data[i];
    164         if (try->mask->data.U8[i] & PSFTRY_MASK_EXT_FAIL) {
    165             source->mode &= ~PM_SOURCE_MODE_PSFSTAR;
    166         }
    167     }
    168 
    169240    // save only the best model;
    170241    // XXX we are not saving the fitted sources
Note: See TracChangeset for help on using the changeset viewer.