Changeset 21264
- Timestamp:
- Feb 2, 2009, 8:05:38 AM (17 years ago)
- Location:
- branches/pap_branch_20090128/psModules/src/camera
- Files:
-
- 2 added
- 6 edited
-
pmFPARead.c (modified) (4 diffs)
-
pmFPAWrite.c (modified) (4 diffs)
-
pmFPAfileIO.c (modified) (2 diffs)
-
pmHDU.c (modified) (3 diffs)
-
pmHDU.h (modified) (2 diffs)
-
pmHDUCovariances.c (added)
-
pmHDUCovariances.h (added)
-
pmHDUGenerate.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/pap_branch_20090128/psModules/src/camera/pmFPARead.c
r21211 r21264 28 28 FPA_READ_TYPE_IMAGE, // Read image 29 29 FPA_READ_TYPE_MASK, // Read mask 30 FPA_READ_TYPE_VARIANCE, // Read variance map30 FPA_READ_TYPE_VARIANCE, // Read variance map 31 31 FPA_READ_TYPE_HEADER // Read header 32 32 } fpaReadType; … … 515 515 } 516 516 517 // XXX for IMAGE, we need the CELL.BAD value, but for MASK, we need the BAD mask value 518 519 float bad = 0; 520 if (type == FPA_READ_TYPE_MASK) { 521 bad = 1.0; 522 } else { 523 bad = psMetadataLookupF32(&mdok, cell->concepts, "CELL.BAD"); // Bad level 517 // Need to set the invalid (unread) pixels appropriately, and to read the mask bits 518 float bad = 0; // Bad level 519 switch (type) { 520 case FPA_READ_TYPE_MASK: { 521 pmHDU *phu = pmHDUGetHighest(cell->parent->parent, cell->parent, cell); // Primary header 522 if (!pmConfigMaskReadHeader(config, phu->header)) { 523 psError(PS_ERR_IO, false, "Unable to determine mask bits"); 524 return false; 525 } 526 bad = pmConfigMaskGet("BAD", config); 527 break; 528 } 529 case FPA_READ_TYPE_IMAGE: 530 case FPA_READ_TYPE_VARIANCE: 531 bad = psMetadataLookupF32(&mdok, cell->concepts, "CELL.BAD"); 532 break; 533 default: 534 psAbort("Unrecognised type: %x", type); 524 535 } 525 536 … … 721 732 return NULL; 722 733 } 734 735 if (type == FPA_READ_TYPE_VARIANCE && hdu->covariances) { 736 psArray *covariances = hdu->covariances; // Covariances in HDU 737 for (int i = 0; i < covariances->n; i++) { 738 pmHDUCovariances *covar = covariances->data[i]; // Covariance information 739 723 740 psFree(readout); // Drop reference 724 741 } … … 852 869 float bad = psMetadataLookupF32(&mdok, cell->concepts, "CELL.BAD"); // Bad level 853 870 if (!mdok) { 854 ps LogMsg(__func__, PS_LOG_WARN,"CELL.BAD is not set --- assuming zero.\n");871 psWarning("CELL.BAD is not set --- assuming zero.\n"); 855 872 bad = 0.0; 856 873 } -
branches/pap_branch_20090128/psModules/src/camera/pmFPAWrite.c
r21211 r21264 29 29 FPA_WRITE_TYPE_IMAGE, // Write image 30 30 FPA_WRITE_TYPE_MASK, // Write mask 31 FPA_WRITE_TYPE_VARIANCE // Write variance map31 FPA_WRITE_TYPE_VARIANCE // Write variance map 32 32 } fpaWriteType; 33 33 … … 74 74 } 75 75 76 77 78 79 // Some type-specific additions to the header 80 static bool writeUpdateHeader(pmFPA *fpa, // FPA of interest 81 pmChip *chip, // Chip of interest, or NULL 82 pmCell *cell, // Cell of interest, or NULL 83 fpaWriteType type // Type to write 84 ) 85 { 86 switch (type) { 87 case FPA_WRITE_TYPE_MASK: { 88 pmHDU *phu = pmHDUGetHighest(fpa, chip, cell); // Primary header 89 if (!pmConfigMaskWriteHeader(config, phu->header)) { 90 psError(PS_ERR_UNKNOWN, false, "Unable to set the mask names in the PHU header"); 91 return false; 92 } 93 break; 94 } 95 case FPA_WRITE_TYPE_VARIANCE: { 96 pmHDU *hdu = pmHDUGetLowest(fpa, chip, cell); // Header being written 97 98 99 76 100 // Write a cell image/mask/variance 77 101 static bool cellWrite(pmCell *cell, // Cell to write … … 97 121 // generate the HDU, but only copies the structure. 98 122 if (!blank && !hdu->blankPHU && !*imageArray && (!pmHDUGenerateForCell(cell) || !*imageArray)) { 99 psError(PS_ERR_UNKNOWN, false, "Unable to generate HDU for cell --- likely programming error. \n");123 psError(PS_ERR_UNKNOWN, false, "Unable to generate HDU for cell --- likely programming error."); 100 124 return false; 101 125 } … … 106 130 107 131 if (writeBlank || writeImage) { 108 109 132 pmFPAUpdateNames(cell->parent->parent, cell->parent, cell); 110 133 pmConceptSource source = PM_CONCEPT_SOURCE_HEADER | PM_CONCEPT_SOURCE_CELLS | 111 134 PM_CONCEPT_SOURCE_DEFAULTS | PM_CONCEPT_SOURCE_DATABASE; 112 135 if (!pmConceptsWriteCell(cell, source, true, config)) { 113 psError(PS_ERR_IO, false, "Unable to write concepts for cell. \n");136 psError(PS_ERR_IO, false, "Unable to write concepts for cell."); 114 137 return false; 115 138 } 139 140 116 141 if (!appropriateWriteFunc(hdu, fits, config, type)) { 117 142 psError(PS_ERR_IO, false, "Unable to write HDU for cell.\n"); -
branches/pap_branch_20090128/psModules/src/camera/pmFPAfileIO.c
r21211 r21264 771 771 } 772 772 773 // XXX if we have a mask file, then we need to read the mask bit names774 // defined for this file775 if (file->type == PM_FPA_FILE_MASK) {776 if (!pmConfigMaskReadHeader (config, phu)) {777 psError(PS_ERR_IO, false, "error in mask bits");778 return false;779 }780 }781 782 773 // determine the current format from the header 783 774 // determine camera if not specified already … … 786 777 psString formatName = NULL; 787 778 psString cameraName = NULL; 788 file->format = pmConfigCameraFormatFromHeader (&camera, &cameraName, &formatName, config, phu, true);779 file->format = pmConfigCameraFormatFromHeader(&camera, &cameraName, &formatName, config, phu, true); 789 780 if (!file->format) { 790 781 psError(PS_ERR_IO, false, "Failed to read CCD format from %s\n", file->filename); -
branches/pap_branch_20090128/psModules/src/camera/pmHDU.c
r21211 r21264 12 12 #include "pmHDU.h" 13 13 #include "pmFPA.h" 14 15 #define COVARIANCE_INDICATOR "PS_COVAR" // FITS keyword to indicate if covariance matrices are present 14 16 15 17 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// … … 160 162 PS_ASSERT_PTR_NON_NULL(fits, false); 161 163 162 return hduRead(hdu, &hdu->variances, fits); 164 if (!hduRead(hdu, &hdu->variances, fits)) { 165 return false; 166 } 167 168 return true; 163 169 } 164 170 … … 240 246 PS_ASSERT_PTR_NON_NULL(fits, false); 241 247 248 pmHDUCovariancesWriteHeader(hdu); 249 242 250 psImageMaskType maskVal = pmConfigMaskGet("MASK.VALUE", config); // Value to mask 243 return hduWrite(hdu, hdu->variances, hdu->masks, maskVal, fits); 244 } 251 if (!hduWrite(hdu, hdu->variances, hdu->masks, maskVal, fits)) { 252 return false; 253 } 254 pmHDUCovarianceClearHeader(hdu); 255 256 if (!pmHDUCovarianceWrite(hdu, fits)) { 257 psError(PS_ERR_UNKNOWN, false, "Unable to write covariance"); 258 return false; 259 } 260 261 return true; 262 } -
branches/pap_branch_20090128/psModules/src/camera/pmHDU.h
r21211 r21264 4 4 * @author Paul Price, IfA 5 5 * 6 * @version $Revision: 1.9.22. 1$ $Name: not supported by cvs2svn $7 * @date $Date: 2009-0 1-29 00:33:51$6 * @version $Revision: 1.9.22.2 $ $Name: not supported by cvs2svn $ 7 * @date $Date: 2009-02-02 18:05:38 $ 8 8 * Copyright 2005-2006 Institute for Astronomy, University of Hawaii 9 9 */ … … 22 22 /// Of course, it is not an exact replica of a FITS HDU --- they have no mask and variance data, but these are 23 23 /// stored here for convenience --- it keeps all the relevant data about the image in one place. 24 typedef struct 25 { 24 typedef struct { 26 25 psString extname; ///< The extension name 27 26 bool blankPHU; ///< Is this a blank FITS Primary Header Unit, i.e., no data? 28 27 psMetadata *format; ///< The camera format 29 28 psMetadata *header; ///< The FITS header, or NULL if primary for FITS; or section info 30 psArray *images; ///< The pixel data31 psArray *variances; ///< The pixel data32 psArray *masks; ///< The pixel data33 } 34 pmHDU;29 psArray *images; ///< Pixel data 30 psArray *variances; ///< Variance in the pixel data, or NULL 31 psArray *masks; ///< Mask for the pixel data, or NULL 32 psArray *covariances; ///< Covariance matrices (pmHDUCovariance), or NULL 33 } pmHDU; 35 34 36 35 -
branches/pap_branch_20090128/psModules/src/camera/pmHDUGenerate.c
r21211 r21264 355 355 psElemType imageType = 0; // Type of readout images 356 356 psElemType maskType = 0; // Type of readout masks 357 psElemType varianceType = 0; // Type of readout variances 357 psElemType varianceType = 0; // Type of readout variances 358 psElemType covarianceType = 0; // Type of readout covariances 358 359 { 359 360 psListIterator *iter = psListIteratorAlloc(cells, PS_LIST_HEAD, false); // Iterator for cells … … 384 385 varianceType = checkTypes(varianceType, readout->variance->type.type); 385 386 } 387 if (!hdu->covariances && readout->covariance) { 388 covarianceType = checkTypes(covarianceType, PS_TYPE_F32); 389 } 386 390 } 387 391 } 388 392 psFree(iter); 389 393 } 390 if (numReadouts == 0 || (imageType == 0 && maskType == 0 && varianceType == 0 )) {394 if (numReadouts == 0 || (imageType == 0 && maskType == 0 && varianceType == 0 && covarianceType == 0)) { 391 395 // Nothing from which to create an HDU 392 396 psFree(cells); … … 428 432 hdu->variances->data[i] = variance; 429 433 } 434 } 435 if (covarianceType) { 436 hdu->covariances = psHashAlloc(psListLength(cells)); 430 437 } 431 438 … … 448 455 449 456 psArray *readouts = cell->readouts; // Array of readouts 457 458 // Check size of covariances 459 int xMinCovar = INT_MAX, xMaxCovar = INT_MIN, yMinCovar = INT_MAX, yMaxCovar = INT_MIN; // Size 460 if (covarianceType) { 461 for (int i = 0; i < readouts->n; i++) { 462 pmReadout *readout = readouts->data[i]; // The readout of interest 463 if (!readout) { 464 continue; 465 } 466 psKernel *covar = readout->covariance; // Covariance matrix 467 xMinCovar = PS_MIN(xMinCovar, covar->xMin); 468 xMaxCovar = PS_MAX(xMaxCovar, covar->xMax); 469 yMinCovar = PS_MIN(yMinCovar, covar->yMin); 470 yMaxCovar = PS_MAX(yMaxCovar, covar->yMax); 471 } 472 } 473 450 474 psArray *hduImages = hdu->images; // Array of images in the HDU 451 475 psArray *hduMasks = hdu->masks; // Array of masks in the HDU 452 476 psArray *hduVariances = hdu->variances; // Array of variances in the HDU 477 psArray *covariances = (covarianceType ? psArrayAlloc(readouts->n) : NULL; // Covariance images 453 478 for (int i = 0; i < readouts->n; i++) { 454 479 pmReadout *readout = readouts->data[i]; // The readout of interest … … 471 496 psFree(readout->variance); 472 497 readout->variance = new; 498 } 499 if (readout->covariance) { 500 psKernel *covar = readout->covariance; // Covariance matrix 501 int xMin = covar->xMin, xMax = covar->xMax, yMin = covar->yMin, yMax = covar->yMax;// Size 502 if (xMin == xMinCovar && xMax == xMaxCovar && yMin == yMinCovar && yMax == yMaxCovar) { 503 variances->data[i] = psMemIncrRefCounter(readout->covariance); 504 } else { 505 psKernel *new = psKernelAlloc(xMinCovar, xMaxCovar, yMinCovar, yMaxCovar);// New covar 506 psImageInit(covar->image, 0); 507 psImageOverlaySection(new->image, covar->image, 508 xMinCovar - xMin, yMinCovar - yMin, "="); 509 variances->data[i] = new; 510 } 473 511 } 474 512 … … 495 533 } 496 534 psFree(biassecsIter); 535 536 if (covariances) { 537 const char *cellName = psMetadataLookupStr(NULL, cell->concepts, "CELL.NAME"); // Name of cell 538 pmChip *chip = cell->parent; // Parent chip 539 const char *chipName = psMetadataLookupStr(NULL, chip->concepts, "CHIP.NAME"); // Name of chip 540 if (!cellName || !chipName) { 541 psError(PS_ERR_UNKNOWN, false, "Unable to find cell or chip name."); 542 return false; 543 } 544 psString name = NULL; // Name for covariance extension 545 psStringAppend(&name, "COVAR_%s_%s", chipName, cellName); 546 if (psHashLookup(hdu->covariances, name)) { 547 psHashRemove(hash, name); 548 } 549 psHashAdd(hdu->covariances, name, covariance); 550 psFree(name); 551 } 497 552 } // Iterating over cells within the HDU 498 553 psFree(iter); … … 504 559 505 560 // Return the level that an extension applies to 506 static pmFPALevel extensionLevel( pmHDU *hdu // HDU to check561 static pmFPALevel extensionLevel(const pmHDU *hdu // HDU to check 507 562 ) 508 563 { … … 512 567 } 513 568 bool mdok = true; // Status of MD lookup 514 psMetadata *file = psMetadataLookupMetadata(&mdok, hdu->format, "FILE"); // File info rmationfor camera format569 psMetadata *file = psMetadataLookupMetadata(&mdok, hdu->format, "FILE"); // File info for camera format 515 570 if (!mdok || !file) { 516 571 psError(PS_ERR_UNEXPECTED_NULL, true, "Can't file FILE information for camera format " … … 581 636 return false; 582 637 } 583 if (hdu->images && hdu->masks && hdu->variances ) {638 if (hdu->images && hdu->masks && hdu->variances && hdu->covariances) { 584 639 // It's already here! 585 640 return true; … … 631 686 return generateForCells(chip); 632 687 } 633 if (hdu->images && hdu->masks && hdu->variances ) {688 if (hdu->images && hdu->masks && hdu->variances && hdu->covariances) { 634 689 // It's already here! 635 690 return true; … … 680 735 return generateForChips(fpa); 681 736 } 682 if (hdu->images && hdu->masks && hdu->variances ) {737 if (hdu->images && hdu->masks && hdu->variances && hdu->covariances) { 683 738 // It's already here! 684 739 return true;
Note:
See TracChangeset
for help on using the changeset viewer.
