IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 26, 2012, 11:31:38 AM (14 years ago)
Author:
eugene
Message:

re-enable MODEL_VAR option for linear photometry fit

Location:
trunk/psModules
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules

  • trunk/psModules/src/objects/pmSourcePhotometry.c

    r33993 r34085  
    899899}
    900900
    901 # if (HAVE_MODEL_VAR)
    902901double pmSourceModelWeight(const pmSource *Mi, int term, const pmSourceFitVarMode fitVarMode, const float covarFactor, psImageMaskType maskVal)
    903 # else
    904 double pmSourceModelWeight(const pmSource *Mi, int term, const bool unweighted_sum, const float covarFactor, psImageMaskType maskVal)
    905 # endif
    906902{
    907903    PS_ASSERT_PTR_NON_NULL(Mi, NAN);
    908 # if (HAVE_MODEL_VAR)
    909     double flux = 0, wt = 1.0, factor = 0;
    910 # else
    911     double flux = 0, wt = 0, factor = 0;
    912 # endif
     904    double flux = 0;
     905    double wt = 1.0;
     906    double factor = 0;
    913907
    914908    const psImage *Pi = Mi->modelFlux;
    915909    assert (Pi != NULL);
    916910
    917 # if (HAVE_MODEL_VAR)
    918911    const psImage *Wi = NULL;
    919912    switch (fitVarMode) {
     
    921914        break;
    922915      case PM_SOURCE_PHOTFIT_IMAGE_VAR:
     916      case PM_SOURCE_PHOTFIT_MODEL_SKY:
     917        Wi = Mi->variance;
     918        psAssert (Wi, "programming error");
     919        break;
     920      case PM_SOURCE_PHOTFIT_MODEL_VAR:
     921        Wi = Mi->modelVar;
     922        psAssert (Wi, "programming error");
     923        break;
     924      case PM_SOURCE_PHOTFIT_NONE:
     925        psAbort("programming error");
     926    }   
     927    const psImage *Ti = Mi->maskObj;
     928    assert (Ti != NULL);
     929
     930    for (int yi = 0; yi < Pi->numRows; yi++) {
     931        for (int xi = 0; xi < Pi->numCols; xi++) {
     932            if (Ti->data.PS_TYPE_IMAGE_MASK_DATA[yi][xi] & maskVal)
     933                continue;
     934            if (fitVarMode != PM_SOURCE_PHOTFIT_CONST) {
     935                wt = covarFactor * Wi->data.F32[yi][xi];
     936                if (wt == 0) continue;
     937            }
     938            switch (term) {
     939              case 0:
     940                factor = 1;
     941                break;
     942              case 1:
     943                factor = xi + Pi->col0;
     944                break;
     945              case 2:
     946                factor = yi + Pi->row0;
     947                break;
     948              default:
     949                psAbort("invalid term for pmSourceWeight");
     950            }
     951
     952            // wt is 1.0 for CONST
     953            flux += (factor * Pi->data.F32[yi][xi]) / wt;
     954        }
     955    }
     956    return flux;
     957}
     958
     959double pmSourceModelDotModel (const pmSource *Mi, const pmSource *Mj, const pmSourceFitVarMode fitVarMode, const float covarFactor, psImageMaskType maskVal)
     960{
     961    PS_ASSERT_PTR_NON_NULL(Mi, NAN);
     962    PS_ASSERT_PTR_NON_NULL(Mj, NAN);
     963    int Xs, Xe, Ys, Ye;
     964    int xi, xj, yi, yj;
     965    int xIs, xJs, yIs, yJs;
     966    int xIe, yIe;
     967    double flux;
     968    double wt = 1.0;
     969
     970    const psImage *Pi = Mi->modelFlux;
     971    assert (Pi != NULL);
     972    const psImage *Pj = Mj->modelFlux;
     973    assert (Pj != NULL);
     974
     975    const psImage *Wi = NULL;
     976    switch (fitVarMode) {
     977      case PM_SOURCE_PHOTFIT_CONST:
     978        break;
     979      case PM_SOURCE_PHOTFIT_IMAGE_VAR:
     980      case PM_SOURCE_PHOTFIT_MODEL_SKY:
     981        Wi = Mi->variance;
     982        psAssert (Wi, "programming error");
     983        break;
     984      case PM_SOURCE_PHOTFIT_MODEL_VAR:
     985        Wi = Mi->modelVar;
     986        psAssert (Wi, "programming error");
     987        break;
     988      case PM_SOURCE_PHOTFIT_NONE:
     989        psAbort("programming error");
     990    }   
     991
     992    const psImage *Ti = Mi->maskObj;
     993    assert (Ti != NULL);
     994    const psImage *Tj = Mj->maskObj;
     995    assert (Tj != NULL);
     996
     997    Xs = PS_MAX (Pi->col0, Pj->col0);
     998    Xe = PS_MIN (Pi->col0 + Pi->numCols, Pj->col0 + Pj->numCols);
     999
     1000    Ys = PS_MAX (Pi->row0, Pj->row0);
     1001    Ye = PS_MIN (Pi->row0 + Pi->numRows, Pj->row0 + Pj->numRows);
     1002
     1003    xIs = Xs - Pi->col0;
     1004    xJs = Xs - Pj->col0;
     1005    yIs = Ys - Pi->row0;
     1006    yJs = Ys - Pj->row0;
     1007
     1008    xIe = Xe - Pi->col0;
     1009    yIe = Ye - Pi->row0;
     1010
     1011    // note that weight is addressing the same image pixels
     1012    flux = 0;
     1013    for (yi = yIs, yj = yJs; yi < yIe; yi++, yj++) {
     1014        for (xi = xIs, xj = xJs; xi < xIe; xi++, xj++) {
     1015            if (Ti->data.PS_TYPE_IMAGE_MASK_DATA[yi][xi] & maskVal)
     1016                continue;
     1017            if (Tj->data.PS_TYPE_IMAGE_MASK_DATA[yj][xj] & maskVal)
     1018                continue;
     1019
     1020            float value = (Pi->data.F32[yi][xi] * Pj->data.F32[yj][xj]);
     1021            switch (fitVarMode) {
     1022              case PM_SOURCE_PHOTFIT_CONST:
     1023                wt = 1.0;
     1024                break;
     1025              case PM_SOURCE_PHOTFIT_IMAGE_VAR:
     1026              case PM_SOURCE_PHOTFIT_MODEL_SKY:
     1027              case PM_SOURCE_PHOTFIT_MODEL_VAR:
     1028                wt = covarFactor * Wi->data.F32[yi][xi];
     1029                break;
     1030              case PM_SOURCE_PHOTFIT_NONE:
     1031                psAbort("programming error");
     1032            }
     1033            // skip pixels with nonsense weight values
     1034            if (wt <= 0) continue;
     1035
     1036            flux += value / wt;
     1037        }
     1038    }
     1039    return flux;
     1040}
     1041
     1042double pmSourceDataDotModel (const pmSource *Mi, const pmSource *Mj, const pmSourceFitVarMode fitVarMode, const float covarFactor, psImageMaskType maskVal)
     1043{
     1044    PS_ASSERT_PTR_NON_NULL(Mi, NAN);
     1045    PS_ASSERT_PTR_NON_NULL(Mj, NAN);
     1046    int Xs, Xe, Ys, Ye;
     1047    int xi, xj, yi, yj;
     1048    int xIs, xJs, yIs, yJs;
     1049    int xIe, yIe;
     1050    double flux;
     1051    double wt = 1.0;
     1052
     1053    const psImage *Pi = Mi->pixels;
     1054    assert (Pi != NULL);
     1055    const psImage *Pj = Mj->modelFlux;
     1056    assert (Pj != NULL);
     1057
     1058    const psImage *Wi = NULL;
     1059    switch (fitVarMode) {
     1060      case PM_SOURCE_PHOTFIT_CONST:
     1061        break;
     1062      case PM_SOURCE_PHOTFIT_IMAGE_VAR:
     1063      case PM_SOURCE_PHOTFIT_MODEL_SKY:
    9231064        Wi = Mi->variance;
    9241065        psAssert (Wi, "programming error");
     
    9311072        psAbort("programming error");
    9321073    }   
    933 # else
    934     const psImage *Wi = Mi->variance;
    935     if (!unweighted_sum) {
    936         assert (Wi != NULL);
    937     }
    938 # endif
    939     const psImage *Ti = Mi->maskObj;
    940     assert (Ti != NULL);
    941 
    942     for (int yi = 0; yi < Pi->numRows; yi++) {
    943         for (int xi = 0; xi < Pi->numCols; xi++) {
    944             if (Ti->data.PS_TYPE_IMAGE_MASK_DATA[yi][xi] & maskVal)
    945                 continue;
    946 # if (HAVE_MODEL_VAR)
    947             if (fitVarMode != PM_SOURCE_PHOTFIT_CONST) {
    948                 wt = covarFactor * Wi->data.F32[yi][xi];
    949                 if (wt == 0) continue;
    950             }
    951 # else
    952             if (!unweighted_sum) {
    953                 wt = covarFactor * Wi->data.F32[yi][xi];
    954                 if (wt == 0)
    955                     continue;
    956             }
    957 # endif
    958 
    959             switch (term) {
    960               case 0:
    961                 factor = 1;
    962                 break;
    963               case 1:
    964                 factor = xi + Pi->col0;
    965                 break;
    966               case 2:
    967                 factor = yi + Pi->row0;
    968                 break;
    969               default:
    970                 psAbort("invalid term for pmSourceWeight");
    971             }
    972 
    973 # if (HAVE_MODEL_VAR)
    974             // wt is 1.0 for CONST
    975             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
    983         }
    984     }
    985     return flux;
    986 }
    987 
    988 # if (HAVE_MODEL_VAR)
    989 double pmSourceModelDotModel (const pmSource *Mi, const pmSource *Mj, const pmSourceFitVarMode fitVarMode, const float covarFactor, psImageMaskType maskVal)
    990 # else
    991 double pmSourceModelDotModel (const pmSource *Mi, const pmSource *Mj, const bool unweighted_sum, const float covarFactor, psImageMaskType maskVal)
    992 # endif
    993 {
    994     PS_ASSERT_PTR_NON_NULL(Mi, NAN);
    995     PS_ASSERT_PTR_NON_NULL(Mj, NAN);
    996     int Xs, Xe, Ys, Ye;
    997     int xi, xj, yi, yj;
    998     int xIs, xJs, yIs, yJs;
    999     int xIe, yIe;
    1000 # if (HAVE_MODEL_VAR)
    1001     double flux;
    1002     double wt = 1.0;
    1003 # else
    1004     double flux, wt;
    1005 # endif
    1006 
    1007     const psImage *Pi = Mi->modelFlux;
    1008     assert (Pi != NULL);
    1009     const psImage *Pj = Mj->modelFlux;
    1010     assert (Pj != NULL);
    1011 
    1012 # if (HAVE_MODEL_VAR)
    1013     const psImage *Wi = NULL;
    1014     switch (fitVarMode) {
    1015       case PM_SOURCE_PHOTFIT_CONST:
    1016         break;
    1017       case PM_SOURCE_PHOTFIT_IMAGE_VAR:
    1018         Wi = Mi->variance;
    1019         psAssert (Wi, "programming error");
    1020         break;
    1021       case PM_SOURCE_PHOTFIT_MODEL_VAR:
    1022         Wi = Mi->modelVar;
    1023         psAssert (Wi, "programming error");
    1024         break;
    1025       case PM_SOURCE_PHOTFIT_NONE:
    1026         psAbort("programming error");
    1027     }   
    1028 # else
    1029     const psImage *Wi = Mi->variance;
    1030     if (!unweighted_sum) {
    1031         assert (Wi != NULL);
    1032     }
    1033 # endif
    10341074
    10351075    const psImage *Ti = Mi->maskObj;
     
    10521092    yIe = Ye - Pi->row0;
    10531093
    1054     // note that weight is addressing the same image pixels
     1094    // note that weight is addressing the same image pixels,
    10551095    flux = 0;
    10561096    for (yi = yIs, yj = yJs; yi < yIe; yi++, yj++) {
     
    10611101                continue;
    10621102
    1063 # if (HAVE_MODEL_VAR)
    10641103            float value = (Pi->data.F32[yi][xi] * Pj->data.F32[yj][xj]);
    10651104            switch (fitVarMode) {
     
    10681107                break;
    10691108              case PM_SOURCE_PHOTFIT_IMAGE_VAR:
     1109              case PM_SOURCE_PHOTFIT_MODEL_SKY:
    10701110              case PM_SOURCE_PHOTFIT_MODEL_VAR:
    10711111                wt = covarFactor * Wi->data.F32[yi][xi];
     
    10781118
    10791119            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
    10911120        }
    10921121    }
    10931122    return flux;
    10941123}
    1095 
    1096 # if (HAVE_MODEL_VAR)
    1097 double pmSourceDataDotModel (const pmSource *Mi, const pmSource *Mj, const pmSourceFitVarMode fitVarMode, const float covarFactor, psImageMaskType maskVal)
    1098 # else
    1099 double pmSourceDataDotModel (const pmSource *Mi, const pmSource *Mj, const bool unweighted_sum, const float covarFactor, psImageMaskType maskVal)
    1100 # endif
    1101 {
    1102     PS_ASSERT_PTR_NON_NULL(Mi, NAN);
    1103     PS_ASSERT_PTR_NON_NULL(Mj, NAN);
    1104     int Xs, Xe, Ys, Ye;
    1105     int xi, xj, yi, yj;
    1106     int xIs, xJs, yIs, yJs;
    1107     int xIe, yIe;
    1108 # if (HAVE_MODEL_VAR)
    1109     double flux;
    1110     double wt = 1.0;
    1111 # else
    1112     double flux, wt;
    1113 # endif
    1114 
    1115     const psImage *Pi = Mi->pixels;
    1116     assert (Pi != NULL);
    1117     const psImage *Pj = Mj->modelFlux;
    1118     assert (Pj != NULL);
    1119 
    1120 # if (HAVE_MODEL_VAR)
    1121     const psImage *Wi = NULL;
    1122     switch (fitVarMode) {
    1123       case PM_SOURCE_PHOTFIT_CONST:
    1124         break;
    1125       case PM_SOURCE_PHOTFIT_IMAGE_VAR:
    1126         Wi = Mi->variance;
    1127         psAssert (Wi, "programming error");
    1128         break;
    1129       case PM_SOURCE_PHOTFIT_MODEL_VAR:
    1130         Wi = Mi->modelVar;
    1131         psAssert (Wi, "programming error");
    1132         break;
    1133       case PM_SOURCE_PHOTFIT_NONE:
    1134         psAbort("programming error");
    1135     }   
    1136 # else
    1137     const psImage *Wi = Mi->variance;
    1138     if (!unweighted_sum) {
    1139         assert (Wi != NULL);
    1140     }
    1141 # endif
    1142 
    1143     const psImage *Ti = Mi->maskObj;
    1144     assert (Ti != NULL);
    1145     const psImage *Tj = Mj->maskObj;
    1146     assert (Tj != NULL);
    1147 
    1148     Xs = PS_MAX (Pi->col0, Pj->col0);
    1149     Xe = PS_MIN (Pi->col0 + Pi->numCols, Pj->col0 + Pj->numCols);
    1150 
    1151     Ys = PS_MAX (Pi->row0, Pj->row0);
    1152     Ye = PS_MIN (Pi->row0 + Pi->numRows, Pj->row0 + Pj->numRows);
    1153 
    1154     xIs = Xs - Pi->col0;
    1155     xJs = Xs - Pj->col0;
    1156     yIs = Ys - Pi->row0;
    1157     yJs = Ys - Pj->row0;
    1158 
    1159     xIe = Xe - Pi->col0;
    1160     yIe = Ye - Pi->row0;
    1161 
    1162     // note that weight is addressing the same image pixels,
    1163     flux = 0;
    1164     for (yi = yIs, yj = yJs; yi < yIe; yi++, yj++) {
    1165         for (xi = xIs, xj = xJs; xi < xIe; xi++, xj++) {
    1166             if (Ti->data.PS_TYPE_IMAGE_MASK_DATA[yi][xi] & maskVal)
    1167                 continue;
    1168             if (Tj->data.PS_TYPE_IMAGE_MASK_DATA[yj][xj] & maskVal)
    1169                 continue;
    1170 
    1171 # if (HAVE_MODEL_VAR)
    1172             float value = (Pi->data.F32[yi][xi] * Pj->data.F32[yj][xj]);
    1173             switch (fitVarMode) {
    1174               case PM_SOURCE_PHOTFIT_CONST:
    1175                 wt = 1.0;
    1176                 break;
    1177               case PM_SOURCE_PHOTFIT_IMAGE_VAR:
    1178               case PM_SOURCE_PHOTFIT_MODEL_VAR:
    1179                 wt = covarFactor * Wi->data.F32[yi][xi];
    1180                 break;
    1181               case PM_SOURCE_PHOTFIT_NONE:
    1182                 psAbort("programming error");
    1183             }
    1184             // skip pixels with nonsense weight values
    1185             if (wt <= 0) continue;
    1186 
    1187             flux += value / wt;
    1188 
    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
    1200         }
    1201     }
    1202     return flux;
    1203 }
Note: See TracChangeset for help on using the changeset viewer.