Changeset 26076 for trunk/ppStack
- Timestamp:
- Nov 9, 2009, 2:53:12 PM (17 years ago)
- Location:
- trunk/ppStack
- Files:
-
- 21 edited
-
. (modified) (1 prop)
-
src/ppStack.h (modified) (2 diffs)
-
src/ppStackArguments.c (modified) (3 diffs)
-
src/ppStackCamera.c (modified) (3 diffs)
-
src/ppStackCleanup.c (modified) (1 diff)
-
src/ppStackCombineFinal.c (modified) (3 diffs)
-
src/ppStackCombineInitial.c (modified) (5 diffs)
-
src/ppStackCombinePrepare.c (modified) (3 diffs)
-
src/ppStackConvolve.c (modified) (9 diffs)
-
src/ppStackFiles.c (modified) (1 diff)
-
src/ppStackLoop.c (modified) (7 diffs)
-
src/ppStackLoop.h (modified) (1 diff)
-
src/ppStackMatch.c (modified) (8 diffs)
-
src/ppStackOptions.c (modified) (4 diffs)
-
src/ppStackOptions.h (modified) (2 diffs)
-
src/ppStackReadout.c (modified) (13 diffs)
-
src/ppStackReject.c (modified) (7 diffs)
-
src/ppStackSetup.c (modified) (2 diffs)
-
src/ppStackSources.c (modified) (1 diff)
-
src/ppStackThread.c (modified) (9 diffs)
-
src/ppStackThread.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppStack
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/czw_branch/cleanup/ppStack merged eligible /branches/eam_branches/20090522/ppStack merged eligible /branches/eam_branches/20090715/ppStack merged eligible /branches/eam_branches/20090820/ppStack merged eligible /branches/pap/ppStack merged eligible /branches/pap_mops/ppStack 25137-25255
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/ppStack/src/ppStack.h
r23573 r26076 59 59 // Perform stacking on a readout 60 60 // 61 // Returns an array of pixels to inspect for each input image61 // Returns two arrays: pixels to inspect for each input image, and pixels to reject for each input image. 62 62 psArray *ppStackReadoutInitial(const pmConfig *config, // Configuration 63 63 pmReadout *outRO, // Output readout … … 83 83 const psArray *rejected, // Array with pixels rejected in each image 84 84 const psVector *weightings, // Weighting factors for each image 85 const psVector *addVariance // Additional variance for rejection 85 const psVector *addVariance, // Additional variance for rejection 86 bool safety, // Enable safety switch? 87 const psVector *norm // Normalisations to apply 86 88 ); 87 89 -
trunk/ppStack/src/ppStackArguments.c
r23841 r26076 148 148 psMetadataAddStr(arguments, PS_LIST_TAIL, "-stamps", 0, "Stamps file with x,y,flux per line", NULL); 149 149 psMetadataAddStr(arguments, PS_LIST_TAIL, "-stats", 0, "Statistics file", NULL); 150 psMetadataAdd S32(arguments, PS_LIST_TAIL, "-iter", 0, "Number of rejection iterations", 0);150 psMetadataAddF32(arguments, PS_LIST_TAIL, "-combine-iter", 0, "Number of rejection iterations per input", NAN); 151 151 psMetadataAddF32(arguments, PS_LIST_TAIL, "-combine-rej", 0, 152 152 "Combination rejection thresold (sigma)", NAN); … … 250 250 } 251 251 252 VALUE_ARG_RECIPE_ INT("-iter", "ITER", S32, 0);252 VALUE_ARG_RECIPE_FLOAT("-combine-iter", "COMBINE.ITER", F32); 253 253 VALUE_ARG_RECIPE_FLOAT("-combine-rej", "COMBINE.REJ", F32); 254 254 VALUE_ARG_RECIPE_FLOAT("-combine-sys", "COMBINE.SYS", F32); … … 260 260 VALUE_ARG_RECIPE_FLOAT("-poor-frac", "POOR.FRACTION", F32); 261 261 262 valueArgRecipeStr(arguments, recipe, "-mask-val", "MASK. VAL",recipe);262 valueArgRecipeStr(arguments, recipe, "-mask-val", "MASK.IN", recipe); 263 263 valueArgRecipeStr(arguments, recipe, "-mask-bad", "MASK.BAD", recipe); 264 264 valueArgRecipeStr(arguments, recipe, "-mask-poor", "MASK.POOR", recipe); -
trunk/ppStack/src/ppStackCamera.c
r25519 r26076 233 233 234 234 // Output image 235 pmFPA * fpa= pmFPAConstruct(config->camera, config->cameraName); // FPA to contain the output236 if (! fpa) {235 pmFPA *outFPA = pmFPAConstruct(config->camera, config->cameraName); // FPA to contain the output 236 if (!outFPA) { 237 237 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to construct an FPA from camera configuration."); 238 238 return false; 239 239 } 240 pmFPAfile *output = pmFPAfileDefineOutput(config, fpa, "PPSTACK.OUTPUT");241 psFree( fpa); // Drop reference240 pmFPAfile *output = pmFPAfileDefineOutput(config, outFPA, "PPSTACK.OUTPUT"); 241 psFree(outFPA); // Drop reference 242 242 if (!output) { 243 243 psError(PS_ERR_IO, false, _("Unable to generate output file from PPSTACK.OUTPUT")); … … 250 250 output->save = true; 251 251 252 if (!pmFPAAddSourceFromFormat( fpa, "Stack", output->format)) {252 if (!pmFPAAddSourceFromFormat(outFPA, "Stack", output->format)) { 253 253 psError(PS_ERR_UNKNOWN, false, "Unable to generate output FPA."); 254 psFree(fpa);255 254 return false; 256 255 } … … 294 293 targetPSF->save = true; 295 294 } 295 296 #if 1 297 // Unconvolved stack 298 pmFPA *unconvFPA = pmFPAConstruct(config->camera, config->cameraName); // FPA to contain unconvolved output 299 if (!unconvFPA) { 300 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to construct an FPA from camera configuration."); 301 return false; 302 } 303 pmFPAfile *unConv = pmFPAfileDefineOutput(config, unconvFPA, "PPSTACK.UNCONV"); 304 psFree(unconvFPA); // Drop reference 305 if (!unConv) { 306 psError(PS_ERR_IO, false, _("Unable to generate output file from PPSTACK.UNCONV")); 307 return false; 308 } 309 if (unConv->type != PM_FPA_FILE_IMAGE) { 310 psError(PS_ERR_IO, true, "PPSTACK.UNCONV is not of type IMAGE"); 311 return false; 312 } 313 unConv->save = true; 314 315 if (!pmFPAAddSourceFromFormat(unconvFPA, "Stack", unConv->format)) { 316 psError(PS_ERR_UNKNOWN, false, "Unable to generate output FPA."); 317 return false; 318 } 319 320 // Unconvolved mask 321 pmFPAfile *unconvMask = pmFPAfileDefineOutput(config, unconvFPA, "PPSTACK.UNCONV.MASK"); 322 if (!unconvMask) { 323 psError(PS_ERR_IO, false, _("Unable to generate output file from PPSTACK.UNCONV.MASK")); 324 return false; 325 } 326 if (unconvMask->type != PM_FPA_FILE_MASK) { 327 psError(PS_ERR_IO, true, "PPSTACK.UNCONV.MASK is not of type MASK"); 328 return false; 329 } 330 unconvMask->save = true; 331 332 // Unconvolved variance 333 if (haveVariances) { 334 pmFPAfile *unconvVariance = pmFPAfileDefineOutput(config, unconvFPA, "PPSTACK.UNCONV.VARIANCE"); 335 if (!unconvVariance) { 336 psError(PS_ERR_IO, false, _("Unable to generate output file from PPSTACK.UNCONV.VARIANCE")); 337 return false; 338 } 339 if (unconvVariance->type != PM_FPA_FILE_VARIANCE) { 340 psError(PS_ERR_IO, true, "PPSTACK.UNCONV.VARIANCE is not of type VARIANCE"); 341 return false; 342 } 343 unconvVariance->save = true; 344 } 345 #endif 296 346 297 347 // Output JPEGs -
trunk/ppStack/src/ppStackCleanup.c
r23341 r26076 74 74 75 75 if (tempDelete) { 76 psString imageResolved = pmConfigConvertFilename(options-> imageNames->data[i],76 psString imageResolved = pmConfigConvertFilename(options->convImages->data[i], 77 77 config, false, false); 78 psString maskResolved = pmConfigConvertFilename(options-> maskNames->data[i],78 psString maskResolved = pmConfigConvertFilename(options->convMasks->data[i], 79 79 config, false, false); 80 psString varianceResolved = pmConfigConvertFilename(options-> varianceNames->data[i],80 psString varianceResolved = pmConfigConvertFilename(options->convVariances->data[i], 81 81 config, false, false); 82 82 if (unlink(imageResolved) == -1 || unlink(maskResolved) == -1 || -
trunk/ppStack/src/ppStackCombineFinal.c
r25096 r26076 10 10 #include "ppStackLoop.h" 11 11 12 bool ppStackCombineFinal(ppStackThreadData *stack, ppStackOptions *options, pmConfig *config) 12 //#define TESTING // Enable test output 13 14 bool ppStackCombineFinal(pmReadout *target, ppStackThreadData *stack, psArray *covariances, 15 ppStackOptions *options, pmConfig *config, bool safe, bool normalise) 13 16 { 14 17 psAssert(stack, "Require stack"); 15 18 psAssert(options, "Require options"); 16 19 psAssert(config, "Require configuration"); 20 21 if (!target->mask) { 22 target->mask = psImageAlloc(target->image->numCols, target->image->numRows, PS_TYPE_IMAGE_MASK); 23 } 17 24 18 25 stack->lastScan = 0; // Reset read … … 30 37 } 31 38 32 // call: ppStackReadoutFinal(config, outRO, readouts, rejected)39 // call: ppStackReadoutFinal(config, target, readouts, rejected) 33 40 psThreadJob *job = psThreadJobAlloc("PPSTACK_FINAL_COMBINE"); // Job to start 41 psArrayAdd(job->args, 1, target); 34 42 psArrayAdd(job->args, 1, thread); 35 43 psArrayAdd(job->args, 1, options); 36 44 psArrayAdd(job->args, 1, config); 45 PS_ARRAY_ADD_SCALAR(job->args, safe, PS_TYPE_U8); 46 PS_ARRAY_ADD_SCALAR(job->args, normalise, PS_TYPE_U8); 37 47 if (!psThreadJobAddPending(job)) { 38 48 psFree(job); … … 48 58 49 59 // 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; 55 continue; 60 if (covariances) { 61 double sumWeights = 0.0; // Sum of weights 62 for (int i = 0; i < options->num; i++) { 63 if (options->inputMask->data.U8[i]) { 64 psFree(covariances->data[i]); 65 covariances->data[i] = NULL; 66 continue; 67 } 68 psKernel *covar = covariances->data[i]; // Covariance matrix 69 if (!covar) { 70 continue; 71 } 72 float weight = options->weightings->data.F32[i]; // Weight to apply 73 psBinaryOp(covar->image, covar->image, "*", psScalarAlloc(weight, PS_TYPE_F32)); 74 sumWeights += weight; 56 75 } 57 psKernel *covar = options->covariances->data[i]; // Covariance matrix 58 if (!covar) { 59 continue; 76 if (sumWeights > 0.0) { 77 target->covariance = psImageCovarianceSum(covariances); 78 psBinaryOp(target->covariance->image, target->covariance->image, "/", 79 psScalarAlloc(sumWeights, PS_TYPE_F32)); 80 psImageCovarianceTransfer(target->variance, target->covariance); 60 81 } 61 float weight = options->weightings->data.F32[i]; // Weight to apply 62 psBinaryOp(covar->image, covar->image, "*", psScalarAlloc(weight, PS_TYPE_F32)); 63 sumWeights += weight; 64 } 65 if (sumWeights > 0.0) { 66 pmReadout *outRO = options->outRO; // Output readout 67 outRO->covariance = psImageCovarianceSum(options->covariances); 68 psBinaryOp(outRO->covariance->image, outRO->covariance->image, "/", 69 psScalarAlloc(sumWeights, PS_TYPE_F32)); 70 psFree(options->covariances); options->covariances = NULL; 71 psImageCovarianceTransfer(outRO->variance, outRO->covariance); 82 } else { 83 target->covariance = psImageCovarianceNone(); 72 84 } 73 85 74 86 #ifdef TESTING 75 pmStackVisualPlotTestImage(outRO->image, "combined_initial.fits"); 76 ppStackWriteImage("combined_final.fits", NULL, outRO->image, config); 87 static int pass = 0; // Pass through 88 psString name = NULL; // Name of file 89 psStringAppend(&name, "combined_image_final_%d.fits", pass); 90 pass++; 91 ppStackWriteImage(name, NULL, target->image, config); 92 psStringSubstitute(&name, "mask", "image"); 93 ppStackWriteImage(name, NULL, target->mask, config); 94 psStringSubstitute(&name, "variance", "mask"); 95 ppStackWriteImage(name, NULL, target->variance, config); 96 psFree(name); 97 98 pmStackVisualPlotTestImage(target->image, "combined_image_final.fits"); 77 99 #endif 78 100 -
trunk/ppStack/src/ppStackCombineInitial.c
r23767 r26076 9 9 #include "ppStack.h" 10 10 #include "ppStackLoop.h" 11 12 //#define TESTING // Enable test output 11 13 12 14 bool ppStackCombineInitial(ppStackThreadData *stack, ppStackOptions *options, pmConfig *config) … … 60 62 // Harvest the jobs, gathering the inspection lists 61 63 options->inspect = psArrayAlloc(options->num); 64 options->rejected = psArrayAlloc(options->num); 62 65 for (int i = 0; i < options->num; i++) { 63 66 if (options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i]) { … … 65 68 } 66 69 options->inspect->data[i] = psArrayAllocEmpty(numChunk); 70 options->rejected->data[i] = psArrayAllocEmpty(numChunk); 67 71 } 68 72 psThreadJob *job; // Completed job … … 71 75 "Job has incorrect type: %s", job->type); 72 76 psArray *results = job->results; // Results of job 77 psAssert(results->n == 2, "Results array has wrong size!"); 78 psArray *inspect = results->data[0]; // Pixels to inspect 79 psArray *reject = results->data[1]; // Pixels to reject 73 80 for (int i = 0; i < options->num; i++) { 74 81 if (options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i]) { 75 82 continue; 76 83 } 77 options->inspect->data[i] = psArrayAdd(options->inspect->data[i], 1, results->data[i]); 84 options->inspect->data[i] = psArrayAdd(options->inspect->data[i], 1, inspect->data[i]); 85 options->rejected->data[i] = psArrayAdd(options->rejected->data[i], 1, reject->data[i]); 78 86 } 79 87 psFree(job); … … 83 91 84 92 #ifdef TESTING 85 ppStackWriteImage("combined_initial.fits", NULL, outRO->image, config); 86 pmStackVisualPlotTestImage(outRO->image, "combined_initial.fits"); 93 ppStackWriteImage("combined_image_initial.fits", NULL, options->outRO->image, config); 94 ppStackWriteImage("combined_mask_initial.fits", NULL, options->outRO->mask, config); 95 ppStackWriteImage("combined_variance_initial.fits", NULL, options->outRO->variance, config); 96 97 pmStackVisualPlotTestImage(options->outRO->image, "combined_image_initial.fits"); 87 98 #endif 88 89 psFree(options->matchChi2); options->matchChi2 = NULL;90 91 99 92 100 if (options->stats) { -
trunk/ppStack/src/ppStackCombinePrepare.c
r23576 r26076 33 33 pmCell *outCell = pmFPAfileThisCell(config->files, view, "PPSTACK.OUTPUT"); // Output cell 34 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 38 35 39 psFree(view); 36 40 … … 39 43 psString maskBadStr = psMetadataLookupStr(NULL, recipe, "MASK.BAD"); // Name of bits to mask for bad 40 44 psImageMaskType maskBad = pmConfigMaskGet(maskBadStr, config); // Bits to mask for bad pixels 45 41 46 if (!pmReadoutStackDefineOutput(options->outRO, col0, row0, numCols, numRows, true, true, maskBad)) { 42 47 psError(PS_ERR_UNKNOWN, false, "Unable to prepare output."); … … 44 49 } 45 50 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 46 58 return true; 47 59 } -
trunk/ppStack/src/ppStackConvolve.c
r23602 r26076 9 9 #include "ppStack.h" 10 10 #include "ppStackLoop.h" 11 12 //#define TESTING 13 11 14 12 15 // Update the value of a concept … … 39 42 options->weightings = psVectorAlloc(num, PS_TYPE_F32); // Combination weightings for images (1/noise^2) 40 43 psVectorInit(options->weightings, 0.0); 41 options->covariances = psArrayAlloc(num); // Covariance matrices 44 options->origCovars = psArrayAlloc(num); 45 options->convCovars = psArrayAlloc(num); // Covariance matrices 46 47 psVector *renorms = psVectorAlloc(num, PS_TYPE_F32); // Renormalisation values for variances 48 psVectorInit(renorms, NAN); 42 49 43 50 psList *fpaList = psListAlloc(NULL); // List of input FPAs, for concept averaging … … 79 86 // Background subtraction, scaling and normalisation is performed automatically by the image matching 80 87 psTimerStart("PPSTACK_MATCH"); 88 options->origCovars->data[i] = psMemIncrRefCounter(readout->covariance); 81 89 if (!ppStackMatch(readout, options, i, config)) { 82 90 psErrorStackPrint(stderr, "Unable to match image %d --- ignoring.", i); … … 85 93 continue; 86 94 } 87 options->covariances->data[i] = psMemIncrRefCounter(readout->covariance); 95 options->convCovars->data[i] = psMemIncrRefCounter(readout->covariance); 96 97 float renorm = psMetadataLookupF32(NULL, readout->analysis, PM_READOUT_ANALYSIS_RENORM); 98 if (!isfinite(renorm)) { 99 renorm = 1.0; 100 } 101 renorms->data.F32[i] = renorm; 88 102 89 103 if (options->stats) { … … 114 128 pmHDU *hdu = readout->parent->parent->parent->hdu; // HDU for convolved image 115 129 assert(hdu); 116 ppStackWriteImage(options-> imageNames->data[i], hdu->header, readout->image, config);130 ppStackWriteImage(options->convImages->data[i], hdu->header, readout->image, config); 117 131 psMetadata *maskHeader = psMetadataCopy(NULL, hdu->header); // Copy of header, for mask 118 132 pmConfigMaskWriteHeader(config, maskHeader); 119 ppStackWriteImage(options-> maskNames->data[i], maskHeader, readout->mask, config);133 ppStackWriteImage(options->convMasks->data[i], maskHeader, readout->mask, config); 120 134 psFree(maskHeader); 121 psImageCovarianceTransfer(readout->variance, readout->covariance); 122 ppStackWriteImage(options->varianceNames->data[i], hdu->header, readout->variance, config); 135 ppStackWriteImage(options->convVariances->data[i], hdu->header, readout->variance, config); 123 136 #ifdef TESTING 124 137 { … … 129 142 psFree(name); 130 143 } 144 { 145 int numCols = readout->image->numCols, numRows = readout->image->numRows; 146 psImage *sn = psImageAlloc(numCols, numRows, PS_TYPE_F32); 147 for (int y = 0; y < numRows; y++) { 148 for (int x = 0; x < numCols; x++) { 149 sn->data.F32[y][x] = readout->image->data.F32[y][x] / 150 sqrtf(readout->variance->data.F32[y][x]); 151 } 152 } 153 psString name = NULL; 154 psStringAppend(&name, "signoise_%d.fits", i); 155 ppStackWriteImage(name, hdu->header, sn, config); 156 psFree(name); 157 psFree(sn); 158 } 131 159 #endif 132 160 … … 149 177 psFree(rng); 150 178 151 psFree(options->norm); options->norm = NULL;152 179 psFree(options->sourceLists); options->sourceLists = NULL; 153 180 psFree(options->psf); options->psf = NULL; … … 211 238 numGood = 0; // Number of good images 212 239 for (int i = 0; i < num; i++) { 213 if (options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i] & PPSTACK_MASK_ALL) {240 if (options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i] & PPSTACK_MASK_ALL) { 214 241 continue; 215 242 } … … 233 260 } 234 261 262 // Correct chi^2 for renormalisation 263 psBinaryOp(options->matchChi2, options->matchChi2, "/", renorms); 264 for (int i = 0; i < num; i++) { 265 psLogMsg("ppStack", PS_LOG_INFO, "Additional variance for image %d: %f\n", 266 i, options->matchChi2->data.F32[i]); 267 } 268 psFree(renorms); 269 235 270 return true; 236 271 } -
trunk/ppStack/src/ppStackFiles.c
r23357 r26076 22 22 /// Output files for the combination 23 23 static char *filesCombine[] = { "PPSTACK.OUTPUT", "PPSTACK.OUTPUT.MASK", "PPSTACK.OUTPUT.VARIANCE", 24 "PPSTACK.UNCONV", "PPSTACK.UNCONV.MASK", "PPSTACK.UNCONV.VARIANCE", 24 25 "PPSTACK.OUTPUT.JPEG1", "PPSTACK.OUTPUT.JPEG2", NULL }; 25 26 -
trunk/ppStack/src/ppStackLoop.c
r25738 r26076 56 56 // Start threading 57 57 ppStackThreadInit(); 58 ppStackThreadData *stack = ppStackThreadDataSetup(options, config );58 ppStackThreadData *stack = ppStackThreadDataSetup(options, config, true); 59 59 if (!stack) { 60 60 psError(PS_ERR_IO, false, "Unable to initialise stack threads."); … … 62 62 return false; 63 63 } 64 psFree(options->cells); options->cells = NULL;65 64 66 65 // Prepare for combination … … 98 97 // Final combination 99 98 psTrace("ppStack", 2, "Final stack of convolved images....\n"); 100 if (!ppStackCombineFinal( stack, options, config)) {99 if (!ppStackCombineFinal(options->outRO, stack, options->convCovars, options, config, false, false)) { 101 100 psError(PS_ERR_UNKNOWN, false, "Unable to perform final combination."); 102 101 psFree(stack); … … 106 105 psLogMsg("ppStack", PS_LOG_INFO, "Stage 5: Final Stack: %f sec", psTimerClear("PPSTACK_STEPS")); 107 106 ppStackMemDump("final"); 108 109 107 110 108 // Clean up … … 121 119 psFree(stack); 122 120 121 #if 1 122 // Unconvolved stack --- it's cheap to calculate, compared to everything else! 123 if (options->convolve) { 124 // Start threading 125 ppStackThreadData *stack = ppStackThreadDataSetup(options, config, false); 126 if (!stack) { 127 psError(PS_ERR_IO, false, "Unable to initialise stack threads."); 128 psFree(options); 129 return false; 130 } 131 psTrace("ppStack", 2, "Stack of unconvolved images....\n"); 132 if (!ppStackCombineFinal(options->unconvRO, stack, options->origCovars, options, config, false, true)) { 133 psError(PS_ERR_UNKNOWN, false, "Unable to perform unconvolved combination."); 134 psFree(stack); 135 psFree(options); 136 return false; 137 } 138 psLogMsg("ppStack", PS_LOG_INFO, "Stage 7: Unconvolved Stack: %f sec", psTimerClear("PPSTACK_STEPS")); 139 ppStackMemDump("unconv"); 140 141 psFree(stack); 142 } 143 psFree(options->cells); options->cells = NULL; 144 #endif 123 145 124 146 // Photometry … … 129 151 return false; 130 152 } 131 psLogMsg("ppStack", PS_LOG_INFO, "Stage 7: Photometry Analysis: %f sec", psTimerClear("PPSTACK_STEPS"));153 psLogMsg("ppStack", PS_LOG_INFO, "Stage 8: Photometry Analysis: %f sec", psTimerClear("PPSTACK_STEPS")); 132 154 ppStackMemDump("photometry"); 133 134 155 135 156 // Finish up … … 140 161 return false; 141 162 } 142 psLogMsg("ppStack", PS_LOG_INFO, "Stage 8: Final output: %f sec", psTimerClear("PPSTACK_STEPS"));163 psLogMsg("ppStack", PS_LOG_INFO, "Stage 9: Final output: %f sec", psTimerClear("PPSTACK_STEPS")); 143 164 ppStackMemDump("finish"); 144 165 145 166 psFree(options); 167 146 168 return true; 147 169 } -
trunk/ppStack/src/ppStackLoop.h
r23576 r26076 56 56 // Final combination 57 57 bool ppStackCombineFinal( 58 pmReadout *target, // Target readout 58 59 ppStackThreadData *stack, // Stack 60 psArray *covariances, // Covariances 59 61 ppStackOptions *options, // Options 60 pmConfig *config // Configuration 62 pmConfig *config, // Configuration 63 bool safe, // Allow safe combination? 64 bool norm // Normalise images? 61 65 ); 62 66 -
trunk/ppStack/src/ppStackMatch.c
r26074 r26076 167 167 ) 168 168 { 169 #if 1 169 170 bool mdok; // Status of metadata lookups 170 171 … … 192 193 psImageMaskType maskBad = pmConfigMaskGet("BLANK", config); // Bits to mask 193 194 195 psImageCovarianceTransfer(readout->variance, readout->covariance); 194 196 return pmReadoutVarianceRenormalise(readout, maskBad, num, minValid, maxValid); 197 #else 198 return true; 199 #endif 195 200 } 196 201 … … 212 217 int size = psMetadataLookupS32(NULL, ppsub, "KERNEL.SIZE"); // Kernel half-size 213 218 214 psString maskValStr = psMetadataLookupStr(NULL, recipe, "MASK.VAL"); // Name of bits to mask going in219 psString maskValStr = psMetadataLookupStr(NULL, ppsub, "MASK.VAL"); // Name of bits to mask going in 215 220 psImageMaskType maskVal = pmConfigMaskGet(maskValStr, config); // Bits to mask going in to pmSubtractionMatch 216 221 psString maskPoorStr = psMetadataLookupStr(NULL, recipe, "MASK.POOR"); // Name of bits to mask for poor … … 257 262 psFitsClose(fits); 258 263 259 if (!readImage(&readout->image, options-> imageNames->data[index], config) ||260 !readImage(&readout->mask, options-> maskNames->data[index], config) ||261 !readImage(&readout->variance, options-> varianceNames->data[index], config)) {264 if (!readImage(&readout->image, options->convImages->data[index], config) || 265 !readImage(&readout->mask, options->convMasks->data[index], config) || 266 !readImage(&readout->variance, options->convVariances->data[index], config)) { 262 267 psError(PS_ERR_IO, false, "Unable to read previously produced image."); 263 268 return false; … … 378 383 } 379 384 #endif 385 386 fprintf(stderr, "vf = %f\n", psImageCovarianceFactor(readout->covariance)); 387 380 388 381 389 if (threads > 0) { … … 517 525 psFree(iter); 518 526 options->matchChi2->data.F32[index] = sum / (psImageCovarianceFactor(readout->covariance) * num); 527 fprintf(stderr, "chi2 = %f ; vf = %f\n", sum/num, psImageCovarianceFactor(readout->covariance)); 519 528 } 520 529 … … 543 552 psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS); // Random number generator 544 553 if (!psImageBackground(bg, NULL, readout->image, readout->mask, maskVal | maskBad, rng)) { 545 psWarning("Can't measure background for image.");546 psErrorClear();554 psWarning("Can't measure background for image."); 555 psErrorClear(); 547 556 } else { 548 if (!psMetadataLookupBool(NULL, config->arguments, "PPSTACK.SKIP.BG.SUB")) {549 psLogMsg("ppStack", PS_LOG_INFO, "Correcting convolved image background by %lf (+/- %lf)",550 psStatsGetValue(bg, PS_STAT_ROBUST_MEDIAN), psStatsGetValue(bg, PS_STAT_ROBUST_STDEV));551 (void)psBinaryOp(readout->image, readout->image, "-",552 psScalarAlloc(psStatsGetValue(bg, PS_STAT_ROBUST_MEDIAN), PS_TYPE_F32));553 }557 if (!psMetadataLookupBool(NULL, config->arguments, "PPSTACK.SKIP.BG.SUB")) { 558 psLogMsg("ppStack", PS_LOG_INFO, "Correcting convolved image background by %lf (+/- %lf)", 559 psStatsGetValue(bg, PS_STAT_ROBUST_MEDIAN), psStatsGetValue(bg, PS_STAT_ROBUST_STDEV)); 560 (void)psBinaryOp(readout->image, readout->image, "-", 561 psScalarAlloc(psStatsGetValue(bg, PS_STAT_ROBUST_MEDIAN), PS_TYPE_F32)); 562 } 554 563 } 555 564 … … 569 578 options->weightings->data.F32[index] = 1.0 / (psStatsGetValue(bg, PS_STAT_ROBUST_MEDIAN) * 570 579 psImageCovarianceFactor(readout->covariance)); 580 psLogMsg("ppStack", PS_LOG_INFO, "Weighting for image %d is %f\n", 581 index, options->weightings->data.F32[index]); 571 582 psMetadataAddF32(readout->analysis, PS_LIST_TAIL, "PPSTACK.WEIGHTING", 0, 572 583 "Weighting by 1/noise^2 for stack", options->weightings->data.F32[index]); -
trunk/ppStack/src/ppStackOptions.c
r23573 r26076 12 12 fclose(options->statsFile); 13 13 } 14 psFree(options->imageNames); 15 psFree(options->maskNames); 16 psFree(options->varianceNames); 14 psFree(options->origImages); 15 psFree(options->origMasks); 16 psFree(options->origVariances); 17 psFree(options->origCovars); 18 psFree(options->convImages); 19 psFree(options->convMasks); 20 psFree(options->convVariances); 17 21 psFree(options->psf); 18 22 psFree(options->inputMask); … … 24 28 psFree(options->matchChi2); 25 29 psFree(options->weightings); 26 psFree(options->co variances);30 psFree(options->convCovars); 27 31 psFree(options->outRO); 32 psFree(options->unconvRO); 28 33 psFree(options->inspect); 29 34 psFree(options->rejected); … … 39 44 options->stats = NULL; 40 45 options->statsFile = NULL; 41 options->imageNames = NULL; 42 options->maskNames = NULL; 43 options->varianceNames = NULL; 46 options->origImages = NULL; 47 options->origMasks = NULL; 48 options->origVariances = NULL; 49 options->origCovars = NULL; 50 options->convImages = NULL; 51 options->convMasks = NULL; 52 options->convVariances = NULL; 44 53 options->num = 0; 45 54 options->psf = NULL; … … 54 63 options->matchChi2 = NULL; 55 64 options->weightings = NULL; 56 options->co variances = NULL;65 options->convCovars = NULL; 57 66 options->outRO = NULL; 67 options->unconvRO = NULL; 58 68 options->inspect = NULL; 59 69 options->rejected = NULL; -
trunk/ppStack/src/ppStackOptions.h
r23573 r26076 11 11 psMetadata *stats; // Statistics for output 12 12 FILE *statsFile; // File to which to write statistics 13 psArray *imageNames, *maskNames, *varianceNames; // Filenames for the temporary convolved images 13 psArray *origImages, *origMasks, *origVariances; // Filenames of the original images 14 psArray *convImages, *convMasks, *convVariances; // Filenames for the temporary convolved images 15 psArray *origCovars; // Original covariances matrices 14 16 int num; // Number of inputs 15 17 // Prepare … … 26 28 psVector *matchChi2; // chi^2 for stamps from matching 27 29 psVector *weightings; // Combination weightings for images (1/noise^2) 28 psArray *co variances; // Covariance matrices30 psArray *convCovars; // Convolved covariance matrices 29 31 // Combine initial 30 32 pmReadout *outRO; // Output readout 33 pmReadout *unconvRO; // Unconvolved readout 31 34 psArray *inspect; // Array of arrays of pixels to inspect 32 35 // Rejection -
trunk/ppStack/src/ppStackReadout.c
r23577 r26076 25 25 psVector *addVariance = options->matchChi2; // Additional variance when rejecting 26 26 27 psArray *inspect = ppStackReadoutInitial(config, outRO, thread->readouts, mask, 28 weightings, addVariance); 29 30 job->results = inspect; 27 job->results = ppStackReadoutInitial(config, outRO, thread->readouts, mask, 28 weightings, addVariance); 31 29 thread->busy = false; 32 30 33 return inspect? true : false;31 return job->results ? true : false; 34 32 } 35 33 … … 39 37 40 38 psArray *args = job->args; // Arguments 41 ppStackThread *thread = args->data[0]; // Thread 42 ppStackOptions *options = args->data[1]; // Options 43 pmConfig *config = args->data[2]; // Configuration 44 45 pmReadout *outRO = options->outRO; // Output readout 39 pmReadout *target = args->data[0]; // Output readout 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? 45 46 46 psVector *mask = options->inputMask; // Mask for inputs 47 47 psArray *rejected = options->rejected; // Rejected pixels 48 48 psVector *weightings = options->weightings; // Weightings (1/noise^2) for each image 49 49 psVector *addVariance = options->matchChi2; // Additional variance when rejecting 50 51 bool status = ppStackReadoutFinal(config, outRO, thread->readouts, mask, rejected, 52 weightings, addVariance); // Status of operation 50 psVector *norm = normalise ? options->norm : NULL; // Normalisations to apply to images 51 52 bool status = ppStackReadoutFinal(config, target, thread->readouts, mask, rejected, 53 weightings, addVariance, safety, norm); // Status of operation 53 54 54 55 thread->busy = false; … … 63 64 64 65 psArray *args = job->args; // Input arguments 65 psArray *inspect = args->data[0]; // Array of pixel arrays 66 int index = PS_SCALAR_VALUE(args->data[1], S32); // Index of interest 67 68 psArray *inputs = inspect->data[index]; // Array of interest 69 psPixels *output = NULL; // Output pixel list 70 for (int i = 0; i < inputs->n; i++) { 71 psPixels *input = inputs->data[i]; // Input pixel list 72 if (!input || input->n == 0) { 73 continue; 74 } 75 output = psPixelsConcatenate(output, input); 76 } 77 78 if (!output) { 79 // If there are no pixels to inspect, then just fake it 80 output = psPixelsAllocEmpty(0); 81 } 82 83 psFree(inputs); 84 inspect->data[index] = output; 66 psArray *inspects = args->data[0]; // Array of pixel arrays 67 psArray *rejects = args->data[1]; // Array of pixel arrays 68 int index = PS_SCALAR_VALUE(args->data[2], S32); // Index of interest 69 70 psArray *inInspects = inspects->data[index]; // Array of interest 71 psArray *inRejects = rejects->data[index]; // Array of interest 72 psAssert(inInspects->n == inRejects->n, "Size should be the same"); 73 psPixels *outInspect = NULL, *outReject = NULL; // Output pixel lists 74 for (int i = 0; i < inInspects->n; i++) { 75 psPixels *inInspect = inInspects->data[i]; // Input pixel list 76 if (inInspect && inInspect->n > 0) { 77 outInspect = psPixelsConcatenate(outInspect, inInspect); 78 } 79 psPixels *inReject = inRejects->data[i]; // Input pixel list 80 if (inReject && inReject->n > 0) { 81 outReject = psPixelsConcatenate(outReject, inReject); 82 } 83 } 84 85 // If there are no pixels to inspect, then just fake it 86 if (!outInspect) { 87 outInspect = psPixelsAllocEmpty(0); 88 } 89 if (!outReject) { 90 outReject = psPixelsAllocEmpty(0); 91 } 92 93 psFree(inspects->data[index]); 94 inspects->data[index] = outInspect; 95 psFree(rejects->data[index]); 96 rejects->data[index] = outReject; 85 97 86 98 return true; … … 104 116 105 117 bool mdok; // Status of MD lookup 106 int iter = psMetadataLookupS32(NULL, recipe, "ITER"); // Rejection iterations118 float iter = psMetadataLookupF32(NULL, recipe, "COMBINE.ITER"); // Rejection iterations 107 119 float combineRej = psMetadataLookupF32(NULL, recipe, "COMBINE.REJ"); // Combination threshold 108 120 float combineSys = psMetadataLookupF32(NULL, recipe, "COMBINE.SYS"); // Combination systematic error … … 114 126 int kernelSize = psMetadataLookupS32(NULL, ppsub, "KERNEL.SIZE"); // Kernel half-size 115 127 116 psString maskValStr = psMetadataLookupStr(NULL, recipe, "MASK. VAL"); // Name of bits to mask going in128 psString maskValStr = psMetadataLookupStr(NULL, recipe, "MASK.IN"); // Name of bits to mask going in 117 129 psImageMaskType maskVal = pmConfigMaskGet(maskValStr, config); // Bits to mask going in to pmSubtractionMatch 130 psString maskSuspectStr = psMetadataLookupStr(NULL, recipe, "MASK.SUSPECT"); // Name of suspect mask bits 131 psImageMaskType maskSuspect = pmConfigMaskGet(maskSuspectStr, config); // Suspect bits 118 132 psString maskBadStr = psMetadataLookupStr(NULL, recipe, "MASK.BAD"); // Name of bits to mask for bad 119 133 psImageMaskType maskBad = pmConfigMaskGet(maskBadStr, config); // Bits to mask for bad pixels … … 149 163 } 150 164 151 if (!pmStackCombine(outRO, stack, maskVal | maskBad, mask Bad, kernelSize, iter,152 combineRej, combineSys, combineDiscard, true,useVariance, safe, false)) {165 if (!pmStackCombine(outRO, stack, maskVal | maskBad, maskSuspect, maskBad, kernelSize, iter, 166 combineRej, combineSys, combineDiscard, useVariance, safe, false)) { 153 167 psError(PS_ERR_UNKNOWN, false, "Unable to combine input readouts with rejection."); 154 168 psFree(stack); … … 156 170 } 157 171 158 // Save list of pixels to inspect172 // Save lists of pixels 159 173 psArray *inspect = psArrayAlloc(num); // List of pixels to inspect 174 psArray *reject = psArrayAlloc(num); // List of pixels rejected 160 175 for (int i = 0; i < num; i++) { 161 176 pmStackData *data = stack->data[i]; // Data for this image … … 168 183 } 169 184 inspect->data[i] = psMemIncrRefCounter(data->inspect); 185 reject->data[i] = psMemIncrRefCounter(data->reject); 170 186 } 171 187 psFree(stack); … … 173 189 sectionNum++; 174 190 175 return inspect; 191 psArray *results = psArrayAlloc(2); // Array of results 192 results->data[0] = inspect; 193 results->data[1] = reject; 194 195 return results; 176 196 } 177 197 … … 180 200 bool ppStackReadoutFinal(const pmConfig *config, pmReadout *outRO, const psArray *readouts, 181 201 const psVector *mask, const psArray *rejected, const psVector *weightings, 182 const psVector *addVariance )202 const psVector *addVariance, bool safety, const psVector *norm) 183 203 { 184 204 assert(config); … … 196 216 197 217 bool mdok; // Status of MD lookup 198 int iter = psMetadataLookupS32(NULL, recipe, "ITER"); // Rejection iterations199 float combineRej = psMetadataLookupF32(NULL, recipe, "COMBINE.REJ"); // Combination threshold200 float combineSys = psMetadataLookupF32(NULL, recipe, "COMBINE.SYS"); // Combination systematic error201 float combineDiscard = psMetadataLookupF32(NULL, recipe, "COMBINE.DISCARD"); // Olympic discard fraction202 218 bool useVariance = psMetadataLookupBool(&mdok, recipe, "VARIANCE"); // Use variance for rejection? 203 219 bool safe = psMetadataLookupBool(&mdok, recipe, "SAFE"); // Be safe when combining small numbers of pixels 204 220 205 psString maskValStr = psMetadataLookupStr(NULL, recipe, "MASK. VAL"); // Name of bits to mask going in221 psString maskValStr = psMetadataLookupStr(NULL, recipe, "MASK.IN"); // Name of bits to mask going in 206 222 psImageMaskType maskVal = pmConfigMaskGet(maskValStr, config); // Bits to mask going in to pmSubtractionMatch 223 psString maskSuspectStr = psMetadataLookupStr(NULL, recipe, "MASK.SUSPECT"); // Name of suspect mask bits 224 psImageMaskType maskSuspect = pmConfigMaskGet(maskSuspectStr, config); // Suspect bits 207 225 psString maskBadStr = psMetadataLookupStr(NULL, recipe, "MASK.BAD"); // Name of bits to mask for bad 208 226 psImageMaskType maskBad = pmConfigMaskGet(maskBadStr, config); // Bits to mask for bad pixels … … 211 229 psArray *stack = psArrayAlloc(num); // Array for stacking 212 230 213 bool entire = true; // Combine entire image? 214 if (rejected) { 215 // We have rejection from a previous combination: combine without flagging pixels to inspect 216 entire = false; 217 safe = false; 218 iter = 0; 219 combineRej = NAN; 220 combineSys = NAN; 221 } 231 // We have rejection from a previous combination: combine without flagging pixels to inspect 232 safe &= safety; 233 int iter = 0; 234 float combineRej = NAN; 235 float combineSys = NAN; 236 float combineDiscard = NAN; 222 237 223 238 for (int i = 0; i < num; i++) { 224 239 pmReadout *ro = readouts->data[i]; 225 if (mask->data.U8[i] & (PPSTACK_MASK_REJECT | PPSTACK_MASK_BAD)) { 226 // Image completely rejected since previous combination 227 entire = true; 228 continue; 229 } else if (mask->data.U8[i]) { 230 // Image completely rejected before original combination 240 if (mask->data.U8[i]) { 241 // Image completely rejected 231 242 continue; 232 243 } … … 252 263 data->reject = rejected ? psMemIncrRefCounter(rejected->data[i]) : NULL; 253 264 stack->data[i] = data; 254 } 255 256 if (!pmStackCombine(outRO, stack, maskVal | maskBad, maskBad, 0, 257 iter, combineRej, combineSys, combineDiscard, 258 entire, useVariance, safe, !rejected)) { 265 266 if (norm) { 267 float normalise = powf(10.0, -0.4 * norm->data.F32[i]); // Normalisation 268 psBinaryOp(ro->image, ro->image, "*", psScalarAlloc(normalise, PS_TYPE_F32)); 269 psBinaryOp(ro->variance, ro->variance, "*", psScalarAlloc(PS_SQR(normalise), PS_TYPE_F32)); 270 } 271 } 272 273 if (!pmStackCombine(outRO, stack, maskVal | maskBad, maskSuspect, maskBad, 0, iter, combineRej, 274 combineSys, combineDiscard, useVariance, safe, true)) { 259 275 psError(PS_ERR_UNKNOWN, false, "Unable to combine input readouts."); 260 276 psFree(stack); -
trunk/ppStack/src/ppStackReject.c
r25466 r26076 23 23 24 24 int num = options->num; // Number of inputs 25 options->rejected = psArrayAlloc(num);26 25 27 26 psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSTACK_RECIPE); // ppStack recipe … … 53 52 psThreadJob *job = psThreadJobAlloc("PPSTACK_INSPECT"); // Job to start 54 53 psArrayAdd(job->args, 1, options->inspect); 54 psArrayAdd(job->args, 1, options->rejected); 55 55 PS_ARRAY_ADD_SCALAR(job->args, i, PS_TYPE_S32); 56 56 if (!psThreadJobAddPending(job)) { … … 92 92 #endif 93 93 94 psPixels *reject = pmStackReject(options->inspect->data[i], options->numCols, options->numRows,95 threshold, poorFrac, stride, options->regions->data[i],96 options->kernels->data[i]); // Rejected pixels97 98 94 #ifdef TESTING 99 95 { 100 psImage *mask = psPixelsToMask(NULL, reject,96 psImage *mask = psPixelsToMask(NULL, options->rejected->data[i], 101 97 psRegionSet(0, options->numCols - 1, 0, options->numRows - 1), 102 98 0xff); // Mask image 103 99 psString name = NULL; // Name of image 104 psStringAppend(&name, " reject_%03d.fits", i);100 psStringAppend(&name, "pre_reject_%03d.fits", i); 105 101 pmStackVisualPlotTestImage(mask, name); 106 102 psFits *fits = psFitsOpen(name, "w"); … … 111 107 } 112 108 #endif 109 110 psPixels *reject = pmStackReject(options->inspect->data[i], options->numCols, options->numRows, 111 threshold, poorFrac, stride, options->regions->data[i], 112 options->kernels->data[i]); // Rejected pixels 113 113 114 114 psFree(options->inspect->data[i]); … … 127 127 "exceeds limit (%.3f)", i, frac, imageRej); 128 128 psFree(reject); 129 // reject == NULL means reject image completely130 129 reject = NULL; 131 130 options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i] |= PPSTACK_MASK_BAD; … … 134 133 } 135 134 136 // Images without a list of rejected pixels (the list may be empty) are rejected completely 137 options->rejected->data[i] = reject; 135 if (reject) { 136 // Add to list of pixels already rejected 137 reject = psPixelsConcatenate(reject, options->rejected->data[i]); 138 options->rejected->data[i] = psPixelsDuplicates(options->rejected->data[i], reject); 139 } 140 141 #ifdef TESTING 142 { 143 psImage *mask = psPixelsToMask(NULL, options->rejected->data[i], 144 psRegionSet(0, options->numCols - 1, 0, options->numRows - 1), 145 0xff); // Mask image 146 psString name = NULL; // Name of image 147 psStringAppend(&name, "reject_%03d.fits", i); 148 pmStackVisualPlotTestImage(mask, name); 149 psFits *fits = psFitsOpen(name, "w"); 150 psFree(name); 151 psFitsWriteImage(fits, NULL, mask, 0, NULL); 152 psFree(mask); 153 psFitsClose(fits); 154 } 155 #endif 138 156 139 157 if (options->stats) { … … 143 161 "Number of pixels rejected", reject ? reject->n : 0); 144 162 } 163 164 psFree(reject); 145 165 psLogMsg("ppStack", PS_LOG_INFO, "Time to perform rejection on image %d: %f sec", i, 146 166 psTimerClear("PPSTACK_REJECT")); -
trunk/ppStack/src/ppStackSetup.c
r26020 r26076 72 72 } 73 73 74 options-> imageNames = psArrayAlloc(num);75 options-> maskNames = psArrayAlloc(num);76 options-> varianceNames = psArrayAlloc(num);74 options->convImages = psArrayAlloc(num); 75 options->convMasks = psArrayAlloc(num); 76 options->convVariances = psArrayAlloc(num); 77 77 for (int i = 0; i < num; i++) { 78 78 psString imageName = NULL, maskName = NULL, varianceName = NULL; // Names for convolved images … … 81 81 psStringAppend(&varianceName, "%s/%s.%d.%s", tempDir, tempName, i, tempVariance); 82 82 psTrace("ppStack", 5, "Temporary files: %s %s %s\n", imageName, maskName, varianceName); 83 options-> imageNames->data[i] = imageName;84 options-> maskNames->data[i] = maskName;85 options-> varianceNames->data[i] = varianceName;83 options->convImages->data[i] = imageName; 84 options->convMasks->data[i] = maskName; 85 options->convVariances->data[i] = varianceName; 86 86 } 87 87 psFree(outputName); 88 89 // Original images 90 options->origImages = psArrayAlloc(num); 91 options->origMasks = psArrayAlloc(num); 92 options->origVariances = psArrayAlloc(num); 93 pmFPAview *view = pmFPAviewAlloc(0); 94 for (int i = 0; i < num; i++) { 95 { 96 pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PPSTACK.INPUT", i); 97 options->origImages->data[i] = pmFPAfileName(file, view, config); 98 } 99 { 100 // We want the convolved mask, since that defines the area that has been tested for outliers 101 options->origMasks->data[i] = psMemIncrRefCounter(options->convMasks->data[i]); 102 } 103 { 104 pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PPSTACK.INPUT.VARIANCE", i); 105 options->origVariances->data[i] = pmFPAfileName(file, view, config); 106 } 107 } 108 psFree(view); 88 109 89 110 if (!pmConfigMaskSetBits(NULL, NULL, config)) { -
trunk/ppStack/src/ppStackSources.c
r25313 r26076 188 188 } 189 189 190 #if 0 191 // Position offsets 192 { 193 psArray *offsets = pmSourceMatchRelastro(matches, num, tol, iter1, starRej1, 194 iter2, starRej2, starLimit); // Shifts for each image 195 if (!offsets) { 196 psError(PS_ERR_UNKNOWN, false, "Unable to measure offsets"); 197 return false; 198 } 199 for (int i = 0; i < num; i++) { 200 psVector *offset = offsets->data[i]; 201 fprintf(stderr, "Offset %d: %f,%f\n", i, offset->data.F32[0], offset->data.F32[1]); 202 } 203 psFree(offsets); 204 } 205 #endif 206 190 207 #ifdef TESTING 191 208 dumpMatches("source_mags.dat", num, matches, zp, trans); -
trunk/ppStack/src/ppStackThread.c
r24796 r26076 56 56 } 57 57 58 ppStackThreadData *ppStackThreadDataSetup(const ppStackOptions *options, const pmConfig *config )58 ppStackThreadData *ppStackThreadDataSetup(const ppStackOptions *options, const pmConfig *config, bool conv) 59 59 { 60 60 psAssert(options, "Require options"); … … 62 62 63 63 const psArray *cells = options->cells; // Array of input cells 64 const psArray *imageNames = options->imageNames; // Names of images to read65 const psArray *maskNames = options->maskNames; // Names of masks to read66 const psArray *varianceNames = options->varianceNames; // Names of variance maps to read67 const psArray *covariances = options->covariances; // Covariance matrices (already read)64 const psArray *imageNames = conv ? options->convImages : options->origImages; // Names of images to read 65 const psArray *maskNames = conv ? options->convMasks : options->origMasks; // Names of masks to read 66 const psArray *varianceNames = conv ? options->convVariances : options->origVariances; // Variance names 67 const psArray *covariances = conv ? options->convCovars : options->origCovars; // Covariance matrices 68 68 69 69 PS_ASSERT_ARRAY_NON_NULL(cells, NULL); 70 PS_ASSERT_ARRAYS_SIZE_EQUAL(cells, imageNames, NULL); 71 PS_ASSERT_ARRAYS_SIZE_EQUAL(cells, maskNames, NULL); 72 PS_ASSERT_ARRAYS_SIZE_EQUAL(cells, varianceNames, NULL); 73 PS_ASSERT_ARRAYS_SIZE_EQUAL(cells, covariances, NULL); 70 if (imageNames) { 71 PS_ASSERT_ARRAYS_SIZE_EQUAL(cells, imageNames, NULL); 72 } 73 if (maskNames) { 74 PS_ASSERT_ARRAYS_SIZE_EQUAL(cells, maskNames, NULL); 75 } 76 if (varianceNames) { 77 PS_ASSERT_ARRAYS_SIZE_EQUAL(cells, varianceNames, NULL); 78 } 79 if (covariances) { 80 PS_ASSERT_ARRAYS_SIZE_EQUAL(cells, covariances, NULL); 81 } 74 82 75 83 ppStackThreadData *stack = psAlloc(sizeof(ppStackThreadData)); // Thread data, to return … … 87 95 continue; 88 96 } 89 // Resolved names 90 psString imageResolved = pmConfigConvertFilename(imageNames->data[i], config, false, false); 91 psString maskResolved = pmConfigConvertFilename(maskNames->data[i], config, false, false); 92 psString varianceResolved = pmConfigConvertFilename(varianceNames->data[i], config, false, false); 93 stack->imageFits->data[i] = psFitsOpen(imageResolved, "r"); 94 stack->maskFits->data[i] = psFitsOpen(maskResolved, "r"); 95 stack->varianceFits->data[i] = psFitsOpen(varianceResolved, "r"); 96 psFree(imageResolved); 97 psFree(maskResolved); 98 psFree(varianceResolved); 99 if (!stack->imageFits->data[i] || !stack->maskFits->data[i] || !stack->varianceFits->data[i]) { 100 psError(PS_ERR_UNKNOWN, false, "Unable to open convolved files %s, %s, %s", 101 (char*)imageNames->data[i], (char*)maskNames->data[i], (char*)varianceNames->data[i]); 102 return NULL; 103 } 97 98 // Open an image 99 #define IMAGE_OPEN(NAMES, FITS, INDEX) \ 100 if (NAMES) { \ 101 psString resolved = pmConfigConvertFilename((NAMES)->data[INDEX], config, false, false); \ 102 (FITS)->data[INDEX] = psFitsOpen(resolved, "r"); \ 103 if (!(FITS)->data[INDEX]) { \ 104 psError(PS_ERR_IO, false, "Unable to open file %s", (char*)(NAMES)->data[INDEX]); \ 105 psFree(resolved); \ 106 return NULL; \ 107 } \ 108 psFree(resolved); \ 109 } 110 111 IMAGE_OPEN(imageNames, stack->imageFits, i); 112 IMAGE_OPEN(maskNames, stack->maskFits, i); 113 IMAGE_OPEN(varianceNames, stack->varianceFits, i); 104 114 } 105 115 … … 116 126 } 117 127 pmReadout *ro = pmReadoutAlloc(cell); // Readout for thread 118 ro->covariance = psMemIncrRefCounter(covariances->data[j]); 128 if (covariances) { 129 ro->covariance = psMemIncrRefCounter(covariances->data[j]); 130 } 119 131 readouts->data[j] = ro; 120 132 } … … 186 198 psFits *varianceFits = stack->varianceFits->data[i]; // FITS file for variance 187 199 188 189 int zMax = 0; 200 int zMax = 0; 190 201 bool keepReading = false; 191 if (pmReadoutMore(ro, imageFits, 0, &zMax, rows, config)) { 202 203 if (imageFits && pmReadoutMore(ro, imageFits, 0, &zMax, rows, config)) { 192 204 keepReading = true; 193 205 if (!pmReadoutReadChunk(ro, imageFits, 0, NULL, rows, overlap, config)) { … … 199 211 } 200 212 201 if ( pmReadoutMoreMask(ro, maskFits, 0, &zMax, rows, config)) {213 if (maskFits && pmReadoutMoreMask(ro, maskFits, 0, &zMax, rows, config)) { 202 214 keepReading = true; 203 215 if (!pmReadoutReadChunkMask(ro, maskFits, 0, NULL, rows, overlap, config)) { … … 209 221 } 210 222 211 if ( pmReadoutMoreVariance(ro, varianceFits, 0, &zMax, rows, config)) {223 if (varianceFits && pmReadoutMoreVariance(ro, varianceFits, 0, &zMax, rows, config)) { 212 224 keepReading = true; 213 225 if (!pmReadoutReadChunkVariance(ro, varianceFits, 0, NULL, rows, overlap, config)) { … … 263 275 264 276 { 265 psThreadTask *task = psThreadTaskAlloc("PPSTACK_INSPECT", 2);277 psThreadTask *task = psThreadTaskAlloc("PPSTACK_INSPECT", 3); 266 278 task->function = &ppStackInspect; 267 279 psThreadTaskAdd(task); … … 270 282 271 283 { 272 psThreadTask *task = psThreadTaskAlloc("PPSTACK_FINAL_COMBINE", 3);284 psThreadTask *task = psThreadTaskAlloc("PPSTACK_FINAL_COMBINE", 6); 273 285 task->function = &ppStackReadoutFinalThread; 274 286 psThreadTaskAdd(task); -
trunk/ppStack/src/ppStackThread.h
r23341 r26076 35 35 ppStackThreadData *ppStackThreadDataSetup( 36 36 const ppStackOptions *options, // Options 37 const pmConfig *config // Configuration 37 const pmConfig *config, // Configuration 38 bool conv // Use convolved products? 38 39 ); 39 40
Note:
See TracChangeset
for help on using the changeset viewer.
