Changeset 9996
- Timestamp:
- Nov 14, 2006, 4:49:37 PM (19 years ago)
- Location:
- trunk/ppMerge/src
- Files:
-
- 2 added
- 5 edited
-
Makefile.am (modified) (2 diffs)
-
ppMerge.c (modified) (2 diffs)
-
ppMergeCombine.c (modified) (5 diffs)
-
ppMergeMask.c (added)
-
ppMergeMask.h (added)
-
ppMergeOptions.c (modified) (10 diffs)
-
ppMergeOptions.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppMerge/src/Makefile.am
r8405 r9996 10 10 ppMergeConfig.c \ 11 11 ppMergeData.c \ 12 ppMergeMask.c \ 12 13 ppMergeOptions.c \ 13 14 ppMergeScaleZero.c … … 20 21 ppMergeConfig.h \ 21 22 ppMergeData.h \ 23 ppMergeMask.h \ 22 24 ppMergeOptions.h \ 23 25 ppMergeScaleZero.h -
trunk/ppMerge/src/ppMerge.c
r9463 r9996 14 14 #include "ppMergeCombine.h" 15 15 #include "ppMergeScaleZero.h" 16 #include "ppMergeMask.h" 16 17 17 18 //#include "ppMem.h" … … 45 46 } 46 47 47 // Measure the background in each image48 48 psImage *scale = NULL; // The scalings 49 49 psImage *zero = NULL; // The zeros 50 ppMergeScaleZero(&scale, &zero, data, options, config);51 50 52 // Do the combination and write 53 ppMergeCombine(scale, zero, data, options, config); 51 if (options->mask) { 52 // Generate a mask 53 ppMergeMask(data, options, config); 54 } else { 55 // Measure the background in each image 56 ppMergeScaleZero(&scale, &zero, data, options, config); 57 58 // Do the combination and write 59 ppMergeCombine(scale, zero, data, options, config); 60 } 54 61 55 62 // Output the statistics -
trunk/ppMerge/src/ppMergeCombine.c
r9954 r9996 78 78 #endif 79 79 80 #if 081 // Write fringe extensions82 static void writeFringes(psMetadata *fringes, // Table of extensions with fringe statistics to write83 psFits *fits // FITS file to which to write84 )85 {86 assert(fringes);87 88 // Write the fringe extensions89 psMetadataIterator *fringesIter = psMetadataIteratorAlloc(fringes, PS_LIST_HEAD, false); // Iterator90 psMetadataItem *fringeItem; // Item from iteration91 while ((fringeItem = psMetadataGetAndIncrement(fringesIter))) {92 const char *extname = fringeItem->name; // Extension name93 psArray *fringe = fringeItem->data.V; // Fringe data (array of fringe components)94 if (!pmFringesWriteFits(fits, NULL, fringe, extname)) {95 psWarning("Unable to write fringe data to extension %s\n", extname);96 }97 }98 99 // Clear the list100 while (psListLength(fringes->list) > 0) {101 psMetadataRemoveIndex(fringes, PS_LIST_TAIL);102 }103 104 return;105 }106 #endif107 80 108 81 // Combine the inputs … … 133 106 pmFPAWrite(data->out, data->outFile, config->database, true, false); // Write header only 134 107 pmChip *chip; // Chip of interest 108 psRandom *rng = NULL; // Random number generator; required for building a mask 109 if (options->mask) { 110 rng = psRandomAlloc(PS_RANDOM_TAUS, 0); 111 } 135 112 while ((chip = pmFPAviewNextChip(view, fpa, 1))) { 136 113 pmChipWrite(chip, data->outFile, config->database, true, false); // Write header only … … 150 127 } 151 128 152 // Building a shutter correction 153 if (options->shutter) { 154 // Read in the pixels 155 int numRead = 0; // Number of inputs read 156 psVector *exptimes = psVectorAlloc(filenames->n, PS_TYPE_F32); // Reference measurements 157 psVectorInit(exptimes, 0); 158 psArray *images = psArrayAlloc(filenames->n); // Array of images 159 psArray *weights = psArrayAlloc(filenames->n); // Array of weights 160 psArray *masks = psArrayAlloc(filenames->n); // Array of masks 129 // Read bit by bit 130 int numRead; // Number of inputs read 131 int numScan = 0; 132 133 do { 134 numRead = 0; 161 135 for (int i = 0; i < filenames->n; i++) { 162 136 if (! filenames->data[i] || strlen(filenames->data[i]) == 0) { … … 167 141 continue; 168 142 } 169 pmFPA *fpaIn = data->in->data[i]; // Input FPA 170 pmChip *chipIn = fpaIn->chips->data[view->chip]; // Input chip 171 pmCell *cellIn = chipIn->cells->data[view->cell]; // Input cell 172 if (!cellIn->file_exists) { 173 // || !cellIn->data_exists) { 174 continue; 175 } 176 if (!pmCellRead(cellIn, fits, config->database) || cellIn->readouts->n == 0) { 177 continue; 178 } 179 if (cellIn->readouts->n > 1) { 180 psWarning("Multiple readouts in file %d, chip %d, cell %d --- " 181 "only the first will be used.\n", i, view->chip, view->cell); 182 } 183 float exptime = psMetadataLookupF32(NULL, cellIn->concepts, "CELL.EXPOSURE"); 184 if (!isfinite(exptime)) { 185 psWarning("File %d, chip %d, cell %d has bad exposure time.\n", 186 i, view->chip, view->cell); 187 } 188 exptimes->data.F32[i] = exptime; 189 pmReadout *readoutIn = cellIn->readouts->data[0]; 190 pmReadoutSetWeight(readoutIn); 191 images->data[i] = psMemIncrRefCounter(readoutIn->image); 192 weights->data[i] = psMemIncrRefCounter(readoutIn->weight); 193 masks->data[i] = psMemIncrRefCounter(readoutIn->mask); 194 numRead++; 143 144 if (!stack->data[i]) { 145 pmFPA *fpaIn = data->in->data[i]; // Input FPA 146 pmChip *chipIn = fpaIn->chips->data[view->chip]; // Input chip 147 pmCell *cellIn = chipIn->cells->data[view->cell]; // Input cell 148 stack->data[i] = pmReadoutAlloc(cellIn); // Input readout 149 } 150 151 // Only reading and writing the first readout in each cell (plane 0) 152 if (pmReadoutReadNext(stack->data[i], fits, 0, options->rows)) { 153 // For anything except BIAS and DARK, we want a mask 154 if (options->scale || options->zero || options->shutter) { 155 pmReadoutSetMask(stack->data[i]); 156 } 157 if (options->shutter) { 158 pmReadoutSetWeight(stack->data[i]); 159 } 160 161 numRead++; 162 } else { 163 psTrace("ppMerge", 3, "Unable to read from file %d for chip %d, " 164 "cell %d, scan %d\n", i, view->chip, view->cell, numScan); 165 } 166 195 167 } 196 if (numRead > 1) { 197 readout->image = pmShutterCorrectionMeasure(exptimes, images, weights, masks, 198 options->shutterSize, options->mean, 199 options->stdev, options->shutterIter, 200 options->shutterRej, 201 options->combine->maskVal); 202 psTrace("ppMerge", 5, "Chip %d, cell %d\n", view->chip, view->cell); 203 } else { 204 psError(PS_ERR_UNKNOWN, true, "Not enough images to combine: %d\n", numRead); 205 psFree(images); 206 psFree(exptimes); 207 return false; 168 169 psTrace("ppMerge", 5, "Chip %d, cell %d, scan %d\n", view->chip, view->cell, numScan); 170 if (numRead > 0) { 171 172 if (options->shutter) { 173 readout->image = pmShutterCorrectionMeasure(stack, options->shutterSize, 174 options->mean, options->stdev, 175 options->shutterIter, 176 options->shutterRej, 177 options->combine->maskVal); 178 } else { 179 pmReadoutCombine(readout, stack, cellZeros, cellScales, options->combine); 180 } 208 181 } 209 psFree(images); 210 psFree(masks); 211 psFree(weights); 212 psFree(exptimes); 213 } else { 214 #if 1 215 // Read bit by bit 216 217 int numRead; // Number of inputs read 218 int numScan = 0; 219 do { 220 numRead = 0; 221 for (int i = 0; i < filenames->n; i++) { 222 if (! filenames->data[i] || strlen(filenames->data[i]) == 0) { 223 continue; 224 } 225 psFits *fits = data->files->data[i]; // FITS file handle 226 if (!fits) { 227 continue; 228 } 229 230 if (!stack->data[i]) { 231 pmFPA *fpaIn = data->in->data[i]; // Input FPA 232 pmChip *chipIn = fpaIn->chips->data[view->chip]; // Input chip 233 pmCell *cellIn = chipIn->cells->data[view->cell]; // Input cell 234 stack->data[i] = pmReadoutAlloc(cellIn); // Input readout 235 } 236 237 // Only reading and writing the first readout in each cell (plane 0) 238 if (pmReadoutReadNext(stack->data[i], fits, 0, options->rows)) { 239 // For anything except BIAS and DARK, we want a mask 240 if (options->scale || options->zero) { 241 pmReadoutSetMask(stack->data[i]); 242 } 243 numRead++; 244 } else { 245 psTrace("ppMerge", 3, "Unable to read from file %d for chip %d, " 246 "cell %d, scan %d\n", i, view->chip, view->cell, numScan); 247 } 248 } 249 250 psTrace("ppMerge", 5, "Chip %d, cell %d, scan %d\n", view->chip, view->cell, numScan); 251 if (numRead > 0) { 252 pmReadoutCombine(readout, stack, cellZeros, cellScales, options->combine); 253 } 254 numScan++; 255 256 } while (numRead > 0); 257 258 #else 259 // Read whole cells at a time 260 261 printf("Chip %d, cell %d\n", view->chip, view->cell); 262 int numRead = 0; // Number of inputs read 263 for (int i = 0; i < filenames->n; i++) { 264 if (! filenames->data[i] || strlen(filenames->data[i]) == 0) { 265 continue; 266 } 267 psFits *fits = data->files->data[i]; // FITS file handle 268 if (!fits) { 269 continue; 270 } 271 pmFPA *fpaIn = data->in->data[i]; // Input FPA 272 pmChip *chipIn = fpaIn->chips->data[view->chip]; // Input chip 273 pmCell *cellIn = chipIn->cells->data[view->cell]; // Input cell 274 if (!cellIn->file_exists || !cellIn->data_exists) { 275 continue; 276 } 277 if (!pmCellRead(cellIn, fits, config->database) || cellIn->readouts->n == 0) { 278 continue; 279 } 280 stack->data[i] = cellIn->readouts->data[0]; 281 numRead++; 282 } 283 if (numRead > 0) { 284 pmReadoutCombine(readout, stack, cellZeros, cellScales, options->combine); 285 psTrace("ppMerge", 5, "Chip %d, cell %d\n", view->chip, view->cell); 286 } 287 288 memCheck(); 289 #endif 290 } 182 numScan++; 183 184 } while (numRead > 0); 291 185 292 186 psFree(stack); … … 392 286 393 287 psFree(view); 288 psFree(rng); 394 289 395 290 return true; -
trunk/ppMerge/src/ppMergeOptions.c
r9832 r9996 37 37 options->fringe = false; 38 38 options->shutter = false; 39 options->mask = false; 39 40 options->sample = 1; 40 41 options->mean = PS_STAT_SAMPLE_MEDIAN; … … 47 48 options->shutterIter = 2; 48 49 options->shutterRej = 3.0; 50 options->maskSuspect = 5.0; 51 options->maskBad = 10.0; 49 52 options->onOff = 0; 50 53 options->combine = pmCombineParamsAlloc(PS_STAT_SAMPLE_MEAN); … … 143 146 OPTION_PARSE(options->shutterIter, recipe, "SHUTTER.ITER", S32); 144 147 OPTION_PARSE(options->shutterRej, recipe, "SHUTTER.REJECT", F32); 148 OPTION_PARSE(options->maskSuspect, recipe, "MASK.SUSPECT", F32); 149 OPTION_PARSE(options->maskBad, recipe, "MASK.BAD", F32); 145 150 146 151 options->combine->combine = parseStat(recipe, "COMBINE"); … … 159 164 options->fringe = false; 160 165 options->shutter = false; 166 options->mask = false; 161 167 } else if (strcasecmp(type, "DARK") == 0) { 162 168 options->zero = false; … … 165 171 options->fringe = false; 166 172 options->shutter = false; 173 options->mask = false; 167 174 } else if (strcasecmp(type, "FLAT") == 0) { 168 175 options->zero = false; … … 171 178 options->fringe = false; 172 179 options->shutter = false; 180 options->mask = false; 173 181 } else if (strcasecmp(type, "FRINGE") == 0) { 174 182 options->zero = true; … … 177 185 options->fringe = true; 178 186 options->shutter = false; 187 options->mask = false; 179 188 } else if (strcasecmp(type, "SHUTTER") == 0) { 180 189 options->zero = false; … … 183 192 options->fringe = false; 184 193 options->shutter = true; 194 options->mask = false; 195 options->rows = 0; // Read the whole image at once 196 } else if (strcasecmp(type, "MASK") == 0) { 197 options->zero = false; 198 options->scale = false; 199 options->darktime = false; 200 options->fringe = false; 201 options->shutter = false; 202 options->mask = true; 185 203 } else { 186 204 psLogMsg(__func__, PS_LOG_WARN, "Unrecognised image type: %s --- assuming BIAS.\n", type); … … 190 208 options->fringe = false; 191 209 options->shutter = false; 210 options->mask = false; 192 211 } 193 212 } else { … … 198 217 options->fringe = false; 199 218 options->shutter = false; 219 options->mask = false; 200 220 } 201 221 -
trunk/ppMerge/src/ppMergeOptions.h
r9832 r9996 24 24 bool fringe; // Make fringe measurements? 25 25 bool shutter; // Generate shutter correction? 26 bool mask; // Generate bad pixel mask? 26 27 unsigned int sample; // Sampling factor for measuring the background 27 28 psStatsOptions mean; // Statistic to use to measure the mean … … 34 35 int shutterIter; // Number of iterations for shutter measurement 35 36 float shutterRej; // Rejection limit for shutter measurement 37 float maskSuspect; // Threshold for identifying suspect pixels 38 float maskBad; // Threshold for identifying bad pixels 36 39 ppOnOff onOff; // On/off pairs? 37 40 pmCombineParams *combine; // Combination parameters
Note:
See TracChangeset
for help on using the changeset viewer.
