Changeset 34085 for trunk/psModules/src/objects/pmSourcePhotometry.c
- Timestamp:
- Jun 26, 2012, 11:31:38 AM (14 years ago)
- Location:
- trunk/psModules
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
src/objects/pmSourcePhotometry.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules
- Property svn:mergeinfo changed
/branches/eam_branches/ipp-20120601/psModules (added) merged: 34002,34044,34049,34051-34053,34073,34076,34078
- Property svn:mergeinfo changed
-
trunk/psModules/src/objects/pmSourcePhotometry.c
r33993 r34085 899 899 } 900 900 901 # if (HAVE_MODEL_VAR)902 901 double pmSourceModelWeight(const pmSource *Mi, int term, const pmSourceFitVarMode fitVarMode, const float covarFactor, psImageMaskType maskVal) 903 # else904 double pmSourceModelWeight(const pmSource *Mi, int term, const bool unweighted_sum, const float covarFactor, psImageMaskType maskVal)905 # endif906 902 { 907 903 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; 913 907 914 908 const psImage *Pi = Mi->modelFlux; 915 909 assert (Pi != NULL); 916 910 917 # if (HAVE_MODEL_VAR)918 911 const psImage *Wi = NULL; 919 912 switch (fitVarMode) { … … 921 914 break; 922 915 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 959 double 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 1042 double 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: 923 1064 Wi = Mi->variance; 924 1065 psAssert (Wi, "programming error"); … … 931 1072 psAbort("programming error"); 932 1073 } 933 # else934 const psImage *Wi = Mi->variance;935 if (!unweighted_sum) {936 assert (Wi != NULL);937 }938 # endif939 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 # else952 if (!unweighted_sum) {953 wt = covarFactor * Wi->data.F32[yi][xi];954 if (wt == 0)955 continue;956 }957 # endif958 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 CONST975 flux += (factor * Pi->data.F32[yi][xi]) / wt;976 # else977 if (unweighted_sum) {978 flux += (factor * Pi->data.F32[yi][xi]);979 } else {980 flux += (factor * Pi->data.F32[yi][xi]) / wt;981 }982 # endif983 }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 # else991 double pmSourceModelDotModel (const pmSource *Mi, const pmSource *Mj, const bool unweighted_sum, const float covarFactor, psImageMaskType maskVal)992 # endif993 {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 # else1004 double flux, wt;1005 # endif1006 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 # else1029 const psImage *Wi = Mi->variance;1030 if (!unweighted_sum) {1031 assert (Wi != NULL);1032 }1033 # endif1034 1074 1035 1075 const psImage *Ti = Mi->maskObj; … … 1052 1092 yIe = Ye - Pi->row0; 1053 1093 1054 // note that weight is addressing the same image pixels 1094 // note that weight is addressing the same image pixels, 1055 1095 flux = 0; 1056 1096 for (yi = yIs, yj = yJs; yi < yIe; yi++, yj++) { … … 1061 1101 continue; 1062 1102 1063 # if (HAVE_MODEL_VAR)1064 1103 float value = (Pi->data.F32[yi][xi] * Pj->data.F32[yj][xj]); 1065 1104 switch (fitVarMode) { … … 1068 1107 break; 1069 1108 case PM_SOURCE_PHOTFIT_IMAGE_VAR: 1109 case PM_SOURCE_PHOTFIT_MODEL_SKY: 1070 1110 case PM_SOURCE_PHOTFIT_MODEL_VAR: 1071 1111 wt = covarFactor * Wi->data.F32[yi][xi]; … … 1078 1118 1079 1119 flux += value / wt; 1080 # else1081 // 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 # endif1091 1120 } 1092 1121 } 1093 1122 return flux; 1094 1123 } 1095 1096 # if (HAVE_MODEL_VAR)1097 double pmSourceDataDotModel (const pmSource *Mi, const pmSource *Mj, const pmSourceFitVarMode fitVarMode, const float covarFactor, psImageMaskType maskVal)1098 # else1099 double pmSourceDataDotModel (const pmSource *Mi, const pmSource *Mj, const bool unweighted_sum, const float covarFactor, psImageMaskType maskVal)1100 # endif1101 {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 # else1112 double flux, wt;1113 # endif1114 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 # else1137 const psImage *Wi = Mi->variance;1138 if (!unweighted_sum) {1139 assert (Wi != NULL);1140 }1141 # endif1142 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 values1185 if (wt <= 0) continue;1186 1187 flux += value / wt;1188 1189 # else1190 // 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 # endif1200 }1201 }1202 return flux;1203 }
Note:
See TracChangeset
for help on using the changeset viewer.
