Changeset 26667
- Timestamp:
- Jan 22, 2010, 10:58:17 AM (16 years ago)
- Location:
- branches/eam_branches/20091201
- Files:
-
- 6 edited
-
ppSub/src/ppSubMatchPSFs.c (modified) (3 diffs)
-
ppSub/src/ppSubReadoutJpeg.c (modified) (3 diffs)
-
psModules/src/imcombine/pmSubtraction.c (modified) (7 diffs)
-
psModules/src/imcombine/pmSubtractionEquation.c (modified) (3 diffs)
-
psModules/src/imcombine/pmSubtractionMatch.c (modified) (12 diffs)
-
psModules/src/imcombine/pmSubtractionMatch.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/20091201/ppSub/src/ppSubMatchPSFs.c
r26649 r26667 131 131 } 132 132 133 134 133 float inFWHM = subImagePSF(data, inRO, inSources); // FWHM for input 135 134 float refFWHM = subImagePSF(data, refRO, refSources); // FWHM for reference … … 139 138 return true; 140 139 } 141 142 // float diff = sqrtf(PS_SQR(PS_MAX(inFWHM, refFWHM)) - PS_SQR(PS_MIN(inFWHM, refFWHM))); // Difference143 float diff = PS_MAX(inFWHM, refFWHM);144 140 145 141 float scaleRef = psMetadataLookupF32(NULL, recipe, "SCALE.REF"); // Reference for scaling … … 153 149 } 154 150 155 float scale = diff / scaleRef; // Scaling factor 156 if (scale < scaleMin) { 157 scale = scaleMin; 158 } 159 if (scale > scaleMax) { 160 scale = scaleMax; 161 } 162 163 for (int i = 0; i < kernelWidths->n; i++) { 164 kernelWidths->data.F32[i] *= scale; 165 } 166 *kernelSize = *kernelSize * scale + 0.5; 167 *stampSize = *stampSize * scale + 0.5; 168 169 psLogMsg("ppSub", PS_LOG_INFO, "Scaled kernel parameters by %f: %d %d", scale, *kernelSize, *stampSize); 151 if (!pmSubtractionParamsScale(kernelSize, stampSize, kernelWidths, inFWHM, refFWHM, 152 scaleRef, scaleMin, scaleMax)) { 153 psError(PS_ERR_UNKNOWN, false, "Unable to scale parameters."); 154 return false; 155 } 170 156 171 157 return true; -
branches/eam_branches/20091201/ppSub/src/ppSubReadoutJpeg.c
r26597 r26667 50 50 } 51 51 52 bool ppSubResidualSampleJpeg(pmConfig *config) { 52 bool ppSubResidualSampleJpeg(pmConfig *config) 53 { 54 return true; 53 55 54 56 pmFPAview *view = ppSubViewReadout(); // View to readout … … 67 69 psMetadataItem *item = NULL;// Item from iteration 68 70 while ((item = psMetadataGetAndIncrement(iter))) { 69 assert(item->type == PS_DATA_ARRAY);70 psArray *sampleStamps = item->data.V; 71 samples = psArrayAdd(samples, 16, sampleStamps);71 assert(item->type == PS_DATA_ARRAY); 72 psArray *sampleStamps = item->data.V; 73 samples = psArrayAdd(samples, 16, sampleStamps); 72 74 } 73 75 psFree(iter); … … 108 110 for (int i = 0; i < samples->n; i++) { 109 111 110 int xBlock = i % NXblock; 111 int yBlock = i / NYblock; 112 113 psArray *kernels = samples->data[i]; 112 int xBlock = i % NXblock; 113 int yBlock = i / NYblock; 114 114 115 for (int j = 0; j < kernels->n; j++) { 115 psArray *kernels = samples->data[i]; 116 116 117 psImage *kernel = kernels->data[j]; 117 for (int j = 0; j < kernels->n; j++) { 118 118 119 int xSub = j % 3; 120 int ySub = j / 3; 119 psImage *kernel = kernels->data[j]; 121 120 122 int xPix = xBlock * (3 * (DX + innerBorder) + outerBorder) + xSub * (DX + innerBorder);123 int yPix = yBlock * (3 * (DX + innerBorder) + outerBorder) + ySub * (DY + innerBorder);121 int xSub = j % 3; 122 int ySub = j / 3; 124 123 125 for (int y = 0; y < kernel->numRows; y++) { 126 for (int x = 0; x < kernel->numCols; x++) { 127 readout->image->data.F32[y + yPix][x + xPix] = kernel->data.F32[y][x]; 128 } 129 } 130 } 124 int xPix = xBlock * (3 * (DX + innerBorder) + outerBorder) + xSub * (DX + innerBorder); 125 int yPix = yBlock * (3 * (DX + innerBorder) + outerBorder) + ySub * (DY + innerBorder); 126 127 for (int y = 0; y < kernel->numRows; y++) { 128 for (int x = 0; x < kernel->numCols; x++) { 129 readout->image->data.F32[y + yPix][x + xPix] = kernel->data.F32[y][x]; 130 } 131 } 132 } 131 133 } 132 134 133 135 { 134 psFits *fits = psFitsOpen ("resid.stamps.fits", "w");135 psFitsWriteImage (fits, NULL, readout->image, 0, NULL);136 psFitsClose (fits);136 psFits *fits = psFitsOpen ("resid.stamps.fits", "w"); 137 psFitsWriteImage (fits, NULL, readout->image, 0, NULL); 138 psFitsClose (fits); 137 139 } 138 140 -
branches/eam_branches/20091201/psModules/src/imcombine/pmSubtraction.c
r26579 r26667 66 66 // Contribute to an image of the solved kernel component using the preCalculated image 67 67 static void solvedKernelPreCalc(psKernel *kernel, // Kernel, updated 68 const pmSubtractionKernels *kernels, // Kernel basis functions69 float value, // Normalisation value for basis function70 int index // Index of basis function of interest68 const pmSubtractionKernels *kernels, // Kernel basis functions 69 float value, // Normalisation value for basis function 70 int index // Index of basis function of interest 71 71 ) 72 72 { … … 162 162 break; 163 163 } 164 case PM_SUBTRACTION_KERNEL_ISIS: 165 case PM_SUBTRACTION_KERNEL_ISIS_RADIAL: 166 case PM_SUBTRACTION_KERNEL_HERM: 164 case PM_SUBTRACTION_KERNEL_ISIS: 165 case PM_SUBTRACTION_KERNEL_ISIS_RADIAL: 166 case PM_SUBTRACTION_KERNEL_HERM: 167 167 case PM_SUBTRACTION_KERNEL_DECONV_HERM: { 168 solvedKernelPreCalc(kernel, kernels, value, i); 169 break;168 solvedKernelPreCalc(kernel, kernels, value, i); 169 break; 170 170 } 171 171 case PM_SUBTRACTION_KERNEL_RINGS: { … … 460 460 // Convolve a stamp using a pre-calculated kernel basis function 461 461 static psKernel *convolveStampPreCalc(const psKernel *image, // Image to convolve 462 const pmSubtractionKernels *kernels, // Kernel basis functions463 int index, // Index of basis function of interest464 int footprint // Half-size of stamp462 const pmSubtractionKernels *kernels, // Kernel basis functions 463 int index, // Index of basis function of interest 464 int footprint // Half-size of stamp 465 465 ) 466 466 { … … 678 678 return convolved; 679 679 } 680 case PM_SUBTRACTION_KERNEL_ISIS: 681 case PM_SUBTRACTION_KERNEL_ISIS_RADIAL: 680 case PM_SUBTRACTION_KERNEL_ISIS: 681 case PM_SUBTRACTION_KERNEL_ISIS_RADIAL: 682 682 case PM_SUBTRACTION_KERNEL_HERM: 683 683 case PM_SUBTRACTION_KERNEL_DECONV_HERM: { 684 return convolveStampPreCalc(image, kernels, index, footprint);685 }684 return convolveStampPreCalc(image, kernels, index, footprint); 685 } 686 686 case PM_SUBTRACTION_KERNEL_RINGS: { 687 687 psKernel *convolved = psKernelAlloc(-footprint, footprint, -footprint, footprint); // Convolved image … … 864 864 int numGood = 0; // Number of good stamps 865 865 double newMean = 0.0; // New mean 866 psString log = NULL; // Log message 867 psStringAppend(&log, "Rejecting stamps, mean = %f, threshold = %f\n", mean, limit); 866 868 for (int i = 0; i < stamps->num; i++) { 867 869 pmSubtractionStamp *stamp = stamps->stamps->data[i]; // Stamp of interest … … 877 879 psTrace("psModules.imcombine", 3, "Rejecting stamp %d (%d,%d)\n", i, 878 880 (int)(stamp->x + 0.5), (int)(stamp->y + 0.5)); 881 psStringAppend(&log, "Stamp %d (%d,%d): %f\n", i, 882 (int)(stamp->x + 0.5), (int)(stamp->y + 0.5), 883 fabsf(deviations->data.F32[i] - mean)); 879 884 numRejected++; 880 885 for (int y = stamp->y - footprint; y <= stamp->y + footprint; y++) { … … 911 916 } 912 917 newMean /= numGood; 918 919 if (numRejected == 0) { 920 psStringAppend(&log, "<none>\n"); 921 } 922 psLogMsg("psModules.imcombine", PS_LOG_DETAIL, "%s", log); 923 psFree(log); 913 924 914 925 if (ds9) { -
branches/eam_branches/20091201/psModules/src/imcombine/pmSubtractionEquation.c
r26609 r26667 1425 1425 } 1426 1426 1427 psString log = psStringCopy("Deviations:\n"); // Log message with deviations 1427 1428 for (int i = 0; i < stamps->num; i++) { 1428 1429 pmSubtractionStamp *stamp = stamps->stamps->data[i]; // The stamp of interest … … 1556 1557 psTrace("psModules.imcombine", 5, "Deviation for stamp %d (%d,%d): %f\n", 1557 1558 i, (int)(stamp->x + 0.5), (int)(stamp->y + 0.5), deviations->data.F32[i]); 1559 psStringAppend(&log, "Stamp %d (%d,%d): %f\n", 1560 i, (int)(stamp->x + 0.5), (int)(stamp->y + 0.5), deviations->data.F32[i]); 1558 1561 if (!isfinite(deviations->data.F32[i])) { 1559 1562 stamp->status = PM_SUBTRACTION_STAMP_REJECTED; … … 1600 1603 1601 1604 } 1605 1606 psLogMsg("psModules.imcombine", PS_LOG_DETAIL, "%s", log); 1607 psFree(log); 1602 1608 1603 1609 // calculate and report the normalization and background for the image center -
branches/eam_branches/20091201/psModules/src/imcombine/pmSubtractionMatch.c
r26580 r26667 496 496 497 497 498 // generate the window function from the set of stamps499 if (!pmSubtractionStampsGetWindow(stamps, size)) {500 goto MATCH_ERROR;501 }498 // generate the window function from the set of stamps 499 if (!pmSubtractionStampsGetWindow(stamps, size)) { 500 goto MATCH_ERROR; 501 } 502 502 503 503 // Define kernel basis functions … … 514 514 kernels = pmSubtractionKernelsGenerate(type, size, spatialOrder, isisWidths, isisOrders, 515 515 inner, binning, ringsOrder, penalty, subMode); 516 // pmSubtractionVisualShowKernels(kernels);516 // pmSubtractionVisualShowKernels(kernels); 517 517 } 518 518 … … 568 568 } 569 569 570 // generate the window function from the set of stamps571 if (!pmSubtractionStampsGetWindow(stamps, size)) {572 goto MATCH_ERROR;573 }574 575 // XXX step 1: calculate normalization570 // generate the window function from the set of stamps 571 if (!pmSubtractionStampsGetWindow(stamps, size)) { 572 goto MATCH_ERROR; 573 } 574 575 // XXX step 1: calculate normalization 576 576 psTrace("psModules.imcombine", 3, "Calculating equation for normalization...\n"); 577 577 if (!pmSubtractionCalculateEquation(stamps, kernels, SUBMODE)) { … … 588 588 589 589 # if (SEPARATE) 590 // set USED -> CALCULATE591 pmSubtractionStampsResetStatus (stamps);592 593 // XXX step 2: calculate kernel parameters590 // set USED -> CALCULATE 591 pmSubtractionStampsResetStatus (stamps); 592 593 // XXX step 2: calculate kernel parameters 594 594 psTrace("psModules.imcombine", 3, "Calculating equation for kernels...\n"); 595 595 if (!pmSubtractionCalculateEquation(stamps, kernels, PM_SUBTRACTION_EQUATION_KERNELS)) { … … 626 626 } 627 627 628 // if we hit the max number of iterations and we have rejected stamps, re-solve628 // if we hit the max number of iterations and we have rejected stamps, re-solve 629 629 if (numRejected > 0) { 630 // XXX step 1: calculate normalization630 // XXX step 1: calculate normalization 631 631 psTrace("psModules.imcombine", 3, "Calculating equation for normalization...\n"); 632 632 if (!pmSubtractionCalculateEquation(stamps, kernels, SUBMODE)) { … … 635 635 } 636 636 637 // solve normalization637 // solve normalization 638 638 psTrace("psModules.imcombine", 3, "Solving equation for kernels...\n"); 639 639 if (!pmSubtractionSolveEquation(kernels, stamps, SUBMODE)) { … … 643 643 644 644 # if (SEPARATE) 645 // set USED -> CALCULATE646 pmSubtractionStampsResetStatus (stamps);647 648 // XXX step 2: calculate kernel parameters645 // set USED -> CALCULATE 646 pmSubtractionStampsResetStatus (stamps); 647 648 // XXX step 2: calculate kernel parameters 649 649 psTrace("psModules.imcombine", 3, "Calculating equation for normalization...\n"); 650 650 if (!pmSubtractionCalculateEquation(stamps, kernels, PM_SUBTRACTION_EQUATION_KERNELS)) { … … 653 653 } 654 654 655 // solve kernel parameters655 // solve kernel parameters 656 656 psTrace("psModules.imcombine", 3, "Solving equation for kernels...\n"); 657 657 if (!pmSubtractionSolveEquation(kernels, stamps, PM_SUBTRACTION_EQUATION_KERNELS)) { … … 992 992 return false; 993 993 } 994 # endif 994 # endif 995 995 996 996 psTrace("psModules.imcombine", 3, "Calculate %s deviations...\n", description); … … 1012 1012 if (numRejected > 0) { 1013 1013 // Allow re-fit with reduced stamps set 1014 psTrace("psModules.imcombine", 3, "Calculating %s normalization equation...\n", description);1015 if (!pmSubtractionCalculateEquation(stamps, kernels, PM_SUBTRACTION_EQUATION_ALL)) {1016 psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation.");1017 return false;1018 }1014 psTrace("psModules.imcombine", 3, "Calculating %s normalization equation...\n", description); 1015 if (!pmSubtractionCalculateEquation(stamps, kernels, PM_SUBTRACTION_EQUATION_ALL)) { 1016 psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation."); 1017 return false; 1018 } 1019 1019 1020 1020 psTrace("psModules.imcombine", 3, "Resolving %s equation...\n", description); … … 1026 1026 1027 1027 # if (SEPARATE) 1028 // set USED -> CALCULATE1029 pmSubtractionStampsResetStatus (stamps);1030 1031 psTrace("psModules.imcombine", 3, "Calculating %s normalization equation...\n", description);1032 if (!pmSubtractionCalculateEquation(stamps, kernels, PM_SUBTRACTION_EQUATION_KERNELS)) {1033 psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation.");1034 return false;1035 }1028 // set USED -> CALCULATE 1029 pmSubtractionStampsResetStatus (stamps); 1030 1031 psTrace("psModules.imcombine", 3, "Calculating %s normalization equation...\n", description); 1032 if (!pmSubtractionCalculateEquation(stamps, kernels, PM_SUBTRACTION_EQUATION_KERNELS)) { 1033 psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation."); 1034 return false; 1035 } 1036 1036 1037 1037 psTrace("psModules.imcombine", 3, "Resolving %s equation...\n", description); … … 1129 1129 } 1130 1130 1131 1132 bool pmSubtractionParamsScale(int *kernelSize, int *stampSize, psVector *widths, 1133 float fwhm1, float fwhm2, float scaleRef, float scaleMin, float scaleMax) 1134 { 1135 PS_ASSERT_PTR_NON_NULL(kernelSize, false); 1136 PS_ASSERT_PTR_NON_NULL(stampSize, false); 1137 PS_ASSERT_VECTOR_NON_NULL(widths, false); 1138 PS_ASSERT_VECTOR_TYPE(widths, PS_TYPE_F32, false); 1139 PS_ASSERT_FLOAT_LARGER_THAN(fwhm1, 0.0, false); 1140 PS_ASSERT_FLOAT_LARGER_THAN(fwhm2, 0.0, false); 1141 PS_ASSERT_FLOAT_LARGER_THAN(scaleRef, 0.0, false); 1142 PS_ASSERT_FLOAT_LARGER_THAN(scaleMin, 0.0, false); 1143 PS_ASSERT_FLOAT_LARGER_THAN(scaleMax, 0.0, false); 1144 PS_ASSERT_FLOAT_LARGER_THAN(scaleMax, scaleMin, false); 1145 1146 // float diff = sqrtf(PS_SQR(PS_MAX(fwhm1, fwhm2)) - PS_SQR(PS_MIN(fwhm1, fwhm2))); // Difference 1147 float scale = PS_MAX(fwhm1, fwhm2) / scaleRef; // Scaling factor 1148 1149 if (isfinite(scaleMin) && scale < scaleMin) { 1150 scale = scaleMin; 1151 } 1152 if (isfinite(scaleMax) && scale > scaleMax) { 1153 scale = scaleMax; 1154 } 1155 1156 for (int i = 0; i < widths->n; i++) { 1157 widths->data.F32[i] *= scale; 1158 } 1159 *kernelSize = *kernelSize * scale + 0.5; 1160 *stampSize = *stampSize * scale + 0.5; 1161 1162 psLogMsg("psModules.imcombine", PS_LOG_INFO, 1163 "Scaling kernel parameters by %f: %d %d", scale, *kernelSize, *stampSize); 1164 1165 return true; 1166 } -
branches/eam_branches/20091201/psModules/src/imcombine/pmSubtractionMatch.h
r26505 r26667 95 95 ); 96 96 97 98 /// Scale subtraction parameters according to the FWHMs of the inputs 99 bool pmSubtractionParamsScale( 100 int *kernelSize, ///< Half-size of the kernel 101 int *stampSize, ///< Half-size of the stamp (footprint) 102 psVector *widths, ///< ISIS widths 103 float fwhm1, float fwhm2, ///< FWHMs for inputs 104 float scaleRef, ///< Reference width for scaling 105 float scaleMin, ///< Minimum scaling ratio, or NAN 106 float scaleMax ///< Maximum scaling ratio, or NAN 107 ); 108 109 97 110 #endif
Note:
See TracChangeset
for help on using the changeset viewer.
