Changeset 9983
- Timestamp:
- Nov 14, 2006, 2:40:02 PM (19 years ago)
- Location:
- trunk/psModules/src/camera
- Files:
-
- 6 edited
-
pmFPARead.c (modified) (1 diff)
-
pmFPAWrite.c (modified) (1 diff)
-
pmFPAWrite.h (modified) (2 diffs)
-
pmHDU.c (modified) (3 diffs)
-
pmHDU.h (modified) (2 diffs)
-
pmHDUGenerate.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/camera/pmFPARead.c
r9949 r9983 263 263 readout->row0 += readout->image->numRows; 264 264 offset = readout->row0; 265 if (numScans == 0) { 266 numScans = naxis2 - offset; 267 } 265 268 } else { 266 269 // Reading columns 267 270 readout->col0 += readout->image->numCols; 268 271 offset = readout->col0; 272 if (numScans == 0) { 273 numScans = naxis1 - offset; 274 } 269 275 } 270 276 } -
trunk/psModules/src/camera/pmFPAWrite.c
r9949 r9983 242 242 243 243 244 bool pmCellWriteMask(pmCell *cell, // Cell to write 245 psFits *fits, // FITS file to which to write 246 psDB *db // Database handle for "concepts" update 247 ) 248 { 249 PS_ASSERT_PTR_NON_NULL(cell, false); 250 PS_ASSERT_PTR_NON_NULL(fits, false); 251 252 pmHDU *hdu = cell->hdu; // The HDU 253 if (!hdu) { 254 return true; // We wrote every HDU that exists 255 } 256 257 psTrace ("pmFPAWrite", 5, "writing mask to Cell\n"); 258 259 // Generate the HDU if needed --- this is required after a pmFPACopy, or similar, which does not 260 // generate the HDU, but only copies the structure. 261 if (!hdu->blankPHU && !hdu->masks) { 262 if (!pmHDUGenerateForCell(cell) || !hdu->masks) { 263 psError(PS_ERR_UNKNOWN, false, "Unable to generate HDU for cell --- likely programming error.\n"); 264 return false; 265 } 266 } 267 268 pmConceptSource source = PM_CONCEPT_SOURCE_HEADER | PM_CONCEPT_SOURCE_CELLS | PM_CONCEPT_SOURCE_DEFAULTS; 269 if (!pmConceptsWriteCell(cell, source, false, NULL)) { 270 psError(PS_ERR_IO, false, "Unable to write concepts for cell.\n"); 271 return false; 272 } 273 if (!pmHDUWriteMask(hdu, fits)) { 274 psError(PS_ERR_IO, false, "Unable to write HDU for cell.\n"); 275 return false; 276 } 277 278 return true; 279 } 280 281 282 bool pmChipWriteMask(pmChip *chip, psFits *fits, psDB *db) 283 { 284 PS_ASSERT_PTR_NON_NULL(chip, false); 285 PS_ASSERT_PTR_NON_NULL(fits, false); 286 287 pmHDU *hdu = chip->hdu; // The HDU 288 if (!hdu) { 289 return true; // We wrote every HDU that exists 290 } 291 292 psTrace ("pmFPAWrite", 5, "writing mask to Chip\n"); 293 294 // Generate the HDU if needed --- this is required after a pmFPACopy, or similar, which does not 295 // generate the HDU, but only copies the structure. 296 if (!hdu->blankPHU && !hdu->masks) { 297 if (!pmHDUGenerateForChip(chip) || !hdu->masks) { 298 psError(PS_ERR_UNKNOWN, false, "Unable to generate HDU for chip --- likely programming error.\n"); 299 return false; 300 } 301 } 302 303 pmConceptSource source = PM_CONCEPT_SOURCE_HEADER | PM_CONCEPT_SOURCE_CELLS | PM_CONCEPT_SOURCE_DEFAULTS; 304 if (!pmConceptsWriteChip(chip, source, false, true, NULL)) { 305 psError(PS_ERR_IO, false, "Unable to write concepts for chip.\n"); 306 return false; 307 } 308 if (!pmHDUWriteMask(hdu, fits)) { 309 psError(PS_ERR_IO, false, "Unable to write HDU for chip.\n"); 310 return false; 311 } 312 313 return true; 314 } 315 316 317 318 bool pmFPAWriteMask(pmFPA *fpa, psFits *fits, psDB *db) 319 { 320 PS_ASSERT_PTR_NON_NULL(fpa, false); 321 PS_ASSERT_PTR_NON_NULL(fits, false); 322 323 pmHDU *hdu = fpa->hdu; // The HDU 324 if (!hdu) { 325 return true; // We wrote every HDU that exists 326 } 327 328 psTrace ("pmFPAWrite", 5, "writing mask to FPA\n"); 329 330 // Generate the HDU if needed --- this is required after a pmFPACopy, or similar, which does not 331 // generate the HDU, but only copies the structure. 332 if (!hdu->blankPHU && !hdu->masks) { 333 if (!pmHDUGenerateForFPA(fpa) || !hdu->masks) { 334 psError(PS_ERR_UNKNOWN, false, "Unable to generate HDU for chip --- likely programming error.\n"); 335 return false; 336 } 337 } 338 339 pmConceptSource source = PM_CONCEPT_SOURCE_HEADER | PM_CONCEPT_SOURCE_CELLS | PM_CONCEPT_SOURCE_DEFAULTS; 340 if (!pmConceptsWriteFPA(fpa, source, true, NULL)) { 341 psError(PS_ERR_IO, false, "Unable to write concepts for FPA.\n"); 342 return false; 343 } 344 if (!pmHDUWriteMask(hdu, fits)) { 345 psError(PS_ERR_IO, false, "Unable to write HDU for FPA.\n"); 346 return false; 347 } 348 349 return true; 350 } 351 352 353 244 354 int pmCellWriteTable(psFits *fits, const pmCell *cell, const char *name) 245 355 { -
trunk/psModules/src/camera/pmFPAWrite.h
r9949 r9983 7 7 /// @author Paul Price, IfA 8 8 /// 9 /// @version $Revision: 1. 5$ $Name: not supported by cvs2svn $10 /// @date $Date: 2006-11-1 3 22:15:05$9 /// @version $Revision: 1.6 $ $Name: not supported by cvs2svn $ 10 /// @date $Date: 2006-11-15 00:40:02 $ 11 11 /// 12 12 /// Copyright 2005-2006 Institute for Astronomy, University of Hawaii … … 67 67 ); 68 68 69 /// Write a cell mask to a FITS file 70 /// 71 /// Generates CELL.TRIMSEC, CELL.BIASSEC and the HDU pixels if required. Writes the concepts to the various 72 /// locations, and then the HDU mask to the FITS file. 73 bool pmCellWriteMask(pmCell *cell, ///< Cell to write 74 psFits *fits, ///< FITS file to which to write 75 psDB *db ///< Database handle for "concepts" update 76 ); 77 78 /// Write a chip mask to a FITS file 79 /// 80 /// Generates CELL.TRIMSEC, CELL.BIASSEC and the HDU pixels if required. Writes the concepts to the various 81 /// locations, and then the HDU mask to the FITS file. 82 bool pmChipWriteMask(pmChip *chip, ///< Chip to write 83 psFits *fits, ///< FITS file to which to write 84 psDB *db ///< Database handle for "concepts" update 85 ); 86 87 /// Write an FPA mask to a FITS file 88 /// 89 /// Generates CELL.TRIMSEC, CELL.BIASSEC and the HDU pixels if required. Writes the concepts to the various 90 /// locations, and then the HDU mask to the FITS file. 91 bool pmFPAWriteMask(pmFPA *fpa, ///< FPA to write 92 psFits *fits, ///< FITS file to which to write 93 psDB *db ///< Database handle for "concepts" update 94 ); 95 69 96 /// Write a FITS table from the cell's analysis metadata. 70 97 /// -
trunk/psModules/src/camera/pmHDU.c
r9609 r9983 124 124 } 125 125 126 // XXX: Add a region specifier? 127 bool pmHDUWrite(pmHDU *hdu, psFits *fits) 126 // Write an HDU to a FITS file 127 bool hduWrite(pmHDU *hdu, // HDU to write 128 psArray *images, // Images to write 129 psFits *fits // FITS file to which to write 130 ) 128 131 { 129 PS_ASSERT_PTR_NON_NULL(hdu, false);130 PS_ASSERT_PTR_NON_NULL(fits, false);132 assert(hdu); 133 assert(fits); 131 134 132 135 psTrace("psModules.camera", 7, "Writing HDU %s\n", hdu->extname); 133 136 134 if (hdu->images && !hdu->header) { 135 psError(PS_ERR_IO, true, "Both image and table data provided in HDU, but no header --- " 136 "don't know which to write!\n"); 137 return false; 138 } 139 140 if (!hdu->images && !hdu->header) { 137 if (!images && !hdu->header) { 141 138 psLogMsg(__func__, PS_LOG_WARN, "Nothing to write for HDU %s\n", hdu->extname); 142 139 return false; … … 154 151 155 152 // Only a header 156 if (! hdu->images && !psFitsWriteBlank(fits, hdu->header, extname)) {153 if (!images && !psFitsWriteBlank(fits, hdu->header, extname)) { 157 154 psError(PS_ERR_IO, false, "Unable to write header for extension %s\n", extname); 158 155 } 159 156 160 if ( hdu->images) {157 if (images) { 161 158 psTrace("psModules.camera", 9, "Writing pixels for %s\n", hdu->extname); 162 if (!psFitsWriteImageCube(fits, hdu->header, hdu->images, extname)) {159 if (!psFitsWriteImageCube(fits, hdu->header, images, extname)) { 163 160 psError(PS_ERR_IO, false, "Unable to write image to extension %s\n", hdu->extname); 164 161 return false; … … 168 165 } 169 166 167 // XXX: Add a region specifier? 168 bool pmHDUWrite(pmHDU *hdu, psFits *fits) 169 { 170 PS_ASSERT_PTR_NON_NULL(hdu, false); 171 PS_ASSERT_PTR_NON_NULL(fits, false); 172 173 return hduWrite(hdu, hdu->images, fits); 174 } 175 176 bool pmHDUWriteMask(pmHDU *hdu, psFits *fits) 177 { 178 PS_ASSERT_PTR_NON_NULL(hdu, false); 179 PS_ASSERT_PTR_NON_NULL(fits, false); 180 181 return hduWrite(hdu, hdu->masks, fits); 182 } 183 -
trunk/psModules/src/camera/pmHDU.h
r9698 r9983 7 7 /// @author Paul Price, IfA 8 8 /// 9 /// @version $Revision: 1. 4$ $Name: not supported by cvs2svn $10 /// @date $Date: 2006-1 0-21 03:00:43$9 /// @version $Revision: 1.5 $ $Name: not supported by cvs2svn $ 10 /// @date $Date: 2006-11-15 00:40:02 $ 11 11 /// 12 12 /// Copyright 2005-2006 Institute for Astronomy, University of Hawaii … … 56 56 ); 57 57 58 /// Write the HDU header and mask 59 bool pmHDUWriteMask(pmHDU *hdu, ///< HDU to write mask 60 psFits *fits ///< FITS file to write to 61 ); 62 58 63 #endif -
trunk/psModules/src/camera/pmHDUGenerate.c
r9730 r9983 218 218 219 219 pmReadout *readout = cell->readouts->data[0]; // The first readout, as representative 220 psImage *image = readout->image;// The proper image 220 // The proper image, used to get the size 221 psImage *image = readout->image ? readout->image : (readout->mask ? readout->mask : readout->weight); 221 222 if (!image) { 222 223 continue; 224 } 225 if (readout->mask && 226 (readout->mask->numCols != image->numCols || readout->mask->numRows != image->numRows)) { 227 psLogMsg(__func__, PS_LOG_WARN, "Image and mask have different sizes (%dx%d vs %dx%d)!\n", 228 image->numCols, image->numRows, readout->mask->numCols, readout->mask->numRows); 229 } 230 if (readout->weight && 231 (readout->weight->numCols != image->numCols || readout->weight->numRows != image->numRows)) { 232 psLogMsg(__func__, PS_LOG_WARN, "Image and weight have different sizes (%dx%d vs %dx%d)!\n", 233 image->numCols, image->numRows, readout->weight->numCols, readout->weight->numRows); 223 234 } 224 235 // New reference … … 239 250 return (position > 0); 240 251 } 252 253 // Check the type for a current image against a previous type 254 static psElemType checkTypes(psElemType previous, // Previously defined type, or 0 255 psElemType current // Current type 256 ) 257 { 258 if (previous == 0) { 259 return current; 260 } 261 262 if (previous != current) { 263 psLogMsg(__func__, PS_LOG_WARN, "Images within the HDU are of different types " 264 "(%x vs %x) --- promoting\n", previous, current); 265 return PS_MAX(previous, current); 266 } 267 268 return previous; 269 } 270 271 272 // Paste the source image into the target, according to the provided region. The source is then updated to 273 // reference the region within the target. 274 static void pasteImage(psImage *target, // Target image, into which the paste is made 275 psImage **sourcePtr,// Source image, from which the paste is made, and then changed 276 psRegion *region // Image section into which to paste 277 ) 278 { 279 psImage *source = *sourcePtr; // Dereference pointer, for convenience 280 if (source->numCols != region->x1 - region->x0 || source->numRows != region->y1 - region->y0) { 281 psString regionString = psRegionToString(*region); 282 psLogMsg(__func__, PS_LOG_WARN, "Image size (%dx%d) does not match region (%s).\n", 283 source->numCols, source->numRows, regionString); 284 psFree(regionString); 285 } 286 psImageOverlaySection(target, source, region->x0, region->y0, "="); 287 288 // Reference the HDU version, so that subsequent changes will touch the HDU 289 psFree(source); 290 *sourcePtr = psImageSubset(target, *region); 291 292 return; 293 } 294 241 295 242 296 // Generate the HDU, given a list of cells below that HDU. This is the main engine function, that does all … … 248 302 // Check the number of readouts is consistent within the HDU 249 303 int numReadouts = -1; // Number of readouts 250 psElemType type = 0; // Type of readout images 304 psElemType imageType = 0; // Type of readout images 305 psElemType maskType = 0; // Type of readout masks 306 psElemType weightType = 0; // Type of readout weights 251 307 { 252 308 psListIterator *iter = psListIteratorAlloc(cells, PS_LIST_HEAD, false); // Iterator for cells … … 264 320 for (int i = 0; i < numReadouts; i++) { 265 321 pmReadout *readout = readouts->data[i]; // The readout 266 if (!readout || !readout->image) {322 if (!readout) { 267 323 continue; 268 324 } 269 psElemType imageType = readout->image->type.type; // Type for this image 270 if (type == 0) { 271 type = imageType; 272 } else if (type != imageType) { 273 psLogMsg(__func__, PS_LOG_WARN, "Images within the HDU are of different types " 274 "(%x vs %x) --- promoting\n", type, imageType); 275 type = PS_MAX(type, imageType); 325 326 if (readout->image) { 327 imageType = checkTypes(imageType, readout->image->type.type); 328 } 329 if (readout->mask) { 330 maskType = checkTypes(maskType, readout->mask->type.type); 331 } 332 if (readout->weight) { 333 weightType = checkTypes(weightType, readout->weight->type.type); 276 334 } 277 335 } … … 279 337 psFree(iter); 280 338 } 281 if (numReadouts == 0 || type == 0) {339 if (numReadouts == 0 || (imageType == 0 && maskType == 0 && weightType == 0)) { 282 340 // Nothing from which to create an HDU 283 341 psFree(cells); … … 293 351 294 352 // Generate the HDU 295 hdu->images = psArrayAlloc(numReadouts); 296 for (int i = 0; i < numReadouts; i++) { 297 psImage *image = psImageAlloc(xSize, ySize, type); 298 psImageInit(image, 0.0); 299 hdu->images->data[i] = image; 353 if (imageType) { 354 hdu->images = psArrayAlloc(numReadouts); 355 for (int i = 0; i < numReadouts; i++) { 356 psImage *image = psImageAlloc(xSize, ySize, imageType); 357 psImageInit(image, 0.0); 358 hdu->images->data[i] = image; 359 } 360 } 361 if (maskType) { 362 hdu->masks = psArrayAlloc(numReadouts); 363 for (int i = 0; i < numReadouts; i++) { 364 psImage *mask = psImageAlloc(xSize, ySize, maskType); 365 psImageInit(mask, 0); 366 hdu->masks->data[i] = mask; 367 } 368 } 369 if (weightType) { 370 hdu->weights = psArrayAlloc(numReadouts); 371 for (int i = 0; i < numReadouts; i++) { 372 psImage *weight = psImageAlloc(xSize, ySize, weightType); 373 psImageInit(weight, 0.0); 374 hdu->weights->data[i] = weight; 375 } 300 376 } 301 377 … … 319 395 psArray *readouts = cell->readouts; // Array of readouts 320 396 psArray *hduImages = hdu->images; // Array of images in the HDU 397 psArray *hduMasks = hdu->masks; // Array of masks in the HDU 398 psArray *hduWeights = hdu->weights; // Array of weights in the HDU 321 399 for (int i = 0; i < readouts->n; i++) { 322 400 pmReadout *readout = readouts->data[i]; // The readout of interest … … 324 402 continue; 325 403 } 326 psImage *image = readout->image; // The image pixels 327 psImage *hduImage = hduImages->data[i]; // The HDU image of interest 328 329 if (image->numCols != trimsec->x1 - trimsec->x0 || 330 image->numRows != trimsec->y1 - trimsec->y0) { 331 psString trimsecString = psRegionToString(*trimsec); 332 psLogMsg(__func__, PS_LOG_WARN, "Image size (%dx%d) does not match CELL.TRIMSEC (%s).\n", 333 image->numCols, image->numRows, trimsecString); 334 psFree(trimsecString); 335 } 336 psImageOverlaySection(hduImage, image, trimsec->x0, trimsec->y0, "="); 337 338 // Reference the HDU version, so that subsequent changes will touch the HDU 339 psFree(image); 340 readout->image = psImageSubset(hduImage, *trimsec); 404 405 if (readout->image) { 406 pasteImage(hduImages->data[i], &readout->image, trimsec); 407 } 408 if (readout->mask) { 409 pasteImage(hduMasks->data[i], &readout->mask, trimsec); 410 } 411 if (readout->weight) { 412 pasteImage(hduWeights->data[i], &readout->weight, trimsec); 413 } 341 414 342 415 if (biassecs->n != readout->bias->n) { … … 351 424 while ((bias = psListGetAndIncrement(biasIter)) && 352 425 (biassec = psListGetAndIncrement(biassecsIter))) { 353 if (bias->numCols != biassec->x1 - biassec->x0 || 354 bias->numRows != biassec->y1 - biassec->y0) { 355 psString biassecString = psRegionToString(*biassec); 356 psLogMsg(__func__, PS_LOG_WARN, "Bias size (%dx%d) does not match CELL.BIASSEC (%s)." 357 "\n", bias->numCols, bias->numRows, biassecString); 358 psFree(biassecString); 359 } 360 361 psImageOverlaySection(hduImage, bias, biassec->x0, biassec->y0, "="); 362 363 // Reference the HDU version, so that subsequent changes will touch the HDU 364 bias = psImageSubset(hduImage, *biassec); 426 pasteImage(hduImages->data[i], &bias, biassec); 365 427 psListAdd(newBias, PS_LIST_TAIL, bias); 366 428 }
Note:
See TracChangeset
for help on using the changeset viewer.
