- Timestamp:
- Mar 29, 2010, 3:55:49 PM (16 years ago)
- Location:
- branches/eam_branches/20100225
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
ppStack/src/ppStackCombineFinal.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/20100225
- Property svn:mergeinfo changed
-
branches/eam_branches/20100225/ppStack/src/ppStackCombineFinal.c
r27004 r27517 14 14 //#define TESTING // Enable test output 15 15 16 bool ppStackCombineFinal(p mReadout *target, ppStackThreadData *stack, psArray *covariances,17 p pStackOptions *options, pmConfig *config, bool safe, bool normalise)16 bool ppStackCombineFinal(ppStackThreadData *stack, psArray *covariances, ppStackOptions *options, 17 pmConfig *config, bool safe, bool normalise, bool grow) 18 18 { 19 19 psAssert(stack, "Require stack"); … … 21 21 psAssert(config, "Require configuration"); 22 22 23 if (!target->mask) { 24 target->mask = psImageAlloc(target->image->numCols, target->image->numRows, PS_TYPE_IMAGE_MASK); 23 pmReadout *outRO = options->outRO; // Output readout 24 pmReadout *expRO = options->expRO; // Exposure readout 25 int numCols = outRO->image->numCols, numRows = outRO->image->numRows; // Size of image 26 27 psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSTACK_RECIPE); // ppStack recipe 28 psAssert(recipe, "We've thrown an error on this before."); 29 float poorFrac = psMetadataLookupF32(NULL, recipe, "POOR.FRACTION"); // Fraction for "poor" 30 31 // Grow the list of rejected pixels, if desired 32 psArray *reject = psArrayAlloc(options->num); // Pixels rejected for each image 33 for (int i = 0; i < options->num; i++) { 34 if (options->inputMask->data.U8[i]) { 35 continue; 36 } 37 if (grow) { 38 reject->data[i] = pmStackRejectGrow(options->rejected->data[i], numCols, numRows, poorFrac, 39 options->regions->data[i], options->kernels->data[i]); 40 if (!reject->data[i]) { 41 psError(psErrorCodeLast(), false, "Unable to grow rejected pixels for image %d", i); 42 psFree(reject); 43 return false; 44 } 45 } else { 46 reject->data[i] = psMemIncrRefCounter(options->rejected->data[i]); 47 } 48 } 49 50 if (!outRO->mask) { 51 outRO->mask = psImageAlloc(numCols, numRows, PS_TYPE_IMAGE_MASK); 52 } 53 if (!expRO->mask) { 54 expRO->mask = psImageAlloc(numCols, numRows, PS_TYPE_IMAGE_MASK); 25 55 } 26 56 … … 32 62 // Something went wrong 33 63 psError(psErrorCodeLast(), false, "Unable to read chunk %d", numChunk); 64 psFree(reject); 34 65 return false; 35 66 } … … 39 70 } 40 71 41 // call: ppStackReadoutFinal(config, target, readouts, rejected)72 // call: ppStackReadoutFinal(config, outRO, readouts, rejected) 42 73 psThreadJob *job = psThreadJobAlloc("PPSTACK_FINAL_COMBINE"); // Job to start 43 psArrayAdd(job->args, 1, target);44 74 psArrayAdd(job->args, 1, thread); 75 psArrayAdd(job->args, 1, reject); 45 76 psArrayAdd(job->args, 1, options); 46 77 psArrayAdd(job->args, 1, config); … … 49 80 if (!psThreadJobAddPending(job)) { 50 81 psFree(job); 82 psFree(reject); 51 83 return false; 52 84 } … … 56 88 if (!psThreadPoolWait(true)) { 57 89 psError(psErrorCodeLast(), false, "Unable to do final combination."); 90 psFree(reject); 58 91 return false; 59 92 } 93 94 psFree(reject); 60 95 61 96 // Sum covariance matrices … … 77 112 } 78 113 if (sumWeights > 0.0) { 79 target->covariance = psImageCovarianceSum(covariances);80 psBinaryOp( target->covariance->image, target->covariance->image, "/",114 outRO->covariance = psImageCovarianceSum(covariances); 115 psBinaryOp(outRO->covariance->image, outRO->covariance->image, "/", 81 116 psScalarAlloc(sumWeights, PS_TYPE_F32)); 82 psImageCovarianceTransfer( target->variance, target->covariance);117 psImageCovarianceTransfer(outRO->variance, outRO->covariance); 83 118 } 84 119 } else { 85 target->covariance = psImageCovarianceNone();120 outRO->covariance = psImageCovarianceNone(); 86 121 } 87 122 … … 99 134 wcsDone = true; 100 135 pmHDU *inHDU = pmHDUFromCell(inRO->parent); // Template HDU 101 pmHDU *outHDU = pmHDUFromCell( target->parent); // Output HDU102 pmChip *outChip = target->parent->parent; // Output chip136 pmHDU *outHDU = pmHDUFromCell(outRO->parent); // Output HDU 137 pmChip *outChip = outRO->parent->parent; // Output chip 103 138 pmFPA *outFPA = outChip->parent; // Output FPA 104 139 if (!outHDU || !inHDU) { … … 123 158 } 124 159 160 // Set exposure time correctly 161 { 162 float exptime = 0.0; // Summed exposure time 163 for (int i = 0; i < options->num; i++) { 164 if (options->inputMask) { 165 continue; 166 } 167 exptime += options->exposures->data.F32[i]; 168 } 169 170 { 171 psMetadataItem *item = psMetadataLookup(outRO->parent->concepts, "CELL.EXPOSURE"); 172 item->data.F32 = exptime; 173 } 174 { 175 psMetadataItem *item = psMetadataLookup(outRO->parent->parent->parent->concepts, "FPA.EXPOSURE"); 176 item->data.F32 = exptime; 177 } 178 } 179 125 180 // Put version information into the header 126 pmHDU *hdu = pmHDUFromCell( target->parent);181 pmHDU *hdu = pmHDUFromCell(outRO->parent); 127 182 if (!hdu) { 128 183 psError(PPSTACK_ERR_PROG, false, "Unable to find HDU for output."); … … 140 195 psStringAppend(&name, "combined_image_final_%d.fits", pass); 141 196 pass++; 142 ppStackWriteImage(name, NULL, target->image, config);197 ppStackWriteImage(name, NULL, outRO->image, config); 143 198 psStringSubstitute(&name, "mask", "image"); 144 ppStackWriteImage(name, NULL, target->mask, config);199 ppStackWriteImage(name, NULL, outRO->mask, config); 145 200 psStringSubstitute(&name, "variance", "mask"); 146 ppStackWriteImage(name, NULL, target->variance, config);201 ppStackWriteImage(name, NULL, outRO->variance, config); 147 202 psFree(name); 148 203 149 pmStackVisualPlotTestImage( target->image, "combined_image_final.fits");204 pmStackVisualPlotTestImage(outRO->image, "combined_image_final.fits"); 150 205 #endif 151 206
Note:
See TracChangeset
for help on using the changeset viewer.
