IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 16, 2006, 4:45:46 PM (20 years ago)
Author:
eugene
Message:

moved pmSourceChisq to psModules, adding sky correction

File:
1 edited

Legend:

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

    r9834 r10032  
    11# include "psphot.h"
    2 bool pmSourceChisq (pmModel *model, psImage *image, psImage *mask, psImage *weight);
    3 
    4 // 2006.02.07 : no leaks!
     2
    53// fit all reasonable sources with the linear PSF model
    64bool psphotEnsemblePSF (pmReadout *readout, psArray *sources, psMetadata *recipe, pmPSF *psf, bool final) {
     
    2927    psArray  *models = psArrayAllocEmpty (sources->n);
    3028    psVector *index  = psVectorAllocEmpty (sources->n, PS_TYPE_U32);
    31     // DROP models->n = index->n = 0;
    3229
    3330    // option to limit analysis to a specific region
     
    6663        // really saturated stars should be re-measured for a better centroid
    6764        // XXX EAM : move this to a 'clear satstar function'
     65        // XXX : place this in pmSourceMoments or wherever it is called?
    6866        if (inSource->mode &  PM_SOURCE_MODE_SATSTAR) {
    6967            status = pmSourceMoments (inSource, INNER_RADIUS);
     
    109107
    110108        // make temporary copies of the image pixels and mask
     109        // we need to have a copy which will not be modified by changes to its neighbor
    111110        otSource->mask   = psImageCopy (NULL, inSource->mask,   PS_TYPE_U8);
    112111        otSource->pixels = psImageCopy (NULL, inSource->pixels, PS_TYPE_F32);
     
    142141    psVector *weight = psVectorAlloc (models->n, PS_TYPE_F32);
    143142    psVector *errors = psVectorAlloc (models->n, PS_TYPE_F32);
     143
     144    // create the border matrix (includes the sparse matrix)
     145    // for just sky: 1 row; for x,y terms: 3 rows
     146    psSparseBorder *border = psSparseBorderAlloc (sparse, 1);
    144147
    145148    for (int i = 0; i < models->n; i++) {
     
    166169        psSparseVectorElement (sparse, i, f / r);
    167170
     171        // add the per-source weights (border region)
     172        p = pmSourceWeight (Mi, CONST, CONSTANT_PHOTOMETRIC_WEIGHTS);
     173        // px = pmSourceWeight (Mi, XTERM, CONSTANT_PHOTOMETRIC_WEIGHTS);
     174        // py = pmSourceWeight (Mi, YTERM, CONSTANT_PHOTOMETRIC_WEIGHTS);
     175        psSparseBorderElementB (border, i, 0, p);
     176        // psSparseBorderElementB (border, i, 1, px);
     177        // psSparseBorderElementB (border, i, 2, py);
     178
    168179        // loop over all other stars following this one
    169180        for (int j = i + 1; j < models->n; j++) {
     
    183194    psLogMsg ("psphot.emsemble", 4, "built matrix: %f (%d elements)\n", psTimerMark ("psphot"), sparse->Nelem);
    184195
     196    // generate the image-wide weight terms
     197    // first, mask all object pixels
     198    for (int i = 0; i < models->n; i++) {
     199        int N = index->data.U32[i];
     200        pmSource *Fi = sources->data[N];
     201        pmSource *Mi = models->data[i];
     202
     203        // XXX need to select the correct mode (check this against the selections below
     204        // - which model is appropriate for the given source?
     205        // - which radius is appropriate for the given source?
     206        // - where do x,y come from?
     207        psImageKeepCircle (Mi->mask, x, y, model->radiusFit, "OR", PM_MASK_MARK);
     208    }   
     209
     210    // accumulate the image statistics from the masked regions
     211    for (int j = 0; j < numRows; j++) {
     212        for (int i = 0; i < numCols; i++) {
     213            w  +=     image->data.F32[j][i]/weight->data.F32[j][i];
     214            x  +=   i*image->data.F32[j][i]/weight->data.F32[j][i];
     215            y  +=   j*image->data.F32[j][i]/weight->data.F32[j][i];
     216            x2 += i*i*image->data.F32[j][i]/weight->data.F32[j][i];
     217            xy += i*j*image->data.F32[j][i]/weight->data.F32[j][i];
     218            y2 += j*j*image->data.F32[j][i]/weight->data.F32[j][i];
     219        }
     220    }
     221    psSparseBorderElementT (border, 0, 0, w);
     222    if (0) {
     223        psSparseBorderElementT (border, 1, 0, x);
     224        psSparseBorderElementT (border, 2, 0, y);
     225        psSparseBorderElementT (border, 0, 1, x);
     226        psSparseBorderElementT (border, 1, 1, x2);
     227        psSparseBorderElementT (border, 2, 1, xy);
     228        psSparseBorderElementT (border, 0, 2, y);
     229        psSparseBorderElementT (border, 1, 2, xy);
     230        psSparseBorderElementT (border, 2, 2, y2);
     231    }   
     232
    185233    psSparseConstraint constraint;
    186234    constraint.paramMin   = 0.0;
     
    190238    // solve for normalization terms (need include local sky?)
    191239    psSparseResort (sparse);
    192     psVector *norm = psSparseSolve (NULL, constraint, sparse, 3);
     240    psSparseBorderSolve (&xFit, &yFit, constraint, border, 3);
     241
     242    // psVector *norm = psSparseSolve (NULL, constraint, sparse, 3);
    193243
    194244    // adjust models, set sources and subtract
     
    244294    return true;
    245295}
    246 
    247 bool pmSourceChisq (pmModel *model, psImage *image, psImage *mask, psImage *weight) {
    248 
    249     double dC = 0.0;
    250     int Npix = 0;
    251     for (int j = 0; j < image->numRows; j++) {
    252         for (int i = 0; i < image->numCols; i++) {
    253             if (mask->data.U8[j][i]) continue;
    254             if (weight->data.F32[j][i] <= 0) continue;
    255             dC += PS_SQR (image->data.F32[j][i]) / weight->data.F32[j][i];
    256             Npix ++;
    257         }
    258     }
    259     model->nDOF = Npix - 1;
    260     model->chisq = dC;
    261 
    262     return (true);
    263 }
Note: See TracChangeset for help on using the changeset viewer.