Changeset 34411
- Timestamp:
- Sep 6, 2012, 1:24:39 PM (14 years ago)
- Location:
- branches/czw_branch/20120906/pswarp/src
- Files:
-
- 9 edited
-
pswarp.c (modified) (2 diffs)
-
pswarp.h (modified) (1 diff)
-
pswarpArguments.c (modified) (4 diffs)
-
pswarpDefine.c (modified) (3 diffs)
-
pswarpFileNames.h (modified) (2 diffs)
-
pswarpLoop.c (modified) (5 diffs)
-
pswarpParseCamera.c (modified) (2 diffs)
-
pswarpTransformReadout.c (modified) (1 diff)
-
pswarpTransformSources.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/czw_branch/20120906/pswarp/src/pswarp.c
r27904 r34411 46 46 goto DIE; 47 47 } 48 if (psMetadataLookupBool(NULL,config->arguments,"BACKGROUND.MODEL")) { 49 fprintf(stderr,"Here!\n"); 50 if (!pswarpDefineBackground(config)) { 51 goto DIE; 52 } 53 } 48 54 49 55 // Open the statistics file … … 66 72 if (!pswarpLoop(config, stats)) { 67 73 goto DIE; 74 } 75 if (psMetadataLookupBool(NULL,config->arguments,"BACKGROUND.MODEL")) { 76 fprintf(stderr,"There!\n"); 77 if (!pswarpLoopBackground(config, stats)) { 78 fprintf(stderr,"Dying!\n"); 79 goto DIE; 80 } 68 81 } 69 82 -
branches/czw_branch/20120906/pswarp/src/pswarp.h
r28043 r34411 81 81 bool pswarpParseCamera (pmConfig *config); 82 82 bool pswarpDefine (pmConfig *config); 83 bool pswarpDefineBackground (pmConfig *config); 83 84 bool pswarpLoop (pmConfig *config, psMetadata *stats); 85 bool pswarpLoopBackground (pmConfig *config, psMetadata *stats); 84 86 psExit pswarpExitCode(psExit exitValue); 85 87 bool pswarpTransformReadout (pmReadout *output, pmReadout *input, pmConfig *config); -
branches/czw_branch/20120906/pswarp/src/pswarpArguments.c
r34089 r34411 86 86 pmConfigFileSetsMD (config->arguments, &argc, argv, "MASK", "-mask", "-masklist"); 87 87 pmConfigFileSetsMD (config->arguments, &argc, argv, "VARIANCE", "-variance", "-variancelist"); 88 88 pmConfigFileSetsMD (config->arguments, &argc, argv, "BACKGROUND", "-background", "-bkglist"); 89 89 90 if (argc != 3) { 90 91 usage(); … … 164 165 } 165 166 167 bool doBKG = psMetadataLookupBool(&status,recipe, "BACKGROUND.MODEL"); ///< Generate the warped background model? 168 if (!status) { 169 doBKG = false; 170 psWarning("BACKGROUND.MODEL is not set in the %s recipe -- defaulting to FALSE.", PSWARP_RECIPE); 171 } 172 int bkgXgrid = psMetadataLookupBool(&status,recipe, "BKG.XGRID"); ///< Xsize of background model 173 if (!status) { 174 bkgXgrid = 10; 175 psWarning("BKG.XGRID is not set in the %s recipe -- defaultint to %d.",PSWARP_RECIPE,bkgXgrid); 176 } 177 int bkgYgrid = psMetadataLookupBool(&status,recipe, "BKG.YGRID"); ///< Xsize of background model 178 if (!status) { 179 bkgYgrid = 10; 180 psWarning("BKG.YGRID is not set in the %s recipe -- defaultint to %d.",PSWARP_RECIPE,bkgYgrid); 181 } 182 183 166 184 // Set recipe values in the recipe (since we've possibly altered some) 167 185 psMetadataAddS32(recipe, PS_LIST_TAIL, "GRID.NX", PS_META_REPLACE, … … 176 194 "Fraction of bad flux for a pixel to be marked as poor", poorFrac); 177 195 psMetadataAddBool(recipe, PS_LIST_TAIL, "PSF", PS_META_REPLACE, "Generate a PSF Model?", PSF); 178 196 psMetadataAddBool(recipe, PS_LIST_TAIL, "BACKGROUND.MODEL", PS_META_REPLACE, "Generate the warped background model?", doBKG); 197 psMetadataAddS32(recipe, PS_LIST_TAIL, "BKG.XGRID", PS_META_REPLACE, "Xsize of background model", bkgXgrid); 198 psMetadataAddS32(recipe, PS_LIST_TAIL, "BKG.YGRID", PS_META_REPLACE, "Ysize of background model", bkgYgrid); 199 200 179 201 // Set recipe values in the arguments 180 202 psMetadataAddS32(config->arguments, PS_LIST_TAIL, "GRID.NX", 0, … … 189 211 "Fraction of bad flux for a pixel to be marked as poor", poorFrac); 190 212 psMetadataAddBool(config->arguments, PS_LIST_TAIL, "PSF", PS_META_REPLACE, "Generate a PSF Model?", PSF); 213 psMetadataAddBool(config->arguments, PS_LIST_TAIL, "BACKGROUND.MODEL", PS_META_REPLACE, "Generate the warped background model?", doBKG); 214 psMetadataAddS32(config->arguments, PS_LIST_TAIL, "BKG.XGRID", PS_META_REPLACE, "Xsize of background model", bkgXgrid); 215 psMetadataAddS32(config->arguments, PS_LIST_TAIL, "BKG.YGRID", PS_META_REPLACE, "Ysize of background model", bkgYgrid); 191 216 192 217 psTrace("pswarp", 1, "Done with pswarpArguments...\n"); -
branches/czw_branch/20120906/pswarp/src/pswarpDefine.c
r27989 r34411 41 41 return false; 42 42 } 43 43 44 44 // open the full skycell file; no need to defer different depths. only load the header data 45 45 pmFPAview *view = pmFPAviewAlloc (0); … … 86 86 psMetadataItemSupplement(&status, target->concepts, source->concepts, "CELL.X0"); 87 87 psMetadataItemSupplement(&status, target->concepts, source->concepts, "CELL.Y0"); 88 89 88 90 } 89 91 … … 123 125 } 124 126 } 125 127 126 128 view->chip = view->cell = view->readout = -1; 127 129 pmFPAAddSourceFromView(output->fpa, view, output->format); 130 128 131 129 132 psFree (view); 130 133 return true; 131 134 } 135 136 bool pswarpDefineBackground (pmConfig *config) { 137 138 // load the PSWARP recipe 139 psMetadata *recipe = psMetadataLookupPtr (NULL, config->recipes, PSWARP_RECIPE); 140 if (!recipe) { 141 psError(PSWARP_ERR_CONFIG, true, "Can't find PSWARP recipe!\n"); 142 return false; 143 } 144 145 // select the input data sources 146 pmFPAfile *skycell = psMetadataLookupPtr (NULL, config->files, "PSWARP.SKYCELL"); 147 if (!skycell) { 148 psError(PSWARP_ERR_CONFIG, false, "Can't find skycell data!\n"); 149 return false; 150 } 151 pmFPAfile *output = psMetadataLookupPtr(NULL, config->files, "PSWARP.OUTPUT.BKGMODEL"); 152 if (!output) { 153 psError(PSWARP_ERR_CONFIG, false, "Can't find output data!\n"); 154 return false; 155 } 156 pmFPAfile *input = psMetadataLookupPtr(NULL, config->files, "PSWARP.INPUT"); 157 if (!input) { 158 psError(PSWARP_ERR_CONFIG, false, "Can't find input data!\n"); 159 return false; 160 } 161 162 // open the full skycell file; no need to defer different depths. only load the header data 163 pmFPAview *view = pmFPAviewAlloc (0); 164 pmFPAfileOpen (skycell, view, config); 165 166 // Read header and create target 167 { 168 if (!pmFPAReadHeaderSet(skycell->fpa, skycell->fits, config)) { 169 psError(psErrorCodeLast(), false, "Unable to read headers for skycell."); 170 psFree(view); 171 return false; 172 } 173 view->chip = 0; 174 view->cell = 0; 175 view->readout = 0; 176 pmCell *source = pmFPAfileThisCell(config->files, view, "PSWARP.SKYCELL"); ///< Source cell 177 pmHDU *hdu = pmHDUFromCell(source); ///< HDU for source 178 if (!hdu || !hdu->header) { 179 psError(PM_ERR_PROG, false, "Unable to find header for sky cell."); 180 psFree(view); 181 return false; 182 } 183 int numCols = psMetadataLookupS32(NULL, hdu->header, "NAXIS1"); ///< Number of columns 184 int numRows = psMetadataLookupS32(NULL, hdu->header, "NAXIS2"); ///< Number of rows 185 if ((numCols == 0) || (numRows == 0)) { 186 psError(PSWARP_ERR_DATA, false, "skycell has invalid dimensions %d x %d", numCols, numRows); 187 psFree(view); 188 return false; 189 } 190 191 pmCell *target = pmFPAviewThisCell(view, output->fpa); ///< Target cell 192 pmReadout *readout = pmReadoutAlloc(target); ///< Target readout 193 readout->image = psImageAlloc(numCols / output->xBin, numRows / output->yBin, PS_TYPE_F32); 194 psImageInit(readout->image, NAN); 195 psFree(readout); // Drop reference 196 197 bool status = false; 198 psMetadataItemSupplement(&status, target->concepts, source->concepts, "CELL.XBIN"); 199 psMetadataItemSupplement(&status, target->concepts, source->concepts, "CELL.YBIN"); 200 /* psMetadataAddS32(target->concepts,PS_LIST_TAIL,"CELL.XBIN",PS_META_REPLACE,"",output->xBin); */ 201 /* psMetadataAddS32(target->concepts,PS_LIST_TAIL,"CELL.YBIN",PS_META_REPLACE,"",output->yBin); */ 202 psMetadataItemSupplement(&status, target->concepts, source->concepts, "CELL.XSIZE"); 203 psMetadataItemSupplement(&status, target->concepts, source->concepts, "CELL.YSIZE"); 204 /* psMetadataAddS32(target->concepts,PS_LIST_TAIL,"CELL.XSIZE",PS_META_REPLACE,"",numCols / output->xBin); */ 205 /* psMetadataAddS32(target->concepts,PS_LIST_TAIL,"CELL.YSIZE",PS_META_REPLACE,"",numRows / output->yBin); */ 206 psMetadataItemSupplement(&status, target->concepts, source->concepts, "CELL.XPARITY"); 207 psMetadataItemSupplement(&status, target->concepts, source->concepts, "CELL.YPARITY"); 208 psMetadataItemSupplement(&status, target->concepts, source->concepts, "CELL.X0"); 209 psMetadataItemSupplement(&status, target->concepts, source->concepts, "CELL.Y0"); 210 211 212 } 213 214 // XXX this is not a sufficient test 215 view->chip = 0; 216 view->cell = 0; 217 view->readout = -1; 218 pmHDU *phu = pmFPAviewThisPHU(view, skycell->fpa); ///< Skycell PHU 219 pmHDU *hdu = pmFPAviewThisHDU(view, skycell->fpa); ///< Skycell header 220 221 pmAstromWCS *WCS = pmAstromWCSfromHeader(hdu->header); 222 223 double cd1f = 1.0 * output->xBin; 224 double cd2f = 1.0 * output->yBin; 225 226 WCS->crpix1 = WCS->crpix1 / cd1f; 227 WCS->crpix2 = WCS->crpix2 / cd2f; 228 229 WCS->cdelt1 *= cd1f; 230 WCS->cdelt2 *= cd2f; 231 232 WCS->trans->x->coeff[1][0] *= cd1f; 233 WCS->trans->x->coeff[0][1] *= cd2f; 234 WCS->trans->y->coeff[1][0] *= cd1f; 235 WCS->trans->y->coeff[0][1] *= cd2f; 236 237 238 pmAstromWCStoHeader (hdu->header,WCS); 239 240 bool bilevelAstrometry = false; 241 if (phu) { 242 char *ctype = psMetadataLookupStr(NULL, phu->header, "CTYPE1"); 243 if (ctype) { 244 bilevelAstrometry = !strcmp(&ctype[4], "-DIS"); 245 } 246 } 247 248 // We read from the skycell into the output. i.e., the output receives the desired astrometry. 249 pmChip *outputChip = pmFPAviewThisChip(view, output->fpa); ///< Chip in the output 250 if (bilevelAstrometry) { 251 if (!pmAstromReadBilevelMosaic(output->fpa, phu->header)) { 252 psError(psErrorCodeLast(), false, "Unable to read bilevel mosaic astrometry for skycell."); 253 psFree(view); 254 return false; 255 } 256 if (!pmAstromReadBilevelChip(outputChip, hdu->header)) { 257 psError(psErrorCodeLast(), false, "Unable to read bilevel chip astrometry for skycell."); 258 psFree(view); 259 return false; 260 } 261 } else { 262 // we use a default FPA pixel scale of 1.0 263 if (!pmAstromReadWCS(output->fpa, outputChip, hdu->header, 1.0)) { 264 psError(psErrorCodeLast(), false, "Unable to read WCS astrometry for skycell."); 265 psFree(view); 266 return false; 267 } 268 } 269 270 271 view->chip = view->cell = view->readout = -1; 272 pmFPAAddSourceFromView(output->fpa, view, output->format); 273 274 275 psFree (view); 276 return true; 277 } -
branches/czw_branch/20120906/pswarp/src/pswarpFileNames.h
r21368 r34411 12 12 "PSWARP.MASK", 13 13 "PSWARP.VARIANCE", 14 "PSWARP.BKGMODEL", 14 15 NULL 15 16 }; … … 20 21 "PSWARP.OUTPUT.MASK", 21 22 "PSWARP.OUTPUT.VARIANCE", 23 "PSWARP.OUTPUT.BKGMODEL", 22 24 NULL 23 25 }; -
branches/czw_branch/20120906/pswarp/src/pswarpLoop.c
r29928 r34411 179 179 // read WCS data from the corresponding header 180 180 pmHDU *hdu = pmFPAviewThisHDU (view, astrom->fpa); 181 182 181 183 if (bilevelAstrometry) { 182 184 if (!pmAstromReadBilevelChip (chip, hdu->header)) { … … 196 198 } 197 199 200 198 201 pmCell *cell; 199 202 while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) { … … 227 230 228 231 pswarpTransformReadout(output, readout, config); 229 232 230 233 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 231 234 psError(psErrorCodeLast(), false, "Unable to write files."); … … 255 258 goto DONE; 256 259 } 257 260 258 261 pmCell *outCell = output->parent; ///< Output cell 259 262 pmChip *outChip = outCell->parent; ///< Output chip … … 450 453 return true; 451 454 } 455 456 // Loop over the inputs, warp them to the output skycell and then write out the output. 457 bool pswarpLoopBackground(pmConfig *config, psMetadata *stats) 458 { 459 bool status; 460 bool mdok; // Status of MD lookup 461 462 const char *skyCamera = psMetadataLookupStr(NULL, config->arguments, 463 "SKYCELL.CAMERA"); // Name of camera for skycell 464 pmConfigCamerasCull(config, skyCamera); 465 pmConfigRecipesCull(config, "PSWARP,PPSTATS,PSPHOT,PSASTRO,MASKS,JPEG"); 466 467 // load the recipe 468 psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSWARP_RECIPE); 469 if (!recipe) { 470 psError(PSWARP_ERR_CONFIG, false, "missing recipe %s", PSWARP_RECIPE); 471 return false; 472 } 473 474 if (!pswarpSetMaskBits(config)) { 475 psError(psErrorCodeLast(), false, "failed to set mask bits"); 476 return NULL; 477 } 478 479 // select the input data sources 480 pmFPAfile *input = psMetadataLookupPtr(NULL, config->files, "PSWARP.BKGMODEL"); 481 if (!input) { 482 psError(PSWARP_ERR_CONFIG, true, "Can't find input data!\n"); 483 return false; 484 } 485 486 // use the external astrometry source if supplied 487 pmFPAfile *astrom = psMetadataLookupPtr(NULL, config->files, "PSWARP.ASTROM"); 488 if (!astrom) { 489 astrom = input; 490 } 491 492 if (astrom->camera != input->camera) { 493 psError(PSWARP_ERR_DATA, true, "Input camera and astrometry camera do not match."); 494 return false; 495 } 496 497 // select the output readout 498 pmFPAview *view = pmFPAviewAlloc(0); 499 view->chip = 0; 500 view->cell = 0; 501 view->readout = 0; 502 pmReadout *output = pmFPAfileThisReadout(config->files, view, "PSWARP.OUTPUT.BKGMODEL"); 503 if (!output) { 504 psError(PSWARP_ERR_CONFIG, true, "Can't find output background data!\n"); 505 return false; 506 } 507 psFree (view); 508 509 // Turn all skycell files on to generate them, and then turn them off for the loop over the input images 510 // the input, which is in a different format. 511 { 512 pswarpFileActivation(config, detectorFiles, false); 513 pswarpFileActivation(config, photFiles, false); 514 pswarpFileActivation(config, independentFiles, false); 515 pswarpFileActivation(config, skycellFiles, true); 516 if (!pswarpIOChecksBefore(config)) { 517 psError(psErrorCodeLast(), false, "Unable to read files."); 518 goto DONE; 519 } 520 pswarpFileActivation(config, skycellFiles, false); 521 } 522 523 // Read the input astrometry 524 // XXX rather than use the activations here, this should just explicitly loop over the desired filerule 525 { 526 pmFPAfileActivate(config->files, true, "PSWARP.ASTROM"); 527 528 pmChip *chip; 529 pmFPAview *view = pmFPAviewAlloc(0); 530 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 531 psError(psErrorCodeLast(), false, "Unable to read files."); 532 goto DONE; 533 } 534 while ((chip = pmFPAviewNextChip (view, input->fpa, 1)) != NULL) { 535 psTrace ("pswarp", 4, "AChip %d: %x %x\n", view->chip, chip->file_exists, chip->process); 536 if (!chip->process || !chip->file_exists) { continue; } 537 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 538 psError(psErrorCodeLast(), false, "Unable to read files."); 539 goto DONE; 540 } 541 pmCell *cell; 542 while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) { 543 psTrace ("pswarp", 4, "ACell %d: %x %x\n", view->cell, cell->file_exists, cell->process); 544 if (!cell->process || !cell->file_exists) { continue; } 545 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE) || 546 !pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) { 547 psError(psErrorCodeLast(), false, "Unable to read files."); 548 goto DONE; 549 } 550 } 551 if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) { 552 psError(psErrorCodeLast(), false, "Unable to write files."); 553 goto DONE; 554 } 555 } 556 if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) { 557 psError(psErrorCodeLast(), false, "Unable to write files."); 558 goto DONE; 559 } 560 psFree(view); 561 562 pswarpFileActivation(config, detectorFiles, true); 563 pmFPAfileActivate(config->files, false, "PSWARP.ASTROM"); 564 } 565 566 /* // Turn on the source output --- we need to get rid of these so that we can measure the PSF */ 567 /* pmFPAfileActivate(config->files, true, "PSWARP.OUTPUT.SOURCES"); */ 568 569 // Don't care about the skycell anymore --- we've read it, and that's all we need to do. 570 pmFPAfileActivate(config->files, false, "PSWARP.SKYCELL"); 571 view = pmFPAviewAlloc(0); 572 573 // find the FPA phu 574 bool bilevelAstrometry = false; 575 pmHDU *phu = pmFPAviewThisPHU(view, astrom->fpa); 576 if (phu) { 577 char *ctype = psMetadataLookupStr(NULL, phu->header, "CTYPE1"); 578 if (ctype) { 579 bilevelAstrometry = !strcmp (&ctype[4], "-DIS"); 580 } 581 } 582 if (bilevelAstrometry) { 583 if (!pmAstromReadBilevelMosaic(input->fpa, phu->header)) { 584 psError(psErrorCodeLast(), false, "Unable to read bilevel mosaic astrometry for input FPA."); 585 psFree(view); 586 psFree(stats); 587 goto DONE; 588 } 589 } 590 591 592 593 psList *cells = psListAlloc(NULL); // List of cells, for concepts averaging 594 595 // files associated with the science image 596 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) { 597 psError(psErrorCodeLast(), false, "Unable to read files."); 598 goto DONE; 599 } 600 601 pmChip *chip; 602 while ((chip = pmFPAviewNextChip (view, input->fpa, 1)) != NULL) { 603 psTrace ("pswarp", 4, "DChip %d: %x %x\n", view->chip, chip->file_exists, chip->process); 604 if (!chip->process || !chip->file_exists) { continue; } 605 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) { 606 psError(psErrorCodeLast(), false, "Unable to read files."); 607 goto DONE; 608 } 609 610 // read WCS data from the corresponding header 611 pmHDU *hdu = pmFPAviewThisHDU (view, astrom->fpa); 612 psMetadataAddS32(config->arguments,PS_LIST_TAIL, 613 "INTERPOLATION.MODE",PS_META_REPLACE,"", PS_INTERPOLATE_BILINEAR); ///< Mode 614 psMetadataAddS32(config->arguments,PS_LIST_TAIL, 615 "INTERPOLATION.NUM",PS_META_REPLACE,"", 64); ///< Mode 616 617 if (bilevelAstrometry) { 618 if (!pmAstromReadBilevelChip (chip, hdu->header)) { 619 psError(psErrorCodeLast(), false, "Unable to read bilevel chip astrometry for input FPA."); 620 psFree(view); 621 psFree(stats); 622 goto DONE; 623 } 624 } else { 625 // we use a default FPA pixel scale of 1.0 626 if (!pmAstromReadWCS (input->fpa, chip, hdu->header, 1.0)) { 627 psError(psErrorCodeLast(), false, "Unable to read WCS astrometry for input FPA."); 628 psFree(view); 629 psFree(stats); 630 goto DONE; 631 } 632 } 633 #define CORRECT_INPUT_WCS 1 634 #if CORRECT_INPUT_WCS 635 // Correct the input WCS 636 pmAstromWCS *WCS = pmAstromWCSfromHeader(hdu->header); 637 638 double cd1f = 1.0 * 400; 639 double cd2f = 1.0 * 400; 640 641 WCS->crpix1 = WCS->crpix1 / cd1f + 0.5; 642 WCS->crpix2 = WCS->crpix2 / cd2f - 0.5; 643 644 WCS->cdelt1 *= cd1f; 645 WCS->cdelt2 *= cd2f; 646 647 WCS->trans->x->coeff[1][0] *= cd1f; 648 WCS->trans->x->coeff[0][1] *= cd2f; 649 WCS->trans->y->coeff[1][0] *= cd1f; 650 WCS->trans->y->coeff[0][1] *= cd2f; 651 652 653 pmAstromWCStoHeader (hdu->header,WCS); 654 // End WCS work. 655 #endif 656 657 pmCell *cell; 658 while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) { 659 psTrace ("pswarp", 4, "DCell %d: %x %x\n", view->cell, cell->file_exists, cell->process); 660 if (!cell->process || !cell->file_exists) { continue; } 661 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) { 662 psError(psErrorCodeLast(), false, "Unable to read files."); 663 goto DONE; 664 } 665 666 psListAdd(cells, PS_LIST_TAIL, cell); 667 668 // process each of the readouts 669 pmReadout *readout; 670 while ((readout = pmFPAviewNextReadout(view, input->fpa, 1)) != NULL) { 671 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 672 psError(psErrorCodeLast(), false, "Unable to read files."); 673 goto DONE; 674 } 675 if (!readout->data_exists) { 676 continue; 677 } 678 679 // Copy the detections from the astrometry carrier to the input, so they can be accessed by 680 // pswarpTransformReadout 681 pmReadout *astromRO = pmFPAviewThisReadout(view, astrom->fpa); // Readout for astrometry 682 pmDetections *detections = psMetadataLookupPtr(&mdok, astromRO->analysis, "PSPHOT.DETECTIONS"); // Sources from astrometry 683 if (detections) { 684 psMetadataAddPtr(readout->analysis, PS_LIST_TAIL, "PSPHOT.DETECTIONS", PS_DATA_ARRAY, "Sources from input astrometry", detections); 685 } 686 687 for (int x = 0; x < readout->image->numCols; x++) { 688 for (int y = 0; y < readout->image->numRows; y++) { 689 readout->image->data.F32[y][x] = readout->image->data.F32[y][x] * (cd1f * cd2f) / 690 (psMetadataLookupS32(&mdok,config->arguments,"BKG.XGRID") * 691 psMetadataLookupS32(&mdok,config->arguments,"BKG.YGRID")); 692 } 693 } 694 psMetadataAddS32(config->arguments,PS_LIST_TAIL, "INTERPOLATION.MODE", PS_META_REPLACE, "", 2); 695 /* psMetadataAddS32(config->arguments,PS_LIST_TAIL, "GRID.NX",PS_META_REPLACE,"",100); ///< Number of grid points in x */ 696 /* psMetadataAddS32(config->arguments,PS_LIST_TAIL, "GRID.NY",PS_META_REPLACE,"",100); ///< Number of grid points in y */ 697 698 pswarpTransformReadout(output, readout, config); 699 700 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 701 psError(psErrorCodeLast(), false, "Unable to write files."); 702 goto DONE; 703 } 704 } 705 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 706 psError(psErrorCodeLast(), false, "Unable to write files."); 707 goto DONE; 708 } 709 } 710 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 711 psError(psErrorCodeLast(), false, "Unable to write files."); 712 goto DONE; 713 } 714 } 715 716 if (!output->data_exists) { 717 psWarning("No overlap between input and skycell."); 718 /* if (stats) { */ 719 /* psMetadataAddS32(stats, PS_LIST_TAIL, "QUALITY", PS_META_REPLACE, */ 720 /* "No overlap between input and skycell", PSWARP_ERR_NO_OVERLAP); */ 721 /* } */ 722 psphotFilesActivate(config, false); 723 psFree(cells); 724 psFree(view); 725 goto DONE; 726 } 727 728 pmCell *outCell = output->parent; ///< Output cell 729 pmChip *outChip = outCell->parent; ///< Output chip 730 pmFPA *outFPA = outChip->parent; ///< Output FP 731 732 if (!pswarpPixelsLit(output, stats, config)) { 733 psError(psErrorCodeLast(), false, "Unable to calculate pixel regions."); 734 psFree(cells); 735 psFree(view); 736 goto DONE; 737 } 738 /* bool doStats = psMetadataLookupBool(&mdok,recipe,"MASK.STATS"); */ 739 /* if (doStats) { */ 740 /* if (!pswarpMaskStats(output, stats, config)) { */ 741 /* psError(psErrorCodeLast(), false, "Unable to calculate mask stats."); */ 742 /* psFree(cells); */ 743 /* psFree(view); */ 744 /* goto DONE; */ 745 /* } */ 746 /* } */ 747 /* // Set covariance matrix for output */ 748 /* { */ 749 /* psList *covariances = psMetadataLookupPtr(&mdok, output->analysis, */ 750 /* PSWARP_ANALYSIS_COVARIANCES); // Covariance matrices */ 751 /* psAssert(covariances, "Should be there"); */ 752 /* psArray *covars = psListToArray(covariances); // Array of covariance matrices */ 753 /* psKernel *covar = psImageCovarianceAverage(covars); */ 754 /* psFree(covars); */ 755 /* psMetadataRemoveKey(output->analysis, PSWARP_ANALYSIS_COVARIANCES); */ 756 757 /* // Correct covariance matrix scale for the mean (square root of the) Jacobian */ 758 /* double jacobian = psMetadataLookupF64(NULL, output->analysis, PSWARP_ANALYSIS_JACOBIAN); // Jacobian */ 759 /* int goodPixels = psMetadataLookupS32(NULL, output->analysis, PSWARP_ANALYSIS_GOODPIX); // Good pixels */ 760 /* jacobian /= goodPixels; */ 761 /* output->covariance = psImageCovarianceScale(covar, jacobian); */ 762 /* psFree(covar); */ 763 764 /* if (output->variance) { */ 765 /* psImageCovarianceTransfer(output->variance, output->covariance); */ 766 /* } */ 767 /* } */ 768 769 /* if (!pmConceptsAverageCells(outCell, cells, NULL, NULL, false)) { */ 770 /* psError(psErrorCodeLast(), false, "Unable to average cell concepts."); */ 771 /* psFree(stats); */ 772 /* psFree(cells); */ 773 /* psFree(view); */ 774 /* goto DONE; */ 775 /* } */ 776 /* psFree(cells); */ 777 778 psRegion *trimsec = psMetadataLookupPtr(NULL, outCell->concepts, "CELL.TRIMSEC"); ///< Trim section 779 trimsec->x0 = trimsec->x1 = trimsec->y0 = trimsec->y1 = 0; ///< All pixels 780 781 if (!psMetadataCopy(outFPA->concepts, input->fpa->concepts)) { 782 psError(psErrorCodeLast(), false, "Unable to copy FPA concepts from input to output."); 783 psFree(stats); 784 psFree(view); 785 goto DONE; 786 } 787 788 // Update ZP from the astrometry 789 /* { */ 790 /* psMetadataItem *item = psMetadataLookup(outFPA->concepts, "FPA.ZP"); */ 791 /* item->data.F32 = psMetadataLookupF32(NULL, astrom->fpa->concepts, "FPA.ZP"); */ 792 /* } */ 793 794 pmHDU *hdu = outFPA->hdu; ///< HDU for the output warped image 795 796 // Copy header from target 797 { 798 pmFPAview *skyView = pmFPAviewAlloc(0); ///< View into skycell 799 skyView->chip = skyView->cell = 0; 800 pmCell *cell = pmFPAfileThisCell(config->files, skyView, "PSWARP.SKYCELL"); // Skycell cell 801 psFree(skyView); 802 pmHDU *skyHDU = pmHDUFromCell(cell); ///< HDU 803 if (!skyHDU) { 804 psError(PSWARP_ERR_DATA, false, "Unable to find skycell HDU."); 805 psFree(view); 806 goto DONE; 807 } 808 hdu->header = psMetadataCopy(hdu->header, skyHDU->header); 809 } 810 811 pswarpVersionHeader(hdu->header); 812 813 if (!pmAstromWriteWCS(hdu->header, outFPA, outChip, WCS_NONLIN_TOL)) { 814 psError(psErrorCodeLast(), false, "Unable to generate WCS header."); 815 psFree(stats); 816 goto DONE; 817 } 818 819 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 820 psError(psErrorCodeLast(), false, "Unable to write files."); 821 goto DONE; 822 } 823 824 // Done with the detector side of things 825 pswarpFileActivation(config, detectorFiles, false); 826 pswarpFileActivation(config, independentFiles, false); 827 828 829 // We need a new PSF model for the warped frame. It would be good to generate this analytically, but 830 // that's going to be tricky. We have a list of sources, so we use those to redetermine the PSF model. 831 832 /* if (psMetadataLookupBool(&mdok, recipe, "PSF")) { */ 833 /* pswarpFileActivation(config, photFiles, true); */ 834 /* if (!pswarpIOChecksBefore(config)) { */ 835 /* psError(psErrorCodeLast(), false, "Unable to read files."); */ 836 /* goto DONE; */ 837 /* } */ 838 839 /* // supply the readout and fpa of interest to psphot */ 840 /* pmFPAfile *photFile = psMetadataLookupPtr(NULL, config->files, "PSPHOT.INPUT"); */ 841 /* pmFPACopy(photFile->fpa, outFPA); */ 842 843 /* pmFPAview *view = pmFPAviewAlloc(0); ///< View into skycell */ 844 /* view->chip = view->cell = view->readout = 0; */ 845 846 /* // grab the sources of interest from the storage location (pmFPAfile PSPHOT.INPUT.CMF) */ 847 /* psArray *sources = psphotLoadPSFSources (config, view); */ 848 /* if (!sources) { */ 849 /* psError(psErrorCodeLast(), false, "No sources supplied to measure PSF"); */ 850 /* goto DONE; */ 851 /* } */ 852 853 /* pmModelClassSetLimits(PM_MODEL_LIMITS_STRICT); */ 854 855 /* // measure the PSF using these sources */ 856 /* if (!psphotReadoutFindPSF(config, view, "PSPHOT.INPUT", sources)) { */ 857 /* // This is likely a data quality issue */ 858 /* // XXX Split into multiple cases using error codes? */ 859 /* psErrorStackPrint(stderr, "Unable to determine PSF"); */ 860 /* psWarning("Unable to determine PSF --- suspect bad data quality."); */ 861 /* if (stats && psMetadataLookupS32(NULL, stats, "QUALITY") == 0) { */ 862 /* psMetadataAddS32(stats, PS_LIST_TAIL, "QUALITY", PS_META_REPLACE, */ 863 /* "Unable to determine PSF", psErrorCodeLast()); */ 864 /* } */ 865 /* psErrorClear(); */ 866 /* psphotFilesActivate(config, false); */ 867 /* } */ 868 869 /* // Ensure seeing is carried over */ 870 /* pmChip *photChip = pmFPAviewThisChip(view, photFile->fpa); // Chip with seeing */ 871 /* psMetadataItem *item = psMetadataLookup(outChip->concepts, "CHIP.SEEING"); // Concept with seeing */ 872 /* item->data.F32 = psMetadataLookupF32(NULL, photChip->concepts, "CHIP.SEEING"); */ 873 874 /* // XXX EAM : put this in a visualization function */ 875 /* #if (TESTING) */ 876 /* { */ 877 /* #define PSF_SIZE 20 ///< Half-size of PSF */ 878 /* #define PSF_FLUX 10000 ///< Central flux for PSF */ 879 /* pmChip *photChip = pmFPAviewThisChip(view, photFile->fpa); */ 880 /* pmPSF *psf = psMetadataLookupPtr(NULL, photChip->analysis, "PSPHOT.PSF"); */ 881 /* psImage *image = psImageAlloc(2 * PSF_SIZE + 1, 2 * PSF_SIZE + 1, PS_TYPE_F32); */ 882 /* psImageInit(image, 0); */ 883 /* pmModel *model = pmModelFromPSFforXY(psf, PSF_SIZE, PSF_SIZE, PSF_FLUX); */ 884 /* pmModelAdd(image, NULL, model, PM_MODEL_OP_FULL, 0); */ 885 /* psFree(model); */ 886 /* psFits *fits = psFitsOpen("psf.fits", "w"); */ 887 /* psFitsWriteImage(fits, NULL, image, 0, NULL); */ 888 /* psFitsClose(fits); */ 889 /* psFree(image); */ 890 /* } */ 891 /* #endif */ 892 893 /* psFree(view); */ 894 /* } */ 895 896 /* // Perform statistics on the output image */ 897 /* if (stats) { */ 898 /* if (!ppStatsFPA(stats, output->parent->parent->parent, view, maskValue, config)) { */ 899 /* psWarning("Unable to perform statistics on warped image."); */ 900 /* } */ 901 /* } */ 902 903 904 // Add MD5 information for readout 905 const char *chipName = psMetadataLookupStr(NULL, output->parent->parent->concepts, "CHIP.NAME"); 906 const char *cellName = psMetadataLookupStr(NULL, output->parent->concepts, "CELL.NAME"); 907 psString headerName = NULL; ///< Header name for MD5 908 psStringAppend(&headerName, "MD5_%s_%s_%d", chipName, cellName, view->readout); 909 psVector *md5 = psImageMD5(output->image); ///< md5 hash 910 psString md5string = psMD5toString(md5); ///< String 911 psFree(md5); 912 psMetadataAddStr(hdu->header, PS_LIST_TAIL, headerName, PS_META_REPLACE, 913 "Image MD5", md5string); 914 psFree(md5string); 915 psFree(headerName); 916 psFree(view); 917 918 DONE: 919 920 return true; 921 } -
branches/czw_branch/20120906/pswarp/src/pswarpParseCamera.c
r28442 r34411 84 84 } 85 85 86 pmFPAfile *inBackground = defineInputFile(config, NULL, "PSWARP.BKGMODEL", "BACKGROUND", 87 PM_FPA_FILE_IMAGE); 88 if (!inBackground) { 89 psLogMsg("pswarp", PS_LOG_INFO, "No background models supplied"); 90 } 91 86 92 // The input skycell is a required argument: it defines the output image 87 93 // XXX we may need a different skycell structure here … … 134 140 } 135 141 142 if (inBackground && psMetadataLookupBool(&mdok, recipe, "BACKGROUND.MODEL")) { 143 pmFPAfile *outBackground = pmFPAfileDefineSkycell(config, NULL, "PSWARP.OUTPUT.BKGMODEL"); 144 /* pmFPAfile *outBackground = pmFPAfileDefineFromFPA(config,output->fpa, */ 145 /* psMetadataLookupS32(&mdok,recipe,"BKG.XGRID"), */ 146 /* psMetadataLookupS32(&mdok,recipe,"BKG.YGRID"), */ 147 /* "PSWARP.OUTPUT.BKGMODEL"); */ 148 outBackground->xBin = psMetadataLookupS32(&mdok, recipe, "BKG.XGRID"); 149 outBackground->yBin = psMetadataLookupS32(&mdok, recipe, "BKG.YGRID"); 150 151 if (!outBackground) { 152 psError(psErrorCodeLast(), false, "Failed to build FPA from PSWARP.OUTPUT.BKGMODEL"); 153 return false; 154 } 155 outBackground->save = true; 156 } 157 136 158 if (psMetadataLookupBool(&mdok, recipe, "PSF")) { 137 159 // This file, PSPHOT.INPUT, is just used as a carrier; output files (eg, PSPHOT.RESID) are defined by -
branches/czw_branch/20120906/pswarp/src/pswarpTransformReadout.c
r34089 r34411 29 29 psImageInterpolateMode interpolationMode = psMetadataLookupS32(NULL, config->arguments, 30 30 "INTERPOLATION.MODE"); ///< Mode for interp 31 31 32 int numKernels = psMetadataLookupS32(NULL, config->arguments, "INTERPOLATION.NUM"); ///< Number of kernels 32 33 -
branches/czw_branch/20120906/pswarp/src/pswarpTransformSources.c
r32351 r34411 41 41 if (!outDetections) { 42 42 outDetections = pmDetectionsAlloc(); 43 psMetadataAddPtr(output->analysis, PS_LIST_TAIL, "PSPHOT.DETECTIONS", PS_DATA_ARRAY , "Warped sources", outDetections);43 psMetadataAddPtr(output->analysis, PS_LIST_TAIL, "PSPHOT.DETECTIONS", PS_DATA_ARRAY , "Warped sources", outDetections); 44 44 } 45 45 psArray *outSources = outDetections->allSources;
Note:
See TracChangeset
for help on using the changeset viewer.
