Changeset 27838 for branches/tap_branches/pswarp/src/pswarpLoop.c
- Timestamp:
- May 3, 2010, 8:41:49 AM (16 years ago)
- Location:
- branches/tap_branches
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
pswarp/src/pswarpLoop.c (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/tap_branches
- Property svn:mergeinfo changed
-
branches/tap_branches/pswarp/src/pswarpLoop.c
r25847 r27838 19 19 20 20 21 // XXX these are generic functions which should be moved to psModules 22 // Activate a list of files 23 static void fileActivation(pmConfig *config, // Configuration 24 char **files, // Files to turn on/off 25 bool state // Activation state 26 ) 27 { 28 for (int i = 0; files[i] != NULL; i++) { 29 pmFPAfileActivate(config->files, state, files[i]); 30 } 31 return; 32 } 33 34 /** 35 * Run down the FPA hierarchy, checking files 36 */ 37 static bool ioChecksBefore(pmConfig *config ///< Configuration 38 ) 39 { 40 pmFPAview *view = pmFPAviewAlloc(0); ///< View for checking 41 bool status = true; ///< Status of checks 42 status &= pmFPAfileIOChecks(config, view, PM_FPA_BEFORE); 43 view->chip = 0; 44 status &= pmFPAfileIOChecks(config, view, PM_FPA_BEFORE); 45 view->cell = 0; 46 status &= pmFPAfileIOChecks(config, view, PM_FPA_BEFORE); 47 psFree(view); 48 return status; 49 } 50 51 /** 52 * Run up the FPA hierarchy, checking files 53 */ 54 static bool ioChecksAfter(pmConfig *config ///< Configuration 55 ) 56 { 57 pmFPAview *view = pmFPAviewAlloc(0); ///< View for checking 58 view->chip = view->cell = 0; 59 bool status = true; ///< Status of checks 60 status &= pmFPAfileIOChecks(config, view, PM_FPA_AFTER); 61 view->cell = -1; 62 status &= pmFPAfileIOChecks(config, view, PM_FPA_AFTER); 63 view->chip = -1; 64 status &= pmFPAfileIOChecks(config, view, PM_FPA_AFTER); 65 psFree(view); 66 return status; 67 } 68 69 70 /** 71 * Loop over the inputs, warp them to the output skycell and then write out the output. 72 */ 73 bool pswarpLoop(pmConfig *config) 21 22 // Loop over the inputs, warp them to the output skycell and then write out the output. 23 bool pswarpLoop(pmConfig *config, psMetadata *stats) 74 24 { 75 25 bool status; 26 bool mdok; // Status of MD lookup 76 27 77 28 const char *skyCamera = psMetadataLookupStr(NULL, config->arguments, 78 "SKYCELL.CAMERA"); // /<Name of camera for skycell29 "SKYCELL.CAMERA"); // Name of camera for skycell 79 30 pmConfigCamerasCull(config, skyCamera); 80 31 pmConfigRecipesCull(config, "PSWARP,PPSTATS,PSPHOT,PSASTRO,MASKS,JPEG"); 81 82 32 83 33 // load the recipe 84 34 psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSWARP_RECIPE); 85 35 if (!recipe) { 86 psError(PS PHOT_ERR_CONFIG, false, "missing recipe %s", PSWARP_RECIPE);36 psError(PSWARP_ERR_CONFIG, false, "missing recipe %s", PSWARP_RECIPE); 87 37 return false; 88 38 } 89 39 90 40 if (!pswarpSetMaskBits(config)) { 91 psError( PS_ERR_IO, false, "failed to set mask bits");41 psError(psErrorCodeLast(), false, "failed to set mask bits"); 92 42 return NULL; 93 43 } … … 111 61 112 62 if (astrom->camera != input->camera) { 113 psError(PS _ERR_UNKNOWN, true, "Input camera and astrometry camera do not match.");63 psError(PSWARP_ERR_DATA, true, "Input camera and astrometry camera do not match."); 114 64 return false; 115 65 } … … 127 77 psFree (view); 128 78 129 bool mdok; ///< Status of MD lookup130 const char *statsName = psMetadataLookupStr(&mdok, config->arguments, "STATS"); ///< Filename for statistics131 psMetadata *stats = NULL; ///< Container for statistics132 FILE *statsFile = NULL; ///< File stream for statistics133 if (mdok && statsName && strlen(statsName) > 0) {134 psString resolved = pmConfigConvertFilename(statsName, config, true, true);135 statsFile = fopen(resolved, "w");136 if (!statsFile) {137 psError(PS_ERR_IO, true, "Unable to open statistics file %s for writing.\n", resolved);138 psFree(resolved);139 return false;140 }141 psFree(resolved);142 stats = psMetadataAlloc();143 psMetadataAddS32(stats, PS_LIST_TAIL, "QUALITY", 0, "No problems", 0);144 }145 79 146 80 // Turn all skycell files on to generate them, and then turn them off for the loop over the input images 147 81 // the input, which is in a different format. 148 82 { 149 fileActivation(config, detectorFiles, false); 150 fileActivation(config, photFiles, false); 151 fileActivation(config, independentFiles, false); 152 fileActivation(config, skycellFiles, true); 153 ioChecksBefore(config); 154 fileActivation(config, skycellFiles, false); 83 pswarpFileActivation(config, detectorFiles, false); 84 pswarpFileActivation(config, photFiles, false); 85 pswarpFileActivation(config, independentFiles, false); 86 pswarpFileActivation(config, skycellFiles, true); 87 if (!pswarpIOChecksBefore(config)) { 88 psError(psErrorCodeLast(), false, "Unable to read files."); 89 goto DONE; 90 } 91 pswarpFileActivation(config, skycellFiles, false); 155 92 } 156 93 … … 162 99 pmChip *chip; 163 100 pmFPAview *view = pmFPAviewAlloc(0); 164 pmFPAfileIOChecks (config, view, PM_FPA_BEFORE); 101 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 102 psError(psErrorCodeLast(), false, "Unable to read files."); 103 goto DONE; 104 } 165 105 while ((chip = pmFPAviewNextChip (view, input->fpa, 1)) != NULL) { 166 106 psTrace ("pswarp", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process); 167 107 if (!chip->process || !chip->file_exists) { continue; } 168 pmFPAfileIOChecks(config, view, PM_FPA_BEFORE); 108 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 109 psError(psErrorCodeLast(), false, "Unable to read files."); 110 goto DONE; 111 } 169 112 pmCell *cell; 170 113 while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) { 171 114 psTrace ("pswarp", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process); 172 115 if (!cell->process || !cell->file_exists) { continue; } 173 pmFPAfileIOChecks (config, view, PM_FPA_BEFORE); 174 pmFPAfileIOChecks (config, view, PM_FPA_AFTER); 175 } 176 pmFPAfileIOChecks (config, view, PM_FPA_AFTER); 177 } 178 pmFPAfileIOChecks (config, view, PM_FPA_AFTER); 179 psFree(view); 180 181 fileActivation(config, detectorFiles, true); 116 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE) || 117 !pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) { 118 psError(psErrorCodeLast(), false, "Unable to read files."); 119 goto DONE; 120 } 121 } 122 if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) { 123 psError(psErrorCodeLast(), false, "Unable to write files."); 124 goto DONE; 125 } 126 } 127 if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) { 128 psError(psErrorCodeLast(), false, "Unable to write files."); 129 goto DONE; 130 } 131 psFree(view); 132 133 pswarpFileActivation(config, detectorFiles, true); 182 134 pmFPAfileActivate(config->files, false, "PSWARP.ASTROM"); 183 135 } … … 201 153 if (bilevelAstrometry) { 202 154 if (!pmAstromReadBilevelMosaic(input->fpa, phu->header)) { 203 psError( PS_ERR_UNKNOWN, false, "Unable to read bilevel mosaic astrometry for input FPA.");155 psError(psErrorCodeLast(), false, "Unable to read bilevel mosaic astrometry for input FPA."); 204 156 psFree(view); 205 157 psFree(stats); 206 return false;158 goto DONE; 207 159 } 208 160 } … … 211 163 212 164 // files associated with the science image 213 pmFPAfileIOChecks (config, view, PM_FPA_BEFORE); 165 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) { 166 psError(psErrorCodeLast(), false, "Unable to read files."); 167 goto DONE; 168 } 214 169 215 170 pmChip *chip; … … 217 172 psTrace ("pswarp", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process); 218 173 if (!chip->process || !chip->file_exists) { continue; } 219 pmFPAfileIOChecks (config, view, PM_FPA_BEFORE); 174 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) { 175 psError(psErrorCodeLast(), false, "Unable to read files."); 176 goto DONE; 177 } 220 178 221 179 // read WCS data from the corresponding header … … 223 181 if (bilevelAstrometry) { 224 182 if (!pmAstromReadBilevelChip (chip, hdu->header)) { 225 psError( PS_ERR_UNKNOWN, false, "Unable to read bilevel chip astrometry for input FPA.");183 psError(psErrorCodeLast(), false, "Unable to read bilevel chip astrometry for input FPA."); 226 184 psFree(view); 227 185 psFree(stats); 228 return false;186 goto DONE; 229 187 } 230 188 } else { 231 189 // we use a default FPA pixel scale of 1.0 232 190 if (!pmAstromReadWCS (input->fpa, chip, hdu->header, 1.0)) { 233 psError( PS_ERR_UNKNOWN, false, "Unable to read WCS astrometry for input FPA.");191 psError(psErrorCodeLast(), false, "Unable to read WCS astrometry for input FPA."); 234 192 psFree(view); 235 193 psFree(stats); 236 return false;194 goto DONE; 237 195 } 238 196 } … … 242 200 psTrace ("pswarp", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process); 243 201 if (!cell->process || !cell->file_exists) { continue; } 244 pmFPAfileIOChecks (config, view, PM_FPA_BEFORE); 202 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) { 203 psError(psErrorCodeLast(), false, "Unable to read files."); 204 goto DONE; 205 } 245 206 246 207 psListAdd(cells, PS_LIST_TAIL, cell); … … 249 210 pmReadout *readout; 250 211 while ((readout = pmFPAviewNextReadout(view, input->fpa, 1)) != NULL) { 251 pmFPAfileIOChecks(config, view, PM_FPA_BEFORE); 212 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 213 psError(psErrorCodeLast(), false, "Unable to read files."); 214 goto DONE; 215 } 252 216 if (!readout->data_exists) { 253 217 continue; 254 218 } 255 219 256 // Copy the sources from the astrometry carrier to the input, so they can be accessed by220 // Copy the detections from the astrometry carrier to the input, so they can be accessed by 257 221 // pswarpTransformReadout 258 222 pmReadout *astromRO = pmFPAviewThisReadout(view, astrom->fpa); // Readout for astrometry 259 psArray *sources = psMetadataLookupPtr(&mdok, astromRO->analysis, 260 "PSPHOT.SOURCES"); // Sources from astrometry 261 if (sources) { 262 psMetadataAddPtr(readout->analysis, PS_LIST_TAIL, "PSPHOT.SOURCES", PS_DATA_ARRAY, 263 "Sources from input astrometry", sources); 223 pmDetections *detections = psMetadataLookupPtr(&mdok, astromRO->analysis, "PSPHOT.DETECTIONS"); // Sources from astrometry 224 if (detections) { 225 psMetadataAddPtr(readout->analysis, PS_LIST_TAIL, "PSPHOT.DETECTIONS", PS_DATA_ARRAY, "Sources from input astrometry", detections); 264 226 } 265 227 266 228 pswarpTransformReadout(output, readout, config); 267 229 268 pmFPAfileIOChecks(config, view, PM_FPA_AFTER); 269 } 270 pmFPAfileIOChecks(config, view, PM_FPA_AFTER); 271 } 272 pmFPAfileIOChecks(config, view, PM_FPA_AFTER); 230 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 231 psError(psErrorCodeLast(), false, "Unable to write files."); 232 goto DONE; 233 } 234 } 235 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 236 psError(psErrorCodeLast(), false, "Unable to write files."); 237 goto DONE; 238 } 239 } 240 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 241 psError(psErrorCodeLast(), false, "Unable to write files."); 242 goto DONE; 243 } 273 244 } 274 245 … … 290 261 291 262 if (!pswarpPixelsLit(output, stats, config)) { 292 psError( PS_ERR_UNKNOWN, false, "Unable to calculate pixel regions.");263 psError(psErrorCodeLast(), false, "Unable to calculate pixel regions."); 293 264 psFree(cells); 294 265 psFree(view); 295 return false;266 goto DONE; 296 267 } 297 268 … … 327 298 328 299 if (!pmConceptsAverageCells(outCell, cells, NULL, NULL, false)) { 329 psError( PS_ERR_UNKNOWN, false, "Unable to average cell concepts.");300 psError(psErrorCodeLast(), false, "Unable to average cell concepts."); 330 301 psFree(stats); 331 302 psFree(cells); 332 303 psFree(view); 333 return false;304 goto DONE; 334 305 } 335 306 psFree(cells); … … 339 310 340 311 if (!psMetadataCopy(outFPA->concepts, input->fpa->concepts)) { 341 psError( PS_ERR_UNKNOWN, false, "Unable to copy FPA concepts from input to output.");312 psError(psErrorCodeLast(), false, "Unable to copy FPA concepts from input to output."); 342 313 psFree(stats); 343 314 psFree(view); 344 return false; 315 goto DONE; 316 } 317 318 // Update ZP from the astrometry 319 { 320 psMetadataItem *item = psMetadataLookup(outFPA->concepts, "FPA.ZP"); 321 item->data.F32 = psMetadataLookupF32(NULL, astrom->fpa->concepts, "FPA.ZP"); 345 322 } 346 323 … … 355 332 pmHDU *skyHDU = pmHDUFromCell(cell); ///< HDU 356 333 if (!skyHDU) { 357 psError(PS _ERR_UNEXPECTED_NULL, false, "Unable to find skycell HDU.");334 psError(PSWARP_ERR_DATA, false, "Unable to find skycell HDU."); 358 335 psFree(view); 359 return false;336 goto DONE; 360 337 } 361 338 hdu->header = psMetadataCopy(hdu->header, skyHDU->header); … … 365 342 366 343 if (!pmAstromWriteWCS(hdu->header, outFPA, outChip, WCS_NONLIN_TOL)) { 367 psError( PS_ERR_UNKNOWN, false, "Unable to generate WCS header.");344 psError(psErrorCodeLast(), false, "Unable to generate WCS header."); 368 345 psFree(stats); 369 return false; 370 } 371 372 pmFPAfileIOChecks(config, view, PM_FPA_AFTER); 346 goto DONE; 347 } 348 349 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 350 psError(psErrorCodeLast(), false, "Unable to write files."); 351 goto DONE; 352 } 373 353 374 354 // Done with the detector side of things 375 fileActivation(config, detectorFiles, false);376 fileActivation(config, independentFiles, false);355 pswarpFileActivation(config, detectorFiles, false); 356 pswarpFileActivation(config, independentFiles, false); 377 357 378 358 // We need a new PSF model for the warped frame. It would be good to generate this analytically, but … … 380 360 381 361 if (psMetadataLookupBool(&mdok, recipe, "PSF")) { 382 fileActivation(config, photFiles, true); 383 ioChecksBefore(config); 362 pswarpFileActivation(config, photFiles, true); 363 if (!pswarpIOChecksBefore(config)) { 364 psError(psErrorCodeLast(), false, "Unable to read files."); 365 goto DONE; 366 } 384 367 385 368 // supply the readout and fpa of interest to psphot … … 393 376 psArray *sources = psphotLoadPSFSources (config, view); 394 377 if (!sources) { 395 psError( PS_ERR_UNKNOWN, false, "No sources supplied to measure PSF");396 return false;378 psError(psErrorCodeLast(), false, "No sources supplied to measure PSF"); 379 goto DONE; 397 380 } 398 381 … … 412 395 psphotFilesActivate(config, false); 413 396 } 397 398 // Ensure seeing is carried over 399 pmChip *photChip = pmFPAviewThisChip(view, photFile->fpa); // Chip with seeing 400 psMetadataItem *item = psMetadataLookup(outChip->concepts, "CHIP.SEEING"); // Concept with seeing 401 item->data.F32 = psMetadataLookupF32(NULL, photChip->concepts, "CHIP.SEEING"); 414 402 415 403 // XXX EAM : put this in a visualization function … … 435 423 } 436 424 437 fileActivation(config, skycellFiles, true);438 439 425 // Perform statistics on the output image 440 426 if (stats) { … … 458 444 psFree(view); 459 445 460 // Ensure everything is written out, at every level461 ioChecksAfter(config);462 463 // Now done with the skycell side of things464 465 446 DONE: 466 467 // Write out summary statistics468 if (stats) {469 psMetadataAddF32(stats, PS_LIST_TAIL, "DT_WARP", 0, "Time for warp completion",470 psTimerMark("pswarp"));471 472 const char *statsMDC = psMetadataConfigFormat(stats);473 if (!statsMDC) {474 psError(PS_ERR_IO, false, "Unable to get statistics MDC file.\n");475 psFree(stats);476 fclose(statsFile);477 return false;478 }479 fprintf(statsFile, "%s", statsMDC);480 psFree((void*)statsMDC);481 fclose(statsFile);482 pmConfigRunFilenameAddWrite(config, "STATS", statsName);483 484 psFree(stats);485 }486 487 // Dump configuration488 psString dump_file = psMetadataLookupStr(&status, config->arguments, "DUMP_CONFIG");489 if (dump_file) {490 if (!pmConfigDump(config, dump_file)) {491 psError(PS_ERR_IO, false, "Unable to dump configuration");492 return false;493 }494 }495 447 496 448 return true;
Note:
See TracChangeset
for help on using the changeset viewer.
