Changeset 26593
- Timestamp:
- Jan 14, 2010, 10:10:51 AM (16 years ago)
- Location:
- branches/eam_branches/20091201/psModules/src/imcombine
- Files:
-
- 4 edited
-
pmSubtractionAnalysis.c (modified) (1 diff)
-
pmSubtractionEquation.c (modified) (4 diffs)
-
pmSubtractionKernels.c (modified) (3 diffs)
-
pmSubtractionKernels.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/20091201/psModules/src/imcombine/pmSubtractionAnalysis.c
r26585 r26593 117 117 } 118 118 119 // sample difference images 120 { 121 psMetadataAddArray(analysis, PS_LIST_TAIL, "SUBTRACTION.SAMPLE.STAMP.SET", PS_META_DUPLICATE_OK, "Sample Difference Stamps", kernels->sampleStamps); 122 } 119 123 120 124 #ifdef TESTING -
branches/eam_branches/20091201/psModules/src/imcombine/pmSubtractionEquation.c
r26586 r26593 1331 1331 } 1332 1332 1333 bool pmSubtractionResidualStats(psVector *fSigRes, psVector *fMaxRes, psVector *fMinRes, psKernel *target, psKernel *source, psKernel *residual, double norm, int footprint) { 1334 1335 // XXX measure some useful stats on the residuals 1336 float sum = 0.0; 1337 float peak = 0.0; 1338 for (int y = - footprint; y <= footprint; y++) { 1339 for (int x = - footprint; x <= footprint; x++) { 1340 sum += 0.5*(target->kernel[y][x] + source->kernel[y][x] * norm); 1341 peak = PS_MAX(peak, 0.5*(target->kernel[y][x] + source->kernel[y][x] * norm)); 1342 } 1343 } 1344 1345 // only count pixels with more than X% of the source flux 1346 // calculate stdev(dflux) 1347 float dflux1 = 0.0; 1348 float dflux2 = 0.0; 1349 int npix = 0; 1350 1351 float dmax = 0.0; 1352 float dmin = 0.0; 1353 1354 for (int y = - footprint; y <= footprint; y++) { 1355 for (int x = - footprint; x <= footprint; x++) { 1356 float dflux = 0.5*(target->kernel[y][x] + source->kernel[y][x] * norm); 1357 if (dflux < 0.02*sum) continue; 1358 dflux1 += residual->kernel[y][x]; 1359 dflux2 += PS_SQR(residual->kernel[y][x]); 1360 dmax = PS_MAX(residual->kernel[y][x], dmax); 1361 dmin = PS_MIN(residual->kernel[y][x], dmin); 1362 npix ++; 1363 } 1364 } 1365 float sigma = sqrt(dflux2 / npix - PS_SQR(dflux1/npix)); 1366 // fprintf (stderr, "sum: %f, peak: %f, sigma: %f, fsigma: %f, fmax: %f, fmin: %f\n", sum, peak, sigma, sigma/sum, dmax/peak, dmin/peak); 1367 psVectorAppend(fSigRes, sigma/sum); 1368 psVectorAppend(fMaxRes, dmax/peak); 1369 psVectorAppend(fMinRes, dmin/peak); 1370 return true; 1371 } 1372 1333 1373 psVector *pmSubtractionCalculateDeviations(pmSubtractionStampList *stamps, 1334 1374 pmSubtractionKernels *kernels) … … 1353 1393 psVector *fMinRes = psVectorAllocEmpty(stamps->num, PS_TYPE_F32); 1354 1394 psVector *fMaxRes = psVectorAllocEmpty(stamps->num, PS_TYPE_F32); 1395 1396 // we want to save the residual images for the 9 brightest stamps. 1397 // identify the 9 brightest stamps 1398 psVector *keepStamps = psVectorAlloc(stamps->num, PS_TYPE_S32); 1399 psVectorInit (keepStamps, 0); 1400 { 1401 psVector *flux = psVectorAlloc(stamps->num, PS_TYPE_F32); 1402 psVectorInit (flux, 0.0); 1403 1404 for (int i = 0; i < stamps->num; i++) { 1405 pmSubtractionStamp *stamp = stamps->stamps->data[i]; 1406 if (!isfinite(stamp->flux)) continue; 1407 flux->data.F32[i] = stamp->flux; 1408 } 1409 1410 psVector *index = psVectorSortIndex(NULL, flux); 1411 for (int i = 0; (i < stamps->num) && (i < 9); i++) { 1412 int n = stamps->num - i - 1; 1413 keepStamps->data.S32[index->data.S32[n]] = 1; 1414 fprintf (stderr, "keeping %d (%d of %d)\n", index->data.S32[n], n, 9); 1415 } 1416 psFree (flux); 1417 psFree (index); 1418 1419 // this function is called multiple times in the iteration, but 1420 // we only know after the interation is done if we will try again. 1421 // therefore we must save the sample each time, and blow away the old one 1422 // if it exists. 1423 psFree (kernels->sampleStamps); 1424 kernels->sampleStamps = psArrayAllocEmpty(9); 1425 } 1355 1426 1356 1427 for (int i = 0; i < stamps->num; i++) { … … 1427 1498 } 1428 1499 1429 // XXX measure some useful stats on the residuals 1430 float sum = 0.0; 1431 float peak = 0.0; 1432 for (int y = - footprint; y <= footprint; y++) { 1433 for (int x = - footprint; x <= footprint; x++) { 1434 sum += 0.5*(target->kernel[y][x] + source->kernel[y][x] * norm); 1435 peak = PS_MAX(peak, 0.5*(target->kernel[y][x] + source->kernel[y][x] * norm)); 1436 } 1437 } 1438 1439 // only count pixels with more than X% of the source flux 1440 // calculate stdev(dflux) 1441 float dflux1 = 0.0; 1442 float dflux2 = 0.0; 1443 int npix = 0; 1444 1445 float dmax = 0.0; 1446 float dmin = 0.0; 1447 1448 for (int y = - footprint; y <= footprint; y++) { 1449 for (int x = - footprint; x <= footprint; x++) { 1450 float dflux = 0.5*(target->kernel[y][x] + source->kernel[y][x] * norm); 1451 if (dflux < 0.02*sum) continue; 1452 dflux1 += residual->kernel[y][x]; 1453 dflux2 += PS_SQR(residual->kernel[y][x]); 1454 dmax = PS_MAX(residual->kernel[y][x], dmax); 1455 dmin = PS_MIN(residual->kernel[y][x], dmin); 1456 npix ++; 1457 } 1458 } 1459 float sigma = sqrt(dflux2 / npix - PS_SQR(dflux1/npix)); 1460 // fprintf (stderr, "sum: %f, peak: %f, sigma: %f, fsigma: %f, fmax: %f, fmin: %f\n", sum, peak, sigma, sigma/sum, dmax/peak, dmin/peak); 1461 psVectorAppend(fSigRes, sigma/sum); 1462 psVectorAppend(fMaxRes, dmax/peak); 1463 psVectorAppend(fMinRes, dmin/peak); 1500 if (keepStamps->data.S32[i]) { 1501 psImage *sample = psImageCopy(NULL, residual->image, PS_TYPE_F32); 1502 psArrayAdd (kernels->sampleStamps, 9, sample); 1503 psFree (sample); 1504 } 1505 1506 pmSubtractionResidualStats(fSigRes, fMaxRes, fMinRes, target, source, residual, norm, footprint); 1507 1464 1508 } else { 1465 1509 // Dual convolution … … 1490 1534 } 1491 1535 } 1536 if (keepStamps->data.S32[i]) { 1537 psImage *sample = psImageCopy(NULL, residual->image, PS_TYPE_F32); 1538 psArrayAdd (kernels->sampleStamps, 9, sample); 1539 psFree (sample); 1540 } 1541 1542 pmSubtractionResidualStats(fSigRes, fMaxRes, fMinRes, image1, image2, residual, norm, footprint); 1492 1543 } 1493 1544 -
branches/eam_branches/20091201/psModules/src/imcombine/pmSubtractionKernels.c
r26590 r26593 29 29 psFree(kernels->solution1); 30 30 psFree(kernels->solution2); 31 psFree(kernels->sampleStamps); 31 32 } 32 33 … … 226 227 if (!forceZeroNull && ((uOrder % 2) || (vOrder % 2))) { 227 228 // Odd function 228 scale2D = 1.0 / sqrt(sum2);229 scale2D = 1.0 / sqrt(sum2); 229 230 } 230 231 … … 573 574 kernels->rms = NAN; 574 575 kernels->numStamps = 0; 576 kernels->sampleStamps = NULL; 575 577 576 578 kernels->fSigResMean = NAN; -
branches/eam_branches/20091201/psModules/src/imcombine/pmSubtractionKernels.h
r26575 r26593 55 55 float fMinResMean; ///< mean fractional negative swing in residuals 56 56 float fMinResStdev; ///< stdev of fractional negative swing in residuals 57 psArray *sampleStamps; ///< array of brightest set of stamps for output visualizations 57 58 } pmSubtractionKernels; 58 59
Note:
See TracChangeset
for help on using the changeset viewer.
