IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 23, 2006, 6:16:11 PM (20 years ago)
Author:
eugene
Message:

fixed some errors with double sources, added second-pass linear PSF fit, multiple-depths

File:
1 edited

Legend:

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

    r6427 r6481  
    126126    psTrace ("psphot.blend", 5, "blob as DBL: %f %f\n", ONE->params->data.F32[2], ONE->params->data.F32[3]);
    127127
    128     source->modelPSF = (pmModel *) DBL->data[0];
    129     source->mode |=  PM_SOURCE_SUBTRACTED;
    130     source->mode &= ~PM_SOURCE_TEMPSUB;
    131 
     128    // drop old model, save new second model...
     129    psFree (source->modelPSF);
     130    source->modelPSF = psMemCopy (DBL->data[0]);
     131    source->mode    |= PM_SOURCE_SUBTRACTED;
     132    source->mode    |= PM_SOURCE_PAIR;
     133    source->mode    &= ~PM_SOURCE_TEMPSUB;
     134
     135    // copy most data from the primary source (modelEXT, blends stay NULL)
     136    pmSource *newSrc = pmSourceAlloc ();
     137    newSrc->peak     = psMemCopy (source->peak);
     138    newSrc->pixels   = psMemCopy (source->pixels);
     139    newSrc->weight   = psMemCopy (source->weight);
     140    newSrc->mask     = psMemCopy (source->mask);
     141    newSrc->moments  = psMemCopy (source->moments);
     142    newSrc->modelPSF = psMemCopy (DBL->data[1]);
     143    newSrc->type     = source->type;
     144    newSrc->mode     = source->mode;
     145    psArrayAdd (sources, 100, newSrc);
     146    psFree (newSrc);
     147    psFree (DBL);
    132148    return true;
    133149}
     
    154170    // save the PSF model from the Ensemble fit
    155171    PSF = source->modelPSF;
    156     psphotCheckRadiusPSF (readout, source, PSF);
     172    psphotCheckRadiusPSFBlend (readout, source, PSF, 8.0);
    157173
    158174    modelSet = psArrayAlloc (2);
     
    160176    DBL = pmModelCopy (PSF);
    161177    DBL->params->data.F32[1] *= 0.5;
    162     DBL->params->data.F32[2] += dx;
    163     DBL->params->data.F32[3] += dy;
     178    DBL->params->data.F32[2] = source->moments->x + dx;
     179    DBL->params->data.F32[3] = source->moments->y + dy;
    164180    modelSet->data[0] = DBL;
    165181
    166182    DBL = pmModelCopy (PSF);
    167183    DBL->params->data.F32[1] *= 0.5;
    168     DBL->params->data.F32[2] -= dx;
    169     DBL->params->data.F32[3] -= dy;
     184    DBL->params->data.F32[2] = source->moments->x - dx;
     185    DBL->params->data.F32[3] = source->moments->y - dy;
    170186    modelSet->data[1] = DBL;
    171187
    172     x = PSF->params->data.F32[2];
    173     y = PSF->params->data.F32[3];
     188    x = source->moments->x;
     189    y = source->moments->y;
    174190
    175191    // fit EXT (not PSF) model (set/unset the pixel mask)
     
    214230    // save the PSF model from the Ensemble fit
    215231    pmModel *PSF = pmModelCopy (source->modelPSF);
    216 
    217     // extend source radius as needed
    218     psphotCheckRadiusPSF (readout, source, PSF);
    219232
    220233    x = PSF->params->data.F32[2];
     
    229242    psArrayAdd (sourceSet, 16, source);
    230243
    231     // counter to track the blend elements used in the fit
    232     psVector *index  = psVectorAlloc (source->blends->n + 1, PS_TYPE_S32);
    233     index->data.S32[0] = -1; // first element corresponds to the primary source
    234 
     244    // we need to include all blends in the fit (unless primary is saturated?)
     245    dR = 0;
    235246    for (int i = 0; i < source->blends->n; i++) {
    236247        pmSource *blend = source->blends->data[i];
    237248
    238         // is this object close enough to include in the fit
    239         // XXX this test is bogus: need to think about this
    240         dR = hypot (blend->peak->x - x, blend->peak->y - y);
    241         if (dR > PSF->radius - 3) continue;
     249        // find the blend which is furthest from source
     250        dR = PS_MAX (dR, hypot (blend->peak->x - x, blend->peak->y - y));
    242251
    243252        // create the model and guess parameters for this blend
     
    256265
    257266        // add this blend to the list
    258         index->data.S32[modelSet->n] = i;
    259267        psArrayAdd (modelSet, 16, model);
    260268        psArrayAdd (sourceSet, 16, blend);
    261269    }
     270
     271    // extend source radius as needed
     272    psphotCheckRadiusPSFBlend (readout, source, PSF, dR);
    262273
    263274    // fit PSF model (set/unset the pixel mask)
     
    273284        // if we skip this one, free the corresponding blend entry model
    274285        if (!psphotEvalPSF (src, model)) {
    275             int n = index->data.S32[i];
    276             pmSource *blend = source->blends->data[n];
     286            pmSource *blend = source->blends->data[i - 1];
    277287            psFree (blend->modelPSF);
    278288            blend->modelPSF = NULL;
     
    285295        src->mode &= ~PM_SOURCE_TEMPSUB;
    286296    }
    287     psFree (index);
    288297    psFree (modelSet);
    289298    psFree (sourceSet);
Note: See TracChangeset for help on using the changeset viewer.