Changeset 21477
- Timestamp:
- Feb 13, 2009, 1:53:56 PM (17 years ago)
- Location:
- trunk/ppStack/src
- Files:
-
- 6 edited
-
ppStack.h (modified) (3 diffs)
-
ppStackArguments.c (modified) (2 diffs)
-
ppStackLoop.c (modified) (16 diffs)
-
ppStackMatch.c (modified) (4 diffs)
-
ppStackReadout.c (modified) (12 diffs)
-
ppStackThread.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppStack/src/ppStack.h
r21366 r21477 46 46 const psArray *maskNames, // Names of masks to read 47 47 const psArray *varianceNames, // Names of variance maps to read 48 const psArray *covariances, // Covariance matrices (already read) 48 49 const pmConfig *config // Configuration 49 50 ); … … 97 98 pmReadout *outRO, // Output readout 98 99 const psArray *readouts, // Input readouts 99 const psArray *regions, // Array with array of regions used in each PSF match 100 const psArray *kernels, // Array with array of kernels used in each PSF match 100 const psVector *mask, // Mask for input readouts 101 101 const psVector *weightings, // Weighting factors for each image 102 102 const psVector *addVariance // Additional variance for rejection … … 115 115 pmReadout *outRO, // Output readout 116 116 const psArray *readouts, // Input readouts 117 const psVector *mask, // Mask for input readouts 117 118 const psArray *rejected, // Array with pixels rejected in each image 118 const psVector *weightings // Weighting factors for each image 119 const psVector *weightings, // Weighting factors for each image 120 const psVector *addVariance // Additional variance for rejection 119 121 ); 120 122 -
trunk/ppStack/src/ppStackArguments.c
r21366 r21477 147 147 psMetadataAddF32(arguments, PS_LIST_TAIL, "-combine-sys", 0, 148 148 "Relative systematic error in combination", NAN); 149 psMetadataAddF32(arguments, PS_LIST_TAIL, "-combine-discard", 0, 150 "Discard fraction for Olympic weighted mean", NAN); 149 151 psMetadataAddStr(arguments, PS_LIST_TAIL, "-mask-val", 0, "Mask value of input bad pixels", NULL); 150 152 psMetadataAddStr(arguments, PS_LIST_TAIL, "-mask-bad", 0, "Mask value to give bad pixels", NULL); … … 232 234 } 233 235 234 VALUE_ARG_RECIPE_INT("-iter", "ITER", S32, 0); 235 VALUE_ARG_RECIPE_FLOAT("-combine-rej", "COMBINE.REJ", F32); 236 VALUE_ARG_RECIPE_FLOAT("-combine-sys", "COMBINE.SYS", F32); 237 VALUE_ARG_RECIPE_FLOAT("-threshold-mask", "THRESHOLD.MASK", F32); 238 VALUE_ARG_RECIPE_FLOAT("-image-rej", "IMAGE.REJ", F32); 239 VALUE_ARG_RECIPE_FLOAT("-deconv-limit", "DECONV.LIMIT", F32); 240 VALUE_ARG_RECIPE_INT("-rows", "ROWS", S32, 0); 241 VALUE_ARG_RECIPE_FLOAT("-poor-frac", "POOR.FRACTION", F32); 236 VALUE_ARG_RECIPE_INT("-iter", "ITER", S32, 0); 237 VALUE_ARG_RECIPE_FLOAT("-combine-rej", "COMBINE.REJ", F32); 238 VALUE_ARG_RECIPE_FLOAT("-combine-sys", "COMBINE.SYS", F32); 239 VALUE_ARG_RECIPE_FLOAT("-combine-discard", "COMBINE.DISCARD", F32); 240 VALUE_ARG_RECIPE_FLOAT("-threshold-mask", "THRESHOLD.MASK", F32); 241 VALUE_ARG_RECIPE_FLOAT("-image-rej", "IMAGE.REJ", F32); 242 VALUE_ARG_RECIPE_FLOAT("-deconv-limit", "DECONV.LIMIT", F32); 243 VALUE_ARG_RECIPE_INT("-rows", "ROWS", S32, 0); 244 VALUE_ARG_RECIPE_FLOAT("-poor-frac", "POOR.FRACTION", F32); 242 245 243 246 valueArgRecipeStr(arguments, recipe, "-mask-val", "MASK.VAL", recipe); -
trunk/ppStack/src/ppStackLoop.c
r21376 r21477 480 480 psMetadataAddF32(stats, PS_LIST_TAIL, "STAMP.NUM", PS_META_DUPLICATE_OK, 481 481 "Number of stamps", kernels->numStamps); 482 482 psMetadataAddF32(stats, PS_LIST_TAIL, "PPSTACK.WEIGHTING", PS_META_DUPLICATE_OK, 483 "Weighting for image", weightings->data.F32[i]); 483 484 } 484 485 psLogMsg("ppStack", PS_LOG_INFO, "Time to match image %d: %f sec", i, psTimerClear("PPSTACK_MATCH")); … … 495 496 writeImage(maskNames->data[i], maskHeader, readout->mask, config); 496 497 psFree(maskHeader); 498 psImageCovarianceTransfer(readout->variance, readout->covariance); 497 499 writeImage(varianceNames->data[i], hdu->header, readout->variance, config); 500 #ifdef TESTING 501 { 502 psString name = NULL; 503 psStringAppend(&name, "covariance_%d.fits", i); 504 writeImage(name, hdu->header, readout->covariance->image, config); 505 psFree(name); 506 } 507 #endif 498 508 499 509 pmCell *inCell = readout->parent; // Input cell … … 605 615 i, matchChi2->data.F32[i]); 606 616 } else { 617 psLogMsg("ppStack", PS_LOG_INFO, "Image %d has matching chi^2: %f", 618 i, matchChi2->data.F32[i]); 607 619 numGood++; 608 620 } … … 630 642 // Start threading 631 643 ppStackThreadInit(); 632 ppStackThreadData *stack = ppStackThreadDataSetup(cells, imageNames, maskNames, varianceNames, config); 644 ppStackThreadData *stack = ppStackThreadDataSetup(cells, imageNames, maskNames, varianceNames, 645 covariances, config); 633 646 if (!stack) { 634 647 psError(PS_ERR_IO, false, "Unable to initialise stack threads."); … … 729 742 psArrayAdd(job->args, 1, config); 730 743 psArrayAdd(job->args, 1, outRO); 731 psArrayAdd(job->args, 1, subRegions); 732 psArrayAdd(job->args, 1, subKernels); 744 psArrayAdd(job->args, 1, inputMask); 733 745 psArrayAdd(job->args, 1, weightings); 734 746 psArrayAdd(job->args, 1, matchChi2); … … 761 773 return false; 762 774 } 763 psFree(matchChi2);764 775 765 776 // Harvest the jobs, gathering the inspection lists … … 787 798 memDump("initial"); 788 799 } 800 801 #ifdef TESTING 802 writeImage("combined_initial.fits", NULL, outRO->image, config); 803 #endif 789 804 790 805 if (stats) { … … 828 843 psFree(rejected); 829 844 psFree(covariances); 845 psFree(matchChi2); 830 846 return false; 831 847 } … … 844 860 psFree(rejected); 845 861 psFree(covariances); 862 psFree(matchChi2); 846 863 return false; 847 864 } … … 939 956 psFree(outRO); 940 957 psFree(covariances); 958 psFree(matchChi2); 941 959 return false; 942 960 } … … 969 987 psFree(outRO); 970 988 psFree(covariances); 989 psFree(matchChi2); 971 990 return false; 972 991 } … … 981 1000 psArrayAdd(job->args, 1, config); 982 1001 psArrayAdd(job->args, 1, outRO); 1002 psArrayAdd(job->args, 1, inputMask); 983 1003 psArrayAdd(job->args, 1, rejected); 984 1004 psArrayAdd(job->args, 1, weightings); 1005 psArrayAdd(job->args, 1, matchChi2); 985 1006 if (!psThreadJobAddPending(job)) { 986 1007 psFree(job); … … 991 1012 psFree(outRO); 992 1013 psFree(covariances); 1014 psFree(matchChi2); 993 1015 return false; 994 1016 } … … 1004 1026 psFree(outRO); 1005 1027 psFree(covariances); 1028 psFree(matchChi2); 1006 1029 return false; 1007 1030 } … … 1009 1032 1010 1033 memDump("final"); 1034 1035 #ifdef TESTING 1036 writeImage("combined_final.fits", NULL, outRO->image, config); 1037 #endif 1011 1038 1012 1039 // Sum covariance matrices … … 1019 1046 outRO->covariance = psImageCovarianceSum(covariances); 1020 1047 psFree(covariances); 1048 psFree(matchChi2); 1021 1049 1022 1050 if (stats) { -
trunk/ppStack/src/ppStackMatch.c
r21366 r21477 170 170 assert(kernels && !*kernels); 171 171 assert(config); 172 *weighting = 0.0; 172 173 173 174 psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSTACK_RECIPE); // ppStack recipe … … 260 261 pmSubtractionAnalysis(readout->analysis, kernels, region, 261 262 readout->image->numCols, readout->image->numRows); 263 264 psKernel *kernel = pmSubtractionKernel(kernels, 0.0, 0.0, false); // Convolution kernel 265 psKernel *covar = psImageCovarianceCalculate(kernel, readout->covariance); // New covariance matrix 266 psFree(readout->covariance); 267 readout->covariance = covar; 268 psFree(kernel); 269 262 270 } else { 263 271 #endif … … 541 549 } 542 550 psFree(iter); 543 *chi2 /= num;551 *chi2 /= psImageCovarianceFactor(readout->covariance) * num; 544 552 } 545 553 … … 579 587 (void)psBinaryOp(readout->image, readout->image, "-", 580 588 psScalarAlloc(psStatsGetValue(bg, PS_STAT_ROBUST_MEDIAN), PS_TYPE_F32)); 581 *weighting = 1.0 / PS_SQR(psStatsGetValue(bg, PS_STAT_ROBUST_STDEV)); 582 psMetadataAddF32(readout->analysis, PS_LIST_TAIL, "PPSTACK.WEIGHTING", 0, 583 "Weighting by 1/noise^2 for stack", 584 1.0 / PS_SQR(psStatsGetValue(bg, PS_STAT_ROBUST_STDEV))); 585 } 589 } 590 591 // Measure the variance level for the weighting 592 if (!psImageBackground(bg, NULL, readout->variance, readout->mask, maskVal | maskBad, rng)) { 593 psError(PS_ERR_UNKNOWN, false, "Can't measure mean variance for image."); 594 psFree(output); 595 return false; 596 } 597 *weighting = 1.0 / (psStatsGetValue(bg, PS_STAT_ROBUST_MEDIAN) * 598 psImageCovarianceFactor(readout->covariance)); 599 psMetadataAddF32(readout->analysis, PS_LIST_TAIL, "PPSTACK.WEIGHTING", 0, 600 "Weighting by 1/noise^2 for stack", *weighting); 601 586 602 psFree(bg); 587 603 -
trunk/ppStack/src/ppStackReadout.c
r21183 r21477 10 10 #include "ppStack.h" 11 11 12 //#define TESTING // Write debugging output?13 14 12 bool ppStackReadoutInitialThread(psThreadJob *job) 15 13 { … … 20 18 pmConfig *config = args->data[1]; // Configuration 21 19 pmReadout *outRO = args->data[2]; // Output readout 22 psArray *subRegions = args->data[3]; // Regions for PSF-matching 23 psArray *subKernels = args->data[4]; // Kernels for PSF-matching 24 psVector *weightings = args->data[5]; // Weightings (1/noise^2) for each image 25 psVector *addVariance = args->data[6]; // Additional variance when rejecting 26 27 psArray *inspect = ppStackReadoutInitial(config, outRO, thread->readouts, subRegions, subKernels, 20 psVector *mask = args->data[3]; // Mask for inputs 21 psVector *weightings = args->data[4]; // Weightings (1/noise^2) for each image 22 psVector *addVariance = args->data[5]; // Additional variance when rejecting 23 24 psArray *inspect = ppStackReadoutInitial(config, outRO, thread->readouts, mask, 28 25 weightings, addVariance); 29 26 … … 42 39 pmConfig *config = args->data[1]; // Configuration 43 40 pmReadout *outRO = args->data[2]; // Output readout 44 psArray *rejected = args->data[3]; // Rejected pixels 45 psVector *weightings = args->data[4]; // Weighting (1/noise^2) for each image 46 47 bool status = ppStackReadoutFinal(config, outRO, thread->readouts, rejected, 48 weightings); // Status of operation 41 psVector *mask = args->data[3]; // Mask for inputs 42 psArray *rejected = args->data[4]; // Rejected pixels 43 psVector *weightings = args->data[5]; // Weighting (1/noise^2) for each image 44 psVector *addVariance = args->data[6]; // Weighting (1/noise^2) for each image 45 46 bool status = ppStackReadoutFinal(config, outRO, thread->readouts, mask, rejected, 47 weightings, addVariance); // Status of operation 49 48 50 49 thread->busy = false; … … 85 84 86 85 psArray *ppStackReadoutInitial(const pmConfig *config, pmReadout *outRO, const psArray *readouts, 87 const psArray *regions, const psArray *kernels, const psVector *weightings, 88 const psVector *addVariance) 86 const psVector *mask, const psVector *weightings, const psVector *addVariance) 89 87 { 90 88 assert(config); 91 89 assert(outRO); 92 90 assert(readouts); 93 assert(regions); 94 assert(kernels); 95 assert(readouts->n == regions->n); 96 assert(regions->n == kernels->n); 91 assert(mask && mask->n == readouts->n && mask->type.type == PS_TYPE_VECTOR_MASK); 97 92 assert(weightings && weightings->n == readouts->n && weightings->type.type == PS_TYPE_F32); 98 93 assert(addVariance && addVariance->n == readouts->n && addVariance->type.type == PS_TYPE_F32); … … 107 102 float combineRej = psMetadataLookupF32(NULL, recipe, "COMBINE.REJ"); // Combination threshold 108 103 float combineSys = psMetadataLookupF32(NULL, recipe, "COMBINE.SYS"); // Combination systematic error 104 float combineDiscard = psMetadataLookupF32(NULL, recipe, "COMBINE.DISCARD"); // Olympic discard fraction 109 105 bool useVariance = psMetadataLookupBool(&mdok, recipe, "VARIANCE"); // Use variance for rejection? 110 106 bool safe = psMetadataLookupBool(&mdok, recipe, "SAFE"); // Be safe when combining small numbers of pixels … … 123 119 for (int i = 0; i < num; i++) { 124 120 pmReadout *ro = readouts->data[i]; 125 if (!ro ) {121 if (!ro || mask->data.PS_TYPE_VECTOR_MASK_DATA[i]) { 126 122 // Bad image 127 123 continue; … … 148 144 } 149 145 150 if (!pmStackCombine(outRO, stack, maskVal | maskBad, maskBad, kernelSize, iter, combineRej, combineSys,151 true, useVariance, safe)) {146 if (!pmStackCombine(outRO, stack, maskVal | maskBad, maskBad, kernelSize, iter, 147 combineRej, combineSys, combineDiscard, true, useVariance, safe)) { 152 148 psError(PS_ERR_UNKNOWN, false, "Unable to combine input readouts with rejection."); 153 149 psFree(stack); 154 150 return false; 155 151 } 156 157 #ifdef TESTING158 {159 psString name = NULL; // Name of image160 psStringAppend(&name, "combined_initial_%03d.fits", sectionNum);161 psFits *fits = psFitsOpen(name, "w");162 psFree(name);163 psFitsWriteImage(fits, NULL, outRO->image, 0, NULL);164 psFitsClose(fits);165 }166 #endif167 152 168 153 // Save list of pixels to inspect … … 189 174 190 175 bool ppStackReadoutFinal(const pmConfig *config, pmReadout *outRO, const psArray *readouts, 191 const psArray *rejected, const psVector *weightings) 176 const psVector *mask, const psArray *rejected, const psVector *weightings, 177 const psVector *addVariance) 192 178 { 193 179 assert(config); … … 196 182 assert(rejected); 197 183 assert(readouts->n == rejected->n); 184 assert(mask && mask->n == readouts->n && mask->type.type == PS_TYPE_VECTOR_MASK); 198 185 assert(weightings && weightings->n == readouts->n && weightings->type.type == PS_TYPE_F32); 199 186 … … 217 204 int numGood = num; // Number of good inputs: images that haven't been completely rejected 218 205 for (int i = 0; i < num; i++) { 219 if (!rejected->data[i]) { 206 pmReadout *ro = readouts->data[i]; 207 if (!ro || !rejected->data[i] || mask->data.PS_TYPE_VECTOR_MASK_DATA[i]) { 220 208 // Image completely rejected 221 209 numGood--; 222 210 continue; 223 211 } 224 225 pmReadout *ro = readouts->data[i];226 assert(ro);227 212 228 213 #if 0 … … 242 227 } 243 228 244 pmStackData *data = pmStackDataAlloc(ro, weightings->data.F32[i], NAN);229 pmStackData *data = pmStackDataAlloc(ro, weightings->data.F32[i], addVariance->data.F32[i]); 245 230 data->reject = psMemIncrRefCounter(rejected->data[i]); 246 231 stack->data[i] = data; 247 232 } 248 233 249 if (!pmStackCombine(outRO, stack, maskVal | maskBad, maskBad, 0, 0, NAN, NAN, 234 if (!pmStackCombine(outRO, stack, maskVal | maskBad, maskBad, 0, 0, NAN, NAN, NAN, 250 235 numGood != num, useVariance, false)) { 251 236 psError(PS_ERR_UNKNOWN, false, "Unable to combine input readouts."); … … 254 239 } 255 240 256 #ifdef TESTING257 {258 psString name = NULL; // Name of image259 psStringAppend(&name, "combined_final_%03d.fits", sectionNum);260 psFits *fits = psFitsOpen(name, "w");261 psFree(name);262 psFitsWriteImage(fits, NULL, outRO->image, 0, NULL);263 psFitsClose(fits);264 }265 #endif266 267 241 pmCell *outCell = outRO->parent; // Output cell 268 242 pmChip *outChip = outCell->parent; // Output chip -
trunk/ppStack/src/ppStackThread.c
r21377 r21477 49 49 ppStackThreadData *ppStackThreadDataSetup(const psArray *cells, const psArray *imageNames, 50 50 const psArray *maskNames, const psArray *varianceNames, 51 const p mConfig *config)51 const psArray *covariances, const pmConfig *config) 52 52 { 53 53 PS_ASSERT_ARRAY_NON_NULL(cells, NULL); … … 55 55 PS_ASSERT_ARRAYS_SIZE_EQUAL(cells, maskNames, NULL); 56 56 PS_ASSERT_ARRAYS_SIZE_EQUAL(cells, varianceNames, NULL); 57 PS_ASSERT_ARRAYS_SIZE_EQUAL(cells, covariances, NULL); 57 58 58 59 ppStackThreadData *stack = psAlloc(sizeof(ppStackThreadData)); // Thread data, to return … … 98 99 continue; 99 100 } 100 readouts->data[j] = pmReadoutAlloc(cell); 101 pmReadout *ro = pmReadoutAlloc(cell); // Readout for thread 102 ro->covariance = psMemIncrRefCounter(covariances->data[j]); 103 readouts->data[j] = ro; 101 104 } 102 105 threads->data[i] = ppStackThreadAlloc(readouts); … … 236 239 237 240 { 238 psThreadTask *task = psThreadTaskAlloc("PPSTACK_INITIAL_COMBINE", 7);241 psThreadTask *task = psThreadTaskAlloc("PPSTACK_INITIAL_COMBINE", 6); 239 242 task->function = &ppStackReadoutInitialThread; 240 243 psThreadTaskAdd(task); … … 250 253 251 254 { 252 psThreadTask *task = psThreadTaskAlloc("PPSTACK_FINAL_COMBINE", 5);255 psThreadTask *task = psThreadTaskAlloc("PPSTACK_FINAL_COMBINE", 7); 253 256 task->function = &ppStackReadoutFinalThread; 254 257 psThreadTaskAdd(task);
Note:
See TracChangeset
for help on using the changeset viewer.
