IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 20, 2012, 12:22:52 PM (14 years ago)
Author:
eugene
Message:

merge changes from trunk

Location:
branches/eam_branches/ipp-20120601
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20120601

  • branches/eam_branches/ipp-20120601/psphot

  • branches/eam_branches/ipp-20120601/psphot/src

  • branches/eam_branches/ipp-20120601/psphot/src/psphotFitSourcesLinear.c

    r33963 r34049  
    1212static bool SetBorderMatrixElements (psSparseBorder *border, pmReadout *readout, psArray *sources, bool constant_weights, int SKY_FIT_ORDER, psImageMaskType markVal);
    1313
     14# if (HAVE_MODEL_VAR)
    1415bool psphotGenerateModelVariance (pmConfig *config, const pmFPAview *view, pmFPAfile *file, int index, psMetadata *recipe, pmReadout *readout, psArray *sources);
    1516pmSourceFitVarMode psphotGetFitVarMode (psMetadata *recipe);
    1617bool psphotFreeModelVariance (pmReadout *readout, psArray *sources);
     18# endif
    1719
    1820// for now, let's store the detections on the readout->analysis for each readout
     
    2830    assert (recipe);
    2931
     32# if (HAVE_MODEL_VAR)
    3033    pmSourceFitVarMode fitVarMode = psphotGetFitVarMode (recipe);
    3134    if (!fitVarMode) {
     
    3740    // do a single pass.
    3841    pmSourceFitVarMode fitVarModePass1 = (fitVarMode == PM_SOURCE_PHOTFIT_MODEL_VAR) ? PM_SOURCE_PHOTFIT_CONST : fitVarMode;
     42# endif
    3943
    4044    int num = psphotFileruleCount(config, filerule);
     
    6468        psAssert (psf, "missing psf?");
    6569
    66         if (!psphotFitSourcesLinearReadout (recipe, readout, sources, psf, final, fitVarModePass1)) {
     70# if (HAVE_MODEL_VAR)
     71        if (!psphotFitSourcesLinearReadout (recipe, readout, sources, psf, final, fitVarModePass1))
     72# else
     73        if (!psphotFitSourcesLinearReadout (recipe, readout, sources, psf, final))
     74# endif
     75        {
    6776            psError (PSPHOT_ERR_CONFIG, false, "failed to fit sources (linear) for %s entry %d", filerule, i);
    6877            return false;
    6978        }
    7079
     80# if (HAVE_MODEL_VAR)
    7181        // the MODEL_VAR weighting scheme requires knowledge of the model fluxes to generate the variance
    7282        // after we have determined the initial set of fits, then we can generate the variance image and
     
    94104            }
    95105        }
     106# endif
    96107
    97108        psphotVisualShowResidualImage (readout, (num > 0));
     
    102113}
    103114
     115# if (HAVE_MODEL_VAR)
    104116// look up the fit variance mode from the recipe; older recipes do not have the value
    105117// 'LINEAR_FIT_VARIANCE_MODE'; in those cases, look for 'CONSTANT_PHOTOMETRIC_WEIGHTS' as a boolean and
     
    130142    return PM_SOURCE_PHOTFIT_NONE;
    131143}
    132 
    133 bool psphotFitSourcesLinearReadout (psMetadata *recipe, pmReadout *readout, psArray *sources, pmPSF *psf, bool final, pmSourceFitVarMode fitVarMode) {
    134 
     144# endif
     145
     146# if (HAVE_MODEL_VAR)
     147bool psphotFitSourcesLinearReadout (psMetadata *recipe, pmReadout *readout, psArray *sources, pmPSF *psf, bool final, pmSourceFitVarMode fitVarMode)
     148# else
     149bool psphotFitSourcesLinearReadout (psMetadata *recipe, pmReadout *readout, psArray *sources, pmPSF *psf, bool final)
     150# endif
     151{
    135152    bool status;
    136153    float x;
     
    168185    if (psRegionIsNaN (AnalysisRegion)) psAbort("analysis region mis-defined");
    169186
     187# if (!HAVE_MODEL_VAR)
     188    bool CONSTANT_PHOTOMETRIC_WEIGHTS =
     189        psMetadataLookupBool(&status, recipe, "CONSTANT_PHOTOMETRIC_WEIGHTS");
     190    if (!status) {
     191        psAbort("You must provide a value for the BOOL recipe CONSTANT_PHOTOMETRIC_WEIGHTS");
     192    }
     193# endif
    170194    int SKY_FIT_ORDER = psMetadataLookupS32(&status, recipe, "SKY_FIT_ORDER");
    171195    if (!status) {
     
    295319    psSparseBorder *border = psSparseBorderAlloc (sparse, nBorder);
    296320
     321# if (HAVE_MODEL_VAR)
    297322    // if fitVarMode is MODEL_VAR, then we need to generate the model image variance
    298323    // XXX we have two possibilities here:
     
    302327
    303328    // 2) do a single pass, and use the model guess to define the model variance (but do I trust the Model Guess?)
     329# endif
    304330
    305331    // fill out the sparse matrix elements and border elements (B)
     
    310336
    311337        // diagonal elements of the sparse matrix (auto-cross-product)
     338# if (HAVE_MODEL_VAR)
    312339        f = pmSourceModelDotModel (SRCi, SRCi, fitVarMode, covarFactor, maskVal);
     340# else
     341        f = pmSourceModelDotModel (SRCi, SRCi, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor, maskVal);
     342# endif
    313343        psSparseMatrixElement (sparse, i, i, f);
    314344
     345# if (HAVE_MODEL_VAR)
    315346        // if we have used CONSTANT errors, then we need to calculate the value of the parameter error
    316347        if (fitVarMode != PM_SOURCE_PHOTFIT_IMAGE_VAR) {
     
    320351            errors->data.F32[i] = 1.0 / sqrt(f);
    321352        }
    322 
     353# else
     354        // the formal error depends on the weighting scheme
     355        if (CONSTANT_PHOTOMETRIC_WEIGHTS) {
     356            float var = pmSourceModelDotModel (SRCi, SRCi, false, covarFactor, maskVal);
     357            errors->data.F32[i] = 1.0 / sqrt(var);
     358        } else {
     359            errors->data.F32[i] = 1.0 / sqrt(f);
     360        }
     361# endif
    323362
    324363        // find the image x model value
     364# if (HAVE_MODEL_VAR)
    325365        f = pmSourceDataDotModel (SRCi, SRCi, fitVarMode, covarFactor, maskVal);
     366# else
     367        f = pmSourceDataDotModel (SRCi, SRCi, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor, maskVal);
     368# endif
    326369        psSparseVectorElement (sparse, i, f);
    327370
     
    329372        switch (SKY_FIT_ORDER) {
    330373          case 1:
     374# if (HAVE_MODEL_VAR)
    331375            f = pmSourceModelWeight (SRCi, 1, fitVarMode, covarFactor, maskVal);
    332376            psSparseBorderElementB (border, i, 1, f);
    333377            f = pmSourceModelWeight (SRCi, 2, fitVarMode, covarFactor, maskVal);
    334378            psSparseBorderElementB (border, i, 2, f);
     379# else
     380            f = pmSourceModelWeight (SRCi, 1, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor, maskVal);
     381            psSparseBorderElementB (border, i, 1, f);
     382            f = pmSourceModelWeight (SRCi, 2, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor, maskVal);
     383            psSparseBorderElementB (border, i, 2, f);
     384# endif
    335385
    336386          case 0:
     387# if (HAVE_MODEL_VAR)
    337388            f = pmSourceModelWeight (SRCi, 0, fitVarMode, covarFactor, maskVal);
     389# else
     390            f = pmSourceModelWeight (SRCi, 0, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor, maskVal);
     391# endif
    338392            psSparseBorderElementB (border, i, 0, f);
    339393            break;
     
    355409
    356410            // got an overlap; calculate cross-product and add to output array
     411# if (HAVE_MODEL_VAR)
    357412            f = pmSourceModelDotModel (SRCi, SRCj, fitVarMode, covarFactor, maskVal);
     413# else
     414            f = pmSourceModelDotModel (SRCi, SRCj, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor, maskVal);
     415# endif
    358416            psSparseMatrixElement (sparse, j, i, f);
    359417        }
     
    393451
    394452    // set the sky, sky_x, sky_y components of border matrix
     453# if (HAVE_MODEL_VAR)
    395454    SetBorderMatrixElements (border, readout, fitSources, (fitVarMode == PM_SOURCE_PHOTFIT_CONST), SKY_FIT_ORDER, markVal);
     455# else
     456    SetBorderMatrixElements (border, readout, fitSources, CONSTANT_PHOTOMETRIC_WEIGHTS, SKY_FIT_ORDER, markVal);
     457# endif
    396458
    397459    psSparseConstraint constraint;
     
    552614}
    553615
     616# if (HAVE_MODEL_VAR)
    554617bool psphotModelBackgroundReadout(psImage *model,  // Model image
    555618                                  psImage *modelStdev, // Model stdev image
     
    661724    return true;
    662725}
     726# endif
Note: See TracChangeset for help on using the changeset viewer.