IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 10171


Ignore:
Timestamp:
Nov 22, 2006, 7:28:54 PM (19 years ago)
Author:
eugene
Message:

added code to fit global sky (and slopes), with config options

File:
1 edited

Legend:

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

    r10104 r10171  
    1010// the analysis is performed wrt the simulated pixel values
    1111
    12 static bool SetBorderT (psSparseBorder *border, pmReadout *readout, psArray *refSources, psArray *fitSources, psVector *index, bool fitSlope, bool constant_weights);
     12static bool SetBorderT (psSparseBorder *border, pmReadout *readout, psArray *refSources, psArray *fitSources, psVector *index, bool constant_weights, int SKY_FIT_ORDER);
    1313
    1414bool psphotEnsemblePSF (pmReadout *readout, psArray *refSources, psMetadata *recipe, pmPSF *psf, bool final) {
     
    1919    float y;
    2020    float f;
    21     float r;
     21    // float r;
    2222
    2323    psTimerStart ("psphot");
     
    3636    if (psRegionIsNaN (AnalysisRegion)) psAbort ("psphot", "analysis region mis-defined");
    3737
    38     const bool CONSTANT_PHOTOMETRIC_WEIGHTS =
     38    bool CONSTANT_PHOTOMETRIC_WEIGHTS =
    3939        psMetadataLookupBool(&status, recipe, "CONSTANT_PHOTOMETRIC_WEIGHTS");
    4040    if (!status) {
    4141        psAbort(PS_FILE_LINE, "You must provide a value for the BOOL recipe CONSTANT_PHOTOMETRIC_WEIGHTS");
     42    }
     43    int SKY_FIT_ORDER = psMetadataLookupS32(&status, recipe, "SKY_FIT_ORDER");
     44    if (!status) {
     45        SKY_FIT_ORDER = 0;
     46    }
     47    bool SKY_FIT_LINEAR = psMetadataLookupBool(&status, recipe, "SKY_FIT_LINEAR");
     48    if (!status) {
     49        SKY_FIT_LINEAR = false;
    4250    }
    4351
     
    100108
    101109    // vectors to store stats for each object
    102     psVector *weight = psVectorAlloc (fitSources->n, PS_TYPE_F32);
     110    // psVector *weight = psVectorAlloc (fitSources->n, PS_TYPE_F32);
    103111    psVector *errors = psVectorAlloc (fitSources->n, PS_TYPE_F32);
    104112
     
    106114    // for just sky: 1 row; for x,y terms: 3 rows
    107115    psSparse *sparse = psSparseAlloc (fitSources->n, 100);
    108     psSparseBorder *border = psSparseBorderAlloc (sparse, 1);
     116    int nBorder = (SKY_FIT_ORDER == 0) ? 1 : 3;
     117    psSparseBorder *border = psSparseBorderAlloc (sparse, nBorder);
    109118
    110119    // fill out the sparse matrix elements and border elements (B)
     
    116125        pmSource *Fi = fitSources->data[i];
    117126
    118         // scale by diagonal element (auto-cross-product)
    119         r = pmSourceCrossProduct (Fi, Fi, CONSTANT_PHOTOMETRIC_WEIGHTS);
    120         weight->data.F32[i] = r;
     127        // diagonal elements of the sparse matrix (auto-cross-product)
     128        f = pmSourceCrossProduct (Fi, Fi, CONSTANT_PHOTOMETRIC_WEIGHTS);
     129        psSparseMatrixElement (sparse, i, i, f);
     130
     131        // XXX being used? weight->data.F32[i] = r;
    121132
    122133        // the formal error depends on the weighting scheme
     
    125136            errors->data.F32[i] = 1.0 / sqrt(var);
    126137        } else {
    127             errors->data.F32[i] = 1.0 / sqrt(r);
     138            errors->data.F32[i] = 1.0 / sqrt(f);
    128139        }
    129140
    130         psSparseMatrixElement (sparse, i, i, 1.0);
    131141
    132142        // find the image x model value
    133143        f = pmSourceCrossProduct (Ri, Fi, CONSTANT_PHOTOMETRIC_WEIGHTS);
    134         psSparseVectorElement (sparse, i, f / r);
     144        psSparseVectorElement (sparse, i, f);
    135145
    136146        // add the per-source weights (border region)
    137         float p = pmSourceWeight (Fi, 0, CONSTANT_PHOTOMETRIC_WEIGHTS);
    138         // float px = pmSourceWeight (Fi, 1, CONSTANT_PHOTOMETRIC_WEIGHTS);
    139         // float py = pmSourceWeight (Fi, 2, CONSTANT_PHOTOMETRIC_WEIGHTS);
    140         psSparseBorderElementB (border, i, 0, p);
    141         // psSparseBorderElementB (border, i, 1, px);
    142         // psSparseBorderElementB (border, i, 2, py);
     147        switch (SKY_FIT_ORDER) {
     148          case 1:
     149            f = pmSourceWeight (Fi, 1, CONSTANT_PHOTOMETRIC_WEIGHTS);
     150            psSparseBorderElementB (border, i, 1, f);
     151            f = pmSourceWeight (Fi, 2, CONSTANT_PHOTOMETRIC_WEIGHTS);
     152            psSparseBorderElementB (border, i, 2, f);
     153
     154          case 0:
     155            f = pmSourceWeight (Fi, 0, CONSTANT_PHOTOMETRIC_WEIGHTS);
     156            psSparseBorderElementB (border, i, 0, f);
     157            break;
     158
     159          default:
     160            psAbort(PS_FILE_LINE, "Invalid SKY_FIT_ORDER %d\n", SKY_FIT_ORDER);
     161            break;
     162        }
    143163
    144164        // loop over all other stars following this one
     
    154174            // got an overlap; calculate cross-product and add to output array
    155175            f = pmSourceCrossProduct (Fi, Fj, CONSTANT_PHOTOMETRIC_WEIGHTS);
    156             psSparseMatrixElement (sparse, j, i, f / r);
     176            psSparseMatrixElement (sparse, j, i, f);
    157177        }
    158178    }
     
    161181
    162182    // set the sky, sky_x, sky_y components of border matrix
    163     // XXX ignore sky slope terms for now
    164     SetBorderT (border, readout, refSources, fitSources, index, false, CONSTANT_PHOTOMETRIC_WEIGHTS);
     183    SetBorderT (border, readout, refSources, fitSources, index, CONSTANT_PHOTOMETRIC_WEIGHTS, SKY_FIT_ORDER);
    165184
    166185    psSparseConstraint constraint;
     
    170189
    171190    // solve for normalization terms (need include local sky?)
    172     # if (1)
    173191    psVector *norm = NULL;
    174192    psVector *skyfit = NULL;
    175     psSparseBorderSolve (&norm, &skyfit, constraint, border, 3);
    176     fprintf (stderr, "skyfit: %f\n", skyfit->data.F32[0]);
    177     # else
    178     psVector *norm = psSparseSolve (NULL, constraint, sparse, 3);
    179     psVector *skyfit = NULL;
    180     # endif
     193    if (SKY_FIT_LINEAR) {
     194        psSparseBorderSolve (&norm, &skyfit, constraint, border, 5);
     195        fprintf (stderr, "skyfit: %f\n", skyfit->data.F32[0]);
     196    } else {
     197        norm = psSparseSolve (NULL, constraint, sparse, 5);
     198        skyfit = NULL;
     199    }
    181200
    182201    // adjust fitSources, set refSources and subtract
     
    220239    psFree (norm);
    221240    psFree (skyfit);
    222     psFree (weight);
    223241    psFree (errors);
    224242    psFree (border);
     
    229247
    230248// calculate the weight terms for the sky fit component of the matrix
    231 static bool SetBorderT (psSparseBorder *border, pmReadout *readout, psArray *refSources, psArray *fitSources, psVector *index, bool fitSlope, bool constant_weights) {
     249static bool SetBorderT (psSparseBorder *border, pmReadout *readout, psArray *refSources, psArray *fitSources, psVector *index, bool constant_weights, int SKY_FIT_ORDER) {
    232250
    233251    // generate the image-wide weight terms
     
    271289            w   += 1/wt;
    272290            fo  += f/wt;
    273 
    274             if (!fitSlope) continue;
     291            if (SKY_FIT_ORDER == 0) continue;
     292
    275293            xc = i + col0;
    276294            yc = j + row0;
     
    291309    psSparseBorderElementG (border, 0, fo);
    292310    psSparseBorderElementT (border, 0, 0, w);
    293     if (fitSlope) {
     311    if (SKY_FIT_ORDER > 0) {
    294312        psSparseBorderElementG (border, 0, fx);
    295313        psSparseBorderElementG (border, 0, fy);
Note: See TracChangeset for help on using the changeset viewer.