- Timestamp:
- Nov 24, 2013, 3:28:13 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20130904/psphot/src/psphotSourceFits.c
r36198 r36310 19 19 static int NfitIterPCM = 0; 20 20 static int NfitPixPCM = 0; 21 22 bool psphotPCMfitCheckSize (pmPCMdata *pcm, pmSource *source, psImageMaskType maskVal, float psfSize); 21 23 22 24 bool psphotFitInit (int nThreads) { … … 585 587 } 586 588 587 float t1, t2, t 4, t5;588 t1 = t2 = t 4 = t5 = 0.0;589 float t1, t2, t3, t4, t5; 590 t1 = t2 = t3 = t4 = t5 = 0.0; 589 591 if (TIMING) { psTimerStart ("psphotFitPCM"); } 590 592 … … 642 644 } 643 645 644 if (TIMING) { t 4= psTimerMark ("psphotFitPCM"); }646 if (TIMING) { t3 = psTimerMark ("psphotFitPCM"); } 645 647 646 648 // psTraceSetLevel("psLib.math.psMinimizeLMChi2", 5); … … 648 650 NfitIterPCM += pcm->modelConv->nIter; 649 651 NfitPixPCM += pcm->modelConv->nDOF; 652 if (TIMING) { t4 = psTimerMark ("psphotFitPCM"); } 653 654 psphotPCMfitCheckSize (pcm, source, maskVal, psfSize); 650 655 if (TIMING) { t5 = psTimerMark ("psphotFitPCM"); } 651 656 652 657 if (TIMING) { 653 658 int nPixBig = source->pixels->numCols * source->pixels->numRows; 654 fprintf (stderr, "psphotFitPCM : nIter: %2d, radius: %6.1f, npix: %5d of %5d, t1: %6.4f, t2: %6.4f, t 4: %6.4f, t5: %6.4f\n", model->nIter, model->fitRadius, model->nPix, nPixBig, t1, t2, t4, t5);659 fprintf (stderr, "psphotFitPCM : nIter: %2d, radius: %6.1f, npix: %5d of %5d, t1: %6.4f, t2: %6.4f, t3: %6.4f, t4: %6.4f, t5: %6.4f\n", model->nIter, model->fitRadius, model->nPix, nPixBig, t1, t2, t3, t4, t5); 655 660 } 656 661 if (EXTRA_VERBOSE && !TIMING) { … … 1246 1251 } 1247 1252 1248 1253 // # define N_REFF_CHECK 11 1254 // float drefCheck[] = {-0.02, -0.04, -0.06, 0.0, 0.85, 0.90, 0.95, 1.00, 1.05, 1.10, 1.15, 1.20, 1.25}; 1255 1256 // we have an initial fit, check to see if the current size is besst 1257 bool psphotPCMfitCheckSize (pmPCMdata *pcm, pmSource *source, psImageMaskType maskVal, float psfSize) { 1258 1259 // PAR is already at my current best guess 1260 psF32 *PAR = pcm->modelConv->params->data.F32; 1261 1262 // store best guess as a shape 1263 psEllipseAxes centerAxes; 1264 pmModelParamsToAxes (¢erAxes, PAR[PM_PAR_SXX], PAR[PM_PAR_SXY], PAR[PM_PAR_SYY], true); 1265 1266 float xMin = NAN; 1267 float iMin = NAN; 1268 float rMin = NAN; 1269 1270 // loop over Reff, keeping the ARatio and Theta constant 1271 for (int j = -20; j < 21; j++) { 1272 1273 float dref = j * 0.02; 1274 1275 psEllipseAxes guessAxes; 1276 guessAxes.major = centerAxes.major + dref; 1277 guessAxes.minor = guessAxes.major * centerAxes.minor / centerAxes.major; 1278 guessAxes.theta = centerAxes.theta; 1279 1280 if (!isfinite(guessAxes.major)) return false; 1281 if (!isfinite(guessAxes.minor)) return false; 1282 if (!isfinite(guessAxes.theta)) return false; 1283 1284 // convert the major,minor,theta to shape parameters for an Reff-like model 1285 pmModelAxesToParams (&PAR[PM_PAR_SXX], &PAR[PM_PAR_SXY], &PAR[PM_PAR_SYY], guessAxes, true); 1286 1287 // generated the modelFlux 1288 pmPCMMakeModel (source, pcm->modelConv, maskVal, psfSize); 1289 1290 float YY = 0.0; 1291 float YM = 0.0; 1292 float MM = 0.0; 1293 bool usePoisson = false; 1294 1295 for (int iy = 0; iy < source->pixels->numRows; iy++) { 1296 for (int ix = 0; ix < source->pixels->numCols; ix++) { 1297 // skip masked points 1298 if (source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix]) { 1299 continue; 1300 } 1301 // skip zero-variance points 1302 if (source->variance->data.F32[iy][ix] == 0) { 1303 continue; 1304 } 1305 // skip nan value points 1306 if (!isfinite(source->pixels->data.F32[iy][ix])) { 1307 continue; 1308 } 1309 1310 float fy = source->pixels->data.F32[iy][ix]; 1311 float fm = source->modelFlux->data.F32[iy][ix]; 1312 float wt = (usePoisson) ? 1.0 / source->variance->data.F32[iy][ix] : 1.0; 1313 1314 YY += PS_SQR(fy) * wt; 1315 YM += fm * fy * wt; 1316 MM += PS_SQR(fm) * wt; 1317 } 1318 } 1319 1320 float Io = YM / MM; 1321 float Chisq = YY - 2 * Io * YM + Io * Io * MM; 1322 if (isnan(xMin) || (Chisq < xMin)) { 1323 xMin = Chisq; 1324 iMin = Io; 1325 rMin = dref; 1326 } 1327 // fprintf (stderr, "%d | %f %f %f | %f %f %f\n", j, dref, Io, Chisq, rMin, iMin, xMin); 1328 } 1329 1330 psEllipseAxes guessAxes; 1331 guessAxes.major = centerAxes.major + rMin; 1332 guessAxes.minor = guessAxes.major * centerAxes.minor / centerAxes.major; 1333 guessAxes.theta = centerAxes.theta; 1334 1335 if (!isfinite(guessAxes.major)) return false; 1336 if (!isfinite(guessAxes.minor)) return false; 1337 if (!isfinite(guessAxes.theta)) return false; 1338 1339 // convert the major,minor,theta to shape parameters for an Reff-like model 1340 pmModelAxesToParams (&PAR[PM_PAR_SXX], &PAR[PM_PAR_SXY], &PAR[PM_PAR_SYY], guessAxes, true); 1341 PAR[PM_PAR_I0] = iMin; 1342 1343 return true; 1344 } 1345
Note:
See TracChangeset
for help on using the changeset viewer.
