- Timestamp:
- Mar 29, 2010, 3:55:49 PM (16 years ago)
- Location:
- branches/eam_branches/20100225
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
psModules/src/objects/pmPSF_IO.c (modified) (34 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/20100225
- Property svn:mergeinfo changed
-
branches/eam_branches/20100225/psModules/src/objects/pmPSF_IO.c
r27263 r27517 28 28 #include "pmConfig.h" 29 29 #include "pmDetrendDB.h" 30 #include "pmErrorCodes.h" 30 31 31 32 #include "pmHDU.h" … … 122 123 if (view->chip == -1) { 123 124 if (!pmPSFmodelWriteFPA(fpa, view, file, config)) { 124 psError( PS_ERR_IO, false, "Failed to write PSF for fpa");125 psError(psErrorCodeLast(), false, "Failed to write PSF for fpa"); 125 126 return false; 126 127 } … … 135 136 if (view->cell == -1) { 136 137 if (!pmPSFmodelWriteChip (chip, view, file, config)) { 137 psError( PS_ERR_IO, false, "Failed to write PSF for chip");138 psError(psErrorCodeLast(), false, "Failed to write PSF for chip"); 138 139 return false; 139 140 } … … 141 142 } 142 143 143 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"); 144 145 return false; 145 146 } … … 158 159 thisView->chip = i; 159 160 if (!pmPSFmodelWriteChip (chip, thisView, file, config)) { 160 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); 161 162 psFree(thisView); 162 163 return false; … … 173 174 PS_ASSERT_PTR_NON_NULL(chip, false); 174 175 175 if (!pmPSFmodelWrite (chip->analysis, view, file, config)) {176 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"); 177 178 return false; 178 179 } … … 197 198 char *headName, *tableName, *residName; 198 199 199 if (!analysis) return false; 200 if (!analysis) { 201 psError(PM_ERR_PROG, true, "No analysis metadata for chip."); 202 return false; 203 } 200 204 201 205 // select the current recipe 202 206 psMetadata *recipe = psMetadataLookupPtr (NULL, config->recipes, "PSPHOT"); 203 207 if (!recipe) { 204 psError(P S_ERR_UNKNOWN, false, "missing recipe %s", "PSPHOT");208 psError(PM_ERR_CONFIG, false, "missing recipe %s", "PSPHOT"); 205 209 return false; 206 210 } … … 213 217 // get the current header 214 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 } 215 223 pmHDU *hdu = psMemIncrRefCounter(pmFPAviewThisHDU(view, fpa)); 216 224 psFree(fpa); 217 225 if (!hdu) { 218 psError(P S_ERR_UNKNOWN, false, "Unable to find HDU");226 psError(PM_ERR_CONFIG, false, "Unable to find HDU"); 219 227 return false; 220 228 } … … 234 242 psMetadata *menu = psMetadataLookupMetadata(&status, file->camera, "EXTNAME.RULES"); 235 243 if (!menu) { 236 psError(P S_ERR_UNKNOWN, true, "missing EXTNAME.RULES in camera.config");244 psError(PM_ERR_CONFIG, true, "missing EXTNAME.RULES in camera.config"); 237 245 psFree(hdu); 238 246 return false; … … 242 250 rule = psMetadataLookupStr(&status, menu, "PSF.HEAD"); 243 251 if (!rule) { 244 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"); 245 253 psFree(hdu); 246 254 return false; … … 251 259 rule = psMetadataLookupStr(&status, menu, "PSF.TABLE"); 252 260 if (!rule) { 253 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"); 254 262 psFree (headName); 255 263 psFree(hdu); … … 261 269 rule = psMetadataLookupStr(&status, menu, "PSF.RESID"); 262 270 if (!rule) { 263 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"); 264 272 psFree (headName); 265 273 psFree (tableName); … … 294 302 } 295 303 296 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 } 297 309 psTrace ("pmFPAfile", 5, "wrote ext head %s (type: %d)\n", file->filename, file->type); 298 310 file->header = hdu->header; … … 304 316 pmPSF *psf = psMetadataLookupPtr (&status, analysis, "PSPHOT.PSF"); 305 317 if (!psf) { 306 psError(P S_ERR_UNKNOWN, true, "missing PSF for this analysis metadata");318 psError(PM_ERR_PROG, true, "missing PSF for this analysis metadata"); 307 319 psFree (tableName); 308 320 psFree (residName); … … 322 334 psMetadataAddBool (header, PS_LIST_TAIL, "ERR_PAR", 0, "Use Poisson errors in fits?", psf->poissonErrorsParams); 323 335 324 int nPar = pmModelClassParameterCount (psf->type) ;336 int nPar = pmModelClassParameterCount (psf->type); 325 337 psMetadataAdd (header, PS_LIST_TAIL, "PSF_NPAR", PS_DATA_S32, "PSF model parameter count", nPar); 326 338 … … 436 448 // write an empty FITS segment if we have no PSF information 437 449 if (psfTable->n == 0) { 438 // XXX this is probably an error (if we have a PSF, how do we have no data?) 439 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; 440 456 } else { 441 457 psTrace ("pmFPAfile", 5, "writing psf data %s\n", tableName); 442 if (!psFitsWriteTable (file->fits, header, psfTable, tableName)) {443 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); 444 460 psFree (tableName); 445 461 psFree (residName); … … 459 475 if (psf->residuals == NULL) { 460 476 // set some header keywords to make it clear there are no residuals? 461 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 } 462 483 psFree (residName); 463 484 psFree (header); … … 486 507 } 487 508 488 psFitsWriteImageCube (file->fits, header, images, residName); 489 psFree (images); 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); 490 520 psFree (residName); 491 521 psFree (header); … … 498 528 if (0) { 499 529 // set some header keywords to make it clear there are no residuals? 500 psFitsWriteBlank (file->fits, header, residName); 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 } 501 536 psFree (residName); 502 537 psFree (header); … … 504 539 } 505 540 506 int DX = 65; 507 int DY = 65; 508 509 psImage *psfMosaic = psImageAlloc (DX, DY, PS_TYPE_F32); 510 psImageInit (psfMosaic, 0.0); 511 512 pmModel *modelRef = pmModelAlloc(psf->type); 513 514 // use the center of the center pixel of the image 515 float xc = 0.5*psf->fieldNx; 516 float yc = 0.5*psf->fieldNy; 517 518 // assign the x and y coords to the image center 519 // create an object with center intensity of 1000 520 modelRef->params->data.F32[PM_PAR_SKY] = 0; 521 modelRef->params->data.F32[PM_PAR_I0] = 1.000; 522 modelRef->params->data.F32[PM_PAR_XPOS] = xc; 523 modelRef->params->data.F32[PM_PAR_YPOS] = yc; 524 525 // create modelPSF from this model 526 pmModel *model = pmModelFromPSF (modelRef, psf); 527 if (model) { 528 // place the reference object in the image center 529 pmModelAddWithOffset (psfMosaic, NULL, model, PM_MODEL_OP_FULL | PM_MODEL_OP_CENTER, 0, 0.0, 0.0); 530 psFree (model); 531 532 if (false) { 533 // this call creates an extension with NAXIS3 = 3 534 psArray *images = psArrayAllocEmpty (3); 535 psArrayAdd (images, 1, psfMosaic); 536 // psArrayAdd (images, 1, psfModel); 537 // psArrayAdd (images, 1, psfModel); 538 539 psFitsWriteImageCube (file->fits, header, images, "PSF_MODEL"); 540 psFree (images); 541 } else { 542 // this call creates an extension with NAXIS3 = 1 543 // XXX need to replace PSF_MODEL with rule-based name like residName 544 psFitsWriteImage(file->fits, header, psfMosaic, 0, "PSF_MODEL"); 545 } 546 } 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 } 547 595 548 596 psFree (psfMosaic); … … 597 645 // find the FPA phu 598 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 } 599 651 pmHDU *phu = psMemIncrRefCounter(pmFPAviewThisPHU(view, fpa)); 600 652 psFree(fpa); … … 607 659 psMetadataCopy (outhead, phu->header); 608 660 } else { 609 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 } 610 666 } 611 667 psFree(phu); 612 668 613 669 psMetadataAddBool (outhead, PS_LIST_TAIL, "EXTEND", PS_META_REPLACE, "this file has extensions", true); 614 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 } 615 675 file->wrote_phu = true; 616 676 … … 642 702 } 643 703 644 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"); 645 705 return false; 646 706 } … … 669 729 670 730 if (!pmPSFmodelRead (chip->analysis, view, file, config)) { 671 psError( PS_ERR_IO, false, "Failed to write PSF for chip");731 psError(psErrorCodeLast(), false, "Failed to write PSF for chip"); 672 732 return false; 673 733 } … … 692 752 psMetadata *recipe = psMetadataLookupPtr (NULL, config->recipes, "PSPHOT"); 693 753 if (!recipe) { 694 psError(P S_ERR_UNKNOWN, false, "missing recipe %s", "PSPHOT");754 psError(PM_ERR_CONFIG, false, "missing recipe %s", "PSPHOT"); 695 755 return false; 696 756 } … … 699 759 psMetadata *menu = psMetadataLookupMetadata(&status, file->camera, "EXTNAME.RULES"); 700 760 if (!menu) { 701 psError(P S_ERR_UNKNOWN, true, "missing EXTNAME.RULES in camera.config");761 psError(PM_ERR_CONFIG, true, "missing EXTNAME.RULES in camera.config"); 702 762 return false; 703 763 } … … 705 765 rule = psMetadataLookupStr(&status, menu, "PSF.TABLE"); 706 766 if (!rule) { 707 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"); 708 768 return false; 709 769 } … … 712 772 rule = psMetadataLookupStr(&status, menu, "PSF.RESID"); 713 773 if (!rule) { 714 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"); 715 775 return false; 716 776 } … … 720 780 // advance to the table data extension 721 781 // since we have read the IMAGE header, the TABLE header should exist 722 if (!psFitsMoveExtName (file->fits, tableName)) { 723 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; 724 785 } 725 786 726 787 // load the PSF model table header 727 788 header = psFitsReadHeader (NULL, file->fits); 728 if (!header) psAbort("cannot read table header"); 789 if (!header) { 790 psError(psErrorCodeLast(), false, "Cannot read PSF table header."); 791 return false; 792 } 729 793 730 794 pmPSFOptions *options = pmPSFOptionsAlloc(); … … 838 902 char *modeName = psMetadataLookupStr (&status, header, name); 839 903 if (!status) { 840 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); 841 905 return false; 842 906 } … … 872 936 // read the raw table data 873 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 } 874 943 875 944 // fill in the matching psf->params entries … … 916 985 // since we have read the IMAGE header, the TABLE header should exist 917 986 if (!psFitsMoveExtName (file->fits, imageName)) { 918 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; 919 990 } 920 991 921 992 header = psFitsReadHeader (NULL, file->fits); 993 if (!header) { 994 psError(psErrorCodeLast(), false, "Unable to read PSF header."); 995 return false; 996 } 922 997 int Naxis = psMetadataLookupS32 (&status, header, "NAXIS"); 923 998 if (Naxis != 0) { … … 939 1014 940 1015 psRegion fullImage = {0, 0, 0, 0}; 941 psFitsReadImageBuffer(psf->residuals->Ro, file->fits, fullImage, 0); // Desired pixels 1016 if (!psFitsReadImageBuffer(psf->residuals->Ro, file->fits, fullImage, 0)) { 1017 psError(psErrorCodeLast(), false, "Unable to read PSF residual image."); 1018 return false; 1019 } 942 1020 943 1021 // note that all N plane are implicitly of the same type, so we convert the mask … … 954 1032 break; 955 1033 case 3: // Ro, Rx and Ry, no mask 956 psFitsReadImageBuffer(psf->residuals->Rx, file->fits, fullImage, 1); // Desired pixels 957 psFitsReadImageBuffer(psf->residuals->Ry, file->fits, fullImage, 2); // Desired pixels 1034 if (!psFitsReadImageBuffer(psf->residuals->Rx, file->fits, fullImage, 1)) { 1035 psError(psErrorCodeLast(), false, "Unable to read PSF residual image."); 1036 return false; 1037 } 1038 if (!psFitsReadImageBuffer(psf->residuals->Ry, file->fits, fullImage, 2)) { 1039 psError(psErrorCodeLast(), false, "Unable to read PSF residual image."); 1040 return false; 1041 } 958 1042 break; 959 1043 case 4: // Ro, Rx, Ry, and mask:
Note:
See TracChangeset
for help on using the changeset viewer.
