- 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/ppStackLoop.c (modified) (6 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/ppStackLoop.c
r23576 r27840 10 10 #include "ppStackLoop.h" 11 11 12 bool ppStackLoop(pmConfig *config) 12 /// Print a summary of the inputs, and return the number of good inputs 13 static int stackSummary(const ppStackOptions *options, // Stack options, with input mask 14 const char *place // Place in code 15 ) 16 { 17 int numGood = 0; // Number of good inputs 18 psString summary = NULL; // Summary of images 19 for (int i = 0; i < options->num; i++) { 20 psString reason = NULL; // Reason for rejecting 21 if (options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i] == 0) { 22 psStringAppend(&reason, " Good."); 23 numGood++; 24 } else { 25 if (options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i] & PPSTACK_MASK_CAL) { 26 psStringAppend(&reason, " Calibration failed."); 27 } 28 if (options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i] & PPSTACK_MASK_PSF) { 29 psStringAppend(&reason, " PSF measurement failed."); 30 } 31 if (options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i] & PPSTACK_MASK_MATCH) { 32 psStringAppend(&reason, " PSF matching failed."); 33 } 34 if (options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i] & PPSTACK_MASK_CHI2) { 35 psStringAppend(&reason, " PSF matching chi^2 deviant."); 36 } 37 if (options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i] & PPSTACK_MASK_REJECT) { 38 psStringAppend(&reason, " Rejection exceeded threshold."); 39 } 40 } 41 psStringAppend(&summary, "Image %d: %s\n", i, reason); 42 psFree(reason); 43 } 44 psLogMsg("ppStack", PS_LOG_INFO, "Summary of images for %s:\n%s", place, summary); 45 psFree(summary); 46 47 return numGood; 48 } 49 50 51 52 bool ppStackLoop(pmConfig *config, ppStackOptions *options) 13 53 { 14 54 assert(config); … … 16 56 psTimerStart("PPSTACK_TOTAL"); 17 57 psTimerStart("PPSTACK_STEPS"); 18 19 ppStackOptions *options = ppStackOptionsAlloc(); // Options for stacking20 58 21 59 // Setup 22 60 psTrace("ppStack", 1, "Setup....\n"); 23 61 if (!ppStackSetup(options, config)) { 24 psError(PS_ERR_UNKNOWN, false, "Unable to setup."); 25 psFree(options); 62 psError(psErrorCodeLast(), false, "Unable to setup."); 26 63 return false; 27 64 } … … 33 70 psTrace("ppStack", 1, "Preparation for stacking: merging sources, determining target PSF....\n"); 34 71 if (!ppStackPrepare(options, config)) { 35 psError(PS_ERR_UNKNOWN, false, "Unable to prepare for stacking."); 36 psFree(options); 72 psError(psErrorCodeLast(), false, "Unable to prepare for stacking."); 37 73 return false; 38 74 } … … 40 76 psTimerClear("PPSTACK_STEPS")); 41 77 ppStackMemDump("prepare"); 42 78 if (options->quality) { 79 // Can't do anything else 80 return true; 81 } 43 82 44 83 // Convolve inputs 45 84 psTrace("ppStack", 1, "Convolving inputs to target PSF....\n"); 46 85 if (!ppStackConvolve(options, config)) { 47 psError(PS_ERR_UNKNOWN, false, "Unable to convolve images."); 48 psFree(options); 86 psError(psErrorCodeLast(), false, "Unable to convolve images."); 49 87 return false; 50 88 } … … 53 91 ppStackMemDump("convolve"); 54 92 93 // Ensure sufficient inputs 94 { 95 int numGood = stackSummary(options, "initial combination"); 96 psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSTACK_RECIPE); // ppStack recipe 97 bool safe = psMetadataLookupBool(NULL, recipe, "SAFE"); // Be safe when combining 98 if (safe && numGood <= 1) { 99 psError(PPSTACK_ERR_REJECTED, true, "Insufficient inputs for combination with safety on"); 100 return false; 101 } 102 } 55 103 56 104 // Start threading 57 105 ppStackThreadInit(); 58 ppStackThreadData *stack = ppStackThreadDataSetup(options, config );106 ppStackThreadData *stack = ppStackThreadDataSetup(options, config, true); 59 107 if (!stack) { 60 psError(PS_ERR_IO, false, "Unable to initialise stack threads."); 61 psFree(options); 62 return false; 63 } 64 psFree(options->cells); options->cells = NULL; 108 psError(psErrorCodeLast(), false, "Unable to initialise stack threads."); 109 return false; 110 } 65 111 66 112 // Prepare for combination 67 if (!ppStackCombinePrepare( stack, options, config)) {68 psError(PS_ERR_UNKNOWN, false, "Unable to prepare for combination.");69 ps Free(stack);70 psFree( options);113 if (!ppStackCombinePrepare("PPSTACK.OUTPUT", "PPSTACK.OUTPUT.EXP", PPSTACK_FILES_STACK, 114 stack, options, config)) { 115 psError(psErrorCodeLast(), false, "Unable to prepare for combination."); 116 psFree(stack); 71 117 return false; 72 118 } … … 75 121 psTrace("ppStack", 1, "Initial stack of convolved images....\n"); 76 122 if (!ppStackCombineInitial(stack, options, config)) { 77 psError(PS_ERR_UNKNOWN, false, "Unable to perform initial combination."); 78 psFree(stack); 79 psFree(options); 80 return false; 81 } 82 psLogMsg("ppStack", PS_LOG_INFO, "Stage 2: Generate Convolutions and Save: %f sec", 83 psTimerClear("PPSTACK_STEPS")); 84 ppStackMemDump("convolve"); 85 psLogMsg("ppStack", PS_LOG_INFO, "Stage 4: Make Initial Stack: %f sec", psTimerClear("PPSTACK_STEPS")); 86 123 psError(psErrorCodeLast(), false, "Unable to perform initial combination."); 124 psFree(stack); 125 return false; 126 } 127 ppStackMemDump("initial"); 128 psLogMsg("ppStack", PS_LOG_INFO, "Stage 3: Make Initial Stack: %f sec", psTimerClear("PPSTACK_STEPS")); 129 130 // Done with stack inputs for now 131 for (int i = 0; i < options->num; i++) { 132 pmCellFreeData(options->cells->data[i]); 133 } 134 psFree(stack); 87 135 88 136 // Pixel rejection 89 137 psTrace("ppStack", 1, "Reject pixels....\n"); 90 138 if (!ppStackReject(options, config)) { 91 psError(PS_ERR_UNKNOWN, false, "Unable to reject pixels."); 92 psFree(stack); 93 psFree(options); 94 return false; 95 } 96 psLogMsg("ppStack", PS_LOG_INFO, "Stage 5: Pixel Rejection: %f sec", psTimerClear("PPSTACK_STEPS")); 97 ppStackMemDump("reject"); 98 139 psError(psErrorCodeLast(), false, "Unable to reject pixels."); 140 psFree(stack); 141 return false; 142 } 143 psLogMsg("ppStack", PS_LOG_INFO, "Stage 4: Pixel Rejection: %f sec", psTimerClear("PPSTACK_STEPS")); 144 145 // Check inputs 146 { 147 int numGood = stackSummary(options, "final combination"); 148 if (numGood <= 0) { 149 psError(PPSTACK_ERR_REJECTED, true, "Insufficient inputs for combination"); 150 return false; 151 } 152 } 153 154 stack = ppStackThreadDataSetup(options, config, true); 155 if (!stack) { 156 psError(psErrorCodeLast(), false, "Unable to initialise stack threads."); 157 return false; 158 } 99 159 100 160 // Final combination 101 161 psTrace("ppStack", 2, "Final stack of convolved images....\n"); 102 if (!ppStackCombineFinal(stack, options, config)) { 103 psError(PS_ERR_UNKNOWN, false, "Unable to perform final combination."); 104 psFree(stack); 105 psFree(options); 106 return false; 107 } 108 psLogMsg("ppStack", PS_LOG_INFO, "Stage 6: Final Stack: %f sec", psTimerClear("PPSTACK_STEPS")); 162 if (!ppStackCombineFinal(stack, options->convCovars, options, config, false, false, true)) { 163 psError(psErrorCodeLast(), false, "Unable to perform final combination."); 164 psFree(stack); 165 return false; 166 } 167 psLogMsg("ppStack", PS_LOG_INFO, "Stage 5: Final Stack: %f sec", psTimerClear("PPSTACK_STEPS")); 109 168 ppStackMemDump("final"); 110 169 170 // Photometry 171 psTrace("ppStack", 1, "Photometering stacked image....\n"); 172 if (!ppStackPhotometry(options, config)) { 173 psError(psErrorCodeLast(), false, "Unable to perform photometry."); 174 return false; 175 } 176 psLogMsg("ppStack", PS_LOG_INFO, "Stage 6: Photometry Analysis: %f sec", psTimerClear("PPSTACK_STEPS")); 177 ppStackMemDump("photometry"); 111 178 112 179 // Clean up 113 180 psTrace("ppStack", 2, "Cleaning up after combination....\n"); 114 181 if (!ppStackCleanup(stack, options, config)) { 115 psError(PS_ERR_UNKNOWN, false, "Unable to clean up."); 116 psFree(stack); 117 psFree(options); 118 return false; 119 } 120 psLogMsg("ppStack", PS_LOG_INFO, "Stage 7: WCS & JPEGS: %f sec", psTimerClear("PPSTACK_STEPS")); 182 psError(psErrorCodeLast(), false, "Unable to clean up."); 183 psFree(stack); 184 return false; 185 } 186 for (int i = 0; i < options->num; i++) { 187 pmCellFreeData(options->cells->data[i]); 188 } 189 psFree(stack); 190 psLogMsg("ppStack", PS_LOG_INFO, "Stage 7: Cleanup, WCS & JPEGS: %f sec", psTimerClear("PPSTACK_STEPS")); 121 191 ppStackMemDump("cleanup"); 122 192 123 psFree(stack); 124 125 126 // Photometry 127 psTrace("ppStack", 1, "Photometering stacked image....\n"); 128 if (!ppStackPhotometry(options, config)) { 129 psError(PS_ERR_UNKNOWN, false, "Unable to perform photometry."); 130 psFree(options); 131 return false; 132 } 133 psLogMsg("ppStack", PS_LOG_INFO, "Stage 8: Photometry Analysis: %f sec", psTimerClear("PPSTACK_STEPS")); 134 ppStackMemDump("photometry"); 135 193 #if 1 194 // Unconvolved stack --- it's cheap to calculate, compared to everything else! 195 if (options->convolve) { 196 // Start threading 197 ppStackThreadData *stack = ppStackThreadDataSetup(options, config, false); 198 if (!stack) { 199 psError(psErrorCodeLast(), false, "Unable to initialise stack threads."); 200 return false; 201 } 202 203 // Prepare for combination 204 if (!ppStackCombinePrepare("PPSTACK.UNCONV", "PPSTACK.UNCONV.EXP", PPSTACK_FILES_UNCONV, 205 stack, options, config)) { 206 psError(psErrorCodeLast(), false, "Unable to prepare for combination."); 207 psFree(stack); 208 return false; 209 } 210 211 psTrace("ppStack", 2, "Stack of unconvolved images....\n"); 212 if (!ppStackCombineFinal(stack, options->origCovars, options, config, 213 false, true, false)) { 214 psError(psErrorCodeLast(), false, "Unable to perform unconvolved combination."); 215 psFree(stack); 216 return false; 217 } 218 psLogMsg("ppStack", PS_LOG_INFO, "Stage 8: Unconvolved Stack: %f sec", psTimerClear("PPSTACK_STEPS")); 219 ppStackMemDump("unconv"); 220 221 if (!ppStackFilesIterateUp(config)) { 222 psError(psErrorCodeLast(), false, "Unable to close files."); 223 psFree(stack); 224 return false; 225 } 226 ppStackFileActivation(config, PPSTACK_FILES_UNCONV, false); 227 options->outRO->data_exists = false; 228 options->outRO->parent->data_exists = false; 229 options->outRO->parent->parent->data_exists = false; 230 psFree(options->outRO); 231 options->outRO = NULL; 232 options->expRO->data_exists = false; 233 options->expRO->parent->data_exists = false; 234 options->expRO->parent->parent->data_exists = false; 235 psFree(options->expRO); 236 options->expRO = NULL; 237 238 for (int i = 0; i < options->num; i++) { 239 pmCellFreeData(options->cells->data[i]); 240 } 241 psFree(stack); 242 } 243 psFree(options->cells); options->cells = NULL; 244 #endif 136 245 137 246 // Finish up 138 247 psTrace("ppStack", 1, "Finishing up....\n"); 139 248 if (!ppStackFinish(options, config)) { 140 psError(PS_ERR_UNKNOWN, false, "Unable to finish up."); 141 psFree(options); 142 return false; 143 } 144 psLogMsg("ppStack", PS_LOG_INFO, "Stage 9: Final output: %f sec", psTimerClear("PPSTACK_STEPS")); 249 psError(psErrorCodeLast(), false, "Unable to finish up."); 250 return false; 251 } 145 252 ppStackMemDump("finish"); 146 253 147 psFree(options);148 254 return true; 149 255 }
Note:
See TracChangeset
for help on using the changeset viewer.
