- Timestamp:
- May 3, 2010, 8:50:52 AM (16 years ago)
- Location:
- branches/simtest_nebulous_branches
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/simtest_nebulous_branches
- Property svn:mergeinfo changed
-
branches/simtest_nebulous_branches/psModules
-
Property svn:mergeinfo
set to (toggle deleted branches)
/trunk/psModules merged eligible /branches/eam_branches/stackphot.20100406/psModules 27623-27653 /branches/pap_delete/psModules 27530-27595
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
branches/simtest_nebulous_branches/psModules/src/objects/pmPSF_IO.c
r21183 r27840 28 28 #include "pmConfig.h" 29 29 #include "pmDetrendDB.h" 30 #include "pmErrorCodes.h" 30 31 31 32 #include "pmHDU.h" … … 49 50 #include "pmSource.h" 50 51 #include "pmModelClass.h" 52 #include "pmModelUtils.h" 51 53 #include "pmSourceIO.h" 52 54 … … 121 123 if (view->chip == -1) { 122 124 if (!pmPSFmodelWriteFPA(fpa, view, file, config)) { 123 psError( PS_ERR_IO, false, "Failed to write PSF for fpa");125 psError(psErrorCodeLast(), false, "Failed to write PSF for fpa"); 124 126 return false; 125 127 } … … 134 136 if (view->cell == -1) { 135 137 if (!pmPSFmodelWriteChip (chip, view, file, config)) { 136 psError( PS_ERR_IO, false, "Failed to write PSF for chip");138 psError(psErrorCodeLast(), false, "Failed to write PSF for chip"); 137 139 return false; 138 140 } … … 140 142 } 141 143 142 psError(P S_ERR_IO, false, "PSF must be written at the chip level");144 psError(PM_ERR_CONFIG, true, "PSF must be written at the chip level"); 143 145 return false; 144 146 } … … 157 159 thisView->chip = i; 158 160 if (!pmPSFmodelWriteChip (chip, thisView, file, config)) { 159 psError( PS_ERR_IO, false, "Failed to write PSF for %dth chip", i);161 psError(psErrorCodeLast(), false, "Failed to write PSF for %dth chip", i); 160 162 psFree(thisView); 161 163 return false; … … 172 174 PS_ASSERT_PTR_NON_NULL(chip, false); 173 175 174 if (!pmPSFmodelWrite (chip->analysis, view, file, config)) {175 psError( PS_ERR_IO, false, "Failed to write PSF for chip");176 if (!pmPSFmodelWrite(chip->analysis, view, file, config)) { 177 psError(psErrorCodeLast(), false, "Failed to write PSF for chip"); 176 178 return false; 177 179 } … … 196 198 char *headName, *tableName, *residName; 197 199 198 if (!analysis) return false; 200 if (!analysis) { 201 psError(PM_ERR_PROG, true, "No analysis metadata for chip."); 202 return false; 203 } 199 204 200 205 // select the current recipe 201 206 psMetadata *recipe = psMetadataLookupPtr (NULL, config->recipes, "PSPHOT"); 202 207 if (!recipe) { 203 psError(P S_ERR_UNKNOWN, false, "missing recipe %s", "PSPHOT");208 psError(PM_ERR_CONFIG, false, "missing recipe %s", "PSPHOT"); 204 209 return false; 205 210 } … … 212 217 // get the current header 213 218 pmFPA *fpa = pmFPAfileSuitableFPA(file, view, config, false); // Suitable FPA for writing 219 if (!fpa) { 220 psError(psErrorCodeLast(), false, "Unable to get FPA for writing."); 221 return false; 222 } 214 223 pmHDU *hdu = psMemIncrRefCounter(pmFPAviewThisHDU(view, fpa)); 215 224 psFree(fpa); 216 225 if (!hdu) { 217 psError(P S_ERR_UNKNOWN, false, "Unable to find HDU");226 psError(PM_ERR_CONFIG, false, "Unable to find HDU"); 218 227 return false; 219 228 } … … 233 242 psMetadata *menu = psMetadataLookupMetadata(&status, file->camera, "EXTNAME.RULES"); 234 243 if (!menu) { 235 psError(P S_ERR_UNKNOWN, true, "missing EXTNAME.RULES in camera.config");244 psError(PM_ERR_CONFIG, true, "missing EXTNAME.RULES in camera.config"); 236 245 psFree(hdu); 237 246 return false; … … 241 250 rule = psMetadataLookupStr(&status, menu, "PSF.HEAD"); 242 251 if (!rule) { 243 psError(P S_ERR_UNKNOWN, false, "missing entry for PSF.HEAD in EXTNAME.RULES in camera.config");252 psError(PM_ERR_CONFIG, false, "missing entry for PSF.HEAD in EXTNAME.RULES in camera.config"); 244 253 psFree(hdu); 245 254 return false; … … 250 259 rule = psMetadataLookupStr(&status, menu, "PSF.TABLE"); 251 260 if (!rule) { 252 psError(P S_ERR_UNKNOWN, false, "missing entry for PSF.TABLE in EXTNAME.RULES in camera.config");261 psError(PM_ERR_CONFIG, false, "missing entry for PSF.TABLE in EXTNAME.RULES in camera.config"); 253 262 psFree (headName); 254 263 psFree(hdu); … … 260 269 rule = psMetadataLookupStr(&status, menu, "PSF.RESID"); 261 270 if (!rule) { 262 psError(P S_ERR_UNKNOWN, false, "missing entry for PSF.RESID in EXTNAME.RULES in camera.config");271 psError(PM_ERR_CONFIG, false, "missing entry for PSF.RESID in EXTNAME.RULES in camera.config"); 263 272 psFree (headName); 264 273 psFree (tableName); … … 267 276 } 268 277 residName = pmFPAfileNameFromRule (rule, file, view); 278 279 // EXTNAME for psf image 280 // rule = psMetadataLookupStr(&status, menu, "PSF.RESID"); 281 // if (!rule) { 282 // psError(PS_ERR_UNKNOWN, false, "missing entry for PSF.RESID in EXTNAME.RULES in camera.config"); 283 // psFree (headName); 284 // psFree (tableName); 285 // psFree(hdu); 286 // return false; 287 // } 288 // residName = pmFPAfileNameFromRule (rule, file, view); 269 289 } 270 290 … … 282 302 } 283 303 284 psFitsWriteBlank (file->fits, hdu->header, headName); 304 if (!psFitsWriteBlank(file->fits, hdu->header, headName)) { 305 psError(psErrorCodeLast(), false, "Unable to write PSF PHU."); 306 psFree(hdu); 307 return false; 308 } 285 309 psTrace ("pmFPAfile", 5, "wrote ext head %s (type: %d)\n", file->filename, file->type); 286 310 file->header = hdu->header; … … 292 316 pmPSF *psf = psMetadataLookupPtr (&status, analysis, "PSPHOT.PSF"); 293 317 if (!psf) { 294 psError(P S_ERR_UNKNOWN, true, "missing PSF for this analysis metadata");318 psError(PM_ERR_PROG, true, "missing PSF for this analysis metadata"); 295 319 psFree (tableName); 296 320 psFree (residName); … … 310 334 psMetadataAddBool (header, PS_LIST_TAIL, "ERR_PAR", 0, "Use Poisson errors in fits?", psf->poissonErrorsParams); 311 335 312 int nPar = pmModelClassParameterCount (psf->type) ;336 int nPar = pmModelClassParameterCount (psf->type); 313 337 psMetadataAdd (header, PS_LIST_TAIL, "PSF_NPAR", PS_DATA_S32, "PSF model parameter count", nPar); 314 338 … … 321 345 pmPSFClump psfClump; 322 346 323 // we now save clump parameters for each region : need to save all of those324 int nRegions = psMetadataLookupS32 (&status, recipe, "PSF.CLUMP.NREGIONS");325 psMetadataAddS32 (header, PS_LIST_TAIL, "PSF_CLN", PS_META_REPLACE, "number of psf clump regions", nRegions);326 for (int i = 0; i < nRegions; i++) {327 char regionName[64];328 snprintf (regionName, 64, "PSF.CLUMP.REGION.%03d", i);329 psMetadata *regionMD = psMetadataLookupPtr (&status, recipe, regionName);330 331 psfClump.X = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.X"); assert (status);332 psfClump.Y = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.Y"); assert (status);333 psfClump.dX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DX"); assert (status);334 psfClump.dY = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DY"); assert (status);335 336 char key[16];337 snprintf (key, 9, "CLX_%03d", i);338 psMetadataAddF32 (header, PS_LIST_TAIL, key, PS_META_REPLACE, "psf clump center", psfClump.X);339 snprintf (key, 9, "CLY_%03d", i);340 psMetadataAddF32 (header, PS_LIST_TAIL, key, PS_META_REPLACE, "psf clump center", psfClump.Y);341 snprintf (key, 9, "CLDX_%03d", i);342 psMetadataAddF32 (header, PS_LIST_TAIL, key, PS_META_REPLACE, "psf clump size", psfClump.dX);343 snprintf (key, 9, "CLDY_%03d", i);344 psMetadataAddF32 (header, PS_LIST_TAIL, key, PS_META_REPLACE, "psf clump size", psfClump.dY);345 }347 // we now save clump parameters for each region : need to save all of those 348 int nRegions = psMetadataLookupS32 (&status, analysis, "PSF.CLUMP.NREGIONS"); 349 psMetadataAddS32 (header, PS_LIST_TAIL, "PSF_CLN", PS_META_REPLACE, "number of psf clump regions", nRegions); 350 for (int i = 0; i < nRegions; i++) { 351 char regionName[64]; 352 snprintf (regionName, 64, "PSF.CLUMP.REGION.%03d", i); 353 psMetadata *regionMD = psMetadataLookupPtr (&status, analysis, regionName); 354 355 psfClump.X = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.X"); assert (status); 356 psfClump.Y = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.Y"); assert (status); 357 psfClump.dX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DX"); assert (status); 358 psfClump.dY = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DY"); assert (status); 359 360 char key[16]; 361 snprintf (key, 9, "CLX_%03d", i); 362 psMetadataAddF32 (header, PS_LIST_TAIL, key, PS_META_REPLACE, "psf clump center", psfClump.X); 363 snprintf (key, 9, "CLY_%03d", i); 364 psMetadataAddF32 (header, PS_LIST_TAIL, key, PS_META_REPLACE, "psf clump center", psfClump.Y); 365 snprintf (key, 9, "CLDX_%03d", i); 366 psMetadataAddF32 (header, PS_LIST_TAIL, key, PS_META_REPLACE, "psf clump size", psfClump.dX); 367 snprintf (key, 9, "CLDY_%03d", i); 368 psMetadataAddF32 (header, PS_LIST_TAIL, key, PS_META_REPLACE, "psf clump size", psfClump.dY); 369 } 346 370 347 371 // save the dimensions of each parameter … … 424 448 // write an empty FITS segment if we have no PSF information 425 449 if (psfTable->n == 0) { 426 // XXX this is probably an error (if we have a PSF, how do we have no data?) 427 psFitsWriteBlank (file->fits, header, tableName); 450 psError(PM_ERR_PROG, true, "No PSF data to write."); 451 psFree(tableName); 452 psFree(residName); 453 psFree(psfTable); 454 psFree(header); 455 return false; 428 456 } else { 429 457 psTrace ("pmFPAfile", 5, "writing psf data %s\n", tableName); 430 if (!psFitsWriteTable (file->fits, header, psfTable, tableName)) {431 psError( PS_ERR_IO, false, "writing psf table data %s\n", tableName);458 if (!psFitsWriteTable(file->fits, header, psfTable, tableName)) { 459 psError(psErrorCodeLast(), false, "Error writing psf table data %s\n", tableName); 432 460 psFree (tableName); 433 461 psFree (residName); … … 447 475 if (psf->residuals == NULL) { 448 476 // set some header keywords to make it clear there are no residuals? 449 psFitsWriteBlank (file->fits, header, residName); 477 if (!psFitsWriteBlank(file->fits, header, residName)) { 478 psError(psErrorCodeLast(), false, "Unable to write blank PSF residual image."); 479 psFree(residName); 480 psFree(header); 481 return false; 482 } 450 483 psFree (residName); 451 484 psFree (header); … … 458 491 psMetadataAddS32 (header, PS_LIST_TAIL, "YCENTER", 0, "", psf->residuals->yCenter); 459 492 460 // write the residuals as three planes of the image 461 // this call creates an extension with NAXIS3 = 3 493 // write the residuals as planes of the image 494 psArray *images = psArrayAllocEmpty (1); 495 psArrayAdd (images, 1, psf->residuals->Ro); // z = 0 is Ro 496 462 497 if (psf->residuals->Rx) { 463 // this call creates an extension with NAXIS3 = 3464 psArray *images = psArrayAllocEmpty (3);465 psArrayAdd (images, 1, psf->residuals->Ro);466 498 psArrayAdd (images, 1, psf->residuals->Rx); 467 499 psArrayAdd (images, 1, psf->residuals->Ry); 468 469 psFitsWriteImageCube (file->fits, header, images, residName); 470 psFree (images); 471 } else { 472 // this call creates an extension with NAXIS3 = 1 473 psFitsWriteImage(file->fits, header, psf->residuals->Ro, 0, residName); 474 } 500 } 501 502 // note that all N plane are implicitly of the same type, so we convert the mask 503 if (psf->residuals->mask) { 504 psImage *mask = psImageCopy (NULL, psf->residuals->mask, psf->residuals->Ro->type.type); 505 psArrayAdd (images, 1, mask); 506 psFree (mask); 507 } 508 509 // psFitsWriteImageCube (file->fits, header, images, residName); 510 // psFree (images); 511 512 if (!psFitsWriteImageCube (file->fits, header, images, residName)) { 513 psError(psErrorCodeLast(), false, "Unable to write PSF residuals."); 514 psFree(images); 515 psFree(residName); 516 psFree(header); 517 return false; 518 } 519 psFree (images); 475 520 psFree (residName); 521 psFree (header); 522 } 523 524 // write a representation of the psf model 525 { 526 psMetadata *header = psMetadataAlloc (); 527 528 if (0) { 529 // set some header keywords to make it clear there are no residuals? 530 if (!psFitsWriteBlank (file->fits, header, residName)) { 531 psError(psErrorCodeLast(), false, "Unable to write blank PSF residuals."); 532 psFree(residName); 533 psFree(header); 534 return false; 535 } 536 psFree (residName); 537 psFree (header); 538 return true; 539 } 540 541 int DX = 65; 542 int DY = 65; 543 544 psImage *psfMosaic = psImageAlloc (DX, DY, PS_TYPE_F32); 545 psImageInit (psfMosaic, 0.0); 546 547 pmModel *modelRef = pmModelAlloc(psf->type); 548 549 // use the center of the center pixel of the image 550 float xc = 0.5*psf->fieldNx; 551 float yc = 0.5*psf->fieldNy; 552 553 // assign the x and y coords to the image center 554 // create an object with center intensity of 1000 555 modelRef->params->data.F32[PM_PAR_SKY] = 0; 556 modelRef->params->data.F32[PM_PAR_I0] = 1.000; 557 modelRef->params->data.F32[PM_PAR_XPOS] = xc; 558 modelRef->params->data.F32[PM_PAR_YPOS] = yc; 559 560 // create modelPSF from this model 561 pmModel *model = pmModelFromPSF (modelRef, psf); 562 if (model) { 563 // place the reference object in the image center 564 pmModelAddWithOffset (psfMosaic, NULL, model, PM_MODEL_OP_FULL | PM_MODEL_OP_CENTER, 0, 0.0, 0.0); 565 psFree (model); 566 567 if (false) { 568 // this call creates an extension with NAXIS3 = 3 569 psArray *images = psArrayAllocEmpty (3); 570 psArrayAdd (images, 1, psfMosaic); 571 // psArrayAdd (images, 1, psfModel); 572 // psArrayAdd (images, 1, psfModel); 573 574 if (!psFitsWriteImageCube (file->fits, header, images, "PSF_MODEL")) { 575 psError(psErrorCodeLast(), false, "Unable to write PSF representation."); 576 psFree(images); 577 psFree(psfMosaic); 578 psFree(modelRef); 579 psFree(header); 580 return false; 581 } 582 psFree (images); 583 } else { 584 // this call creates an extension with NAXIS3 = 1 585 // XXX need to replace PSF_MODEL with rule-based name like residName 586 if (!psFitsWriteImage(file->fits, header, psfMosaic, 0, "PSF_MODEL")) { 587 psError(psErrorCodeLast(), false, "Unable to write PSF representation."); 588 psFree(psfMosaic); 589 psFree(modelRef); 590 psFree(header); 591 return false; 592 } 593 } 594 } 595 596 psFree (psfMosaic); 597 psFree (modelRef); 476 598 psFree (header); 477 599 } … … 523 645 // find the FPA phu 524 646 pmFPA *fpa = pmFPAfileSuitableFPA(file, view, config, false); // Suitable FPA for writing 647 if (!fpa) { 648 psError(psErrorCodeLast(), false, "Unable to build FPA to write."); 649 return false; 650 } 525 651 pmHDU *phu = psMemIncrRefCounter(pmFPAviewThisPHU(view, fpa)); 526 652 psFree(fpa); … … 533 659 psMetadataCopy (outhead, phu->header); 534 660 } else { 535 pmConfigConformHeader (outhead, file->format); 661 if (!pmConfigConformHeader (outhead, file->format)) { 662 psError(psErrorCodeLast(), false, "Unable to conform header of PSF PHU."); 663 psFree(phu); 664 return false; 665 } 536 666 } 537 667 psFree(phu); 538 668 539 669 psMetadataAddBool (outhead, PS_LIST_TAIL, "EXTEND", PS_META_REPLACE, "this file has extensions", true); 540 psFitsWriteBlank (file->fits, outhead, ""); 670 if (!psFitsWriteBlank (file->fits, outhead, "")) { 671 psError(psErrorCodeLast(), false, "Unable to write PHU for PSF."); 672 psFree(outhead); 673 return false; 674 } 541 675 file->wrote_phu = true; 542 676 … … 568 702 } 569 703 570 psError(P S_ERR_IO, false, "PSF must be read at the chip level");704 psError(PM_ERR_CONFIG, true, "PSF must be read at the chip level"); 571 705 return false; 572 706 } … … 595 729 596 730 if (!pmPSFmodelRead (chip->analysis, view, file, config)) { 597 psError( PS_ERR_IO, false, "Failed to write PSF for chip");731 psError(psErrorCodeLast(), false, "Failed to write PSF for chip"); 598 732 return false; 599 733 } … … 618 752 psMetadata *recipe = psMetadataLookupPtr (NULL, config->recipes, "PSPHOT"); 619 753 if (!recipe) { 620 psError(P S_ERR_UNKNOWN, false, "missing recipe %s", "PSPHOT");754 psError(PM_ERR_CONFIG, false, "missing recipe %s", "PSPHOT"); 621 755 return false; 622 756 } … … 625 759 psMetadata *menu = psMetadataLookupMetadata(&status, file->camera, "EXTNAME.RULES"); 626 760 if (!menu) { 627 psError(P S_ERR_UNKNOWN, true, "missing EXTNAME.RULES in camera.config");761 psError(PM_ERR_CONFIG, true, "missing EXTNAME.RULES in camera.config"); 628 762 return false; 629 763 } … … 631 765 rule = psMetadataLookupStr(&status, menu, "PSF.TABLE"); 632 766 if (!rule) { 633 psError(P S_ERR_UNKNOWN, true, "missing entry for PSF.TABLE in EXTNAME.RULES in camera.config");767 psError(PM_ERR_CONFIG, true, "missing entry for PSF.TABLE in EXTNAME.RULES in camera.config"); 634 768 return false; 635 769 } … … 638 772 rule = psMetadataLookupStr(&status, menu, "PSF.RESID"); 639 773 if (!rule) { 640 psError(P S_ERR_UNKNOWN, true, "missing entry for PSF.RESID in EXTNAME.RULES in camera.config");774 psError(PM_ERR_CONFIG, true, "missing entry for PSF.RESID in EXTNAME.RULES in camera.config"); 641 775 return false; 642 776 } … … 646 780 // advance to the table data extension 647 781 // since we have read the IMAGE header, the TABLE header should exist 648 if (!psFitsMoveExtName (file->fits, tableName)) { 649 psAbort("cannot find data extension %s in %s", tableName, file->filename); 782 if (!psFitsMoveExtName(file->fits, tableName)) { 783 psError(psErrorCodeLast(), false, "cannot find data extension %s in %s", tableName, file->filename); 784 return false; 650 785 } 651 786 652 787 // load the PSF model table header 653 788 header = psFitsReadHeader (NULL, file->fits); 654 if (!header) psAbort("cannot read table header"); 789 if (!header) { 790 psError(psErrorCodeLast(), false, "Cannot read PSF table header."); 791 return false; 792 } 655 793 656 794 pmPSFOptions *options = pmPSFOptionsAlloc(); … … 667 805 int nRegions = psMetadataLookupS32 (&status, header, "PSF_CLN"); 668 806 if (!status) { 669 // read old-style psf clump data670 671 char regionName[64];672 snprintf (regionName, 64, "PSF.CLUMP.REGION.000");673 psMetadataAddS32 (recipe, PS_LIST_TAIL, "PSF.CLUMP.NREGIONS", PS_META_REPLACE, "psf clump regions", 1);674 675 psMetadata *regionMD = psMetadataLookupPtr (&status, recipe, regionName);676 if (!regionMD) {677 regionMD = psMetadataAlloc();678 psMetadataAddMetadata (recipe, PS_LIST_TAIL, regionName, PS_META_REPLACE, "psf clump region", regionMD);679 psFree (regionMD);680 }681 682 // psf clump data683 pmPSFClump psfClump;684 685 psfClump.X = psMetadataLookupF32 (&status, header, "PSF_CLX" ); assert(status);686 psfClump.Y = psMetadataLookupF32 (&status, header, "PSF_CLY" ); assert(status);687 psfClump.dX = psMetadataLookupF32 (&status, header, "PSF_CLDX"); assert(status);688 psfClump.dY = psMetadataLookupF32 (&status, header, "PSF_CLDY"); assert(status);689 690 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.X", PS_META_REPLACE, "psf clump center", psfClump.X);691 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.Y", PS_META_REPLACE, "psf clump center", psfClump.Y);692 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DX", PS_META_REPLACE, "psf clump center", psfClump.dX);693 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DY", PS_META_REPLACE, "psf clump center", psfClump.dY);807 // read old-style psf clump data 808 809 char regionName[64]; 810 snprintf (regionName, 64, "PSF.CLUMP.REGION.000"); 811 psMetadataAddS32 (analysis, PS_LIST_TAIL, "PSF.CLUMP.NREGIONS", PS_META_REPLACE, "psf clump regions", 1); 812 813 psMetadata *regionMD = psMetadataLookupPtr (&status, analysis, regionName); 814 if (!regionMD) { 815 regionMD = psMetadataAlloc(); 816 psMetadataAddMetadata (analysis, PS_LIST_TAIL, regionName, PS_META_REPLACE, "psf clump region", regionMD); 817 psFree (regionMD); 818 } 819 820 // psf clump data 821 pmPSFClump psfClump; 822 823 psfClump.X = psMetadataLookupF32 (&status, header, "PSF_CLX" ); assert(status); 824 psfClump.Y = psMetadataLookupF32 (&status, header, "PSF_CLY" ); assert(status); 825 psfClump.dX = psMetadataLookupF32 (&status, header, "PSF_CLDX"); assert(status); 826 psfClump.dY = psMetadataLookupF32 (&status, header, "PSF_CLDY"); assert(status); 827 828 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.X", PS_META_REPLACE, "psf clump center", psfClump.X); 829 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.Y", PS_META_REPLACE, "psf clump center", psfClump.Y); 830 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DX", PS_META_REPLACE, "psf clump center", psfClump.dX); 831 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DY", PS_META_REPLACE, "psf clump center", psfClump.dY); 694 832 } else { 695 psMetadataAddS32 (recipe, PS_LIST_TAIL, "PSF.CLUMP.NREGIONS", PS_META_REPLACE, "psf clump regions", nRegions);696 697 for (int i = 0; i < nRegions; i++) {698 char key[10];699 char regionName[64];700 snprintf (regionName, 64, "PSF.CLUMP.REGION.%03d", i);701 702 psMetadata *regionMD = psMetadataLookupPtr (&status, recipe, regionName);703 if (!regionMD) {704 regionMD = psMetadataAlloc();705 psMetadataAddMetadata (recipe, PS_LIST_TAIL, regionName, PS_META_REPLACE, "psf clump region", regionMD);706 psFree (regionMD);707 }708 709 // psf clump data710 pmPSFClump psfClump;711 712 snprintf (key, 9, "CLX_%03d", i);713 psfClump.X = psMetadataLookupF32 (&status, header, key); assert(status);714 snprintf (key, 9, "CLY_%03d", i);715 psfClump.Y = psMetadataLookupF32 (&status, header, key); assert(status);716 snprintf (key, 9, "CLDX_%03d", i);717 psfClump.dX = psMetadataLookupF32 (&status, header, key); assert(status);718 snprintf (key, 9, "CLDY_%03d", i);719 psfClump.dY = psMetadataLookupF32 (&status, header, key); assert(status);720 721 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.X", PS_META_REPLACE, "psf clump center", psfClump.X);722 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.Y", PS_META_REPLACE, "psf clump center", psfClump.Y);723 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DX", PS_META_REPLACE, "psf clump center", psfClump.dX);724 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DY", PS_META_REPLACE, "psf clump center", psfClump.dY);725 }833 psMetadataAddS32 (analysis, PS_LIST_TAIL, "PSF.CLUMP.NREGIONS", PS_META_REPLACE, "psf clump regions", nRegions); 834 835 for (int i = 0; i < nRegions; i++) { 836 char key[10]; 837 char regionName[64]; 838 snprintf (regionName, 64, "PSF.CLUMP.REGION.%03d", i); 839 840 psMetadata *regionMD = psMetadataLookupPtr (&status, analysis, regionName); 841 if (!regionMD) { 842 regionMD = psMetadataAlloc(); 843 psMetadataAddMetadata (analysis, PS_LIST_TAIL, regionName, PS_META_REPLACE, "psf clump region", regionMD); 844 psFree (regionMD); 845 } 846 847 // psf clump data 848 pmPSFClump psfClump; 849 850 snprintf (key, 9, "CLX_%03d", i); 851 psfClump.X = psMetadataLookupF32 (&status, header, key); assert(status); 852 snprintf (key, 9, "CLY_%03d", i); 853 psfClump.Y = psMetadataLookupF32 (&status, header, key); assert(status); 854 snprintf (key, 9, "CLDX_%03d", i); 855 psfClump.dX = psMetadataLookupF32 (&status, header, key); assert(status); 856 snprintf (key, 9, "CLDY_%03d", i); 857 psfClump.dY = psMetadataLookupF32 (&status, header, key); assert(status); 858 859 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.X", PS_META_REPLACE, "psf clump center", psfClump.X); 860 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.Y", PS_META_REPLACE, "psf clump center", psfClump.Y); 861 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DX", PS_META_REPLACE, "psf clump center", psfClump.dX); 862 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DY", PS_META_REPLACE, "psf clump center", psfClump.dY); 863 } 726 864 } 727 865 … … 764 902 char *modeName = psMetadataLookupStr (&status, header, name); 765 903 if (!status) { 766 psError(P S_ERR_UNKNOWN, true, "inconsistent PSF header: NX & NY defined for PAR %d, but not MD", i);904 psError(PM_ERR_PROG, true, "inconsistent PSF header: NX & NY defined for PAR %d, but not MD", i); 767 905 return false; 768 906 } … … 798 936 // read the raw table data 799 937 psArray *table = psFitsReadTable (file->fits); 938 if (!table) { 939 psError(psErrorCodeLast(), false, "Unable to read PSF table."); 940 psFree(header); 941 return false; 942 } 800 943 801 944 // fill in the matching psf->params entries … … 842 985 // since we have read the IMAGE header, the TABLE header should exist 843 986 if (!psFitsMoveExtName (file->fits, imageName)) { 844 psAbort("cannot find data extension %s in %s", imageName, file->filename); 987 psError(psErrorCodeLast(), false, "Cannot find PSF data extension %s in %s", 988 imageName, file->filename); 989 return false; 845 990 } 846 991 847 992 header = psFitsReadHeader (NULL, file->fits); 993 if (!header) { 994 psError(psErrorCodeLast(), false, "Unable to read PSF header."); 995 return false; 996 } 848 997 int Naxis = psMetadataLookupS32 (&status, header, "NAXIS"); 849 998 if (Naxis != 0) { … … 865 1014 866 1015 psRegion fullImage = {0, 0, 0, 0}; 867 psFitsReadImageBuffer(psf->residuals->Ro, file->fits, fullImage, 0); // Desired pixels 868 if (Nz > 1) { 869 assert (Nz == 3); 870 psFitsReadImageBuffer(psf->residuals->Rx, file->fits, fullImage, 1); // Desired pixels 871 psFitsReadImageBuffer(psf->residuals->Ry, file->fits, fullImage, 2); // Desired pixels 872 } 873 // XXX notice that we are not saving the resid->mask 1016 if (!psFitsReadImageBuffer(psf->residuals->Ro, file->fits, fullImage, 0)) { 1017 psError(psErrorCodeLast(), false, "Unable to read PSF residual image."); 1018 return false; 1019 } 1020 1021 // note that all N plane are implicitly of the same type, so we convert the mask 1022 psImage *mask = psImageCopy(NULL, psf->residuals->mask, psf->residuals->Ro->type.type); 1023 psImageInit (psf->residuals->mask, 0); 1024 psImageInit (psf->residuals->Rx, 0.0); 1025 psImageInit (psf->residuals->Ry, 0.0); 1026 switch (Nz) { 1027 case 1: // Ro only 1028 break; 1029 case 2: // Ro and mask 1030 if (!psFitsReadImageBuffer(mask, file->fits, fullImage, 1)) { 1031 psError(psErrorCodeLast(), false, "Unable to read PSF residual image."); 1032 return false; 1033 } 1034 psImageCopy (psf->residuals->mask, mask, PM_TYPE_RESID_MASK); 1035 break; 1036 case 3: // Ro, Rx and Ry, no mask 1037 if (!psFitsReadImageBuffer(psf->residuals->Rx, file->fits, fullImage, 1)) { 1038 psError(psErrorCodeLast(), false, "Unable to read PSF residual image."); 1039 return false; 1040 } 1041 if (!psFitsReadImageBuffer(psf->residuals->Ry, file->fits, fullImage, 2)) { 1042 psError(psErrorCodeLast(), false, "Unable to read PSF residual image."); 1043 return false; 1044 } 1045 break; 1046 case 4: // Ro, Rx, Ry, and mask: 1047 if (!psFitsReadImageBuffer(psf->residuals->Rx, file->fits, fullImage, 1)) { 1048 psError(psErrorCodeLast(), false, "Unable to read PSF residual image."); 1049 return false; 1050 } 1051 if (!psFitsReadImageBuffer(psf->residuals->Ry, file->fits, fullImage, 2)) { 1052 psError(psErrorCodeLast(), false, "Unable to read PSF residual image."); 1053 return false; 1054 } 1055 if (!psFitsReadImageBuffer(mask, file->fits, fullImage, 3)) { 1056 psError(psErrorCodeLast(), false, "Unable to read PSF residual image."); 1057 return false; 1058 } 1059 psImageCopy (psf->residuals->mask, mask, PM_TYPE_RESID_MASK); 1060 break; 1061 } 1062 psFree (mask); 874 1063 } 875 1064
Note:
See TracChangeset
for help on using the changeset viewer.
