Changeset 29543 for trunk/psModules/src/imcombine/pmSubtractionStamps.c
- Timestamp:
- Oct 25, 2010, 2:45:41 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/imcombine/pmSubtractionStamps.c
r29019 r29543 51 51 psFree(list->y); 52 52 psFree(list->flux); 53 psFree(list->window); 53 54 psFree(list->window1); 54 55 psFree(list->window2); … … 96 97 97 98 // fprintf (stderr, "xMin, xMax: %d, %d -> ", xMin, xMax); 99 // float xRaw = xMin; 100 // float yRaw = yMin; 98 101 99 102 // Ensure we're not going to go outside the bounds of the image … … 103 106 yMax = PS_MIN(numRows - border - 1, yMax); 104 107 105 if (xMax < xMin) return false; 106 if (yMax < yMin) return false; 108 if (xMax < xMin) { 109 // fprintf (stderr, "%f,%f : x-border\n", xRaw, yRaw); 110 return false; 111 } 112 if (yMax < yMin) { 113 // fprintf (stderr, "%f,%f : y-border\n", xRaw, yRaw); 114 return false; 115 } 107 116 108 117 psAssert (xMin <= xMax, "x mismatch?"); … … 118 127 if (subMask && subMask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & 119 128 (PM_SUBTRACTION_MASK_BORDER | PM_SUBTRACTION_MASK_REJ)) { 129 // fprintf (stderr, "%f,%f : masked\n", xRaw, yRaw); 120 130 return false; 121 131 } … … 133 143 } 134 144 145 // if (!found) { 146 // fprintf (stderr, "%f,%f : fails flux test\n", xRaw, yRaw); 147 // } 148 135 149 return found; 136 150 } … … 232 246 list->flux = NULL; 233 247 list->normFrac = normFrac; 248 list->normValue = NAN; 249 list->window = NULL; 234 250 list->window1 = NULL; 235 251 list->window2 = NULL; … … 256 272 out->y = NULL; 257 273 out->flux = NULL; 274 out->window = psMemIncrRefCounter(in->window); 258 275 out->window1 = psMemIncrRefCounter(in->window1); 259 276 out->window2 = psMemIncrRefCounter(in->window2); … … 331 348 stamp->vector = NULL; 332 349 stamp->norm = NAN; 350 stamp->normI1 = NAN; 351 stamp->normI2 = NAN; 352 stamp->normSquare1 = NAN; 353 stamp->normSquare2 = NAN; 354 355 stamp->MxxI1 = NULL; 356 stamp->MyyI1 = NULL; 357 stamp->MxxI2 = NULL; 358 stamp->MyyI2 = NULL; 359 360 stamp->MxxI1raw = NAN; 361 stamp->MyyI1raw = NAN; 362 stamp->MxxI2raw = NAN; 363 stamp->MyyI2raw = NAN; 333 364 334 365 return stamp; … … 431 462 // Take stamps off the top of the (sorted) list 432 463 for (int j = xList->n - 1; j >= 0 && !goodStamp; j--) { 464 // fprintf (stderr, "%d : xList: %ld elements\n", i, xList->n); 433 465 // Chop off the top of the list 434 466 xList->n = j; … … 459 491 yList->data.F32[j], yList->data.F32[j], numCols, numRows, border); 460 492 #endif 461 if (0 && goodStamp) {462 fprintf (stderr, "find: %6.1f < %6.1f < %6.1f, %6.1f < %6.1f %6.1f\n",463 region->x0 + size, xStamp, region->x1 - size,464 region->y0 + size, yStamp, region->y1 - size);465 }466 493 } 467 494 } else { … … 656 683 psImageInit(stamps->window2->image, 0.0); 657 684 685 // Generate a weighting window based on the fwhms (20% larger than the largest) 686 { 687 float fwhm1, fwhm2; 688 689 // XXX this is annoyingly hack-ish 690 pmSubtractionGetFWHMs(&fwhm1, &fwhm2); 691 692 float sigma = 1.5 * PS_MAX(fwhm1, fwhm2) / 2.35; 693 694 psFree (stamps->window); 695 stamps->window = psKernelAlloc(-size, size, -size, size); 696 psImageInit(stamps->window->image, 0.0); 697 698 for (int y = -size; y <= size; y++) { 699 for (int x = -size; x <= size; x++) { 700 stamps->window->kernel[y][x] = exp(-0.5*(x*x + y*y)/(sigma*sigma)); 701 } 702 } 703 } 704 658 705 // generate normalizations for each stamp 659 706 psVector *norm1 = psVectorAlloc(stamps->num, PS_TYPE_F32); … … 678 725 679 726 // storage vector for flux data 680 psStats *stats = psStatsAlloc (PS_STAT_ ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV);727 psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN); 681 728 psVector *flux1 = psVectorAllocEmpty(2*stamps->num, PS_TYPE_F32); 682 729 psVector *flux2 = psVectorAllocEmpty(2*stamps->num, PS_TYPE_F32); … … 706 753 psAbort ("failed to generate stats"); 707 754 } 708 float f1 = stats-> robustMedian;755 float f1 = stats->sampleMedian; 709 756 710 757 psStatsInit (stats); … … 712 759 psAbort ("failed to generate stats"); 713 760 } 714 float f2 = stats-> robustMedian;761 float f2 = stats->sampleMedian; 715 762 716 763 stamps->window1->kernel[y][x] = f1; … … 728 775 } 729 776 777 #if 0 778 { 779 psFits *fits = NULL; 780 fits = psFitsOpen ("window1.raw.fits", "w"); 781 psFitsWriteImage (fits, NULL, stamps->window1->image, 0, NULL); 782 psFitsClose (fits); 783 fits = psFitsOpen ("window2.raw.fits", "w"); 784 psFitsWriteImage (fits, NULL, stamps->window2->image, 0, NULL); 785 psFitsClose (fits); 786 } 787 #endif 788 730 789 psTrace("psModules.imcombine", 3, "Window total (1): %f, threshold: %f\n", sum1, (1.0 - stamps->normFrac) * sum1); 731 790 psTrace("psModules.imcombine", 3, "Window total (2): %f, threshold: %f\n", sum2, (1.0 - stamps->normFrac) * sum2); 732 791 733 # if ( 0)792 # if (1) 734 793 // this block attempts to calculate the radius based on the first radial moment 735 bool done1 = false;736 bool done2 = false;737 double prior1 = 0.0;738 double prior2 = 0.0;794 double Sr1 = 0.0; 795 double Sr2 = 0.0; 796 double Sf1 = 0.0; 797 double Sf2 = 0.0; 739 798 for (int y = -size; y <= size; y++) { 740 799 for (int x = -size; x <= size; x++) { … … 750 809 float R2 = Sr2 / Sf2; 751 810 752 stamps->normWindow1 = 2.5*R1; 753 stamps->normWindow1 = 2.5*R2; 811 stamps->normWindow1 = 2.0*R1; 812 stamps->normWindow2 = 2.0*R2; 813 psLogMsg ("psModules.imcombine", PS_LOG_DETAIL, "Kron Radii: %f for 1, %f for 2\n", stamps->normWindow1, stamps->normWindow2); 814 754 815 # else 755 816 // XXX : this block attempts to calculate the radius by looking at the curve of growth (or something vaguely equivalent). … … 778 839 // interpolate to the radius at which delta2 is normFrac: 779 840 stamps->normWindow1 = radius - (stamps->normFrac - delta1) / (delta1o - delta1); 780 fprintf (stderr, "choosing %f (%d) for 1 (%f : %f)\n", stamps->normWindow1, radius, within1, delta1);841 psLogMsg ("psModules.imcombine", PS_LOG_DETAIL, "choosing %f (%d) for 1 (%f : %f)\n", stamps->normWindow1, radius, within1, delta1); 781 842 done1 = true; 782 843 } … … 785 846 // interpolate to the radius at which delta2 is normFrac: 786 847 stamps->normWindow2 = radius - (stamps->normFrac - delta2) / (delta2o - delta2); 787 fprintf (stderr, "choosing %f (%d) for 2 (%f : %f)\n", stamps->normWindow2, radius, within2, delta2);848 psLogMsg ("psModules.imcombine", PS_LOG_DETAIL, "choosing %f (%d) for 2 (%f : %f)\n", stamps->normWindow2, radius, within2, delta2); 788 849 done2 = true; 789 850 } … … 833 894 { 834 895 psFits *fits = NULL; 835 fits = psFitsOpen ("window1. fits", "w");896 fits = psFitsOpen ("window1.norm.fits", "w"); 836 897 psFitsWriteImage (fits, NULL, stamps->window1->image, 0, NULL); 837 898 psFitsClose (fits); 838 fits = psFitsOpen ("window2. fits", "w");899 fits = psFitsOpen ("window2.norm.fits", "w"); 839 900 psFitsWriteImage (fits, NULL, stamps->window2->image, 0, NULL); 840 901 psFitsClose (fits); … … 906 967 float M2 = pmSubtractionKernelPenaltySingle(kernel->kernel, zeroNull); 907 968 908 penalty1 = M2 + PS_SQR(fwhm1 / 2.35); // rescale the unconvolved second-moment by the image second moment 909 penalty2 = M2 + PS_SQR(fwhm2 / 2.35); // rescale the unconvolved second-moment by the image second moment 969 if (1) { 970 penalty1 = M2 * PS_SQR(fwhm1 / 2.35); // rescale the unconvolved second-moment by the image second moment 971 penalty2 = M2 * PS_SQR(fwhm2 / 2.35); // rescale the unconvolved second-moment by the image second moment 972 // penalty1 = M2 + PS_SQR(fwhm1 / 2.35); // rescale the unconvolved second-moment by the image second moment 973 // penalty2 = M2 + PS_SQR(fwhm2 / 2.35); // rescale the unconvolved second-moment by the image second moment 974 } else { 975 penalty1 = PS_SQR(fwhm1 / 2.35); // rescale the unconvolved second-moment by the image second moment 976 penalty2 = PS_SQR(fwhm2 / 2.35); // rescale the unconvolved second-moment by the image second moment 977 } 910 978 } 911 979 kernels->penalties1->data.F32[index] = kernels->penalty * penalty1; … … 915 983 psAssert (isfinite(kernels->penalties2->data.F32[index]), "invalid penalty"); 916 984 917 fprintf(stderr, "penalty1: %f, penalty2: %f\n", penalty1, penalty2);985 // fprintf(stderr, "penalty1: %f, penalty2: %f\n", penalty1, penalty2); 918 986 919 987 return true; … … 942 1010 penalty *= 1.0 / sum2; 943 1011 944 if ( 1) {945 fprintf(stderr, "min: %lf, max: %lf, moment: %lf, flux^2: %lf\n", min, max, penalty, sum2);1012 if (0) { 1013 // fprintf(stderr, "min: %lf, max: %lf, moment: %lf, flux^2: %lf\n", min, max, penalty, sum2); 946 1014 // psTrace("psModules.imcombine", 7, "Kernel %d: %f %d %d %f\n", index, fwhm, uOrder, vOrder, penalty); 947 1015 } … … 983 1051 984 1052 if (x < bounds.x0 + size || x > bounds.x1 - size || y < bounds.y0 + size || y > bounds.y1 - size) { 985 psError(PM_ERR_PROG, false, "Stamp %d (%d,%d) is within the region border.\n", i, x, y); 986 return false; 1053 psLogMsg("psModules.imcombine", 3, "Stamp %d (%d,%d) is within the region border.\n", i, x, y); 1054 stamp->status = PM_SUBTRACTION_STAMP_NONE; 1055 continue; 987 1056 } 988 1057
Note:
See TracChangeset
for help on using the changeset viewer.
