Changeset 19385
- Timestamp:
- Sep 4, 2008, 10:21:35 PM (18 years ago)
- Location:
- trunk/psModules/src/camera
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/camera/pmFPAWrite.c
r18177 r19385 36 36 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 37 37 38 39 // Update the FPA.OBS, CHIP.NAME and CELL.NAME in the FITS header, if required40 bool pmFPAUpdateNames(pmFPA *fpa, pmChip *chip, pmCell *cell)41 {42 pmHDU *hdu = pmHDUGetHighest(fpa, chip, cell); // Highest HDU, i.e., the PHU43 if (!hdu) {44 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find HDU.\n");45 return false;46 }47 if (!hdu->header) {48 hdu->header = psMetadataAlloc();49 }50 bool mdok; // Status of MD lookup51 psMetadata *fileData = psMetadataLookupMetadata(&mdok, hdu->format, "FILE"); // File information52 if (!mdok || !fileData) {53 psError(PS_ERR_UNKNOWN, true, "Unable to find FILE information in camera format.\n");54 return false;55 }56 if (fpa) {57 const char *fpaObsHdr = psMetadataLookupStr(&mdok, fileData, "FPA.OBS");58 if (mdok && fpaObsHdr && strlen(fpaObsHdr) > 0) {59 const char *fpaObs = psMetadataLookupStr(NULL, fpa->concepts, "FPA.OBS");60 psMetadataAddStr(hdu->header, PS_LIST_TAIL, fpaObsHdr, PS_META_REPLACE,61 "Observation identifier", fpaObs);62 }63 }64 65 if (fpa && !fpa->hdu && (chip || cell)) {66 const char *rule = psMetadataLookupStr(NULL, fileData, "CONTENT.RULE"); // How to define the CONTENT67 if (!rule) {68 psError(PS_ERR_UNKNOWN, false, "Unable to find CONTENT.RULE in FILE in camera format.");69 return false;70 }71 72 pmFPAview *view = pmFPAviewGenerate(fpa, chip, cell, NULL); // View for fpa, chip, cell73 psString content = pmFPANameFromRule(rule, fpa, view); // Content of this file, specified by the rule74 psFree(view);75 76 const char *contentKey = psMetadataLookupStr(NULL, fileData, "CONTENT"); // The CONTENT header keyword77 if (!contentKey) {78 psError(PS_ERR_UNKNOWN, false, "Unable to find CONTENT in FILE in the camera format.");79 psFree(content);80 return false;81 }82 83 psMetadataAddStr(hdu->header, PS_LIST_TAIL, contentKey, PS_META_REPLACE, "Content of file", content);84 psFree(content); // Drop reference85 }86 87 return true;88 }89 90 38 // Return the appropriate image array for the given type 91 39 static psArray **appropriateImageArray(pmHDU *hdu, // HDU containing the image arrays … … 109 57 static bool appropriateWriteFunc(pmHDU *hdu, // HDU to write 110 58 psFits *fits, // FITS file to which to write 59 const pmConfig *config, // Configuration 111 60 fpaWriteType type // Type to write 112 61 ) … … 114 63 switch (type) { 115 64 case FPA_WRITE_TYPE_IMAGE: 116 return pmHDUWrite(hdu, fits );65 return pmHDUWrite(hdu, fits, config); 117 66 case FPA_WRITE_TYPE_MASK: 118 return pmHDUWriteMask(hdu, fits );67 return pmHDUWriteMask(hdu, fits, config); 119 68 case FPA_WRITE_TYPE_WEIGHT: 120 return pmHDUWriteWeight(hdu, fits );69 return pmHDUWriteWeight(hdu, fits, config); 121 70 default: 122 71 psAbort("Unknown write type: %x\n", type); … … 165 114 return false; 166 115 } 167 if (!appropriateWriteFunc(hdu, fits, type)) {116 if (!appropriateWriteFunc(hdu, fits, config, type)) { 168 117 psError(PS_ERR_IO, false, "Unable to write HDU for cell.\n"); 169 118 return false; … … 215 164 return false; 216 165 } 217 if (!appropriateWriteFunc(hdu, fits, type)) {166 if (!appropriateWriteFunc(hdu, fits, config, type)) { 218 167 psError(PS_ERR_IO, false, "Unable to write HDU for chip.\n"); 219 168 return false; … … 279 228 return false; 280 229 } 281 if (!appropriateWriteFunc(hdu, fits, type)) {230 if (!appropriateWriteFunc(hdu, fits, config, type)) { 282 231 psError(PS_ERR_IO, false, "Unable to write HDU for FPA.\n"); 283 232 return false; … … 305 254 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 306 255 256 // Update the FPA.OBS, CHIP.NAME and CELL.NAME in the FITS header, if required 257 bool pmFPAUpdateNames(pmFPA *fpa, pmChip *chip, pmCell *cell) 258 { 259 pmHDU *hdu = pmHDUGetHighest(fpa, chip, cell); // Highest HDU, i.e., the PHU 260 if (!hdu) { 261 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find HDU.\n"); 262 return false; 263 } 264 if (!hdu->header) { 265 hdu->header = psMetadataAlloc(); 266 } 267 bool mdok; // Status of MD lookup 268 psMetadata *fileData = psMetadataLookupMetadata(&mdok, hdu->format, "FILE"); // File information 269 if (!mdok || !fileData) { 270 psError(PS_ERR_UNKNOWN, true, "Unable to find FILE information in camera format.\n"); 271 return false; 272 } 273 if (fpa) { 274 const char *fpaObsHdr = psMetadataLookupStr(&mdok, fileData, "FPA.OBS"); 275 if (mdok && fpaObsHdr && strlen(fpaObsHdr) > 0) { 276 const char *fpaObs = psMetadataLookupStr(NULL, fpa->concepts, "FPA.OBS"); 277 psMetadataAddStr(hdu->header, PS_LIST_TAIL, fpaObsHdr, PS_META_REPLACE, 278 "Observation identifier", fpaObs); 279 } 280 } 281 282 if (fpa && !fpa->hdu && (chip || cell)) { 283 const char *rule = psMetadataLookupStr(NULL, fileData, "CONTENT.RULE"); // How to define the CONTENT 284 if (!rule) { 285 psError(PS_ERR_UNKNOWN, false, "Unable to find CONTENT.RULE in FILE in camera format."); 286 return false; 287 } 288 289 pmFPAview *view = pmFPAviewGenerate(fpa, chip, cell, NULL); // View for fpa, chip, cell 290 psString content = pmFPANameFromRule(rule, fpa, view); // Content of this file, specified by the rule 291 psFree(view); 292 293 const char *contentKey = psMetadataLookupStr(NULL, fileData, "CONTENT"); // The CONTENT header keyword 294 if (!contentKey) { 295 psError(PS_ERR_UNKNOWN, false, "Unable to find CONTENT in FILE in the camera format."); 296 psFree(content); 297 return false; 298 } 299 300 psMetadataAddStr(hdu->header, PS_LIST_TAIL, contentKey, PS_META_REPLACE, "Content of file", content); 301 psFree(content); // Drop reference 302 } 303 304 return true; 305 } 306 307 307 bool pmReadoutWriteNext(pmReadout *readout, psFits *fits, int z) 308 308 { … … 347 347 return false; 348 348 } 349 psImage *image = readout->image; // The image from the HDU to write 349 psImage *image = readout->image; // The image from the HDU to write 350 // psImage *mask = readout->mask; // Corresponding mask image 350 351 if (readout->row0 == 0 && readout->col0 == 0 && z == 0) { 351 352 // Then we can assume that nothing has been written to the FITS file for now -
trunk/psModules/src/camera/pmHDU.c
r15973 r19385 9 9 10 10 #include "pmConfig.h" 11 #include "pmConfigMask.h" 11 12 #include "pmHDU.h" 12 13 #include "pmFPA.h" … … 164 165 // Write an HDU to a FITS file 165 166 static bool hduWrite(pmHDU *hdu, // HDU to write 166 psArray *images, // Images to write 167 const psArray *images, // Images to write 168 const psArray *masks, // Masks to use when writing 169 psMaskType maskVal,// Value to mask 167 170 psFits *fits // FITS file to which to write 168 171 ) … … 205 208 if (images) { 206 209 psTrace("psModules.camera", 9, "Writing pixels for %s\n", hdu->extname); 207 if (!psFitsWriteImageCube (fits, hdu->header, images, extname)) {210 if (!psFitsWriteImageCubeWithMask(fits, hdu->header, images, masks, maskVal, extname)) { 208 211 psError(PS_ERR_IO, false, "Unable to write image to extension %s\n", hdu->extname); 209 212 return false; … … 214 217 215 218 // XXX: Add a region specifier? 216 bool pmHDUWrite(pmHDU *hdu, psFits *fits) 217 { 218 PS_ASSERT_PTR_NON_NULL(hdu, false); 219 PS_ASSERT_PTR_NON_NULL(fits, false); 220 221 return hduWrite(hdu, hdu->images, fits); 222 } 223 224 bool pmHDUWriteMask(pmHDU *hdu, psFits *fits) 225 { 226 PS_ASSERT_PTR_NON_NULL(hdu, false); 227 PS_ASSERT_PTR_NON_NULL(fits, false); 228 229 return hduWrite(hdu, hdu->masks, fits); 230 } 231 232 bool pmHDUWriteWeight(pmHDU *hdu, psFits *fits) 233 { 234 PS_ASSERT_PTR_NON_NULL(hdu, false); 235 PS_ASSERT_PTR_NON_NULL(fits, false); 236 237 return hduWrite(hdu, hdu->weights, fits); 238 } 219 bool pmHDUWrite(pmHDU *hdu, psFits *fits, const pmConfig *config) 220 { 221 PS_ASSERT_PTR_NON_NULL(hdu, false); 222 PS_ASSERT_PTR_NON_NULL(fits, false); 223 224 psMaskType maskVal = pmConfigMaskGet("MASK.VALUE", config); // Value to mask 225 return hduWrite(hdu, hdu->images, hdu->masks, maskVal, fits); 226 } 227 228 bool pmHDUWriteMask(pmHDU *hdu, psFits *fits, const pmConfig *config) 229 { 230 PS_ASSERT_PTR_NON_NULL(hdu, false); 231 PS_ASSERT_PTR_NON_NULL(fits, false); 232 233 // We don't supply a mask because we're writing the mask! 234 return hduWrite(hdu, hdu->masks, NULL, 0, fits); 235 } 236 237 bool pmHDUWriteWeight(pmHDU *hdu, psFits *fits, const pmConfig *config) 238 { 239 PS_ASSERT_PTR_NON_NULL(hdu, false); 240 PS_ASSERT_PTR_NON_NULL(fits, false); 241 242 psMaskType maskVal = pmConfigMaskGet("MASK.VALUE", config); // Value to mask 243 return hduWrite(hdu, hdu->weights, hdu->masks, maskVal, fits); 244 } -
trunk/psModules/src/camera/pmHDU.h
r15973 r19385 4 4 * @author Paul Price, IfA 5 5 * 6 * @version $Revision: 1. 8$ $Name: not supported by cvs2svn $7 * @date $Date: 2008-0 1-02 20:33:41$6 * @version $Revision: 1.9 $ $Name: not supported by cvs2svn $ 7 * @date $Date: 2008-09-05 08:21:35 $ 8 8 * Copyright 2005-2006 Institute for Astronomy, University of Hawaii 9 9 */ … … 11 11 #ifndef PM_HDU_H 12 12 #define PM_HDU_H 13 14 #include <pslib.h> 15 #include "pmConfig.h" 13 16 14 17 /// @addtogroup Camera Camera Layout … … 62 65 bool pmHDUReadWeight(pmHDU *hdu, ///< HDU to read 63 66 psFits *fits ///< FITS file to read from 64 );67 ); 65 68 66 69 /// Write the HDU header and pixels 67 70 bool pmHDUWrite(pmHDU *hdu, ///< HDU to write 68 psFits *fits ///< FITS file to write to 69 ); 71 psFits *fits, ///< FITS file to write to 72 const pmConfig *config ///< Configuration 73 ); 70 74 71 75 /// Write the HDU header and mask 72 76 bool pmHDUWriteMask(pmHDU *hdu, ///< HDU to write 73 psFits *fits ///< FITS file to write to 74 ); 77 psFits *fits, ///< FITS file to write to 78 const pmConfig *config ///< Configuration 79 ); 75 80 76 81 /// Write the HDU header and weight map 77 82 bool pmHDUWriteWeight(pmHDU *hdu, ///< HDU to write 78 psFits *fits ///< FITS file to write to 79 ); 83 psFits *fits, ///< FITS file to write to 84 const pmConfig *config ///< Configuration 85 ); 80 86 81 87 /// @}
Note:
See TracChangeset
for help on using the changeset viewer.
