IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 5704


Ignore:
Timestamp:
Dec 6, 2005, 7:57:54 AM (21 years ago)
Author:
eugene
Message:

adding basic deblending

Location:
trunk/psphot/src
Files:
2 edited

Legend:

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

    r5672 r5704  
    66{
    77
    8     // sources must be sorted by Y
    9     // index must be sorted by SN
     8    // source analysis is done in S/N order (brightest first)
     9    sources = psArraySort (sources, psphotSortByY);
    1010
    11     // search for sources which fall within current box
     11    psVector *SN = psVectorAlloc (sources->n, PS_DATA_F32);
     12    for (int i = 0; i < SN->n; i++) {
     13      source = sources->data[i];
     14      SN->data.F32[i] = source->moments->SN;
     15    }
     16    psVector *index = psVectorSortIndex (NULL, SN);
     17   
     18    psArray *overlap = psArrayAlloc (100);
    1219
    13     // generate source contour (1/4 peak counts)
    14    
    15     // find sources from overlap which fall in contour
    16     // mark source
     20    for (int i = 0; i < sources->n; i++) {
     21      N = index->data.U32[i];
     22      source = sources->data[N];
     23      overlap->n = 0;
    1724
    18     // select the candidate PSF stars (pointers to original sources)
    19     for (int i = 0; (i < sources->n) && (stars->n < NSTARS); i++) {
    20         pmSource *source = sources->data[i];
    21         if (source->type != PM_SOURCE_PSFSTAR) continue;
    22         psArrayAdd (stars, 200, source);
    23     }
    24     psTrace (".psphot.pspsf", 3, "selected candidate %d PSF objects\n", stars->n);
     25      // search backwards for overlapping sources
     26      for (int j = N - 1; j >= 0; j--) {
     27        testSource = sources->data[j];
     28        if (testSource->moments->x < source->pixels->col0) continue;
     29        if (testSource->moments->x >= source->pixels->col0 + source->pixels->numCols) continue;
     30        if (testSource->moments->y < source->pixels->row0) break;
     31        if (testSource->moments->y >= source->pixels->row0 + source->pixels->numRows) {
     32          fprintf (stderr, "warning: invalid condition\n");
     33          continue;
     34        }
     35        psArrayAdd (overlap, 100, testSource);
     36      }
    2537
    26     // get the fixed PSF fit radius
    27     // XXX EAM : check that PSF_FIT_RADIUS < SKY_OUTER_RADIUS
    28     float RADIUS = psMetadataLookupF32 (&status, config, "PSF_FIT_RADIUS");
     38      // search forwards for overlapping sources
     39      for (int j = N + 1; j < sources->n; j++) {
     40        testSource = sources->data[j];
     41        if (testSource->moments->x < source->pixels->col0) continue;
     42        if (testSource->moments->x >= source->pixels->col0 + source->pixels->numCols) continue;
     43        if (testSource->moments->y < source->pixels->row0) {
     44          fprintf (stderr, "warning: invalid condition\n");
     45          continue;
     46        }
     47        if (testSource->moments->y >= source->pixels->row0 + source->pixels->numRows) break;
     48        psArrayAdd (overlap, 100, testSource);
     49      }
    2950
    30     // get the list pointers for the PSF_MODEL entries
    31     psMetadataItem *mdi = psMetadataLookup (config, "PSF_MODEL");
    32     if (mdi == NULL) psAbort ("psphotChoosePSF", "missing PSF_MODEL selection");
     51      // generate source contour (1/4 peak counts)
     52      if (overlap->n > 0) {
     53        // XXX EAM : make the 1/4 user-defined.
     54        threshold = 0.25 * (source->moments->Peak - source->moments->Sky) + source->moments->Sky);
     55        psArray *contour = pmSourceContour_EAM (source->pixels, source->moments->x, source->moments->x, threshold);
    3356
    34     psList *list = (psList *) mdi->data.list;
    35     psListIterator *iter = psListIteratorAlloc (list, PS_LIST_HEAD, FALSE);
    36 
    37     // set up an array to store the results
    38     psArray *models = psArrayAlloc (list->n);
    39 
    40     // try each model option listed in config
    41     for (int i = 0; i < models->n; i++) {
    42 
    43         item = psListGetAndIncrement (iter);
    44         modelName = item->data.V;
    45 
    46         models->data[i] = pmPSFtryModel (stars, modelName, RADIUS);
    47         psFree (modelName);
    48         psFree (item);
    49     }
    50     psFree (iter);
    51     // psFree (list); XXX EAM - is list freed with iter?
    52     psFree (stars);
    53 
    54     // select the best of the models
    55     // here we are using the clippedStdev on the metric as the indicator
    56     try = models->data[0];
    57     int bestN = 0;
    58     float bestM = try->psf->dApResid;
    59     for (int i = 1; i < models->n; i++) {
    60         try = models->data[i];
    61         float M = try->psf->dApResid;
    62         if (M < bestM) {
    63             bestM = M;
    64             bestN = i;
    65         }
     57        // XXX EAM : the order is wrong: need to check j, j+1 contour points
     58        psVector *xv = contour->data[0];
     59        psVector *yv = contour->data[1];
     60        for (int j = 0; j < xv->n; j++) {
     61          for (int k = 0; k < overlap->n; k++) {
     62            testSource = overlap->data[k];
     63            if (fabs(yv->data.F32[j] - testSource->moments->y) > 0.5) continue;
     64            if (xv->data.F32[j] > testSource->moments->x) continue;
     65            if (xv->data.F32[j] < testSource->moments->x) continue;
     66            // XXX EAM : mark source with flag (blended)
     67          }
     68        } 
    6669    }
    6770
    68     // keep only the selected model:
    69     try = models->data[bestN];
    70     pmPSF *psf = psMemCopy(try->psf);
    71     psFree (models);                             // keep only the pmPSF resulting from this analysis
    72 
    73     modelName = pmModelGetType (psf->type);
    7471    psLogMsg ("psphot.pspsf", 3, "selected psf model %s, ApResid: %f +/- %f\n", modelName, psf->ApResid, psf->dApResid);
    7572
  • trunk/psphot/src/psphotEnsemblePSF.c

    r5672 r5704  
    9696            pmSource *Mj = models->data[j];
    9797
     98            // XXX double check that this is working!  should not break here
     99            check me here;
    98100            if (Mi->pixels->col0 + Mi->pixels->numCols < Mj->pixels->col0) break;
    99101            if (Mj->pixels->col0 + Mj->pixels->numCols < Mi->pixels->col0) continue;
Note: See TracChangeset for help on using the changeset viewer.