IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 29, 2012, 4:55:13 PM (14 years ago)
Author:
eugene
Message:

add MODEL_VAR option to weighting scheme

Location:
branches/eam_branches/ipp-20120405/psModules
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20120405/psModules

  • branches/eam_branches/ipp-20120405/psModules/src/objects/pmModelFuncs.h

    r29004 r33947  
    4646
    4747typedef enum {
    48     PM_MODEL_OP_NONE    = 0x00,
    49     PM_MODEL_OP_FUNC    = 0x01,
    50     PM_MODEL_OP_RES0    = 0x02,
    51     PM_MODEL_OP_RES1    = 0x04,
    52     PM_MODEL_OP_FULL    = 0x07,
    53     PM_MODEL_OP_SKY     = 0x08,
    54     PM_MODEL_OP_CENTER  = 0x10,
    55     PM_MODEL_OP_NORM    = 0x20,
    56     PM_MODEL_OP_NOISE   = 0x40,
     48    PM_MODEL_OP_NONE     = 0x00,
     49    PM_MODEL_OP_FUNC     = 0x01,
     50    PM_MODEL_OP_RES0     = 0x02,
     51    PM_MODEL_OP_RES1     = 0x04,
     52    PM_MODEL_OP_FULL     = 0x07,
     53    PM_MODEL_OP_SKY      = 0x08,
     54    PM_MODEL_OP_CENTER   = 0x10,
     55    PM_MODEL_OP_NORM     = 0x20,
     56    PM_MODEL_OP_NOISE    = 0x40,
     57    PM_MODEL_OP_MODELVAR = 0x80,
    5758} pmModelOpMode;
    5859
  • branches/eam_branches/ipp-20120405/psModules/src/objects/pmSource.c

    r33690 r33947  
    5050    psFree(tmp->pixels);
    5151    psFree(tmp->variance);
     52    psFree(tmp->modelVar);
    5253    psFree(tmp->maskObj);
    5354    psFree(tmp->maskView);
     
    7677    psFree (source->pixels);
    7778    psFree (source->variance);
     79    psFree (source->modelVar);
    7880    psFree (source->maskObj);
    7981    psFree (source->maskView);
     
    8385    source->pixels = NULL;
    8486    source->variance = NULL;
     87    source->modelVar = NULL;
    8588    source->maskObj = NULL;
    8689    source->maskView = NULL;
     
    112115    source->pixels = NULL;
    113116    source->variance = NULL;
     117    source->modelVar = NULL;
    114118    source->maskObj = NULL;
    115119    source->maskView = NULL;
     
    198202    source->pixels   = in->pixels   ? psImageCopyView(NULL, in->pixels)   : NULL;
    199203    source->variance = in->variance ? psImageCopyView(NULL, in->variance) : NULL;
     204    source->modelVar = NULL;
    200205    source->maskView = in->maskView ? psImageCopyView(NULL, in->maskView) : NULL;
    201206
     
    10261031
    10271032    bool addNoise = mode & PM_MODEL_OP_NOISE;
     1033    bool addModelVar = mode & PM_MODEL_OP_MODELVAR;
     1034
     1035    if (addModelVar) psAssert (source->modelVar, "programming error");
    10281036
    10291037    // require the use of pmModelAddWithOffset if we are adding noise (because the model size and norm are rescaled)
     
    10481056        }
    10491057
    1050         psF32 **target = source->pixels->data.F32;
     1058        psF32 **target = addModelVar ? source->modelVar->data.F32 : source->pixels->data.F32;
    10511059
    10521060        for (int iy = 0; iy < source->modelFlux->numRows; iy++) {
     
    10631071            }
    10641072        }
    1065         if (add) {
    1066             source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED;
    1067         } else {
    1068             source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED;
     1073        if (!addModelVar) {
     1074            if (add) {
     1075                source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED;
     1076            } else {
     1077                source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED;
     1078            }
    10691079        }
    10701080        return true;
     
    10751085        target = source->variance;
    10761086    }
     1087    if (addModelVar) {
     1088        target = source->modelVar;
     1089    }
    10771090
    10781091    if (add) {
    10791092        status = pmModelAddWithOffset (target, source->maskObj, model, PM_MODEL_OP_FULL, maskVal, dx, dy);
    1080         source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED;
     1093        if (!addNoise && !addModelVar) source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED;
    10811094    } else {
    10821095        status = pmModelSubWithOffset (target, source->maskObj, model, PM_MODEL_OP_FULL, maskVal, dx, dy);
    1083         source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED;
     1096        if (!addNoise && !addModelVar) source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED;
    10841097    }
    10851098
  • branches/eam_branches/ipp-20120405/psModules/src/objects/pmSource.h

    r33690 r33947  
    7272    psImage *pixels;                    ///< Rectangular region including object pixels.
    7373    psImage *variance;                  ///< Image variance.
     74    psImage *modelVar;                  ///< variance based on current models
    7475    psImage *maskObj;                   ///< unique mask for this object which marks included pixels associated with objects.
    7576    psImage *maskView;                  ///< view into global image mask for this object region
  • branches/eam_branches/ipp-20120405/psModules/src/objects/pmSourcePhotometry.c

    r32998 r33947  
    899899}
    900900
    901 double pmSourceModelWeight(const pmSource *Mi, int term, const bool unweighted_sum, const float covarFactor, psImageMaskType maskVal)
     901double pmSourceModelWeight(const pmSource *Mi, int term, const pmSourceFitVarMode fitVarMode, const float covarFactor, psImageMaskType maskVal)
    902902{
    903903    PS_ASSERT_PTR_NON_NULL(Mi, NAN);
    904     double flux = 0, wt = 0, factor = 0;
     904    double flux = 0, wt = 1.0, factor = 0;
    905905
    906906    const psImage *Pi = Mi->modelFlux;
    907907    assert (Pi != NULL);
    908     const psImage *Wi = Mi->variance;
    909     if (!unweighted_sum) {
    910         assert (Wi != NULL);
    911     }
     908
     909    const psImage *Wi = NULL;
     910    switch (fitVarMode) {
     911      case PM_SOURCE_PHOTFIT_CONST:
     912        break;
     913      case PM_SOURCE_PHOTFIT_IMAGE_VAR:
     914        Wi = Mi->variance;
     915        psAssert (Wi, "programming error");
     916        break;
     917      case PM_SOURCE_PHOTFIT_MODEL_VAR:
     918        Wi = Mi->modelVar;
     919        psAssert (Wi, "programming error");
     920        break;
     921      case PM_SOURCE_PHOTFIT_NONE:
     922        psAbort("programming error");
     923    }   
     924
    912925    const psImage *Ti = Mi->maskObj;
    913926    assert (Ti != NULL);
     
    915928    for (int yi = 0; yi < Pi->numRows; yi++) {
    916929        for (int xi = 0; xi < Pi->numCols; xi++) {
    917             if (Ti->data.PS_TYPE_IMAGE_MASK_DATA[yi][xi] & maskVal)
    918                 continue;
    919             if (!unweighted_sum) {
     930            if (Ti->data.PS_TYPE_IMAGE_MASK_DATA[yi][xi] & maskVal) continue;
     931            if (fitVarMode != PM_SOURCE_PHOTFIT_CONST) {
    920932                wt = covarFactor * Wi->data.F32[yi][xi];
    921                 if (wt == 0)
    922                     continue;
     933                if (wt == 0) continue;
    923934            }
    924935
     
    937948            }
    938949
    939             if (unweighted_sum) {
    940                 flux += (factor * Pi->data.F32[yi][xi]);
    941             } else {
    942                 flux += (factor * Pi->data.F32[yi][xi]) / wt;
    943             }
     950            // wt is 1.0 for CONST
     951            flux += (factor * Pi->data.F32[yi][xi]) / wt;
    944952        }
    945953    }
     
    947955}
    948956
    949 double pmSourceModelDotModel (const pmSource *Mi, const pmSource *Mj, const bool unweighted_sum, const float covarFactor, psImageMaskType maskVal)
     957double pmSourceModelDotModel (const pmSource *Mi, const pmSource *Mj, const pmSourceFitVarMode fitVarMode, const float covarFactor, psImageMaskType maskVal)
    950958{
    951959    PS_ASSERT_PTR_NON_NULL(Mi, NAN);
     
    962970    assert (Pj != NULL);
    963971
    964     const psImage *Wi = Mi->variance;
    965     if (!unweighted_sum) {
    966         assert (Wi != NULL);
    967     }
     972    const psImage *Wi = NULL;
     973    switch (fitVarMode) {
     974      case PM_SOURCE_PHOTFIT_CONST:
     975        break;
     976      case PM_SOURCE_PHOTFIT_IMAGE_VAR:
     977        Wi = Mi->variance;
     978        psAssert (Wi, "programming error");
     979        break;
     980      case PM_SOURCE_PHOTFIT_MODEL_VAR:
     981        Wi = Mi->modelVar;
     982        psAssert (Wi, "programming error");
     983        break;
     984      case PM_SOURCE_PHOTFIT_NONE:
     985        psAbort("programming error");
     986    }   
    968987
    969988    const psImage *Ti = Mi->maskObj;
     
    9951014                continue;
    9961015
    997             // XXX skip the nonsense weight pixels?
    998             if (unweighted_sum) {
    999                 flux += (Pi->data.F32[yi][xi] * Pj->data.F32[yj][xj]);
    1000             } else {
     1016            float value = (Pi->data.F32[yi][xi] * Pj->data.F32[yj][xj]);
     1017            switch (fitVarMode) {
     1018              case PM_SOURCE_PHOTFIT_CONST:
     1019                wt = 1.0;
     1020                break;
     1021              case PM_SOURCE_PHOTFIT_IMAGE_VAR:
     1022              case PM_SOURCE_PHOTFIT_MODEL_VAR:
    10011023                wt = covarFactor * Wi->data.F32[yi][xi];
    1002                 if (wt > 0) {
    1003                     flux += (Pi->data.F32[yi][xi] * Pj->data.F32[yj][xj]) / wt;
    1004                 }
    1005             }
     1024                break;
     1025              case PM_SOURCE_PHOTFIT_NONE:
     1026                psAbort("programming error");
     1027            }
     1028            // skip pixels with nonsense weight values
     1029            if (wt <= 0) continue;
     1030
     1031            flux += value / wt;
    10061032        }
    10071033    }
     
    10091035}
    10101036
    1011 double pmSourceDataDotModel (const pmSource *Mi, const pmSource *Mj, const bool unweighted_sum, const float covarFactor, psImageMaskType maskVal)
     1037double pmSourceDataDotModel (const pmSource *Mi, const pmSource *Mj, const pmSourceFitVarMode fitVarMode, const float covarFactor, psImageMaskType maskVal)
    10121038{
    10131039    PS_ASSERT_PTR_NON_NULL(Mi, NAN);
     
    10241050    assert (Pj != NULL);
    10251051
    1026     const psImage *Wi = Mi->variance;
    1027     if (!unweighted_sum) {
    1028         assert (Wi != NULL);
    1029     }
     1052    const psImage *Wi = NULL;
     1053    switch (fitVarMode) {
     1054      case PM_SOURCE_PHOTFIT_CONST:
     1055        break;
     1056      case PM_SOURCE_PHOTFIT_IMAGE_VAR:
     1057        Wi = Mi->variance;
     1058        psAssert (Wi, "programming error");
     1059        break;
     1060      case PM_SOURCE_PHOTFIT_MODEL_VAR:
     1061        Wi = Mi->modelVar;
     1062        psAssert (Wi, "programming error");
     1063        break;
     1064      case PM_SOURCE_PHOTFIT_NONE:
     1065        psAbort("programming error");
     1066    }   
    10301067
    10311068    const psImage *Ti = Mi->maskObj;
     
    10571094                continue;
    10581095
    1059             // XXX skip the nonsense weight pixels?
    1060             if (unweighted_sum) {
    1061                 flux += (Pi->data.F32[yi][xi] * Pj->data.F32[yj][xj]);
    1062             } else {
     1096            float value = (Pi->data.F32[yi][xi] * Pj->data.F32[yj][xj]);
     1097            switch (fitVarMode) {
     1098              case PM_SOURCE_PHOTFIT_CONST:
     1099                wt = 1.0;
     1100                break;
     1101              case PM_SOURCE_PHOTFIT_IMAGE_VAR:
     1102              case PM_SOURCE_PHOTFIT_MODEL_VAR:
    10631103                wt = covarFactor * Wi->data.F32[yi][xi];
    1064                 if (wt > 0) {
    1065                     flux += (Pi->data.F32[yi][xi] * Pj->data.F32[yj][xj]) / wt;
    1066                 }
    1067             }
     1104                break;
     1105              case PM_SOURCE_PHOTFIT_NONE:
     1106                psAbort("programming error");
     1107            }
     1108            // skip pixels with nonsense weight values
     1109            if (wt <= 0) continue;
     1110
     1111            flux += value / wt;
     1112
    10681113        }
    10691114    }
  • branches/eam_branches/ipp-20120405/psModules/src/objects/pmSourcePhotometry.h

    r31670 r33947  
    3838} pmSourcePhotometryMode;
    3939
     40typedef enum {
     41    PM_SOURCE_PHOTFIT_NONE       = 0,
     42    PM_SOURCE_PHOTFIT_CONST      = 1,
     43    PM_SOURCE_PHOTFIT_IMAGE_VAR  = 2,
     44    PM_SOURCE_PHOTFIT_MODEL_VAR  = 3,
     45} pmSourceFitVarMode;
     46
    4047bool pmSourcePhotometryModel(
    4148    float *fitMag,                      ///< integrated fit magnitude
     
    7582bool pmSourceMeasureDiffStats (pmSource *source, psImageMaskType maskVal, psImageMaskType markVal);
    7683
    77 double pmSourceDataDotModel (const pmSource *Mi, const pmSource *Mj, const bool unweighted_sum, const float covarFactor, psImageMaskType maskVal);
    78 double pmSourceModelDotModel (const pmSource *Mi, const pmSource *Mj, const bool unweighted_sum, const float covarFactor, psImageMaskType maskVal);
    79 double pmSourceModelWeight(const pmSource *Mi, int term, const bool unweighted_sum, const float covarFactor, psImageMaskType maskVal);
     84double pmSourceDataDotModel (const pmSource *Mi, const pmSource *Mj, const pmSourceFitVarMode fitVarMode, const float covarFactor, psImageMaskType maskVal);
     85double pmSourceModelDotModel (const pmSource *Mi, const pmSource *Mj, const pmSourceFitVarMode fitVarMode, const float covarFactor, psImageMaskType maskVal);
     86double pmSourceModelWeight(const pmSource *Mi, int term, const pmSourceFitVarMode fitVarMode, const float covarFactor, psImageMaskType maskVal);
    8087
    8188bool pmSourceNeighborFlags (pmSource *source);
Note: See TracChangeset for help on using the changeset viewer.