IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 33993 for trunk


Ignore:
Timestamp:
Jun 8, 2012, 6:32:36 AM (14 years ago)
Author:
eugene
Message:

ifdef-ed out all modelVar related code from recent updates. turn on or off with pmModel.h HAVE_MODEL_VAR

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/objects/pmModelFuncs.h

    r33963 r33993  
    2929# define PM_MODEL_FUNCS_H
    3030
     31# define HAVE_MODEL_VAR 1
     32
    3133/// @addtogroup Objects Object Detection / Analysis Functions
    3234/// @{
     
    5557    PM_MODEL_OP_NORM     = 0x20,
    5658    PM_MODEL_OP_NOISE    = 0x40,
     59# if (HAVE_MODEL_VAR)
    5760    PM_MODEL_OP_MODELVAR = 0x80,
     61# endif
    5862} pmModelOpMode;
    5963
  • trunk/psModules/src/objects/pmSource.c

    r33963 r33993  
    5151    psFree(tmp->pixels);
    5252    psFree(tmp->variance);
     53# if (HAVE_MODEL_VAR)
    5354    psFree(tmp->modelVar);
     55# endif
    5456    psFree(tmp->maskObj);
    5557    psFree(tmp->maskView);
     
    7880    psFree (source->pixels);
    7981    psFree (source->variance);
     82# if (HAVE_MODEL_VAR)
    8083    psFree (source->modelVar);
     84# endif
    8185    psFree (source->maskObj);
    8286    psFree (source->maskView);
     
    8690    source->pixels = NULL;
    8791    source->variance = NULL;
     92# if (HAVE_MODEL_VAR)
    8893    source->modelVar = NULL;
     94# endif
    8995    source->maskObj = NULL;
    9096    source->maskView = NULL;
     
    116122    source->pixels = NULL;
    117123    source->variance = NULL;
     124# if (HAVE_MODEL_VAR)
    118125    source->modelVar = NULL;
     126# endif
    119127    source->maskObj = NULL;
    120128    source->maskView = NULL;
     
    204212    source->pixels   = in->pixels   ? psImageCopyView(NULL, in->pixels)   : NULL;
    205213    source->variance = in->variance ? psImageCopyView(NULL, in->variance) : NULL;
     214# if (HAVE_MODEL_VAR)
    206215    source->modelVar = NULL;
     216# endif
    207217    source->maskView = in->maskView ? psImageCopyView(NULL, in->maskView) : NULL;
    208218
     
    10331043
    10341044    bool addNoise = mode & PM_MODEL_OP_NOISE;
     1045
     1046# if (HAVE_MODEL_VAR)
    10351047    bool addModelVar = mode & PM_MODEL_OP_MODELVAR;
    1036 
    10371048    if (addModelVar) psAssert (source->modelVar, "programming error");
     1049# endif
    10381050
    10391051    // require the use of pmModelAddWithOffset if we are adding noise (because the model size and norm are rescaled)
     
    10581070        }
    10591071
     1072# if (HAVE_MODEL_VAR)
    10601073        psF32 **target = addModelVar ? source->modelVar->data.F32 : source->pixels->data.F32;
     1074# else
     1075        psF32 **target = source->pixels->data.F32;
     1076# endif
    10611077
    10621078        for (int iy = 0; iy < source->modelFlux->numRows; iy++) {
     
    10731089            }
    10741090        }
     1091# if (HAVE_MODEL_VAR)
    10751092        if (!addModelVar) {
    10761093            if (add) {
     
    10801097            }
    10811098        }
     1099# else
     1100        if (add) {
     1101            source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED;
     1102        } else {
     1103            source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED;
     1104        }
     1105# endif
    10821106        return true;
    10831107    }
     
    10871111        target = source->variance;
    10881112    }
     1113# if (HAVE_MODEL_VAR)
    10891114    if (addModelVar) {
    10901115        target = source->modelVar;
    10911116    }
     1117# endif
    10921118
    10931119    if (add) {
    10941120        status = pmModelAddWithOffset (target, source->maskObj, model, PM_MODEL_OP_FULL, maskVal, dx, dy);
     1121# if (HAVE_MODEL_VAR)
    10951122        if (!addNoise && !addModelVar) source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED;
     1123# else
     1124        source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED;
     1125# endif
    10961126    } else {
    10971127        status = pmModelSubWithOffset (target, source->maskObj, model, PM_MODEL_OP_FULL, maskVal, dx, dy);
     1128# if (HAVE_MODEL_VAR)
    10981129        if (!addNoise && !addModelVar) source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED;
     1130# else
     1131        source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED;
     1132# endif
    10991133    }
    11001134
  • trunk/psModules/src/objects/pmSource.h

    r33963 r33993  
    7272    psImage *pixels;                    ///< Rectangular region including object pixels.
    7373    psImage *variance;                  ///< Image variance.
     74# if (HAVE_MODEL_VAR)
    7475    psImage *modelVar;                  ///< variance based on current models
     76# endif
    7577    psImage *maskObj;                   ///< unique mask for this object which marks included pixels associated with objects.
    7678    psImage *maskView;                  ///< view into global image mask for this object region
  • trunk/psModules/src/objects/pmSourcePhotometry.c

    r33963 r33993  
    899899}
    900900
     901# if (HAVE_MODEL_VAR)
    901902double pmSourceModelWeight(const pmSource *Mi, int term, const pmSourceFitVarMode fitVarMode, const float covarFactor, psImageMaskType maskVal)
     903# else
     904double pmSourceModelWeight(const pmSource *Mi, int term, const bool unweighted_sum, const float covarFactor, psImageMaskType maskVal)
     905# endif
    902906{
    903907    PS_ASSERT_PTR_NON_NULL(Mi, NAN);
     908# if (HAVE_MODEL_VAR)
    904909    double flux = 0, wt = 1.0, factor = 0;
     910# else
     911    double flux = 0, wt = 0, factor = 0;
     912# endif
    905913
    906914    const psImage *Pi = Mi->modelFlux;
    907915    assert (Pi != NULL);
    908916
     917# if (HAVE_MODEL_VAR)
    909918    const psImage *Wi = NULL;
    910919    switch (fitVarMode) {
     
    922931        psAbort("programming error");
    923932    }   
    924 
     933# else
     934    const psImage *Wi = Mi->variance;
     935    if (!unweighted_sum) {
     936        assert (Wi != NULL);
     937    }
     938# endif
    925939    const psImage *Ti = Mi->maskObj;
    926940    assert (Ti != NULL);
     
    928942    for (int yi = 0; yi < Pi->numRows; yi++) {
    929943        for (int xi = 0; xi < Pi->numCols; xi++) {
    930             if (Ti->data.PS_TYPE_IMAGE_MASK_DATA[yi][xi] & maskVal) continue;
     944            if (Ti->data.PS_TYPE_IMAGE_MASK_DATA[yi][xi] & maskVal)
     945                continue;
     946# if (HAVE_MODEL_VAR)
    931947            if (fitVarMode != PM_SOURCE_PHOTFIT_CONST) {
    932948                wt = covarFactor * Wi->data.F32[yi][xi];
    933949                if (wt == 0) continue;
    934950            }
     951# else
     952            if (!unweighted_sum) {
     953                wt = covarFactor * Wi->data.F32[yi][xi];
     954                if (wt == 0)
     955                    continue;
     956            }
     957# endif
    935958
    936959            switch (term) {
     
    948971            }
    949972
     973# if (HAVE_MODEL_VAR)
    950974            // wt is 1.0 for CONST
    951975            flux += (factor * Pi->data.F32[yi][xi]) / wt;
     976# else
     977            if (unweighted_sum) {
     978                flux += (factor * Pi->data.F32[yi][xi]);
     979            } else {
     980                flux += (factor * Pi->data.F32[yi][xi]) / wt;
     981            }
     982# endif
    952983        }
    953984    }
     
    955986}
    956987
     988# if (HAVE_MODEL_VAR)
    957989double pmSourceModelDotModel (const pmSource *Mi, const pmSource *Mj, const pmSourceFitVarMode fitVarMode, const float covarFactor, psImageMaskType maskVal)
     990# else
     991double pmSourceModelDotModel (const pmSource *Mi, const pmSource *Mj, const bool unweighted_sum, const float covarFactor, psImageMaskType maskVal)
     992# endif
    958993{
    959994    PS_ASSERT_PTR_NON_NULL(Mi, NAN);
     
    963998    int xIs, xJs, yIs, yJs;
    964999    int xIe, yIe;
     1000# if (HAVE_MODEL_VAR)
    9651001    double flux;
    9661002    double wt = 1.0;
     1003# else
     1004    double flux, wt;
     1005# endif
    9671006
    9681007    const psImage *Pi = Mi->modelFlux;
     
    9711010    assert (Pj != NULL);
    9721011
     1012# if (HAVE_MODEL_VAR)
    9731013    const psImage *Wi = NULL;
    9741014    switch (fitVarMode) {
     
    9861026        psAbort("programming error");
    9871027    }   
     1028# else
     1029    const psImage *Wi = Mi->variance;
     1030    if (!unweighted_sum) {
     1031        assert (Wi != NULL);
     1032    }
     1033# endif
    9881034
    9891035    const psImage *Ti = Mi->maskObj;
     
    10151061                continue;
    10161062
     1063# if (HAVE_MODEL_VAR)
    10171064            float value = (Pi->data.F32[yi][xi] * Pj->data.F32[yj][xj]);
    10181065            switch (fitVarMode) {
     
    10311078
    10321079            flux += value / wt;
     1080# else
     1081            // XXX skip the nonsense weight pixels?
     1082            if (unweighted_sum) {
     1083                flux += (Pi->data.F32[yi][xi] * Pj->data.F32[yj][xj]);
     1084            } else {
     1085                wt = covarFactor * Wi->data.F32[yi][xi];
     1086                if (wt > 0) {
     1087                    flux += (Pi->data.F32[yi][xi] * Pj->data.F32[yj][xj]) / wt;
     1088                }
     1089            }
     1090# endif
    10331091        }
    10341092    }
     
    10361094}
    10371095
     1096# if (HAVE_MODEL_VAR)
    10381097double pmSourceDataDotModel (const pmSource *Mi, const pmSource *Mj, const pmSourceFitVarMode fitVarMode, const float covarFactor, psImageMaskType maskVal)
     1098# else
     1099double pmSourceDataDotModel (const pmSource *Mi, const pmSource *Mj, const bool unweighted_sum, const float covarFactor, psImageMaskType maskVal)
     1100# endif
    10391101{
    10401102    PS_ASSERT_PTR_NON_NULL(Mi, NAN);
     
    10441106    int xIs, xJs, yIs, yJs;
    10451107    int xIe, yIe;
     1108# if (HAVE_MODEL_VAR)
    10461109    double flux;
    10471110    double wt = 1.0;
     1111# else
     1112    double flux, wt;
     1113# endif
    10481114
    10491115    const psImage *Pi = Mi->pixels;
     
    10521118    assert (Pj != NULL);
    10531119
     1120# if (HAVE_MODEL_VAR)
    10541121    const psImage *Wi = NULL;
    10551122    switch (fitVarMode) {
     
    10671134        psAbort("programming error");
    10681135    }   
     1136# else
     1137    const psImage *Wi = Mi->variance;
     1138    if (!unweighted_sum) {
     1139        assert (Wi != NULL);
     1140    }
     1141# endif
    10691142
    10701143    const psImage *Ti = Mi->maskObj;
     
    10961169                continue;
    10971170
     1171# if (HAVE_MODEL_VAR)
    10981172            float value = (Pi->data.F32[yi][xi] * Pj->data.F32[yj][xj]);
    10991173            switch (fitVarMode) {
     
    11131187            flux += value / wt;
    11141188
     1189# else
     1190            // XXX skip the nonsense weight pixels?
     1191            if (unweighted_sum) {
     1192                flux += (Pi->data.F32[yi][xi] * Pj->data.F32[yj][xj]);
     1193            } else {
     1194                wt = covarFactor * Wi->data.F32[yi][xi];
     1195                if (wt > 0) {
     1196                    flux += (Pi->data.F32[yi][xi] * Pj->data.F32[yj][xj]) / wt;
     1197                }
     1198            }
     1199# endif
    11151200        }
    11161201    }
  • trunk/psModules/src/objects/pmSourcePhotometry.h

    r33963 r33993  
    3838} pmSourcePhotometryMode;
    3939
     40# if (HAVE_MODEL_VAR)
    4041typedef enum {
    4142    PM_SOURCE_PHOTFIT_NONE       = 0,
     
    4445    PM_SOURCE_PHOTFIT_MODEL_VAR  = 3,
    4546} pmSourceFitVarMode;
     47# endif
    4648
    4749bool pmSourcePhotometryModel(
     
    8284bool pmSourceMeasureDiffStats (pmSource *source, psImageMaskType maskVal, psImageMaskType markVal);
    8385
     86# if (HAVE_MODEL_VAR)
    8487double pmSourceDataDotModel (const pmSource *Mi, const pmSource *Mj, const pmSourceFitVarMode fitVarMode, const float covarFactor, psImageMaskType maskVal);
    8588double pmSourceModelDotModel (const pmSource *Mi, const pmSource *Mj, const pmSourceFitVarMode fitVarMode, const float covarFactor, psImageMaskType maskVal);
    8689double pmSourceModelWeight(const pmSource *Mi, int term, const pmSourceFitVarMode fitVarMode, const float covarFactor, psImageMaskType maskVal);
     90# else
     91double pmSourceDataDotModel (const pmSource *Mi, const pmSource *Mj, const bool unweighted_sum, const float covarFactor, psImageMaskType maskVal);
     92double pmSourceModelDotModel (const pmSource *Mi, const pmSource *Mj, const bool unweighted_sum, const float covarFactor, psImageMaskType maskVal);
     93double pmSourceModelWeight(const pmSource *Mi, int term, const bool unweighted_sum, const float covarFactor, psImageMaskType maskVal);
     94# endif
    8795
    8896bool pmSourceNeighborFlags (pmSource *source);
  • trunk/psphot/src/psphotEfficiency.c

    r33963 r33993  
    420420
    421421    // psphotFitSourcesLinearReadout subtracts the model fits
     422# if (HAVE_MODEL_VAR)
    422423    if (!psphotFitSourcesLinearReadout(recipe, readout, fakeSourcesAll, psf, true, PM_SOURCE_PHOTFIT_CONST)) {
     424# else
     425    if (!psphotFitSourcesLinearReadout(recipe, readout, fakeSourcesAll, psf, true)) {
     426# endif
    423427        psError(PS_ERR_UNKNOWN, false, "Unable to perform linear fit on fake sources.");
    424428        psFree(fakeSources);
  • trunk/psphot/src/psphotFitSourcesLinear.c

    r33963 r33993  
    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
     70# if (HAVE_MODEL_VAR)
    6671        if (!psphotFitSourcesLinearReadout (recipe, readout, sources, psf, final, fitVarModePass1)) {
     72# else
     73        if (!psphotFitSourcesLinearReadout (recipe, readout, sources, psf, final)) {
     74# endif
    6775            psError (PSPHOT_ERR_CONFIG, false, "failed to fit sources (linear) for %s entry %d", filerule, i);
    6876            return false;
    6977        }
    7078
     79# if (HAVE_MODEL_VAR)
    7180        // the MODEL_VAR weighting scheme requires knowledge of the model fluxes to generate the variance
    7281        // after we have determined the initial set of fits, then we can generate the variance image and
     
    94103            }
    95104        }
     105# endif
    96106
    97107        psphotVisualShowResidualImage (readout, (num > 0));
     
    102112}
    103113
     114# if (HAVE_MODEL_VAR)
    104115// look up the fit variance mode from the recipe; older recipes do not have the value
    105116// 'LINEAR_FIT_VARIANCE_MODE'; in those cases, look for 'CONSTANT_PHOTOMETRIC_WEIGHTS' as a boolean and
     
    130141    return PM_SOURCE_PHOTFIT_NONE;
    131142}
    132 
     143# endif
     144
     145# if (HAVE_MODEL_VAR)
    133146bool psphotFitSourcesLinearReadout (psMetadata *recipe, pmReadout *readout, psArray *sources, pmPSF *psf, bool final, pmSourceFitVarMode fitVarMode) {
     147# else
     148bool psphotFitSourcesLinearReadout (psMetadata *recipe, pmReadout *readout, psArray *sources, pmPSF *psf, bool final) {
     149# endif
    134150
    135151    bool status;
     
    168184    if (psRegionIsNaN (AnalysisRegion)) psAbort("analysis region mis-defined");
    169185
     186# if (!HAVE_MODEL_VAR)
     187    bool CONSTANT_PHOTOMETRIC_WEIGHTS =
     188        psMetadataLookupBool(&status, recipe, "CONSTANT_PHOTOMETRIC_WEIGHTS");
     189    if (!status) {
     190        psAbort("You must provide a value for the BOOL recipe CONSTANT_PHOTOMETRIC_WEIGHTS");
     191    }
     192# endif
    170193    int SKY_FIT_ORDER = psMetadataLookupS32(&status, recipe, "SKY_FIT_ORDER");
    171194    if (!status) {
     
    295318    psSparseBorder *border = psSparseBorderAlloc (sparse, nBorder);
    296319
     320# if (HAVE_MODEL_VAR)
    297321    // if fitVarMode is MODEL_VAR, then we need to generate the model image variance
    298322    // XXX we have two possibilities here:
     
    302326
    303327    // 2) do a single pass, and use the model guess to define the model variance (but do I trust the Model Guess?)
     328# endif
    304329
    305330    // fill out the sparse matrix elements and border elements (B)
     
    310335
    311336        // diagonal elements of the sparse matrix (auto-cross-product)
     337# if (HAVE_MODEL_VAR)
    312338        f = pmSourceModelDotModel (SRCi, SRCi, fitVarMode, covarFactor, maskVal);
     339# else
     340        f = pmSourceModelDotModel (SRCi, SRCi, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor, maskVal);
     341# endif
    313342        psSparseMatrixElement (sparse, i, i, f);
    314343
     344# if (HAVE_MODEL_VAR)
    315345        // if we have used CONSTANT errors, then we need to calculate the value of the parameter error
    316346        if (fitVarMode != PM_SOURCE_PHOTFIT_IMAGE_VAR) {
     
    320350            errors->data.F32[i] = 1.0 / sqrt(f);
    321351        }
    322 
     352# else
     353        // the formal error depends on the weighting scheme
     354        if (CONSTANT_PHOTOMETRIC_WEIGHTS) {
     355            float var = pmSourceModelDotModel (SRCi, SRCi, false, covarFactor, maskVal);
     356            errors->data.F32[i] = 1.0 / sqrt(var);
     357        } else {
     358            errors->data.F32[i] = 1.0 / sqrt(f);
     359        }
     360# endif
    323361
    324362        // find the image x model value
     363# if (HAVE_MODEL_VAR)
    325364        f = pmSourceDataDotModel (SRCi, SRCi, fitVarMode, covarFactor, maskVal);
     365# else
     366        f = pmSourceDataDotModel (SRCi, SRCi, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor, maskVal);
     367# endif
    326368        psSparseVectorElement (sparse, i, f);
    327369
     
    329371        switch (SKY_FIT_ORDER) {
    330372          case 1:
     373# if (HAVE_MODEL_VAR)
    331374            f = pmSourceModelWeight (SRCi, 1, fitVarMode, covarFactor, maskVal);
    332375            psSparseBorderElementB (border, i, 1, f);
    333376            f = pmSourceModelWeight (SRCi, 2, fitVarMode, covarFactor, maskVal);
    334377            psSparseBorderElementB (border, i, 2, f);
     378# else
     379            f = pmSourceModelWeight (SRCi, 1, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor, maskVal);
     380            psSparseBorderElementB (border, i, 1, f);
     381            f = pmSourceModelWeight (SRCi, 2, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor, maskVal);
     382            psSparseBorderElementB (border, i, 2, f);
     383# endif
    335384
    336385          case 0:
     386# if (HAVE_MODEL_VAR)
    337387            f = pmSourceModelWeight (SRCi, 0, fitVarMode, covarFactor, maskVal);
     388# else
     389            f = pmSourceModelWeight (SRCi, 0, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor, maskVal);
     390# endif
    338391            psSparseBorderElementB (border, i, 0, f);
    339392            break;
     
    355408
    356409            // got an overlap; calculate cross-product and add to output array
     410# if (HAVE_MODEL_VAR)
    357411            f = pmSourceModelDotModel (SRCi, SRCj, fitVarMode, covarFactor, maskVal);
     412# else
     413            f = pmSourceModelDotModel (SRCi, SRCj, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor, maskVal);
     414# endif
    358415            psSparseMatrixElement (sparse, j, i, f);
    359416        }
     
    393450
    394451    // set the sky, sky_x, sky_y components of border matrix
     452# if (HAVE_MODEL_VAR)
    395453    SetBorderMatrixElements (border, readout, fitSources, (fitVarMode == PM_SOURCE_PHOTFIT_CONST), SKY_FIT_ORDER, markVal);
     454# else
     455    SetBorderMatrixElements (border, readout, fitSources, CONSTANT_PHOTOMETRIC_WEIGHTS, SKY_FIT_ORDER, markVal);
     456# endif
    396457
    397458    psSparseConstraint constraint;
     
    552613}
    553614
     615# if (HAVE_MODEL_VAR)
    554616bool psphotModelBackgroundReadout(psImage *model,  // Model image
    555617                                  psImage *modelStdev, // Model stdev image
     
    661723    return true;
    662724}
     725# endif
Note: See TracChangeset for help on using the changeset viewer.