Changeset 14652 for trunk/psModules/src/objects/pmPSF_IO.c
- Timestamp:
- Aug 23, 2007, 2:11:02 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/objects/pmPSF_IO.c (modified) (29 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/objects/pmPSF_IO.c
r14207 r14652 6 6 * @author EAM, IfA 7 7 * 8 * @version $Revision: 1.2 0$ $Name: not supported by cvs2svn $9 * @date $Date: 2007-0 7-14 03:20:22 $8 * @version $Revision: 1.21 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2007-08-24 00:11:02 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 40 40 #include "pmGrowthCurve.h" 41 41 #include "pmResiduals.h" 42 #include "pmPSF.h" 42 43 #include "pmModel.h" 43 #include "pmPSF.h"44 44 #include "pmPSF_IO.h" 45 45 #include "pmSource.h" 46 #include "pmModel Group.h"46 #include "pmModelClass.h" 47 47 #include "pmSourceIO.h" 48 48 49 bool pm FPAviewCheckDataStatusForPSFmodel(const pmFPAview *view, const pmFPAfile *file)49 bool pmPSFmodelCheckDataStatusForView (const pmFPAview *view, const pmFPAfile *file) 50 50 { 51 51 pmFPA *fpa = file->fpa; 52 52 53 53 if (view->chip == -1) { 54 bool exists = pm FPACheckDataStatusForPSFmodel(fpa);54 bool exists = pmPSFmodelCheckDataStatusForFPA (fpa); 55 55 return exists; 56 56 } … … 62 62 63 63 if (view->cell == -1) { 64 bool exists = pm ChipCheckDataStatusForPSFmodel(chip);64 bool exists = pmPSFmodelCheckDataStatusForChip (chip); 65 65 return exists; 66 66 } … … 69 69 return false; 70 70 } 71 pmCell *cell = chip->cells->data[view->cell]; 72 73 if (view->readout == -1) { 74 bool exists = pmCellCheckDataStatusForPSFmodel (cell); 75 return exists; 76 } 77 78 if (view->readout >= cell->readouts->n) { 79 psError(PS_ERR_IO, true, "Requested readout == %d >= cell->readouds->n == %ld", view->readout, cell->readouts->n); 80 return false; 81 } 82 pmReadout *readout = cell->readouts->data[view->readout]; 83 84 return pmReadoutCheckDataStatusForPSFmodel (readout); 85 } 86 87 bool pmFPACheckDataStatusForPSFmodel (const pmFPA *fpa) { 71 psError(PS_ERR_IO, false, "PSF only valid at the chip level"); 72 return false; 73 } 74 75 bool pmPSFmodelCheckDataStatusForFPA (const pmFPA *fpa) { 88 76 89 77 for (int i = 0; i < fpa->chips->n; i++) { 90 78 pmChip *chip = fpa->chips->data[i]; 91 79 if (!chip) continue; 92 if (pm ChipCheckDataStatusForPSFmodel(chip)) return true;80 if (pmPSFmodelCheckDataStatusForChip (chip)) return true; 93 81 } 94 82 return false; 95 83 } 96 84 97 bool pmChipCheckDataStatusForPSFmodel (const pmChip *chip) { 98 99 for (int i = 0; i < chip->cells->n; i++) { 100 pmCell *cell = chip->cells->data[i]; 101 if (!cell) continue; 102 if (pmCellCheckDataStatusForPSFmodel (cell)) return true; 103 } 104 return false; 105 } 106 107 bool pmCellCheckDataStatusForPSFmodel (const pmCell *cell) { 108 109 for (int i = 0; i < cell->readouts->n; i++) { 110 pmReadout *readout = cell->readouts->data[i]; 111 if (!readout) continue; 112 if (pmReadoutCheckDataStatusForPSFmodel (readout)) return true; 113 } 114 return false; 115 } 116 117 bool pmReadoutCheckDataStatusForPSFmodel (const pmReadout *readout) { 85 bool pmPSFmodelCheckDataStatusForChip (const pmChip *chip) { 118 86 119 87 bool status; 120 88 121 89 // select the psf of interest 122 pmPSF *psf = psMetadataLookupPtr(&status, readout->analysis, "PSPHOT.PSF");90 pmPSF *psf = psMetadataLookupPtr(&status, chip->analysis, "PSPHOT.PSF"); 123 91 return psf ? true : false; 124 92 } 125 93 126 bool pm FPAviewWritePSFmodel(const pmFPAview *view, pmFPAfile *file, const pmConfig *config)94 bool pmPSFmodelWriteForView (const pmFPAview *view, pmFPAfile *file, const pmConfig *config) 127 95 { 128 96 … … 130 98 131 99 if (view->chip == -1) { 132 if (!pm FPAWritePSFmodel(fpa, view, file, config)) {100 if (!pmPSFmodelWriteFPA(fpa, view, file, config)) { 133 101 psError(PS_ERR_IO, false, "Failed to write PSF for fpa"); 134 102 return false; … … 143 111 144 112 if (view->cell == -1) { 145 if (!pm ChipWritePSFmodel(chip, view, file, config)) {113 if (!pmPSFmodelWriteChip (chip, view, file, config)) { 146 114 psError(PS_ERR_IO, false, "Failed to write PSF for chip"); 147 115 return false; … … 150 118 } 151 119 152 if (view->cell >= chip->cells->n) { 153 return false; 154 } 155 pmCell *cell = chip->cells->data[view->cell]; 156 157 if (view->readout == -1) { 158 if (!pmCellWritePSFmodel (cell, view, file, config)) { 159 psError(PS_ERR_IO, false, "Failed to write PSF for cell"); 160 return false; 161 } 162 return true; 163 } 164 165 if (view->readout >= cell->readouts->n) { 166 return false; 167 } 168 pmReadout *readout = cell->readouts->data[view->readout]; 169 170 if (!pmReadoutWritePSFmodel (readout, view, file, config)) { 171 psError(PS_ERR_IO, false, "Failed to write PSF for readout"); 172 return false; 173 } 174 return true; 120 psError(PS_ERR_IO, false, "PSF must be written at the chip level"); 121 return false; 175 122 } 176 123 177 124 // read in all chip-level PSFmodel files for this FPA 178 bool pm FPAWritePSFmodel(pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)125 bool pmPSFmodelWriteFPA (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, const pmConfig *config) 179 126 { 180 127 181 128 for (int i = 0; i < fpa->chips->n; i++) { 182 129 pmChip *chip = fpa->chips->data[i]; 183 if (!pm ChipWritePSFmodel(chip, view, file, config)) {130 if (!pmPSFmodelWriteChip (chip, view, file, config)) { 184 131 psError(PS_ERR_IO, false, "Failed to write PSF for %dth chip", i); 185 132 return false; … … 190 137 191 138 // read in all cell-level PSFmodel files for this chip 192 bool pmChipWritePSFmodel (pmChip *chip, const pmFPAview *view, pmFPAfile *file, const pmConfig *config) 193 { 194 for (int i = 0; i < chip->cells->n; i++) { 195 pmCell *cell = chip->cells->data[i]; 196 if (!pmCellWritePSFmodel (cell, view, file, config)) { 197 psError(PS_ERR_IO, false, "Failed to write PSF for %dth cell", i); 198 return false; 199 } 139 bool pmPSFmodelWriteChip (pmChip *chip, const pmFPAview *view, pmFPAfile *file, const pmConfig *config) 140 { 141 if (!pmPSFmodelWrite (chip->analysis, view, file, config)) { 142 psError(PS_ERR_IO, false, "Failed to write PSF for chip"); 143 return false; 200 144 } 201 145 return true; 202 146 } 203 147 204 // read in all readout-level PSFmodel files for this cell 205 bool pmCellWritePSFmodel (pmCell *cell, const pmFPAview *view, pmFPAfile *file, const pmConfig *config) 206 { 207 for (int i = 0; i < cell->readouts->n; i++) { 208 pmReadout *readout = cell->readouts->data[i]; 209 if (!pmReadoutWritePSFmodel (readout, view, file, config)) { 210 psError(PS_ERR_IO, false, "Failed to write PSF for %dth readout", i); 211 return false; 212 } 213 } 214 return true; 215 } 216 217 // for each Readout (ie, analysed image), we write out 148 // for a pmPSF supplied on the analysis metadata, we write out 218 149 // - image header : FITS Image NAXIS = 0 219 150 // - psf table (+header) : FITS Table 220 151 // - psf resid (+header) : FITS Image 221 152 // if needed, we also write out a PHU blank header 222 bool pm ReadoutWritePSFmodel (pmReadout *readout, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)153 bool pmPSFmodelWrite (psMetadata *analysis, const pmFPAview *view, pmFPAfile *file, const pmConfig *config) 223 154 { 224 155 bool status; 225 156 pmHDU *hdu; 226 157 char *headName, *tableName, *residName; 158 159 if (!analysis) return false; 227 160 228 161 // write a PHU? (only if input image is MEF) … … 300 233 301 234 // select the psf of interest 302 pmPSF *psf = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.PSF");235 pmPSF *psf = psMetadataLookupPtr (&status, analysis, "PSPHOT.PSF"); 303 236 if (!psf) { 304 psError(PS_ERR_UNKNOWN, true, "missing PSF for this readout");237 psError(PS_ERR_UNKNOWN, true, "missing PSF for this analysis metadata"); 305 238 psFree (tableName); 306 239 psFree (residName); … … 313 246 psMetadata *header = psMetadataAlloc(); 314 247 315 char *modelName = pmModel GetType (psf->type);248 char *modelName = pmModelClassGetName (psf->type); 316 249 psMetadataAddStr (header, PS_LIST_TAIL, "PSF_NAME", 0, "PSF model name", modelName); 317 250 318 251 psMetadataAddBool (header, PS_LIST_TAIL, "POISSON", 0, "Use Poisson errors in fits?", psf->poissonErrors); 319 252 320 int nPar = pmModel ParameterCount (psf->type) ;253 int nPar = pmModelClassParameterCount (psf->type) ; 321 254 psMetadataAdd (header, PS_LIST_TAIL, "PSF_NPAR", PS_DATA_S32, "PSF model parameter count", nPar); 322 255 … … 324 257 for (int i = 0; i < nPar; i++) { 325 258 char name[9]; 326 psPolynomial2D *poly = psf->params _NEW->data[i];259 psPolynomial2D *poly = psf->params->data[i]; 327 260 if (poly == NULL) continue; 328 261 snprintf (name, 9, "PAR%02d_NX", i); … … 344 277 psArray *psfTable = psArrayAllocEmpty (100); 345 278 for (int i = 0; i < nPar; i++) { 346 psPolynomial2D *poly = psf->params _NEW->data[i];279 psPolynomial2D *poly = psf->params->data[i]; 347 280 if (poly == NULL) continue; // skip unset parameters (eg, XPOS) 348 281 for (int ix = 0; ix <= poly->nX; ix++) { … … 445 378 446 379 // if this file needs to have a PHU written out, write one 447 bool pmPSF _WritePHU (const pmFPAview *view, pmFPAfile *file, const pmConfig *config) {380 bool pmPSFmodelWritePHU (const pmFPAview *view, pmFPAfile *file, const pmConfig *config) { 448 381 449 382 // not needed if already written … … 487 420 } 488 421 489 bool pm FPAviewReadPSFmodel(const pmFPAview *view, pmFPAfile *file, const pmConfig *config)422 bool pmPSFmodelReadForView (const pmFPAview *view, pmFPAfile *file, const pmConfig *config) 490 423 { 491 424 … … 493 426 494 427 if (view->chip == -1) { 495 return pm FPAReadPSFmodel(fpa, view, file, config);428 return pmPSFmodelReadFPA(fpa, view, file, config); 496 429 } 497 430 … … 502 435 503 436 if (view->cell == -1) { 504 return pmChipReadPSFmodel(chip, view, file, config); 505 } 506 507 if (view->cell >= chip->cells->n) { 508 psAbort("Programming error: view does not apply to FPA."); 509 } 510 pmCell *cell = chip->cells->data[view->cell]; 511 512 if (view->readout == -1) { 513 return pmCellReadPSFmodel(cell, view, file, config); 514 } 515 516 if (view->readout >= cell->readouts->n) { 517 psAbort("Programming error: view does not apply to FPA."); 518 } 519 pmReadout *readout = cell->readouts->data[view->readout]; 520 521 return pmReadoutReadPSFmodel(readout, view, file, config); 437 return pmPSFmodelReadChip(chip, view, file, config); 438 } 439 440 psError(PS_ERR_IO, false, "PSF must be read at the chip level"); 441 return false; 522 442 } 523 443 524 444 // read in all chip-level PSFmodel files for this FPA 525 bool pm FPAReadPSFmodel(pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)445 bool pmPSFmodelReadFPA (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, const pmConfig *config) 526 446 { 527 447 bool success = true; // Was everything successful? 528 448 for (int i = 0; i < fpa->chips->n; i++) { 529 449 pmChip *chip = fpa->chips->data[i]; 530 success &= pm ChipReadPSFmodel(chip, view, file, config);450 success &= pmPSFmodelReadChip(chip, view, file, config); 531 451 } 532 452 return success; … … 534 454 535 455 // read in all cell-level PSFmodel files for this chip 536 bool pmChipReadPSFmodel (pmChip *chip, const pmFPAview *view, pmFPAfile *file, const pmConfig *config) 537 { 538 bool success = true; // Was everything successful? 539 for (int i = 0; i < chip->cells->n; i++) { 540 pmCell *cell = chip->cells->data[i]; 541 success &= pmCellReadPSFmodel (cell, view, file, config); 542 } 543 return success; 544 } 545 546 // read in all readout-level PSFmodel files for this cell 547 bool pmCellReadPSFmodel (pmCell *cell, const pmFPAview *view, pmFPAfile *file, const pmConfig *config) 548 { 549 bool success = true; // Was everything successful? 550 for (int i = 0; i < cell->readouts->n; i++) { 551 pmReadout *readout = cell->readouts->data[i]; 552 success &= pmReadoutReadPSFmodel(readout, view, file, config); 553 } 554 return success; 456 bool pmPSFmodelReadChip (pmChip *chip, const pmFPAview *view, pmFPAfile *file, const pmConfig *config) 457 { 458 if (!pmPSFmodelRead (chip->analysis, view, file, config)) { 459 psError(PS_ERR_IO, false, "Failed to write PSF for chip"); 460 return false; 461 } 462 return true; 555 463 } 556 464 557 465 // for each Readout (ie, analysed image), we write out: header + table with PSF model parameters, 558 466 // and header + image for the PSF residual images 559 bool pm ReadoutReadPSFmodel(pmReadout *readout, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)467 bool pmPSFmodelRead (psMetadata *analysis, const pmFPAview *view, pmFPAfile *file, const pmConfig *config) 560 468 { 561 469 bool status; … … 599 507 // load the PSF model parameters from the FITS table 600 508 char *modelName = psMetadataLookupStr (&status, header, "PSF_NAME"); 601 pmModelType type = pmModel SetType (modelName);509 pmModelType type = pmModelClassGetType (modelName); 602 510 if (type == -1) { 603 511 psError(PS_ERR_UNKNOWN, true, "invalid model name %s in psf file %s", modelName, file->filename); … … 612 520 // check the number of expected parameters 613 521 int nPar = psMetadataLookupS32 (&status, header, "PSF_NPAR"); 614 if (nPar != pmModel ParameterCount (psf->type))522 if (nPar != pmModelClassParameterCount (psf->type)) 615 523 psAbort("mismatch model par count"); 616 524 … … 627 535 return false; 628 536 } 629 psf->params _NEW->data[i] = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, nXorder, nYorder);537 psf->params->data[i] = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, nXorder, nYorder); 630 538 } 631 539 … … 650 558 // XXX sanity check here 651 559 652 psPolynomial2D *poly = psf->params _NEW->data[iPar];560 psPolynomial2D *poly = psf->params->data[iPar]; 653 561 if (poly == NULL) { 654 562 psError(PS_ERR_UNKNOWN, true, "values for parameter %d, but missing NX", iPar); … … 698 606 } 699 607 700 psMetadataAdd ( readout->analysis, PS_LIST_TAIL, "PSPHOT.PSF", PS_DATA_UNKNOWN, "psphot psf", psf);608 psMetadataAdd (analysis, PS_LIST_TAIL, "PSPHOT.PSF", PS_DATA_UNKNOWN, "psphot psf", psf); 701 609 psFree (psf); 702 610 … … 708 616 } 709 617 710 /************ old support functions, deprecate? **************/ 711 618 // create a psMetadata representation (human-readable) of a psf model 712 619 psMetadata *pmPSFtoMetadata (psMetadata *metadata, pmPSF *psf) 713 620 { … … 717 624 } 718 625 719 char *modelName = pmModel GetType (psf->type);626 char *modelName = pmModelClassGetName (psf->type); 720 627 psMetadataAdd (metadata, PS_LIST_TAIL, "PSF_MODEL_NAME", PS_DATA_STRING, "PSF model name", modelName); 721 628 722 int nPar = pmModel ParameterCount (psf->type) ;629 int nPar = pmModelClassParameterCount (psf->type) ; 723 630 psMetadataAdd (metadata, PS_LIST_TAIL, "PSF_MODEL_NPAR", PS_DATA_S32, "PSF model parameter count", nPar); 724 631 725 632 for (int i = 0; i < nPar; i++) { 726 psPolynomial2D *poly = psf->params _NEW->data[i];633 psPolynomial2D *poly = psf->params->data[i]; 727 634 if (poly == NULL) 728 635 continue; … … 742 649 } 743 650 651 // parse a psMetadata representation (human-readable) of a psf model 744 652 pmPSF *pmPSFfromMetadata (psMetadata *metadata) 745 653 { … … 749 657 750 658 char *modelName = psMetadataLookupPtr (&status, metadata, "PSF_MODEL_NAME"); 751 pmModelType type = pmModel SetType (modelName);659 pmModelType type = pmModelClassGetType (modelName); 752 660 753 661 bool poissonErrors = psMetadataLookupPtr (&status, metadata, "PSF_POISSON_ERRORS"); … … 759 667 760 668 int nPar = psMetadataLookupS32 (&status, metadata, "PSF_MODEL_NPAR"); 761 if (nPar != pmModel ParameterCount (psf->type))669 if (nPar != pmModelClassParameterCount (psf->type)) 762 670 psAbort("mismatch model par count"); 763 671 … … 770 678 continue; 771 679 psPolynomial2D *poly = psPolynomial2DfromMetadata (folder); 772 psFree (psf->params _NEW->data[i]);773 psf->params _NEW->data[i] = poly;680 psFree (psf->params->data[i]); 681 psf->params->data[i] = poly; 774 682 } 775 683 sprintf (keyword, "APTREND"); … … 789 697 return (psf); 790 698 } 791 792 // read in all readout-level Objects files for this cell793 bool pmReadoutWritePSFmodel_Config (pmReadout *readout, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)794 {795 bool status;796 char *filename;797 char *realname;798 799 pmPSF *psf = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.PSF");800 801 switch (file->type) {802 case PM_FPA_FILE_PSF:803 filename = pmFPAfileNameFromRule (file->filerule, file, view);804 bool create = file->mode == PM_FPA_MODE_WRITE ? true : false;805 realname = pmConfigConvertFilename (filename, config, create);806 807 psMetadata *psfData = pmPSFtoMetadata (NULL, psf);808 psMetadataConfigWrite (psfData, realname);809 psFree (psfData);810 psFree (realname);811 psFree (filename);812 return true;813 814 default:815 fprintf (stderr, "warning: type mismatch\n");816 break;817 }818 return false;819 }820 821 // read in all readout-level Objects files for this cell822 bool pmReadoutReadPSFmodel_Config (pmReadout *readout, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)823 {824 825 unsigned int Nfail;826 char *filename;827 char *realname;828 829 switch (file->type) {830 case PM_FPA_FILE_PSF:831 filename = pmFPAfileNameFromRule (file->filerule, file, view);832 bool create = file->mode == PM_FPA_MODE_WRITE ? true : false;833 realname = pmConfigConvertFilename (filename, config, create);834 835 psMetadata *psfData = psMetadataConfigRead(NULL, &Nfail, realname, FALSE);836 pmPSF *psf = pmPSFfromMetadata (psfData);837 psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.PSF", PS_DATA_UNKNOWN, "psphot psf", psf);838 839 psFree (psf);840 psFree (psfData);841 psFree (realname);842 psFree (filename);843 844 return true;845 846 default:847 fprintf (stderr, "warning: type mismatch\n");848 break;849 }850 return false;851 }852
Note:
See TracChangeset
for help on using the changeset viewer.
