Changeset 34800 for trunk/pswarp/src
- Timestamp:
- Dec 11, 2012, 2:04:31 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 11 edited
-
. (modified) (1 prop)
-
pswarp/src/pswarp.c (modified) (2 diffs)
-
pswarp/src/pswarp.h (modified) (2 diffs)
-
pswarp/src/pswarpArguments.c (modified) (4 diffs)
-
pswarp/src/pswarpDefine.c (modified) (3 diffs)
-
pswarp/src/pswarpFileNames.h (modified) (2 diffs)
-
pswarp/src/pswarpLoop.c (modified) (5 diffs)
-
pswarp/src/pswarpParseCamera.c (modified) (2 diffs)
-
pswarp/src/pswarpTransformReadout.c (modified) (6 diffs)
-
pswarp/src/pswarpTransformSources.c (modified) (1 diff)
-
pswarp/src/pswarpTransformTile.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
trunk/pswarp/src/pswarp.c
r27904 r34800 46 46 goto DIE; 47 47 } 48 if (psMetadataLookupBool(NULL,config->arguments,"BACKGROUND.MODEL")) { 49 if (!pswarpDefineBackground(config)) { 50 goto DIE; 51 } 52 } 48 53 49 54 // Open the statistics file … … 66 71 if (!pswarpLoop(config, stats)) { 67 72 goto DIE; 73 } 74 if (psMetadataLookupBool(NULL,config->arguments,"BACKGROUND.MODEL")) { 75 if (!pswarpLoopBackground(config, stats)) { 76 fprintf(stderr,"Dying!\n"); 77 goto DIE; 78 } 68 79 } 69 80 -
trunk/pswarp/src/pswarp.h
r28043 r34800 62 62 psImage *region; 63 63 64 /** values which are needed to control the background model warping. */ 65 bool background_warping; 66 double offset_x; 67 double offset_y; 68 64 69 /** input values for this tile */ 65 70 int gridX; … … 81 86 bool pswarpParseCamera (pmConfig *config); 82 87 bool pswarpDefine (pmConfig *config); 88 bool pswarpDefineBackground (pmConfig *config); 83 89 bool pswarpLoop (pmConfig *config, psMetadata *stats); 90 bool pswarpLoopBackground (pmConfig *config, psMetadata *stats); 84 91 psExit pswarpExitCode(psExit exitValue); 85 92 bool pswarpTransformReadout (pmReadout *output, pmReadout *input, pmConfig *config); -
trunk/pswarp/src/pswarpArguments.c
r34089 r34800 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 = psMetadataLookupS32(&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 = psMetadataLookupS32(&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"); -
trunk/pswarp/src/pswarpDefine.c
r27989 r34800 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 } -
trunk/pswarp/src/pswarpFileNames.h
r21368 r34800 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 }; -
trunk/pswarp/src/pswarpLoop.c
r29928 r34800 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)) { … … 195 197 } 196 198 } 197 199 198 200 pmCell *cell; 199 201 while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) { … … 227 229 228 230 pswarpTransformReadout(output, readout, config); 229 231 230 232 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 231 233 psError(psErrorCodeLast(), false, "Unable to write files."); … … 255 257 goto DONE; 256 258 } 257 259 258 260 pmCell *outCell = output->parent; ///< Output cell 259 261 pmChip *outChip = outCell->parent; ///< Output chip … … 450 452 return true; 451 453 } 454 455 // Loop over the inputs, warp them to the output skycell and then write out the output. 456 bool pswarpLoopBackground(pmConfig *config, psMetadata *stats) 457 { 458 bool status; 459 bool mdok; // Status of MD lookup 460 const char *skyCamera = psMetadataLookupStr(NULL, config->arguments, 461 "SKYCELL.CAMERA"); // Name of camera for skycell 462 pmConfigCamerasCull(config, skyCamera); 463 pmConfigRecipesCull(config, "PSWARP,PPSTATS,PSPHOT,PSASTRO,MASKS,JPEG"); 464 465 // load the recipe 466 psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSWARP_RECIPE); 467 if (!recipe) { 468 psError(PSWARP_ERR_CONFIG, false, "missing recipe %s", PSWARP_RECIPE); 469 return false; 470 } 471 472 if (!pswarpSetMaskBits(config)) { 473 psError(psErrorCodeLast(), false, "failed to set mask bits"); 474 return NULL; 475 } 476 477 // select the input data sources 478 pmFPAfile *input = psMetadataLookupPtr(NULL, config->files, "PSWARP.BKGMODEL"); 479 if (!input) { 480 psError(PSWARP_ERR_CONFIG, true, "Can't find input data!\n"); 481 return false; 482 } 483 484 // use the external astrometry source if supplied 485 pmFPAfile *astrom = psMetadataLookupPtr(NULL, config->files, "PSWARP.ASTROM"); 486 if (!astrom) { 487 astrom = input; 488 } 489 490 if (astrom->camera != input->camera) { 491 psError(PSWARP_ERR_DATA, true, "Input camera and astrometry camera do not match."); 492 return false; 493 } 494 495 // select the output readout 496 pmFPAview *view = pmFPAviewAlloc(0); 497 view->chip = 0; 498 view->cell = 0; 499 view->readout = 0; 500 pmReadout *output = pmFPAfileThisReadout(config->files, view, "PSWARP.OUTPUT.BKGMODEL"); 501 if (!output) { 502 psError(PSWARP_ERR_CONFIG, true, "Can't find output background data!\n"); 503 return false; 504 } 505 psFree (view); 506 // Turn all skycell files on to generate them, and then turn them off for the loop over the input images 507 // the input, which is in a different format. 508 { 509 pswarpFileActivation(config, detectorFiles, false); 510 pswarpFileActivation(config, photFiles, false); 511 pswarpFileActivation(config, independentFiles, false); 512 pswarpFileActivation(config, skycellFiles, true); 513 if (!pswarpIOChecksBefore(config)) { 514 psError(psErrorCodeLast(), false, "Unable to read files."); 515 goto DONE; 516 } 517 pswarpFileActivation(config, skycellFiles, false); 518 } 519 // Read the input astrometry 520 // XXX rather than use the activations here, this should just explicitly loop over the desired filerule 521 { 522 523 pmFPAfileActivate(config->files, true, "PSWARP.ASTROM"); 524 525 pmChip *chip; 526 pmFPAview *view = pmFPAviewAlloc(0); 527 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 528 psError(psErrorCodeLast(), false, "Unable to read files."); 529 goto DONE; 530 } 531 532 while ((chip = pmFPAviewNextChip (view, input->fpa, 1)) != NULL) { 533 #if 0 534 // This needs to be removed because otherwise it throws an error of duplicate PSPHOT.DETECTIONS. 535 if (!chip->process || !chip->file_exists) { continue; } 536 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 537 psError(psErrorCodeLast(), false, "Unable to read files."); 538 goto DONE; 539 } 540 #endif 541 pmCell *cell; 542 while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) { 543 psTrace ("pswarp", 4, "ACell %d: %x %x %d\n", view->cell, cell->file_exists, cell->process,psErrorCodeLast()); 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 pswarpFileActivation(config, detectorFiles, true); 562 pmFPAfileActivate(config->files, false, "PSWARP.ASTROM"); 563 } 564 565 // Don't care about the skycell anymore --- we've read it, and that's all we need to do. 566 pmFPAfileActivate(config->files, false, "PSWARP.SKYCELL"); 567 view = pmFPAviewAlloc(0); 568 569 // find the FPA phu 570 bool bilevelAstrometry = false; 571 pmHDU *phu = pmFPAviewThisPHU(view, astrom->fpa); 572 573 // pmAstromWCS *WCSF = pmAstromWCSfromHeader(phu->header); 574 575 if (phu) { 576 char *ctype = psMetadataLookupStr(NULL, phu->header, "CTYPE1"); 577 if (ctype) { 578 bilevelAstrometry = !strcmp (&ctype[4], "-DIS"); 579 } 580 } 581 if (bilevelAstrometry) { 582 if (!pmAstromReadBilevelMosaic(input->fpa, phu->header)) { 583 psError(psErrorCodeLast(), false, "Unable to read bilevel mosaic astrometry for input FPA."); 584 psFree(view); 585 psFree(stats); 586 goto DONE; 587 } 588 } 589 590 psList *cells = psListAlloc(NULL); // List of cells, for concepts averaging 591 592 // files associated with the science image 593 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) { 594 psError(psErrorCodeLast(), false, "Unable to read files."); 595 goto DONE; 596 } 597 pmChip *chip; 598 while ((chip = pmFPAviewNextChip (view, input->fpa, 1)) != NULL) { 599 psTrace ("pswarp", 4, "DChip %d: %x %x\n", view->chip, chip->file_exists, chip->process); 600 if (!chip->process || !chip->file_exists) { continue; } 601 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) { 602 psError(psErrorCodeLast(), false, "Unable to read files."); 603 goto DONE; 604 } 605 606 // Pull information from the header of the background files so we can use it to set values. 607 pmHDU *hdu = pmFPAviewThisHDU(view,input->fpa); 608 psMetadata *header = hdu->header; 609 610 int IMAXIS1 = psMetadataLookupS32(NULL,header,"IMNAXIS1"); 611 int IMAXIS2 = psMetadataLookupS32(NULL,header,"IMNAXIS2"); 612 int NAXIS1 = psMetadataLookupS32(NULL,header,"NAXIS1"); 613 int NAXIS2 = psMetadataLookupS32(NULL,header,"NAXIS2"); 614 char *CCDSUM = psMetadataLookupStr(NULL,header,"CCDSUM"); 615 int CCDSUM1 = atoi(strtok(CCDSUM," ")); 616 int CCDSUM2 = atoi(strtok(NULL," ")); 617 618 psMetadataAddF32(config->arguments,PS_LIST_TAIL,"BKG_WARP_XOFFSET", PS_META_REPLACE, 619 "xoffset for background model data", (NAXIS1 * CCDSUM1 - IMAXIS1) / (2.0 * CCDSUM1)); 620 psMetadataAddF32(config->arguments,PS_LIST_TAIL,"BKG_WARP_YOFFSET", PS_META_REPLACE, 621 "yoffset for background model data", (NAXIS2 * CCDSUM2 - IMAXIS2) / (2.0 * CCDSUM2)); 622 psTrace("pswarp",5,"%d %d %d %d %d %d %g %g %d %d", 623 psMetadataLookupS32(NULL,header,"IMNAXIS1"), 624 psMetadataLookupS32(NULL,header,"IMNAXIS2"), 625 psMetadataLookupS32(NULL,header,"NAXIS1"), 626 psMetadataLookupS32(NULL,header,"NAXIS2"), 627 CCDSUM1,CCDSUM2, 628 psMetadataLookupF32(NULL,config->arguments,"BKG_WARP_XOFFSET"), 629 psMetadataLookupF32(NULL,config->arguments,"BKG_WARP_YOFFSET"), 630 psMetadataLookupS32(NULL,config->arguments,"BKG.XGRID"), 631 psMetadataLookupS32(NULL,config->arguments,"BKG.YGRID")); 632 633 634 // read WCS data from the corresponding header 635 hdu = pmFPAviewThisHDU (view, astrom->fpa); 636 637 pmAstromWCS *WCS = pmAstromWCSfromHeader(hdu->header); 638 639 double cd1f = (1.0 * CCDSUM1);// * (1.0 * psMetadataLookupS32(NULL,config->arguments,"BKG.XGRID")); 640 double cd2f = (1.0 * CCDSUM2);// * (1.0 * psMetadataLookupS32(NULL,config->arguments,"BKG.YGRID")); 641 642 WCS->cdelt1 *= cd1f; 643 WCS->cdelt2 *= cd2f; 644 WCS->crpix1 = WCS->crpix1 / cd1f; 645 WCS->crpix2 = WCS->crpix2 / cd2f; 646 647 // WCS->trans->x->nX/nY 648 for (int q = 0; q <= WCS->trans->x->nX; q++) { 649 for (int r = 0; r <= WCS->trans->x->nY; r++) { 650 WCS->trans->x->coeff[q][r] *= pow(cd1f,q) * pow(cd2f,r); 651 } 652 } 653 for (int q = 0; q <= WCS->trans->y->nX; q++) { 654 for (int r = 0; r <= WCS->trans->y->nY; r++) { 655 WCS->trans->y->coeff[q][r] *= pow(cd1f,q) * pow(cd2f,r); 656 } 657 } 658 pmAstromWCStoHeader (hdu->header,WCS); 659 660 if (bilevelAstrometry) { 661 if (!pmAstromReadBilevelChip (chip, hdu->header)) { 662 psError(psErrorCodeLast(), false, "Unable to read bilevel chip astrometry for input FPA."); 663 psFree(view); 664 psFree(stats); 665 goto DONE; 666 } 667 } else { 668 // we use a default FPA pixel scale of 1.0 669 if (!pmAstromReadWCS (astrom->fpa, chip, hdu->header, 1.0)) { 670 psError(psErrorCodeLast(), false, "Unable to read WCS astrometry for input FPA."); 671 psFree(view); 672 psFree(stats); 673 goto DONE; 674 } 675 } 676 // Modify structure here. 677 678 679 pmCell *cell; 680 while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) { 681 psTrace ("pswarp", 4, "DCell %d: %x %x\n", view->cell, cell->file_exists, cell->process); 682 if (!cell->process || !cell->file_exists) { continue; } 683 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) { 684 psError(psErrorCodeLast(), false, "Unable to read files."); 685 goto DONE; 686 } 687 688 psListAdd(cells, PS_LIST_TAIL, cell); 689 690 // process each of the readouts 691 pmReadout *readout; 692 while ((readout = pmFPAviewNextReadout(view, input->fpa, 1)) != NULL) { 693 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 694 psError(psErrorCodeLast(), false, "Unable to read files."); 695 goto DONE; 696 } 697 if (!readout->data_exists) { 698 continue; 699 } 700 701 for (int x = 0; x < readout->image->numCols; x++) { 702 for (int y = 0; y < readout->image->numRows; y++) { 703 readout->image->data.F32[y][x] = readout->image->data.F32[y][x] * (cd1f * cd2f) / 704 (psMetadataLookupS32(&mdok,config->arguments,"BKG.XGRID") * 705 psMetadataLookupS32(&mdok,config->arguments,"BKG.YGRID")); 706 } 707 } 708 709 psMetadataAddS32(config->arguments,PS_LIST_TAIL, "INTERPOLATION.MODE", PS_META_REPLACE, "", 8); 710 711 psMetadataAddBool(config->arguments,PS_LIST_TAIL, "BACKGROUND_WARPING", PS_META_REPLACE, "", true); 712 pswarpTransformReadout(output, readout, config); 713 psMetadataAddBool(config->arguments,PS_LIST_TAIL, "BACKGROUND_WARPING", PS_META_REPLACE, "", false); 714 715 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 716 psError(psErrorCodeLast(), false, "Unable to write files."); 717 goto DONE; 718 } 719 } 720 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 721 psError(psErrorCodeLast(), false, "Unable to write files."); 722 goto DONE; 723 } 724 } 725 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 726 psError(psErrorCodeLast(), false, "Unable to write files."); 727 goto DONE; 728 } 729 } 730 if (!output->data_exists) { 731 psWarning("No overlap between input and skycell."); 732 psphotFilesActivate(config, false); 733 psFree(cells); 734 psFree(view); 735 goto DONE; 736 } 737 pmCell *outCell = output->parent; ///< Output cell 738 pmChip *outChip = outCell->parent; ///< Output chip 739 pmFPA *outFPA = outChip->parent; ///< Output FP 740 741 /* if (!pswarpPixelsLit(output, stats, config)) { */ 742 /* psError(psErrorCodeLast(), false, "Unable to calculate pixel regions."); */ 743 /* psFree(cells); */ 744 /* psFree(view); */ 745 /* goto DONE; */ 746 /* } */ 747 psRegion *trimsec = psMetadataLookupPtr(NULL, outCell->concepts, "CELL.TRIMSEC"); ///< Trim section 748 trimsec->x0 = trimsec->x1 = trimsec->y0 = trimsec->y1 = 0; ///< All pixels 749 750 if (!psMetadataCopy(outFPA->concepts, input->fpa->concepts)) { 751 psError(psErrorCodeLast(), false, "Unable to copy FPA concepts from input to output."); 752 psFree(stats); 753 psFree(view); 754 goto DONE; 755 } 756 757 pmHDU *hdu = outFPA->hdu; ///< HDU for the output warped image 758 759 // Copy header from target 760 { 761 pmFPAview *skyView = pmFPAviewAlloc(0); ///< View into skycell 762 skyView->chip = skyView->cell = 0; 763 pmCell *cell = pmFPAfileThisCell(config->files, skyView, "PSWARP.SKYCELL"); // Skycell cell 764 psFree(skyView); 765 pmHDU *skyHDU = pmHDUFromCell(cell); ///< HDU 766 if (!skyHDU) { 767 psError(PSWARP_ERR_DATA, false, "Unable to find skycell HDU."); 768 psFree(view); 769 goto DONE; 770 } 771 hdu->header = psMetadataCopy(hdu->header, skyHDU->header); 772 } 773 pswarpVersionHeader(hdu->header); 774 775 if (!pmAstromWriteWCS(hdu->header, outFPA, outChip, WCS_NONLIN_TOL)) { 776 psError(psErrorCodeLast(), false, "Unable to generate WCS header."); 777 psFree(stats); 778 goto DONE; 779 } 780 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 781 psError(psErrorCodeLast(), false, "Unable to write files."); 782 goto DONE; 783 } 784 // Done with the detector side of things 785 pswarpFileActivation(config, detectorFiles, false); 786 pswarpFileActivation(config, independentFiles, false); 787 788 789 // Add MD5 information for readout 790 const char *chipName = psMetadataLookupStr(NULL, output->parent->parent->concepts, "CHIP.NAME"); 791 const char *cellName = psMetadataLookupStr(NULL, output->parent->concepts, "CELL.NAME"); 792 psString headerName = NULL; ///< Header name for MD5 793 psStringAppend(&headerName, "MD5_%s_%s_%d", chipName, cellName, view->readout); 794 psVector *md5 = psImageMD5(output->image); ///< md5 hash 795 psString md5string = psMD5toString(md5); ///< String 796 psFree(md5); 797 psMetadataAddStr(hdu->header, PS_LIST_TAIL, headerName, PS_META_REPLACE, 798 "Image MD5", md5string); 799 psFree(md5string); 800 psFree(headerName); 801 psFree(view); 802 DONE: 803 804 return true; 805 } -
trunk/pswarp/src/pswarpParseCamera.c
r28442 r34800 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 -
trunk/pswarp/src/pswarpTransformReadout.c
r34089 r34800 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 … … 60 61 // output coordinates to input coordinates 61 62 pswarpMapGrid *grid = pswarpMapGridFromImage(input, output, nGridX, nGridY); 62 63 // if (psMetadataLookupBool(NULL,config->arguments,"BACKGROUND_WARPING")) { 64 63 65 // XXX optionally modify the grid based on this result and force the maxError < XXX 64 66 double maxError = pswarpMapGridMaxError(grid); // Maximum (positional) error from using grid … … 130 132 args->goodPixels = 0; 131 133 134 if (psMetadataLookupBool(NULL,config->arguments,"BACKGROUND_WARPING")) { 135 args->background_warping = true; 136 args->offset_x = psMetadataLookupF32(NULL,config->arguments,"BKG_WARP_XOFFSET"); 137 args->offset_y = psMetadataLookupF32(NULL,config->arguments,"BKG_WARP_YOFFSET"); 138 } 139 140 132 141 // allocate a job 133 142 psThreadJob *job = psThreadJobAlloc ("PSWARP_TRANSFORM_TILE"); … … 171 180 } else { 172 181 pswarpTransformTileArgs *args = job->args->data[0]; 173 // fprintf (stderr, "finished job %d,%d, Nargs: %ld\n", args->gridX, args->gridY, job->args->n);174 182 goodPixels += args->goodPixels; 175 183 xMin = PS_MIN(args->xMin, xMin); … … 183 191 jacobian += args->jacobian * args->goodPixels; 184 192 } 193 194 185 195 } 186 196 psFree(job); … … 201 211 202 212 if (goodPixels > 0 && psMetadataLookupBool(&mdok, recipe, "SOURCES")) { 213 if (!psMetadataLookupBool(NULL,config->arguments,"BACKGROUND_WARPING")) { 203 214 if (!pswarpTransformSources(output, input, config)) { 204 psError(psErrorCodeLast(), false, "Unable to interpolate image.");205 return false;215 psError(psErrorCodeLast(), false, "Unable to interpolate image."); 216 return false; 206 217 } 218 } 207 219 } 208 220 -
trunk/pswarp/src/pswarpTransformSources.c
r32351 r34800 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; -
trunk/pswarp/src/pswarpTransformTile.c
r29331 r34800 46 46 args->jacobian = NAN; 47 47 48 args->background_warping = false; 49 args->offset_x = 0.0; 50 args->offset_y = 0.0; 51 48 52 return args; 49 53 } … … 83 87 // Iterate over the output image pixels (parent frame) 84 88 long goodPixels = 0; ///< Number of input pixels landing on the output image 89 85 90 for (int y = yMin; y < yMax; y++) { 86 91 for (int x = xMin; x < xMax; x++) { 87 88 92 // Only transform those pixels requested 89 93 if (region && region->data.PS_TYPE_IMAGE_MASK_DATA[y][x]) { 90 94 continue; 91 95 } 92 93 96 // pswarpMapApply converts the output coordinate (x,y) to the input coordinate. 94 97 // both are in the parent frames of the input and output images. 95 98 double xIn, yIn; // Input pixel coordinates 96 99 pswarpMapApply(&xIn, &yIn, map, x + 0.5, y + 0.5); 100 101 // This needs to use a more reliable method to do this offset and limiting 102 // if (args->interp->mode == 8) { 103 if (args->background_warping) { 104 // double xOffset = 177.0 / 400.0; // (modelsize * modelbinning - xsize) / 2.0 105 // double yOffset = 166.0 / 400.0; // (modelsize * modelbinning - ysize) / 2.0 106 xIn += args->offset_x; 107 yIn += args->offset_y; 108 109 if ((xIn > inNumCols - args->offset_x)|| 110 (yIn > inNumRows - args->offset_y)|| 111 (xIn < args->offset_x)|| 112 (yIn < args->offset_y)) { 113 continue; 114 } 115 } 116 97 117 if (xIn < 0 || xIn >= inNumCols || yIn < 0 || yIn >= inNumRows) { 98 118 continue;
Note:
See TracChangeset
for help on using the changeset viewer.
