Changeset 21244 for trunk/ppMerge/src/ppMergeMask.c
- Timestamp:
- Feb 1, 2009, 11:43:05 AM (17 years ago)
- File:
-
- 1 edited
-
trunk/ppMerge/src/ppMergeMask.c (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppMerge/src/ppMergeMask.c
r21183 r21244 1 /** @file ppMergeMask.c 2 * 3 * @brief 4 * 5 * @ingroup ppMerge 6 * 7 * @author IfA 8 * @version $Revision: 1.17 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2009-02-01 21:43:05 $ 10 * Copyright 2009 Institute for Astronomy, University of Hawaii 11 */ 12 1 13 #include "ppMerge.h" 2 14 3 static bool mergeMask(pmConfig *config, // Configuration4 const pmFPAview *view, // View to chip5 bool writeOut, // Write output?6 psRandom *rng, // Random number generator7 psMetadata *stats // Statistics output15 static bool mergeMask(pmConfig *config, ///< Configuration 16 const pmFPAview *view, ///< View to chip 17 bool writeOut, ///< Write output? 18 psRandom *rng, ///< Random number generator 19 psMetadata *stats ///< Statistics output 8 20 ) 9 21 { … … 12 24 assert(view->chip != -1 && view->cell == -1 && view->readout == -1); 13 25 14 bool mdok; // Status of MD lookup15 int numFiles = psMetadataLookupS32(NULL, config->arguments, "INPUTS.NUM"); // Number of input files16 psStatsOptions meanStat = psMetadataLookupS32(NULL, config->arguments, "MEAN"); // Statistic for mean17 psStatsOptions stdevStat = psMetadataLookupS32(NULL, config->arguments, "STDEV"); // Statistic for stdev18 int sample = psMetadataLookupS32(NULL, config->arguments, "SAMPLE"); // Size of sample for statistics19 bool chipStats = psMetadataLookupBool(&mdok, config->arguments, "MASK.CHIPSTATS"); // Statistics on chip?20 float maskSuspect = psMetadataLookupF32(NULL, config->arguments, "MASK.SUSPECT"); // Threshold for suspect pixels21 float maskBad = psMetadataLookupF32(NULL, config->arguments, "MASK.BAD"); // Threshold for bad pixels22 pmMaskIdentifyMode maskMode = psMetadataLookupS32(NULL, config->arguments, "MASK.MODE"); // Mode for identifying bad pixels23 int maskGrow = psMetadataLookupS32(NULL, config->arguments, "MASK.GROW"); // Radius to grow mask24 25 bool smoothSuspect = psMetadataLookupBool(&mdok, config->arguments, "MASK.SMOOTH.SUSPECT"); // Radius to grow mask26 float smoothScale = psMetadataLookupF32(&mdok, config->arguments, "MASK.SMOOTH.SCALE"); // Radius to grow mask26 bool mdok; ///< Status of MD lookup 27 int numFiles = psMetadataLookupS32(NULL, config->arguments, "INPUTS.NUM"); ///< Number of input files 28 psStatsOptions meanStat = psMetadataLookupS32(NULL, config->arguments, "MEAN"); ///< Statistic for mean 29 psStatsOptions stdevStat = psMetadataLookupS32(NULL, config->arguments, "STDEV"); ///< Statistic for stdev 30 int sample = psMetadataLookupS32(NULL, config->arguments, "SAMPLE"); ///< Size of sample for statistics 31 bool chipStats = psMetadataLookupBool(&mdok, config->arguments, "MASK.CHIPSTATS"); ///< Statistics on chip? 32 float maskSuspect = psMetadataLookupF32(NULL, config->arguments, "MASK.SUSPECT"); ///< Threshold for suspect pixels 33 float maskBad = psMetadataLookupF32(NULL, config->arguments, "MASK.BAD"); ///< Threshold for bad pixels 34 pmMaskIdentifyMode maskMode = psMetadataLookupS32(NULL, config->arguments, "MASK.MODE"); ///< Mode for identifying bad pixels 35 int maskGrow = psMetadataLookupS32(NULL, config->arguments, "MASK.GROW"); ///< Radius to grow mask 36 37 bool smoothSuspect = psMetadataLookupBool(&mdok, config->arguments, "MASK.SMOOTH.SUSPECT"); ///< Radius to grow mask 38 float smoothScale = psMetadataLookupF32(&mdok, config->arguments, "MASK.SMOOTH.SCALE"); ///< Radius to grow mask 27 39 28 40 psImageMaskType markVal; … … 40 52 } 41 53 42 psStats *statistics = psStatsAlloc(meanStat | stdevStat); // Statistics for background43 44 psString outName = ppMergeOutputFile(config); // Name of output file45 pmChip *outChip = pmFPAfileThisChip(config->files, view, outName); // Output chip54 psStats *statistics = psStatsAlloc(meanStat | stdevStat); ///< Statistics for background 55 56 psString outName = ppMergeOutputFile(config); ///< Name of output file 57 pmChip *outChip = pmFPAfileThisChip(config->files, view, outName); ///< Output chip 46 58 psFree(outName); 47 59 … … 58 70 59 71 // For each input file, get the statistics, which can be calculated at the chip or cell levels 60 psVector *values = psVectorAlloc(sample, PS_TYPE_F32); // Pixel values for statistics61 pmFPAview *inView = pmFPAviewAlloc(0); // View for input72 psVector *values = psVectorAlloc(sample, PS_TYPE_F32); ///< Pixel values for statistics 73 pmFPAview *inView = pmFPAviewAlloc(0); ///< View for input 62 74 for (int i = 0; i < numFiles; i++) { 63 75 pmFPAfileActivate(config->files, false, NULL); 64 psArray *files = ppMergeFileActivateSingle(config, PPMERGE_FILES_INPUT, true, i); // Input files65 pmFPAfile *input = files->data[0]; // Input file76 psArray *files = ppMergeFileActivateSingle(config, PPMERGE_FILES_INPUT, true, i); ///< Input files 77 pmFPAfile *input = files->data[0]; ///< Input file 66 78 psFree(files); 67 pmFPA *inFPA = input->fpa; // Input FPA79 pmFPA *inFPA = input->fpa; ///< Input FPA 68 80 *inView = *view; 69 81 70 int valueIndex = 0; // Index for vector of pixel values71 72 pmCell *inCell; // Input cell82 int valueIndex = 0; ///< Index for vector of pixel values 83 84 pmCell *inCell; ///< Input cell 73 85 while ((inCell = pmFPAviewNextCell(inView, inFPA, 1))) { 74 86 75 87 // the output FPA structure carries the information about which cells to process 76 pmCell *outCell = pmFPAfileThisCell(config->files, inView, "PPMERGE.OUTPUT.MASK"); // Output cell88 pmCell *outCell = pmFPAfileThisCell(config->files, inView, "PPMERGE.OUTPUT.MASK"); ///< Output cell 77 89 if (!outCell->process) continue; 78 90 79 pmHDU *hdu = pmHDUFromCell(inCell); // HDU for cell91 pmHDU *hdu = pmHDUFromCell(inCell); ///< HDU for cell 80 92 if (!hdu || hdu->blankPHU) { 81 93 // No data here … … 106 118 pmReadout *readout; 107 119 if (inCell->readouts && inCell->readouts->n == 1) { 108 readout = psMemIncrRefCounter(inCell->readouts->data[0]); // Input readout120 readout = psMemIncrRefCounter(inCell->readouts->data[0]); ///< Input readout 109 121 } else { 110 122 readout = pmReadoutAlloc(inCell); … … 118 130 } 119 131 120 pmReadout *outRO = NULL; // Output readout132 pmReadout *outRO = NULL; ///< Output readout 121 133 if (outCell->readouts && outCell->readouts->n == 1) { 122 134 outRO = psMemIncrRefCounter(outCell->readouts->data[0]); … … 124 136 outRO = pmReadoutAlloc(outCell); 125 137 } 126 psImage *outMask = outRO->mask; // Output mask image (for iterative generation of mask)127 128 psImage *image = readout->image, *mask = readout->mask; // Image and mask129 int numCols = readout->image->numCols, numRows = readout->image->numRows; // Image size130 int numPix = numCols * numRows; // Number of pixels131 int num = PS_MIN(numPix, sample / numCells); // Number of values to add138 psImage *outMask = outRO->mask; ///< Output mask image (for iterative generation of mask) 139 140 psImage *image = readout->image, *mask = readout->mask; ///< Image and mask 141 int numCols = readout->image->numCols, numRows = readout->image->numRows; ///< Image size 142 int numPix = numCols * numRows; ///< Number of pixels 143 int num = PS_MIN(numPix, sample / numCells); ///< Number of values to add 132 144 if (!chipStats) { 133 145 valueIndex = 0; … … 187 199 188 200 // the output FPA structure carries the information about which cells to process 189 pmCell *outCell = pmFPAfileThisCell(config->files, inView, "PPMERGE.OUTPUT.MASK"); // Output cell201 pmCell *outCell = pmFPAfileThisCell(config->files, inView, "PPMERGE.OUTPUT.MASK"); ///< Output cell 190 202 if (!outCell->process) continue; 191 203 192 pmHDU *hdu = pmHDUFromCell(inCell); // HDU for cell204 pmHDU *hdu = pmHDUFromCell(inCell); ///< HDU for cell 193 205 if (!hdu || hdu->blankPHU) continue; 194 206 195 pmReadout *readout = inCell->readouts->data[0]; // Readout of interest207 pmReadout *readout = inCell->readouts->data[0]; ///< Readout of interest 196 208 197 209 inView->readout = 0; … … 225 237 ppMergeFileActivate(config, PPMERGE_FILES_OUTPUT, true); 226 238 } 227 pmFPA *outFPA = outChip->parent; // Output FPA228 pmCell *outCell; // Output cell229 pmFPAview *outView = pmFPAviewAlloc(0); // View into output FPA239 pmFPA *outFPA = outChip->parent; ///< Output FPA 240 pmCell *outCell; ///< Output cell 241 pmFPAview *outView = pmFPAviewAlloc(0); ///< View into output FPA 230 242 *outView = *view; 231 243 while ((outCell = pmFPAviewNextCell(outView, outFPA, 1))) { … … 234 246 if (!outCell->process) continue; 235 247 236 pmHDU *hdu = pmHDUFromCell(outCell); // HDU for cell248 pmHDU *hdu = pmHDUFromCell(outCell); ///< HDU for cell 237 249 if (!hdu || hdu->blankPHU) continue; 238 250 … … 240 252 241 253 assert(outCell->readouts && outCell->readouts->n == 1); 242 pmReadout *outRO = outCell->readouts->data[0]; // Output readout254 pmReadout *outRO = outCell->readouts->data[0]; ///< Output readout 243 255 244 256 if (smoothSuspect) { 245 257 // XXX test output of suspect pixel image 246 psImage *suspects = psMetadataLookupPtr(NULL, outRO->analysis, PM_MASK_ANALYSIS_SUSPECT); // Suspect img258 psImage *suspects = psMetadataLookupPtr(NULL, outRO->analysis, PM_MASK_ANALYSIS_SUSPECT); ///< Suspect img 247 259 assert (suspects); 248 psImageSmooth (suspects, smoothScale, 3); // extend smoothing region to 3-sigma260 psImageSmooth (suspects, smoothScale, 3); ///< extend smoothing region to 3-sigma 249 261 } 250 262 … … 259 271 // The counts image is fairly useless, but it preserves the model 260 272 pmCell *countsCell = pmFPAfileThisCell(config->files, outView, "PPMERGE.OUTPUT.COUNT"); 261 pmReadout *countsRO = pmReadoutAlloc(countsCell); // Readout with count of inputs per pixel273 pmReadout *countsRO = pmReadoutAlloc(countsCell); ///< Readout with count of inputs per pixel 262 274 countsRO->image = psImageAlloc(outRO->mask->numCols, outRO->mask->numRows, PS_TYPE_F32); 263 275 psImageInit(countsRO->image, numFiles); … … 266 278 267 279 pmCell *sigmaCell = pmFPAfileThisCell(config->files, outView, "PPMERGE.OUTPUT.SIGMA"); 268 pmReadout *sigmaRO = pmReadoutAlloc(sigmaCell); // Readout with suspect image280 pmReadout *sigmaRO = pmReadoutAlloc(sigmaCell); ///< Readout with suspect image 269 281 psImage *suspect = psMetadataLookupPtr(NULL, outRO->analysis, PM_MASK_ANALYSIS_SUSPECT); 270 282 sigmaRO->image = psImageCopy(sigmaRO->image, suspect, PS_TYPE_F32); … … 275 287 276 288 if (maskGrow > 0) { 277 psImage *grown = psImageGrowMask(NULL, outRO->mask, maskValOut, maskGrow, maskValOut); // Grown mask289 psImage *grown = psImageGrowMask(NULL, outRO->mask, maskValOut, maskGrow, maskValOut); ///< Grown mask 278 290 psFree(outRO->mask); 279 291 outRO->mask = grown; … … 289 301 290 302 // Average concepts 291 psList *cells = psListAlloc(NULL); // List of cells, for concept averaging303 psList *cells = psListAlloc(NULL); ///< List of cells, for concept averaging 292 304 for (int i = 0; i < numFiles; i++) { 293 pmFPAfile *inFile = pmFPAfileSelectSingle(config->files, "PPMERGE.INPUT", i); // Input file294 pmCell *inCell = pmFPAviewThisCell(outView, inFile->fpa); // Input cell305 pmFPAfile *inFile = pmFPAfileSelectSingle(config->files, "PPMERGE.INPUT", i); ///< Input file 306 pmCell *inCell = pmFPAviewThisCell(outView, inFile->fpa); ///< Input cell 295 307 psListAdd(cells, PS_LIST_TAIL, inCell); 296 308 } … … 340 352 assert(config); 341 353 342 bool mdok; // Status of MD lookup343 int numFiles = psMetadataLookupS32(NULL, config->arguments, "INPUTS.NUM"); // Number of inputs344 bool haveMasks = psMetadataLookupBool(&mdok, config->arguments, "INPUTS.MASKS"); // Do we have masks?345 bool haveWeights = psMetadataLookupBool(&mdok, config->arguments, "INPUTS.WEIGHTS"); // Do we have weights?346 int iter = psMetadataLookupS32(NULL, config->arguments, "ITER"); // Number of rejection iterations354 bool mdok; ///< Status of MD lookup 355 int numFiles = psMetadataLookupS32(NULL, config->arguments, "INPUTS.NUM"); ///< Number of inputs 356 bool haveMasks = psMetadataLookupBool(&mdok, config->arguments, "INPUTS.MASKS"); ///< Do we have masks? 357 bool haveWeights = psMetadataLookupBool(&mdok, config->arguments, "INPUTS.WEIGHTS"); ///< Do we have weights? 358 int iter = psMetadataLookupS32(NULL, config->arguments, "ITER"); ///< Number of rejection iterations 347 359 348 360 PS_ASSERT_INT_POSITIVE(iter, false); 349 361 350 pmFPAview *view = pmFPAviewAlloc(0); // View to component of interest351 psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 0); // Random number generator352 353 psMetadata *stats = NULL; // Statistics for output362 pmFPAview *view = pmFPAviewAlloc(0); ///< View to component of interest 363 psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 0); ///< Random number generator 364 365 psMetadata *stats = NULL; ///< Statistics for output 354 366 if (psMetadataLookup(config->arguments, "STATS.NAME")) { 355 367 stats = psMetadataAlloc(); … … 357 369 } 358 370 359 psArray *inputs = ppMergeFileDataLevel(config, "PPMERGE.INPUT", PM_FPA_LEVEL_READOUT); // Input images371 psArray *inputs = ppMergeFileDataLevel(config, "PPMERGE.INPUT", PM_FPA_LEVEL_READOUT); ///< Input images 360 372 psFree(inputs); 361 373 if (haveMasks) { … … 380 392 // for the input masks. 381 393 382 psString outName = ppMergeOutputFile(config); // Name of output file383 pmFPAfile *output = psMetadataLookupPtr(NULL, config->files, outName); // Output file394 psString outName = ppMergeOutputFile(config); ///< Name of output file 395 pmFPAfile *output = psMetadataLookupPtr(NULL, config->files, outName); ///< Output file 384 396 psFree(outName); 385 397 assert(output && output->fpa); 386 pmFPA *outFPA = output->fpa; // Output FPA398 pmFPA *outFPA = output->fpa; ///< Output FPA 387 399 388 400 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 389 401 goto PPMERGE_MASK_ERROR; 390 402 } 391 pmChip *outChip; // Chip of interest403 pmChip *outChip; ///< Chip of interest 392 404 while ((outChip = pmFPAviewNextChip(view, outFPA, 1))) { 393 405 … … 408 420 psList *inChips = psListAlloc(NULL); 409 421 for (int i=0; i < numFiles; i++) { 410 pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PPMERGE.INPUT", i); // Input file422 pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PPMERGE.INPUT", i); ///< Input file 411 423 pmChip *chip = pmFPAviewThisChip(view, file->fpa); 412 424 psListAdd(inChips, PS_LIST_TAIL, chip); … … 427 439 } 428 440 429 psList *fpaList = psListAlloc(NULL);// List of FPAs for concept averaging441 psList *fpaList = psListAlloc(NULL);///< List of FPAs for concept averaging 430 442 for (int i = 0; i < numFiles; i++) { 431 pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PPMERGE.INPUT", i); // Input file443 pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PPMERGE.INPUT", i); ///< Input file 432 444 psListAdd(fpaList, PS_LIST_TAIL, file->fpa); 433 445 }
Note:
See TracChangeset
for help on using the changeset viewer.
