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