IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 15023


Ignore:
Timestamp:
Sep 25, 2007, 1:53:33 PM (19 years ago)
Author:
eugene
Message:

adding test for field coverage of psf candidates

Location:
trunk/psphot/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot/src/Makefile.am

    r14963 r15023  
    6969        psphotDiagnosticPlots.c  \
    7070        psphotMakeFluxScale.c    \
     71        psphotCheckStarDistribution.c \
    7172        psphotAddNoise.c
    7273
  • trunk/psphot/src/psphot.h

    r15000 r15023  
    170170bool psphotMakeFluxScale (psImage *image, psMetadata *recipe, pmPSF *psf);
    171171
     172bool psphotCheckStarDistribution (psArray *sources, psArray *stars, pmPSFOptions *options);
     173int psphotSupplementStars (psArray *stars, psArray *sources, psImageBinning *binning, int ix, int iy);
     174
    172175#endif
  • trunk/psphot/src/psphotCheckStarDistribution.c

    r15017 r15023  
    33// examine the x,y distribution of the psfstars and extend the selection if needed
    44// desired region and coverage are specified by pmPSFOptions
    5 bool psphotCheckStarDistribution (psArray *sources, pmPSFOptions *options) {
     5// even if stars->n is at the limit, we will add more sources to fill out the area
     6
     7bool psphotCheckStarDistribution (psArray *stars, psArray *sources, pmPSFOptions *options) {
    68
    79    // count the number of PSFSTAR sources in each cell.  for polynomial representations, we
     
    1618    // set up and image and an image binning structure to cover the field
    1719    psImage *nCell = psImageAlloc (Nx, Ny, PS_TYPE_S32);
    18     psImageInit (nCell);
     20    psImageInit (nCell, 0);
    1921
    2022    psImageBinning *binning = psImageBinningAlloc();
     
    2729    psImageBinningSetSkipByOffset (binning, options->psfFieldXo, options->psfFieldYo);
    2830
    29     for (int i = 0; i < sources->n; i++) {
     31    // where are the PSF stars located?
     32    for (int i = 0; i < stars->n; i++) {
    3033       
    31         pmSource *source = sources->data[i];
    32         if (source->modelEXT == NULL) continue;
     34        pmSource *source = stars->data[i];
     35        if (source->peak == NULL) continue;
    3336        if (!(source->mode & PM_SOURCE_MODE_PSFSTAR)) continue;
    3437
    35         int binX = psImageBinningGetRuffX (binning, source->modelEXT->params->data.F32[PM_PAR_XPOS]);
    36         int binY = psImageBinningGetRuffX (binning, source->modelEXT->params->data.F32[PM_PAR_YPOS]);
     38        int binX = psImageBinningGetRuffX (binning, source->peak->xf);
     39        int binY = psImageBinningGetRuffX (binning, source->peak->yf);
    3740
    3841        assert (binX >= 0);
     
    4548       
    4649    // do any cells have too few PSFSTAR sources?
     50    // we use 3 as a minimum (slightly arbitrary...)
    4751    for (int iy = 0; iy < nCell->numRows; iy++) {
    4852        for (int ix = 0; ix < nCell->numCols; ix++) {
    49             if (nCell->data.S32[binY][binX] < NNN) {
     53            if (nCell->data.S32[iy][ix] < 3) {
     54                int nNew = psphotSupplementStars (stars, sources, binning, ix, iy);
     55                if (nNew) {
     56                    psLogMsg ("pmObjects", 3, "added %d fainter PSF candidates to %d,%d\n", nNew, ix, iy);
     57                } else {
     58                    psLogMsg ("pmObjects", 3, "tried to add to %d,%d, but no more sources are available\n", ix, iy);               
     59                }
    5060            }
    5161        }
    5262    }
    5363
     64    psFree (nCell);
     65    psFree (binning);
     66    return true;
    5467}
    5568
    5669// select more possible PSF stars in the specified cell
    5770// sources should be sorted by SN before calling this function
    58 bool psphotSupplementStars (psArray *sources, psImageBinning *binning, int ix, int iy) {
     71int psphotSupplementStars (psArray *stars, psArray *sources, psImageBinning *binning, int ix, int iy) {
    5972
    6073    int nNew = 0;
     
    6679    float Ye = psImageBinningGetFineY (binning, iy + 1);
    6780
    68     //
    6981    for (int i = 0; i < sources->n; i++) {
    70        
     82
     83        // add sources which are marked as stars, in S/N order until...
    7184        pmSource *source = sources->data[i];
    72         if (source->modelEXT == NULL) continue;
    73         if (!(source->mode & PM_SOURCE_MODE_PSFSTAR)) continue;
     85        if (source->peak == NULL) continue;
     86        if (source->moments == NULL) continue;
     87        if (source->mode & PM_SOURCE_MODE_PSFSTAR) continue;
     88        if (source->type != PM_SOURCE_TYPE_STAR) continue;
    7489
    75         float x = source->modelEXT->params->data.F32[PM_PAR_XPOS];
    76         float y = source->modelEXT->params->data.F32[PM_PAR_YPOS];
     90        float x = source->peak->xf;
     91        float y = source->peak->yf;
    7792
     93        if (x < Xs) continue;
     94        if (y < Ys) continue;
     95        if (x > Xe) continue;
     96        if (y > Ye) continue;
     97
     98        source->mode |= PM_SOURCE_MODE_PSFSTAR;
     99        psArrayAdd (stars, 200, source);
     100
     101        nNew ++;
     102    }
     103    return nNew;
    78104}
  • trunk/psphot/src/psphotChoosePSF.c

    r15017 r15023  
    6262
    6363    pmSourceFitModelInit (15, 0.01, PS_SQR(SKY_SIG), options->poissonErrorsPhotLMM);
    64 
    65     // check that the identified psf stars sufficiently cover the region; if not, extend the
    66     // limits somewhat
    67     // psphotCheckStarDistribution (sources, options);
    6864
    6965    psArray *stars = psArrayAllocEmpty (sources->n);
     
    8177        }
    8278    }
     79    // check that the identified psf stars sufficiently cover the region; if not, extend the
     80    // limits somewhat
     81    psphotCheckStarDistribution (stars, sources, options);
     82
    8383    psLogMsg ("psphot.pspsf", PS_LOG_DETAIL, "selected candidate %ld PSF objects\n", stars->n);
    84 
    85     if (stars->n == 0) {
    86         psLogMsg ("psphot.choosePSF", PS_LOG_WARN, "Failed to find any PSF candidates");
    87         psFree (stars);
    88         return NULL;
    89     }
    9084
    9185    // get the list pointers for the PSF_MODEL entries
     
    10094        if (item->type != PS_DATA_METADATA_MULTI) psAbort("missing PSF_MODEL selection");
    10195        modelNames = psListToArray (item->data.list);
     96    }
     97
     98    // generate a psf model using the first selection
     99    if (stars->n == 0) {
     100        // XXX optionally give up here
     101        psError(PSPHOT_ERR_PSF, false, "Failed to fit any models when choosing PSF");
     102        psErrorStackPrint (stderr, "Using guess PSF model");
     103        psErrorClear ();
     104       
     105        // unset the PSFSTAR flags (none are used):
     106        for (int i = 0; i < sources->n; i++) {
     107            pmSource *source = sources->data[i];
     108            source->mode &= ~PM_SOURCE_MODE_PSFSTAR;
     109        }
     110
     111        // XXX set sxx, etc from FWHM in recipe
     112        pmPSF *psf = pmPSFBuildSimple (modelNames->data[0], 1.0, 1.0, 0.0, 1.0);
     113        psf->fieldNx = readout->image->numCols;
     114        psf->fieldNy = readout->image->numRows;
     115        psFree (modelNames);
     116
     117        bool status = true;
     118        status &= psphotMakeFluxScale (readout->image, recipe, psf);
     119        status &= psphotPSFstats (readout, recipe, psf);
     120        if (!status) {
     121            psError(PSPHOT_ERR_PSF, false, "Failed to fit any models when choosing PSF");
     122            psFree (psf);
     123            return NULL;
     124        }
     125
     126        // XXX set DSX_MEAN, etc?
     127        return psf;
    102128    }
    103129
Note: See TracChangeset for help on using the changeset viewer.