Changeset 9996 for trunk/ppMerge/src/ppMergeCombine.c
- Timestamp:
- Nov 14, 2006, 4:49:37 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/ppMerge/src/ppMergeCombine.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
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;
Note:
See TracChangeset
for help on using the changeset viewer.
