- Timestamp:
- May 3, 2010, 8:50:52 AM (16 years ago)
- Location:
- branches/simtest_nebulous_branches
- Files:
-
- 3 edited
-
. (modified) (1 prop)
-
ppStack/src (modified) (1 prop)
-
ppStack/src/ppStackCombineFinal.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/simtest_nebulous_branches
- Property svn:mergeinfo changed
-
branches/simtest_nebulous_branches/ppStack/src
- Property svn:ignore
-
old new 10 10 stamp-h1 11 11 ppStackVersionDefinitions.h 12 ppStackErrorCodes.c 13 ppStackErrorCodes.h
-
- Property svn:ignore
-
branches/simtest_nebulous_branches/ppStack/src/ppStackCombineFinal.c
r23769 r27840 10 10 #include "ppStackLoop.h" 11 11 12 bool ppStackCombineFinal(ppStackThreadData *stack, ppStackOptions *options, pmConfig *config) 12 #define WCS_TOLERANCE 0.001 // Tolerance for WCS 13 14 //#define TESTING // Enable test output 15 16 bool ppStackCombineFinal(ppStackThreadData *stack, psArray *covariances, ppStackOptions *options, 17 pmConfig *config, bool safe, bool normalise, bool grow) 13 18 { 14 19 psAssert(stack, "Require stack"); 15 20 psAssert(options, "Require options"); 16 21 psAssert(config, "Require configuration"); 22 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); 55 } 17 56 18 57 stack->lastScan = 0; // Reset read … … 22 61 if (!status) { 23 62 // Something went wrong 24 psError(PS_ERR_UNKNOWN, false, "Unable to read chunk %d", numChunk); 63 psError(psErrorCodeLast(), false, "Unable to read chunk %d", numChunk); 64 psFree(reject); 25 65 return false; 26 66 } … … 33 73 psThreadJob *job = psThreadJobAlloc("PPSTACK_FINAL_COMBINE"); // Job to start 34 74 psArrayAdd(job->args, 1, thread); 75 psArrayAdd(job->args, 1, reject); 35 76 psArrayAdd(job->args, 1, options); 36 77 psArrayAdd(job->args, 1, config); 78 PS_ARRAY_ADD_SCALAR(job->args, safe, PS_TYPE_U8); 79 PS_ARRAY_ADD_SCALAR(job->args, normalise, PS_TYPE_U8); 37 80 if (!psThreadJobAddPending(job)) { 38 81 psFree(job); 82 psFree(reject); 39 83 return false; 40 84 } … … 43 87 44 88 if (!psThreadPoolWait(true)) { 45 psError(PS_ERR_UNKNOWN, false, "Unable to do final combination."); 89 psError(psErrorCodeLast(), false, "Unable to do final combination."); 90 psFree(reject); 46 91 return false; 47 92 } 48 93 94 psFree(reject); 95 49 96 // Sum covariance matrices 50 double sumWeights = 0.0; // Sum of weights 51 for (int i = 0; i < options->num; i++) { 52 if (options->inputMask->data.U8[i]) { 53 psFree(options->covariances->data[i]); 54 options->covariances->data[i] = NULL; 97 if (covariances) { 98 outRO->covariance = psImageCovarianceAverageWeighted(covariances, options->weightings); 99 } else { 100 outRO->covariance = psImageCovarianceNone(); 101 } 102 103 // Propagate WCS 104 bool wcsDone = false; // Have we done the WCS? 105 for (int i = 0; i < options->num && !wcsDone; i++) { 106 if (options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i]) { 55 107 continue; 56 108 } 57 psKernel *covar = options->covariances->data[i]; // Covariance matrix 58 float weight = options->weightings->data.F32[i]; // Weight to apply 59 psBinaryOp(covar->image, covar->image, "*", psScalarAlloc(weight, PS_TYPE_F32)); 60 sumWeights += weight; 109 110 ppStackThread *thread = stack->threads->data[0]; // Representative stack 111 pmReadout *inRO = thread->readouts->data[i]; // Template readout 112 if (inRO && !wcsDone) { 113 // Copy astrometry over 114 wcsDone = true; 115 pmHDU *inHDU = pmHDUFromCell(inRO->parent); // Template HDU 116 pmHDU *outHDU = pmHDUFromCell(outRO->parent); // Output HDU 117 pmChip *outChip = outRO->parent->parent; // Output chip 118 pmFPA *outFPA = outChip->parent; // Output FPA 119 if (!outHDU || !inHDU) { 120 psWarning("Unable to find HDU at FPA level to copy astrometry."); 121 } else { 122 if (!pmAstromReadWCS(outFPA, outChip, inHDU->header, 1.0)) { 123 psErrorClear(); 124 psWarning("Unable to read WCS astrometry from input FPA."); 125 wcsDone = false; 126 } else { 127 if (!outHDU->header) { 128 outHDU->header = psMetadataAlloc(); 129 } 130 if (!pmAstromWriteWCS(outHDU->header, outFPA, outChip, WCS_TOLERANCE)) { 131 psErrorClear(); 132 psWarning("Unable to write WCS astrometry to output FPA."); 133 wcsDone = false; 134 } 135 } 136 } 137 } 61 138 } 62 pmReadout *outRO = options->outRO; // Output readout 63 outRO->covariance = psImageCovarianceSum(options->covariances); 64 psBinaryOp(outRO->covariance->image, outRO->covariance->image, "/", 65 psScalarAlloc(sumWeights, PS_TYPE_F32)); 66 psFree(options->covariances); options->covariances = NULL; 67 psImageCovarianceTransfer(outRO->variance, outRO->covariance); 139 140 // Set exposure time correctly 141 { 142 float exptime = 0.0; // Summed exposure time 143 for (int i = 0; i < options->num; i++) { 144 if (options->inputMask->data.U8[i]) { 145 continue; 146 } 147 exptime += options->exposures->data.F32[i]; 148 } 149 150 { 151 psMetadataItem *item = psMetadataLookup(outRO->parent->concepts, "CELL.EXPOSURE"); 152 item->data.F32 = exptime; 153 } 154 { 155 psMetadataItem *item = psMetadataLookup(outRO->parent->parent->parent->concepts, "FPA.EXPOSURE"); 156 item->data.F32 = exptime; 157 } 158 } 159 160 // Put version information into the header 161 pmHDU *hdu = pmHDUFromCell(outRO->parent); 162 if (!hdu) { 163 psError(PPSTACK_ERR_PROG, false, "Unable to find HDU for output."); 164 return false; 165 } 166 if (!hdu->header) { 167 hdu->header = psMetadataAlloc(); 168 } 169 ppStackVersionHeader(hdu->header); 170 68 171 69 172 #ifdef TESTING 70 pmStackVisualPlotTestImage(outRO->image, "combined_initial.fits"); 71 ppStackWriteImage("combined_final.fits", NULL, outRO->image, config); 173 static int pass = 0; // Pass through 174 psString name = NULL; // Name of file 175 psStringAppend(&name, "combined_image_final_%d.fits", pass); 176 pass++; 177 ppStackWriteImage(name, NULL, outRO->image, config); 178 psStringSubstitute(&name, "mask", "image"); 179 ppStackWriteImage(name, NULL, outRO->mask, config); 180 psStringSubstitute(&name, "variance", "mask"); 181 ppStackWriteImage(name, NULL, outRO->variance, config); 182 psFree(name); 183 184 pmStackVisualPlotTestImage(outRO->image, "combined_image_final.fits"); 72 185 #endif 73 186
Note:
See TracChangeset
for help on using the changeset viewer.
