Changeset 31337
- Timestamp:
- Apr 21, 2011, 12:17:34 PM (15 years ago)
- Location:
- branches/eam_branches/ipp-20110404/psphot/src
- Files:
-
- 4 edited
-
psphotKronMasked.c (modified) (5 diffs)
-
psphotLoadSRCTEXT.c (modified) (1 diff)
-
psphotMergeSources.c (modified) (1 diff)
-
psphotReadout.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20110404/psphot/src/psphotKronMasked.c
r31328 r31337 1 1 # include "psphotInternal.h" 2 3 bool psphotKronMag (pmSource *source, float radius, psImageMaskType maskVal); 2 4 3 5 bool psphotKronMasked (pmConfig *config, const pmFPAview *view, const char *filerule) … … 29 31 psAssert (detections, "missing detections?"); 30 32 31 psArray *sources = detections-> newSources;33 psArray *sources = detections->allSources; 32 34 psAssert (sources, "missing sources?"); 33 35 … … 58 60 if (!status) { 59 61 nThreads = 0; 62 } 63 64 float RADIUS = psMetadataLookupF32 (&status, readout->analysis, "PSF_MOMENTS_RADIUS"); 65 if (!status) { 66 RADIUS = psMetadataLookupF32 (&status, recipe, "PSF_MOMENTS_RADIUS"); 60 67 } 61 68 … … 84 91 if (!source->moments) continue; 85 92 93 // replace object in image 94 if (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED) { 95 pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal); 96 } 97 98 psphotKronMag (source, RADIUS, maskVal); 99 100 // re-subtract the object, leave local sky 101 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 102 103 continue; 104 105 // XXX skip this code 86 106 // generate the pixel masks 87 107 // int Xo = source->moments->Mx; … … 117 137 return true; 118 138 } 139 140 bool psphotKronMag (pmSource *source, float radius, psImageMaskType maskVal) { 141 142 PS_ASSERT_PTR_NON_NULL(source, false); 143 PS_ASSERT_PTR_NON_NULL(source->peak, false); 144 PS_ASSERT_PTR_NON_NULL(source->pixels, false); 145 PS_ASSERT_FLOAT_LARGER_THAN(radius, 0.0, false); 146 147 psF32 Sum = 0.0; 148 psF32 Var = 0.0; 149 psF32 R2 = PS_SQR(radius); 150 151 // a note about coordinates: coordinates of objects throughout psphot refer to the primary 152 // image coordinates. the source->pixels image has an offset relative to its parent of 153 // col0,row0: a pixel (x,y) in the primary image has coordinates of (x-col0, y-row0) in 154 // this subimage. we subtract off the peak coordinates, adjusted to this subimage, to have 155 // minimal round-off error in the sums. since these values are subtracted just to minimize 156 // the dynamic range and are added back below, the exact value does not matter. these are 157 // (int) so they can be used in the image index below. 158 159 // Now calculate higher-order moments, using the above-calculated first moments to adjust coordinates 160 // Xn = SUM (x - xc)^n * (z - sky) 161 162 psF32 RF = 0.0; 163 psF32 RS = 0.0; 164 165 # if (1) 166 float dX = source->moments->Mx - source->peak->xf; 167 float dY = source->moments->My - source->peak->yf; 168 float dR = hypot(dX, dY); 169 float Xo = (dR < 2.0) ? source->moments->Mx : source->peak->xf; 170 float Yo = (dR < 2.0) ? source->moments->My : source->peak->yf; 171 # else 172 float Xo = source->moments->Mx; 173 float Yo = source->moments->My; 174 # endif 175 176 // center of mass in subimage. Note: the calculation below uses pixel index, so we correct 177 // xCM, yCM from pixel coords to pixel index here. 178 psF32 xCM = Xo - 0.5 - source->pixels->col0; // coord of peak in subimage 179 psF32 yCM = Yo - 0.5 - source->pixels->row0; // coord of peak in subimage 180 181 for (psS32 row = 0; row < source->pixels->numRows ; row++) { 182 183 psF32 yDiff = row - yCM; 184 if (fabs(yDiff) > radius) continue; 185 186 psF32 *vPix = source->pixels->data.F32[row]; 187 188 psImageMaskType *vMsk = (source->maskObj == NULL) ? NULL : source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[row]; 189 190 for (psS32 col = 0; col < source->pixels->numCols ; col++, vPix++) { 191 if (vMsk) { 192 if (*vMsk & maskVal) { 193 vMsk++; 194 continue; 195 } 196 vMsk++; 197 } 198 if (isnan(*vPix)) continue; 199 200 psF32 xDiff = col - xCM; 201 if (fabs(xDiff) > radius) continue; 202 203 // radius is just a function of (xDiff, yDiff) 204 psF32 r2 = PS_SQR(xDiff) + PS_SQR(yDiff); 205 if (r2 > R2) continue; 206 207 psF32 pDiff = *vPix; 208 209 Sum += pDiff; 210 211 // Kron Flux uses the 1st radial moment (NOT Gaussian windowed) 212 psF32 rf = pDiff * sqrt(r2); 213 psF32 rs = pDiff; 214 215 RF += rf; 216 RS += rs; 217 } 218 } 219 220 // Saturate the 1st radial moment 221 float Mrf = MIN(radius, MAX(0.25*radius, RF/RS)); 222 223 // Calculate the Kron magnitude (make this block optional?) 224 float radKron = 2.5*Mrf; 225 float radKron2 = radKron*radKron; 226 227 int nKronPix = 0; 228 Sum = Var = 0.0; 229 230 for (psS32 row = 0; row < source->pixels->numRows ; row++) { 231 232 psF32 yDiff = row - yCM; 233 if (fabs(yDiff) > radKron) continue; 234 235 psF32 *vPix = source->pixels->data.F32[row]; 236 psF32 *vWgt = source->variance->data.F32[row]; 237 238 psImageMaskType *vMsk = (source->maskObj == NULL) ? NULL : source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[row]; 239 240 for (psS32 col = 0; col < source->pixels->numCols ; col++, vPix++, vWgt++) { 241 if (vMsk) { 242 if (*vMsk & maskVal) { 243 vMsk++; 244 continue; 245 } 246 vMsk++; 247 } 248 if (isnan(*vPix)) continue; 249 250 psF32 xDiff = col - xCM; 251 if (fabs(xDiff) > radKron) continue; 252 253 // radKron is just a function of (xDiff, yDiff) 254 psF32 r2 = PS_SQR(xDiff) + PS_SQR(yDiff); 255 if (r2 > radKron2) continue; 256 257 psF32 pDiff = *vPix; 258 psF32 wDiff = *vWgt; 259 260 Sum += pDiff; 261 Var += wDiff; 262 nKronPix ++; 263 } 264 } 265 // XXX for a test, save the old values here: 266 source->moments->KronCore = source->moments->KronFlux; 267 source->moments->KronCoreErr = source->moments->KronFluxErr; 268 269 source->moments->KronFlux = Sum * M_PI * PS_SQR(radKron) / nKronPix; 270 source->moments->KronFluxErr = sqrt(Var) * M_PI * PS_SQR(radKron) / nKronPix; 271 272 return true; 273 } -
branches/eam_branches/ipp-20110404/psphot/src/psphotLoadSRCTEXT.c
r31154 r31337 52 52 53 53 // NOTE: most of these values are irrelevant for loaded source positions 54 source->seq = 0;54 source->seq = source->id; 55 55 PAR[PM_PAR_XPOS] = X; 56 56 PAR[PM_PAR_YPOS] = Y; -
branches/eam_branches/ipp-20110404/psphot/src/psphotMergeSources.c
r31154 r31337 137 137 pmSource *source = extSourcesTXT->data[i]; 138 138 source->mode |= PM_SOURCE_MODE_EXTERNAL; 139 140 // the supplied peak flux needs to be re-normalized 141 source->peak->rawFlux = 1.0; 142 source->peak->smoothFlux = 1.0; 143 source->peak->detValue = 1.0; 139 144 140 145 // drop the loaded source modelPSF -
branches/eam_branches/ipp-20110404/psphot/src/psphotReadout.c
r31328 r31337 146 146 } 147 147 148 // psphotKronMasked(config, view, filerule);149 150 148 // find blended neighbors of very saturated stars (detections->newSources) 151 149 // if (!psphotDeblendSatstars (config, view, filerule)) { … … 201 199 psphotFitSourcesLinear (config, view, filerule, false); // pass 1 (detections->allSources) 202 200 psphotDumpChisqs (config, view, filerule); 201 202 // XXX re-measure the kron mags with models subtracted 203 psphotKronMasked(config, view, filerule); 203 204 204 205 // identify CRs and extended sources (only unmeasured sources are measured) … … 311 312 pass1finish: 312 313 314 // XXX re-measure the kron mags with models subtracted 315 psphotKronMasked(config, view, filerule); 316 313 317 // measure source size for the remaining sources 314 318 // NOTE: applies only to NEW (unmeasured) sources
Note:
See TracChangeset
for help on using the changeset viewer.
