Changeset 27319
- Timestamp:
- Mar 18, 2010, 12:01:15 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 15 edited
-
ppStack/src/ppStack.c (modified) (1 diff)
-
ppStack/src/ppStack.h (modified) (1 diff)
-
ppStack/src/ppStackCleanup.c (modified) (2 diffs)
-
ppStack/src/ppStackCombineFinal.c (modified) (5 diffs)
-
ppStack/src/ppStackCombinePrepare.c (modified) (4 diffs)
-
ppStack/src/ppStackFiles.c (modified) (2 diffs)
-
ppStack/src/ppStackFinish.c (modified) (2 diffs)
-
ppStack/src/ppStackLoop.c (modified) (5 diffs)
-
ppStack/src/ppStackLoop.h (modified) (3 diffs)
-
ppStack/src/ppStackPhotometry.c (modified) (1 diff)
-
ppStack/src/ppStackReadout.c (modified) (1 diff)
-
ppStack/src/ppStackReject.c (modified) (4 diffs)
-
ppStack/src/ppStackThread.c (modified) (1 diff)
-
psModules/src/imcombine/pmStackReject.c (modified) (5 diffs)
-
psModules/src/imcombine/pmStackReject.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppStack/src/ppStack.c
r27160 r27319 70 70 ppStackFileActivation(config, PPSTACK_FILES_PREPARE, true); 71 71 ppStackFileActivation(config, PPSTACK_FILES_CONVOLVE, true); 72 ppStackFileActivation(config, PPSTACK_FILES_COMBINE, true); 72 ppStackFileActivation(config, PPSTACK_FILES_STACK, true); 73 ppStackFileActivation(config, PPSTACK_FILES_UNCONV, true); 73 74 ppStackFileActivation(config, PPSTACK_FILES_PHOT, true); 74 75 if (!ppStackFilesIterateUp(config)) { -
trunk/ppStack/src/ppStack.h
r27108 r27319 27 27 PPSTACK_FILES_PREPARE, // Files for preparation 28 28 PPSTACK_FILES_CONVOLVE, // Files for convolution 29 PPSTACK_FILES_COMBINE, // Files for combination 29 PPSTACK_FILES_STACK, // Stack files 30 PPSTACK_FILES_UNCONV, // Unconvolved stack files 30 31 PPSTACK_FILES_PHOT // Files for photometry 31 32 } ppStackFileList; -
trunk/ppStack/src/ppStackCleanup.c
r27004 r27319 6 6 #include <pslib.h> 7 7 #include <psmodules.h> 8 #include <ppStats.h> 8 9 9 10 #include "ppStack.h" … … 59 60 } 60 61 62 // Statistics on output 63 if (options->stats) { 64 psTrace("ppStack", 1, "Gathering statistics on stacked image....\n"); 65 psString maskBadStr = psMetadataLookupStr(NULL, recipe, "MASK.BAD"); // Name of bits for bad 66 psImageMaskType maskBad = pmConfigMaskGet(maskBadStr, config); // Bits to mask for bad pixels 67 68 pmFPAview *view = pmFPAviewAlloc(0); // View to readout 69 view->chip = view->cell = view->readout = 0; 70 71 ppStatsFPA(options->stats, options->outRO->parent->parent->parent, view, maskBad, config); 72 73 psFree(view); 74 } 75 61 76 return true; 62 77 } -
trunk/ppStack/src/ppStackCombineFinal.c
r27004 r27319 15 15 16 16 bool ppStackCombineFinal(pmReadout *target, ppStackThreadData *stack, psArray *covariances, 17 ppStackOptions *options, pmConfig *config, bool safe, bool normalise )17 ppStackOptions *options, pmConfig *config, bool safe, bool normalise, bool grow) 18 18 { 19 19 psAssert(stack, "Require stack"); 20 20 psAssert(options, "Require options"); 21 21 psAssert(config, "Require configuration"); 22 23 int numCols = target->image->numCols, numRows = target->image->numRows; // Size of image 24 25 psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSTACK_RECIPE); // ppStack recipe 26 psAssert(recipe, "We've thrown an error on this before."); 27 float poorFrac = psMetadataLookupF32(NULL, recipe, "POOR.FRACTION"); // Fraction for "poor" 28 29 // Grow the list of rejected pixels, if desired 30 psArray *reject = psArrayAlloc(options->num); // Pixels rejected for each image 31 for (int i = 0; i < options->num; i++) { 32 if (grow) { 33 reject->data[i] = pmStackRejectGrow(options->rejected->data[i], numCols, numRows, poorFrac, 34 options->regions->data[i], options->kernels->data[i]); 35 if (!reject->data[i]) { 36 psError(psErrorCodeLast(), false, "Unable to grow rejected pixels for image %d", i); 37 psFree(reject); 38 return false; 39 } 40 } else { 41 reject->data[i] = psMemIncrRefCounter(options->rejected->data[i]); 42 } 43 } 22 44 23 45 if (!target->mask) { … … 32 54 // Something went wrong 33 55 psError(psErrorCodeLast(), false, "Unable to read chunk %d", numChunk); 56 psFree(reject); 34 57 return false; 35 58 } … … 43 66 psArrayAdd(job->args, 1, target); 44 67 psArrayAdd(job->args, 1, thread); 68 psArrayAdd(job->args, 1, reject); 45 69 psArrayAdd(job->args, 1, options); 46 70 psArrayAdd(job->args, 1, config); … … 49 73 if (!psThreadJobAddPending(job)) { 50 74 psFree(job); 75 psFree(reject); 51 76 return false; 52 77 } … … 56 81 if (!psThreadPoolWait(true)) { 57 82 psError(psErrorCodeLast(), false, "Unable to do final combination."); 83 psFree(reject); 58 84 return false; 59 85 } 86 87 psFree(reject); 60 88 61 89 // Sum covariance matrices -
trunk/ppStack/src/ppStackCombinePrepare.c
r27004 r27319 10 10 #include "ppStackLoop.h" 11 11 12 bool ppStackCombinePrepare(ppStackThreadData *stack, ppStackOptions *options, pmConfig *config) 12 bool ppStackCombinePrepare(pmReadout **ro, const char *name, ppStackFileList files, ppStackThreadData *stack, 13 ppStackOptions *options, pmConfig *config) 13 14 { 14 15 psAssert(stack, "Require stack"); … … 25 26 26 27 pmFPAfileActivate(config->files, false, NULL); 27 ppStackFileActivation(config, PPSTACK_FILES_COMBINE, true);28 ppStackFileActivation(config, files, true); 28 29 pmFPAview *view = ppStackFilesIterateDown(config); // View to readout 29 30 if (!view) { … … 31 32 } 32 33 33 pmCell *outCell = pmFPAfileThisCell(config->files, view, "PPSTACK.OUTPUT"); // Output cell 34 options->outRO = pmReadoutAlloc(outCell); // Output readout 35 36 pmCell *unconvCell = pmFPAfileThisCell(config->files, view, "PPSTACK.UNCONV"); // Unconvolved cell 37 options->unconvRO = pmReadoutAlloc(unconvCell); // Unconvolved readout 34 pmCell *cell = pmFPAfileThisCell(config->files, view, name); // Output cell 35 *ro = pmReadoutAlloc(cell); // Output readout 38 36 39 37 psFree(view); … … 44 42 psImageMaskType maskBad = pmConfigMaskGet(maskBadStr, config); // Bits to mask for bad pixels 45 43 46 if (!pmReadoutStackDefineOutput( options->outRO, col0, row0, numCols, numRows, true, true, maskBad)) {44 if (!pmReadoutStackDefineOutput(*ro, col0, row0, numCols, numRows, true, true, maskBad)) { 47 45 psError(PPSTACK_ERR_ARGUMENTS, false, "Unable to prepare output."); 48 46 return false; 49 47 } 50 48 51 options->unconvRO->image = psImageCopy(NULL, options->outRO->image, PS_TYPE_F32);52 // options->unconvRO->mask = psImageCopy(NULL, options->outRO->mask, PS_TYPE_IMAGE_MASK);53 options->unconvRO->col0 = options->outRO->col0;54 options->unconvRO->row0 = options->outRO->row0;55 56 57 58 49 return true; 59 50 } -
trunk/ppStack/src/ppStackFiles.c
r27004 r27319 21 21 // "PPSTACK.CONV.KERNEL", NULL }; 22 22 23 /// Output files for the combination 24 static char *filesCombine[] = { "PPSTACK.OUTPUT", "PPSTACK.OUTPUT.MASK", "PPSTACK.OUTPUT.VARIANCE", 25 "PPSTACK.UNCONV", "PPSTACK.UNCONV.MASK", "PPSTACK.UNCONV.VARIANCE", 26 "PPSTACK.OUTPUT.JPEG1", "PPSTACK.OUTPUT.JPEG2", NULL }; 23 /// Regular (convolved) stack files 24 static char *filesStack[] = { "PPSTACK.OUTPUT", "PPSTACK.OUTPUT.MASK", "PPSTACK.OUTPUT.VARIANCE", 25 "PPSTACK.OUTPUT.JPEG1", "PPSTACK.OUTPUT.JPEG2", NULL }; 26 /// Unconvolved stack files 27 static char *filesUnconv[] = { "PPSTACK.UNCONV", "PPSTACK.UNCONV.MASK", "PPSTACK.UNCONV.VARIANCE", NULL }; 27 28 28 29 /// Files for photometry … … 37 38 case PPSTACK_FILES_PREPARE: return filesPrepare; 38 39 case PPSTACK_FILES_CONVOLVE: return filesConvolve; 39 case PPSTACK_FILES_COMBINE: return filesCombine; 40 case PPSTACK_FILES_STACK: return filesStack; 41 case PPSTACK_FILES_UNCONV: return filesUnconv; 40 42 case PPSTACK_FILES_PHOT: return filesPhot; 41 43 default: -
trunk/ppStack/src/ppStackFinish.c
r27189 r27319 7 7 #include <pslib.h> 8 8 #include <psmodules.h> 9 #include <ppStats.h>10 9 #include <psphot.h> 11 10 … … 49 48 } 50 49 51 52 // Statistics on output53 if (options->stats) {54 psTrace("ppStack", 1, "Gathering statistics on stacked image....\n");55 psString maskBadStr = psMetadataLookupStr(NULL, recipe, "MASK.BAD"); // Name of bits for bad56 psImageMaskType maskBad = pmConfigMaskGet(maskBadStr, config); // Bits to mask for bad pixels57 58 pmFPAview *view = pmFPAviewAlloc(0); // View to readout59 view->chip = view->cell = view->readout = 0;60 61 ppStatsFPA(options->stats, options->outRO->parent->parent->parent, view, maskBad, config);62 63 psFree(view);64 }65 66 ppStackMemDump("stats");67 68 psFree(options->outRO); options->outRO = NULL;69 50 70 51 return true; -
trunk/ppStack/src/ppStackLoop.c
r27309 r27319 111 111 112 112 // Prepare for combination 113 if (!ppStackCombinePrepare(stack, options, config)) { 113 if (!ppStackCombinePrepare(&options->outRO, "PPSTACK.OUTPUT", PPSTACK_FILES_STACK, 114 stack, options, config)) { 114 115 psError(psErrorCodeLast(), false, "Unable to prepare for combination."); 115 116 psFree(stack); … … 148 149 // Final combination 149 150 psTrace("ppStack", 2, "Final stack of convolved images....\n"); 150 if (!ppStackCombineFinal(options->outRO, stack, options->convCovars, options, config, false, false)) { 151 if (!ppStackCombineFinal(options->outRO, stack, options->convCovars, options, config, 152 false, false, true)) { 151 153 psError(psErrorCodeLast(), false, "Unable to perform final combination."); 152 154 psFree(stack); … … 163 165 return false; 164 166 } 165 psLogMsg("ppStack", PS_LOG_INFO, "Stage 6: Cleanup, WCS & JPEGS: %f sec", psTimerClear("PPSTACK_STEPS")); 167 168 // Photometry 169 psTrace("ppStack", 1, "Photometering stacked image....\n"); 170 if (!ppStackPhotometry(options, config)) { 171 psError(psErrorCodeLast(), false, "Unable to perform photometry."); 172 return false; 173 } 174 psLogMsg("ppStack", PS_LOG_INFO, "Stage 6: Photometry Analysis: %f sec", psTimerClear("PPSTACK_STEPS")); 175 ppStackMemDump("photometry"); 176 177 if (!ppStackFilesIterateUp(config)) { 178 psError(psErrorCodeLast(), false, "Unable to close files."); 179 return false; 180 } 181 ppStackFileActivation(config, PPSTACK_FILES_STACK, false); 182 ppStackFileActivation(config, PPSTACK_FILES_PHOT, false); 183 options->outRO->data_exists = false; 184 options->outRO->parent->data_exists = false; 185 options->outRO->parent->parent->data_exists = false; 186 psFree(options->outRO); 187 options->outRO = NULL; 188 189 psLogMsg("ppStack", PS_LOG_INFO, "Stage 7: Cleanup, WCS & JPEGS: %f sec", psTimerClear("PPSTACK_STEPS")); 166 190 ppStackMemDump("cleanup"); 167 191 … … 177 201 return false; 178 202 } 203 204 // Prepare for combination 205 if (!ppStackCombinePrepare(&options->unconvRO, "PPSTACK.UNCONV", PPSTACK_FILES_UNCONV, 206 stack, options, config)) { 207 psError(psErrorCodeLast(), false, "Unable to prepare for combination."); 208 psFree(stack); 209 return false; 210 } 211 179 212 psTrace("ppStack", 2, "Stack of unconvolved images....\n"); 180 if (!ppStackCombineFinal(options->unconvRO, stack, options->origCovars, options, config, false, true)) { 213 if (!ppStackCombineFinal(options->unconvRO, stack, options->origCovars, options, config, 214 false, true, false)) { 181 215 psError(psErrorCodeLast(), false, "Unable to perform unconvolved combination."); 182 216 psFree(stack); 183 217 return false; 184 218 } 185 psLogMsg("ppStack", PS_LOG_INFO, "Stage 7: Unconvolved Stack: %f sec", psTimerClear("PPSTACK_STEPS"));219 psLogMsg("ppStack", PS_LOG_INFO, "Stage 8: Unconvolved Stack: %f sec", psTimerClear("PPSTACK_STEPS")); 186 220 ppStackMemDump("unconv"); 221 222 if (!ppStackFilesIterateUp(config)) { 223 psError(psErrorCodeLast(), false, "Unable to close files."); 224 psFree(stack); 225 return false; 226 } 227 ppStackFileActivation(config, PPSTACK_FILES_UNCONV, false); 228 options->unconvRO->data_exists = false; 229 options->unconvRO->parent->data_exists = false; 230 options->unconvRO->parent->parent->data_exists = false; 231 psFree(options->unconvRO); 232 options->unconvRO = NULL; 187 233 188 234 psFree(stack); … … 190 236 psFree(options->cells); options->cells = NULL; 191 237 #endif 192 193 // Photometry194 psTrace("ppStack", 1, "Photometering stacked image....\n");195 if (!ppStackPhotometry(options, config)) {196 psError(psErrorCodeLast(), false, "Unable to perform photometry.");197 return false;198 }199 psLogMsg("ppStack", PS_LOG_INFO, "Stage 8: Photometry Analysis: %f sec", psTimerClear("PPSTACK_STEPS"));200 ppStackMemDump("photometry");201 238 202 239 // Finish up -
trunk/ppStack/src/ppStackLoop.h
r27160 r27319 7 7 #include "ppStackOptions.h" 8 8 #include "ppStackThread.h" 9 #include "ppStack.h" 9 10 10 11 … … 37 38 // Prepare for combination 38 39 bool ppStackCombinePrepare( 40 pmReadout **readout, // Readout to set 41 const char *name, // Name of file 42 ppStackFileList files, // Files of interest 39 43 ppStackThreadData *stack, // Stack 40 44 ppStackOptions *options, // Options … … 63 67 pmConfig *config, // Configuration 64 68 bool safe, // Allow safe combination? 65 bool norm // Normalise images? 69 bool norm, // Normalise images? 70 bool grow // Grow rejection masks? 66 71 ); 67 72 -
trunk/ppStack/src/ppStackPhotometry.c
r27158 r27319 26 26 psTimerStart("PPSTACK_PHOT"); 27 27 28 p pStackFileActivation(config, PPSTACK_FILES_COMBINE, false);28 pmFPAfileActivate(config->files, false, NULL); 29 29 ppStackFileActivation(config, PPSTACK_FILES_PHOT, true); 30 30 pmFPAview *photView = ppStackFilesIterateDown(config); // View to readout 31 ppStackFileActivation(config, PPSTACK_FILES_ COMBINE, true);31 ppStackFileActivation(config, PPSTACK_FILES_STACK, true); 32 32 33 33 pmFPAfile *photFile = psMetadataLookupPtr(NULL, config->files, "PSPHOT.INPUT"); // File for photometry -
trunk/ppStack/src/ppStackReadout.c
r27105 r27319 39 39 pmReadout *target = args->data[0]; // Output readout 40 40 ppStackThread *thread = args->data[1]; // Thread 41 ppStackOptions *options = args->data[2]; // Options 42 pmConfig *config = args->data[3]; // Configuration 43 bool safety = PS_SCALAR_VALUE(args->data[4], U8); // Safety switch on? 44 bool normalise = PS_SCALAR_VALUE(args->data[5], U8); // Normalise images? 41 psArray *reject = args->data[2]; // Rejected pixels for each image 42 ppStackOptions *options = args->data[3]; // Options 43 pmConfig *config = args->data[4]; // Configuration 44 bool safety = PS_SCALAR_VALUE(args->data[5], U8); // Safety switch on? 45 bool normalise = PS_SCALAR_VALUE(args->data[6], U8); // Normalise images? 45 46 46 47 psVector *mask = options->inputMask; // Mask for inputs 47 psArray *rejected = options->rejected; // Rejected pixels48 48 psVector *weightings = options->weightings; // Weightings (1/noise^2) for each image 49 49 psVector *addVariance = options->matchChi2; // Additional variance when rejecting 50 50 psVector *norm = normalise ? options->norm : NULL; // Normalisations to apply to images 51 51 52 bool status = ppStackReadoutFinal(config, target, thread->readouts, mask, reject ed,52 bool status = ppStackReadoutFinal(config, target, thread->readouts, mask, reject, 53 53 weightings, addVariance, safety, norm); // Status of operation 54 54 -
trunk/ppStack/src/ppStackReject.c
r27309 r27319 31 31 32 32 float threshold = psMetadataLookupF32(NULL, recipe, "THRESHOLD.MASK"); // Threshold for mask deconvolution 33 float poorFrac = psMetadataLookupF32(NULL, recipe, "POOR.FRACTION"); // Fraction for "poor"34 33 float imageRej = psMetadataLookupF32(NULL, recipe, "IMAGE.REJ"); // Maximum fraction of image to reject 35 34 // before rejecting entire image … … 109 108 110 109 psPixels *reject = pmStackReject(options->inspect->data[i], options->numCols, options->numRows, 111 threshold, poorFrac,stride, options->regions->data[i],110 threshold, stride, options->regions->data[i], 112 111 options->kernels->data[i]); // Rejected pixels 113 112 … … 130 129 options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i] |= PPSTACK_MASK_BAD; 131 130 numRejected++; 131 } else { 132 // Add to list of pixels already rejected 133 reject = psPixelsConcatenate(reject, options->rejected->data[i]); 134 options->rejected->data[i] = psPixelsDuplicates(options->rejected->data[i], reject); 132 135 } 133 }134 135 if (reject) {136 // Add to list of pixels already rejected137 reject = psPixelsConcatenate(reject, options->rejected->data[i]);138 options->rejected->data[i] = psPixelsDuplicates(options->rejected->data[i], reject);139 136 } 140 137 … … 170 167 171 168 psFree(options->inspect); options->inspect = NULL; 172 psFree(options->kernels); options->kernels = NULL;173 psFree(options->regions); options->regions = NULL;174 169 175 170 if (numRejected >= num) { -
trunk/ppStack/src/ppStackThread.c
r27004 r27319 284 284 285 285 { 286 psThreadTask *task = psThreadTaskAlloc("PPSTACK_FINAL_COMBINE", 6);286 psThreadTask *task = psThreadTaskAlloc("PPSTACK_FINAL_COMBINE", 7); 287 287 task->function = &ppStackReadoutFinalThread; 288 288 psThreadTaskAdd(task); -
trunk/psModules/src/imcombine/pmStackReject.c
r27307 r27319 10 10 #include "pmSubtractionThreads.h" 11 11 #include "pmSubtractionKernels.h" 12 13 #include "pmStackReject.h" 12 14 13 15 #define PIXEL_LIST_BUFFER 100 // Number of pixels to add to list at a time … … 115 117 116 118 117 psPixels *pmStackReject(const psPixels *in, int numCols, int numRows, float threshold, float poorFrac,118 int stride,const psArray *subRegions, const psArray *subKernels)119 psPixels *pmStackReject(const psPixels *in, int numCols, int numRows, float threshold, int stride, 120 const psArray *subRegions, const psArray *subKernels) 119 121 { 120 122 PS_ASSERT_PIXELS_NON_NULL(in, NULL); … … 223 225 psTrace("psModules.imcombine", 7, "Found %ld bad pixels", bad->n); 224 226 225 // Now, grow the mask to include everything that touches a bad pixel in the convolution 226 psImage *source = psPixelsToMask(NULL, bad, psRegionSet(0, numCols - 1, 0, numRows - 1), 227 return bad; 228 } 229 230 231 psPixels *pmStackRejectGrow(const psPixels *in, int numCols, int numRows, float poorFrac, 232 const psArray *subRegions, const psArray *subKernels) 233 { 234 PS_ASSERT_PIXELS_NON_NULL(in, NULL); 235 PS_ASSERT_ARRAY_NON_NULL(subRegions, NULL); 236 PS_ASSERT_ARRAY_NON_NULL(subKernels, NULL); 237 PS_ASSERT_ARRAYS_SIZE_EQUAL(subRegions, subKernels, NULL); 238 239 psImage *source = psPixelsToMask(NULL, in, psRegionSet(0, numCols - 1, 0, numRows - 1), 227 240 PM_STACK_MASK_BAD); // Mask image to grow 228 241 … … 243 256 bool oldThreads = psImageConvolveSetThreads(false); // Old value of threading for psImageColvolve 244 257 245 psImage *target = psImage Recycle(convolved,numCols, numRows, PS_TYPE_IMAGE_MASK); // Grown image258 psImage *target = psImageAlloc(numCols, numRows, PS_TYPE_IMAGE_MASK); // Grown image 246 259 psImageInit(target, 0); 247 260 for (int i = 0; i < subRegions->n; i++) { … … 326 339 327 340 psFree(source); 328 bad = psPixelsFromMask(bad, target, PM_STACK_MASK_ALL);341 psPixels *bad = psPixelsFromMask(NULL, target, PM_STACK_MASK_ALL); // All bad pixels 329 342 psFree(target); 330 343 psTrace("psModules.imcombine", 7, "Total %ld bad pixels", bad->n); -
trunk/psModules/src/imcombine/pmStackReject.h
r20568 r27319 12 12 int numCols, int numRows, ///< Size of image of interest 13 13 float threshold, ///< Threshold on convolved image, 0..1 14 float poorFrac, ///< Fraction for "poor"15 14 int stride, ///< Size of convolution patches 16 15 const psArray *regions, ///< Array of image regions for image 17 16 const psArray *kernels ///< Array of kernel parameters for each region 17 ); 18 19 /// Given a list of pixels from the convolved image, we grow them by convolution to get the list of all pixels 20 /// which should be rejected. 21 psPixels *pmStackRejectGrow(const psPixels *in, ///< List of pixels in the convolved image 22 int numCols, int numRows, ///< Size of image of interest 23 float poorFrac, ///< Fraction for "poor" 24 const psArray *regions, ///< Array of image regions for image 25 const psArray *kernels ///< Array of kernel parameters for each region 18 26 ); 19 27
Note:
See TracChangeset
for help on using the changeset viewer.
