IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 1, 2005, 9:55:16 AM (21 years ago)
Author:
eugene
Message:

adding ensemble photometry

File:
1 edited

Legend:

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

    r5653 r5654  
    11# include "psphot.h"
    22
    3 psSparse *psphotStarOverlaps (psArray *sources) {
     3bool psphotEnsemblePSF (eamReadout *imdata, psMetadata *config, psArray *sources, pmPSF *psf, psStats *sky) {
    44
    5     pmModelFunc modelFunc = pmModelFunc_GetFunction (model->type);
    6     psVector *x = psVectorAlloc(2, PS_TYPE_F32);
    7     psVector *params = model->params;
     5    bool  status;
     6    float x;
     7    float y;
     8    float Sky;
     9    int   Nfit = 0;
    810
    9     // source analysis is done in S/N order (brightest first)
     11    psTimerStart ("psphot");
     12
     13    // source analysis is done in spatial order
    1014    sources = psArraySort (sources, psphotSortByY);
    1115
    12     // fill out the models for each object
    13     // XXX need to assign the model parameters using the PSF function, with unit peak
     16    float OUTER_RADIUS     = psMetadataLookupF32 (&status, config, "SKY_OUTER_RADIUS");
     17    float PSF_FIT_NSIGMA   = psMetadataLookupF32 (&status, config, "PSF_FIT_NSIGMA");
     18    float PSF_FIT_PADDING  = psMetadataLookupF32 (&status, config, "PSF_FIT_PADDING");
     19
     20    // set the object surface-brightness limit for fitted pixels
     21    float FLUX_LIMIT  = PSF_FIT_NSIGMA * sky->sampleStdev;
     22    psLogMsg ("psphot.apply_psf_model", 4, "fitting pixels with at least %f object counts\n", FLUX_LIMIT);
     23
     24    // vector for model input coordinates
     25    psVector *x = psVectorAlloc(2, PS_TYPE_F32);
     26
     27    // this function specifies the radius at this the model hits the given flux
     28    pmModelRadius modelRadius = pmModelRadius_GetFunction (psf->type);
     29
     30    // this is the function to get the model function
     31    pmModelFunc modelFunc = pmModelFunc_GetFunction (model->type);
     32
     33    // pre-calculate all model pixels
    1434    psArray  *pixlist = psArrayAlloc (sources->n);
    1535    for (int k = 0; k < sources->n; k++) {
    16         src = sources->data[k];
     36        source = sources->data[k];
     37
     38        // use the source moments, etc to guess basic model parameters
     39        pmModel *modelFLT = pmSourceModelGuess (source, psf->type);
     40
     41        // set PSF parameters for this model
     42        pmModel *model = pmModelFromPSF (modelFLT, psf);
     43        // model->params->data.F32[2] = source->peak->x;
     44        // model->params->data.F32[3] = source->peak->y;
     45        model->params->data.F32[1] = 1.0;
     46        x = model->params->data.F32[2];
     47        y = model->params->data.F32[3];
     48        psFree (modelFLT);
     49
     50        // set the fit radius based on the object flux limit and the model
     51        // XXX EAM : FLUX_LIMIT should be set based on local sky model (not global median)
     52        model->radius = modelRadius (model->params, FLUX_LIMIT) + PSF_FIT_PADDING;
     53        if (isnan(model->radius)) {
     54          psAbort ("apply_psf_model", "error in radius");
     55        }
     56
     57        // build the model image
    1758        nx = src->pixels->numCols;
    1859        ny = src->pixels->numRows;
    1960        im = psImageAlloc (nx, ny, PS_DATA_F32);
     61        mk = psImageAlloc (nx, ny, PS_DATA_U8);
     62
     63        // fill in the model pixel values
     64        psImageKeepCircle (mk, x, y, model->radius, "OR", PSPHOT_MASK_MARKED);
     65        psVector *params = model->params;
    2066        for (int i = 0; i < nx; i++) {
    2167            for (int j = 0; j < ny; j++) {
     68                if (mk->data.U8[j][i]) continue;
    2269                x->data.F32[0] = (float) i + pix->col0;
    2370                x->data.F32[1] = (float) j + pix->row0;
     
    2875    }
    2976   
    30     psVector *Aij = psVectorAlloc (100, PS_DATA_F32);
    31     psVector *Bfj = psVectorAlloc (100, PS_DATA_F32);
    32     psVector *Si  = psVectorAlloc (100, PS_DATA_S32);
    33     psVector *Sj  = psVectorAlloc (100, PS_DATA_S32);
     77    // fill out the sparse matrix
     78    psSparse *sparse = psSparseAlloc (sources->n, 100);
     79    psVector *Aij = sparse->Aij;
     80    psVector *Bfj = sparse->Bfj;
     81    psVector *Si  = sparse->Si;
     82    psVector *Sj  = sparse->Sj;
    3483
    3584    int Ri, Rj;
     
    4291        // diagonal element (auto-cross-product)
    4392        f = psphotCrossProduct (pi, pi);
    44         Aij->data.F32[Nelem] = f;
    45         Si->data.S32[Nelem] = i;
    46         Sj->data.S32[Nelem] = j;
    47         Nelem ++;
    48 
    49         Qii->data.F32[i] = f;
     93        psSparseMatrixElement (sparse, i, i, f);
    5094
    5195        // find the image x model value
    5296        f = psphotCrossProduct (pi, pf);
    53         Bfj->data.F32[i] = f;
     97        psSparseVectorElement (sparse, i, f);
    5498
    5599        // loop over all other stars following this one
     
    64108            // got an overlap; calculate cross-product and add to output array
    65109            f = psphotCrossProduct (pi, pj);
    66            
    67             Aij->data.F32[Nelem] = f;
    68             Si->data.S32[Nelem] = i;
    69             Sj->data.S32[Nelem] = j;
    70             Nelem ++;
    71 
    72             Aij->data.F32[Nelem] = f;
    73             Si->data.S32[Nelem] = j;
    74             Sj->data.S32[Nelem] = i;
    75             Nelem ++;
     110            psSparseMatrixElement (sparse, j, i, f);
    76111        }
    77112    }
    78 
    79     index = psVectorSortIndex (NULL, Sj);
    80 
    81     psVector *tAij = psVectorAlloc (Nelem, PS_DATA_F32);
    82     psVector *tSi  = psVectorAlloc (Nelem, PS_DATA_S32);
    83     psVector *tSj  = psVectorAlloc (Nelem, PS_DATA_S32);
    84     for (i = 0; i < Nelem; i++) {
    85         j = index->data.U32[i];
    86         tAij->data.F32[i] = Aij->data.F32[j];
    87         tSi->data.S32[i]  = Si->data.S32[j];
    88         tSj->data.S32[i]  = Sj->data.S32[j];
    89     }
    90     psFree (Aij);
    91     psFree (Si);
    92     psFree (Sj);
    93 
    94     sparse->Aij = Aij;
    95     sparse->Bfj = Bfj;
    96     sparse->Qii = Qii;
    97     sparse->Si = Si;
    98     sparse->Sj = Sj;
    99     sparse->Nelem = Nelem;
    100     sparse->Nrows = sources->n;
    101 
     113   
     114    psSparseResort (sparse);
    102115    return (match);
    103116}
Note: See TracChangeset for help on using the changeset viewer.