Changeset 18830
- Timestamp:
- Jul 31, 2008, 2:01:26 PM (18 years ago)
- Location:
- trunk/psModules/src
- Files:
-
- 9 edited
-
camera/pmFPA.c (modified) (2 diffs)
-
camera/pmFPA.h (modified) (2 diffs)
-
camera/pmFPARead.c (modified) (14 diffs)
-
camera/pmReadoutStack.c (modified) (7 diffs)
-
camera/pmReadoutStack.h (modified) (2 diffs)
-
config/pmConfig.c (modified) (1 diff)
-
imcombine/pmReadoutCombine.c (modified) (9 diffs)
-
imcombine/pmReadoutCombine.h (modified) (2 diffs)
-
objects/Makefile.am (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/camera/pmFPA.c
r18364 r18830 176 176 readout->col0 = 0; 177 177 readout->row0 = 0; 178 readout->imageScan = 0; 179 readout->maskScan = 0; 180 readout->weightScan = 0; 178 179 readout->thisImageScan = 0; 180 readout->thisMaskScan = 0; 181 readout->thisWeightScan = 0; 182 183 readout->lastImageScan = 0; 184 readout->lastMaskScan = 0; 185 readout->lastWeightScan = 0; 181 186 } 182 187 … … 269 274 tmpReadout->col0 = 0; 270 275 271 tmpReadout->imageScan = 0; 272 tmpReadout->maskScan = 0; 273 tmpReadout->weightScan = 0; 276 tmpReadout->thisImageScan = 0; 277 tmpReadout->thisMaskScan = 0; 278 tmpReadout->thisWeightScan = 0; 279 280 tmpReadout->lastImageScan = 0; 281 tmpReadout->lastMaskScan = 0; 282 tmpReadout->lastWeightScan = 0; 274 283 275 284 return(tmpReadout); -
trunk/psModules/src/camera/pmFPA.h
r17911 r18830 6 6 * @author Eugene Magnier, IfA 7 7 * 8 * @version $Revision: 1.2 2$ $Name: not supported by cvs2svn $9 * @date $Date: 2008-0 6-05 01:31:33$8 * @version $Revision: 1.23 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2008-08-01 00:01:25 $ 10 10 * Copyright 2005-2006 Institute for Astronomy, University of Hawaii 11 11 */ … … 127 127 bool file_exists; ///< Does the file for this readout exist (read case only)? 128 128 bool data_exists; ///< Does the data for this readout exist (read case only)? 129 int imageScan, maskScan, weightScan;///< Separate tracking numbers for reading images incrementally 129 int thisImageScan; ///< start scan for next/current read 130 int lastImageScan; ///< start scan of the last read 131 int thisMaskScan; ///< start scan for next/current read 132 int lastMaskScan; ///< start scan of the last read 133 int thisWeightScan; ///< start scan for next/current read 134 int lastWeightScan; ///< start scan of the last read 130 135 } pmReadout; 131 136 -
trunk/psModules/src/camera/pmFPARead.c
r18210 r18830 45 45 46 46 // Return pointer to appropriate value for tracking scans 47 static int *readoutScansByType(pmReadout *readout, // Readout of interest48 fpaReadType type // Type of image47 static int readoutGetThisScan(pmReadout *readout, // Readout of interest 48 fpaReadType type // Type of image 49 49 ) 50 50 { 51 51 switch (type) { 52 52 case FPA_READ_TYPE_IMAGE: 53 return &readout->imageScan;53 return readout->thisImageScan; 54 54 case FPA_READ_TYPE_MASK: 55 return &readout->maskScan;55 return readout->thisMaskScan; 56 56 case FPA_READ_TYPE_WEIGHT: 57 return &readout->weightScan;57 return readout->thisWeightScan; 58 58 default: 59 59 psAbort("Unknown read type: %x\n", type); 60 60 } 61 } 62 63 // Return pointer to appropriate value for tracking scans 64 static int readoutSetLastScan(pmReadout *readout, // Readout of interest 65 fpaReadType type, // Type of image 66 int numScans // requested number of scans 67 ) 68 { 69 switch (type) { 70 case FPA_READ_TYPE_IMAGE: 71 readout->lastImageScan = readout->thisImageScan + numScans; 72 return readout->lastImageScan; 73 case FPA_READ_TYPE_MASK: 74 readout->lastMaskScan = readout->thisMaskScan + numScans; 75 return readout->lastMaskScan; 76 case FPA_READ_TYPE_WEIGHT: 77 readout->lastWeightScan = readout->thisWeightScan + numScans; 78 return readout->lastWeightScan; 79 default: 80 psAbort("Unknown read type: %x\n", type); 81 } 82 return false; 61 83 } 62 84 … … 134 156 } 135 157 136 137 // Determine readout scan properties: the next and last scans 138 // Requires that cellNumReadouts() has been called before (for header and concepts to have been read) 139 // In the process, adjusts the TRIMSEC 140 static bool readoutScanProperties(int *next, // Index of next scan 141 int *last, // Index of last scan 142 pmReadout *readout, // Readout of interest 143 int numScans, // Number of scans to read at a time 144 fpaReadType type, // Type of image 145 pmConfig *config // Configuration 158 // Does the current readout, with scans set for a new read, represent any real data, or is it 159 // beyond the end? Requires that cellNumReadouts() has been called before (for header and 160 // concepts to have been read) In the process, adjusts the TRIMSEC 161 static bool readoutHaveMoreScans(bool *result, // true : more data to read 162 pmReadout *readout, // Readout of interest 163 int numScans, // Number of scans to read at a time 164 fpaReadType type, // Type of image 165 pmConfig *config // Configuration 146 166 ) 147 167 { 148 assert(next); 149 assert(last); 168 assert(result); 150 169 assert(readout); 151 170 152 psImage *image = *readoutImageByType(readout, type); // Appropriate image from readout171 *result = false; 153 172 154 173 if (!pmConceptsReadCell(readout->parent, PM_CONCEPT_SOURCE_DEFAULTS | PM_CONCEPT_SOURCE_DATABASE, … … 163 182 PS_ASSERT_PTR_NON_NULL(cell, false); 164 183 pmHDU *hdu = pmHDUFromCell(cell); // HDU for data 184 165 185 bool mdok = true; // Status of MD lookup 166 186 psRegion *trimsec = psMetadataLookupPtr(&mdok, cell->concepts, "CELL.TRIMSEC"); // Trim sections … … 195 215 // Calculate the segment offset and upper limit 196 216 if (numScans == 0) { 197 *next = (readdir == 1) ? trimsec->y0 : trimsec->x0; 198 } else { 199 *next = image ? *readoutScansByType(readout, type) + numScans : 0; 200 } 201 *last = (readdir == 1) ? trimsec->y1 : trimsec->x1; 202 217 // in the case of numScans == 0, we never call this funtion unless the data has not yet 218 // been read. thus, only if the delta is should we return false (ie, trimsec defines an empty region) 219 int thisScan = (readdir == 1) ? trimsec->y0 : trimsec->x0; 220 int lastScan = (readdir == 1) ? trimsec->y1 : trimsec->x1; 221 *result = (lastScan > thisScan); 222 return true; 223 } 224 225 // allow multiple threads to read different segments into different readouts 226 // this thread may not have read a segment yet; but others have. trust readout->imageScan 227 228 // is the start scan of the read less than the last possible scan? 229 int thisScan = readoutGetThisScan(readout, type); 230 int lastScan = (readdir == 1) ? trimsec->y1 : trimsec->x1; 231 232 *result = (lastScan > thisScan); 203 233 return true; 234 // XXX fold this and the above case together 204 235 } 205 236 … … 217 248 psImage *image = *readoutImageByType(readout, type); 218 249 250 // XXX this may not be the valid test in a multithread environment. consider a fileGroup of 251 // N readouts, but numScans set to 0. only the first should report that it requires data, 252 // even if all readouts lack the image pointer. 219 253 if (!image) { 220 254 return true; 221 } else if (numScans == 0) { 222 // Can only read the entire image once 255 } 256 257 // If we have already read an image, this result implies we are done (no more to read) 258 if (numScans == 0) { 223 259 return false; 224 260 } … … 235 271 } 236 272 237 int next; // Next position 238 int last; // Last position 239 if (!readoutScanProperties(&next, &last, readout, numScans, type, config)) { 273 bool haveData; 274 if (!readoutHaveMoreScans(&haveData, readout, numScans, type, config)) { 240 275 psError(PS_ERR_UNKNOWN, false, "Unable to determine readout properties."); 241 276 return false; 242 277 } 243 278 244 return (next < last);279 return haveData; 245 280 } 246 281 … … 423 458 } 424 459 425 int next; // Next position 426 int last; // Last position 427 if (!readoutScanProperties(&next, &last, readout, numScans, type, config)) { 460 bool haveData; 461 if (!readoutHaveMoreScans (&haveData, readout, type, numScans, config)) { 428 462 psError(PS_ERR_UNKNOWN, false, "Unable to determine readout properties."); 429 463 return false; 430 464 } 431 if ( next >= last) {465 if (!haveData) { 432 466 psError(PS_ERR_IO, true, "No more of the readout to read."); 433 467 return false; 434 468 } 469 435 470 436 471 pmHDU *hdu = pmHDUFromCell(cell); // The HDU … … 459 494 } 460 495 461 462 463 496 // Check the third dimension 464 497 int naxis = psMetadataLookupS32(&mdok, hdu->header, "NAXIS"); // The number of axes … … 478 511 } 479 512 480 // Update number of scansread481 int *scansTracker = readoutScansByType(readout, type); // Tracker for how many scans have been read482 *scansTracker = next;483 if ( next== 0) {513 // Determine the numbe of scans to read 514 int thisScan = readoutGetThisScan(readout, type); 515 int lastScan = readoutSetLastScan (readout, type, numScans); 516 if (thisScan == 0) { 484 517 overlap = 0; 485 518 } 486 next-= overlap;519 thisScan -= overlap; 487 520 488 521 // Calculate limits, adjust readout->row0,col0 … … 491 524 if (readdir == 1) { 492 525 // Reading rows 493 readout->row0 = next;526 readout->row0 = thisScan; 494 527 readout->col0 = trimsec->x0; 495 528 if (numScans == 0) { … … 498 531 } else { 499 532 // Reading cols 500 readout->col0 = next;533 readout->col0 = thisScan; 501 534 readout->row0 = trimsec->y0; 502 535 if (numScans == 0) { … … 504 537 } 505 538 } 506 int upper = next + numScans + overlap; // Upper limit to next section507 539 508 540 // Blow away existing data. … … 510 542 psFree(*image); 511 543 *image = NULL; 512 *image = readoutReadComponent(*image, fits, trimsec, readdir, next, upper, z, bad, pixelTypes[type]);544 *image = readoutReadComponent(*image, fits, trimsec, readdir, thisScan, lastScan, z, bad, pixelTypes[type]); 513 545 514 546 // Read overscans only for "image" type --- weights and masks shouldn't record overscans … … 528 560 psRegion *biassec = NULL; // Bias section from iteration 529 561 while ((biassec = psListGetAndIncrement(biassecsIter))) { 530 psImage *bias = readoutReadComponent(NULL, fits, biassec, readdir, next, upper, z, 531 bad, pixelTypes[type]); // The bias 562 psImage *bias = readoutReadComponent(NULL, fits, biassec, readdir, thisScan, lastScan, z, bad, pixelTypes[type]); // The bias 532 563 psListAdd(readout->bias, PS_LIST_TAIL, bias); 533 564 psFree(bias); // Drop reference -
trunk/psModules/src/camera/pmReadoutStack.c
r17228 r18830 8 8 9 9 #include "pmReadoutStack.h" 10 11 // generate the specified image 12 // XXX should it be an error for the image to exist? 13 psImage *pmReadoutSetAnalysisImage(pmReadout *readout, // Readout containing image 14 const char *name, // Name of image in analysis metadata 15 int numCols, int numRows, // Expected size of image 16 psElemType type, // Expected type of image 17 double init // Initial value 18 ) 19 { 20 PS_ASSERT_PTR_NON_NULL(readout, false); 21 PS_ASSERT_STRING_NON_EMPTY(name, false); 22 23 psImage *image = psImageAlloc(numCols, numRows, type); 24 25 if (!psMetadataAddImage(readout->analysis, PS_LIST_TAIL, name, 0, "Analysis image from " __FILE__, image)) { 26 psAbort ("analysis image already exists"); 27 } 28 psImageInit(image, init); 29 30 psFree (image); // we still have a view on readout->analysis 31 return image; 32 } 33 34 // retrieve the specified image 35 // XXX not sure why this should call psMemIncrRefCounter 36 psImage *pmReadoutGetAnalysisImage(pmReadout *readout, // Readout containing image 37 const char *name // Name of image in analysis metadata 38 ) 39 { 40 PS_ASSERT_PTR_NON_NULL(readout, false); 41 PS_ASSERT_STRING_NON_EMPTY(name, false); 42 43 bool mdok; // Status of MD lookup 44 psImage *image = psMetadataLookupPtr(&mdok, readout->analysis, name); 45 return image; 46 } 10 47 11 48 psImage *pmReadoutAnalysisImage(pmReadout *readout, // Readout containing image … … 40 77 } 41 78 42 bool pmReadoutUpdateSize(pmReadout *readout, int minCols, int minRows, 43 int numCols, int numRows, bool mask, bool weight, 44 psMaskType blank) 45 { 46 PS_ASSERT_PTR_NON_NULL(readout, false); 47 48 if (readout->image) { 49 readout->col0 = PS_MIN(minCols, readout->col0); 50 readout->row0 = PS_MIN(minRows, readout->row0); 51 } else { 52 readout->col0 = minCols; 53 readout->row0 = minRows; 54 } 55 56 // (reAllocate the images 57 if (!readout->image) { 58 readout->image = psImageAlloc(numCols, numRows, PS_TYPE_F32); 59 psImageInit(readout->image, NAN); 60 } 61 if (readout->image->numCols < numCols || readout->image->numRows < numRows) { 62 // Generate the new output image by extending the current one, or making a whole new one 63 psImage *newImage = psImageAlloc(numCols, numRows, PS_TYPE_F32); 64 psImageInit(newImage, NAN); 65 psImageOverlaySection(newImage, readout->image, readout->col0, readout->row0, "="); 66 psFree(readout->image); 67 readout->image = newImage; 68 } 79 // XXX for the moment, use col0, row0, numCols, numRows supplied from the outside 80 bool pmReadoutStackDefineOutput(pmReadout *readout, int col0, int row0, int numCols, int numRows, bool mask, bool weight, psMaskType blank) 81 { 82 PS_ASSERT_PTR_NON_NULL(readout, false); 83 84 // XXX is this an error? 85 if (readout->image) return false; 86 readout->col0 = col0; 87 readout->row0 = row0; 88 89 // allocate the images 90 readout->image = psImageAlloc(numCols, numRows, PS_TYPE_F32); 91 psImageInit(readout->image, NAN); 69 92 70 93 if (mask) { 71 if (!readout->mask) { 72 readout->mask = psImageAlloc(numCols, numRows, PS_TYPE_MASK); 73 psImageInit(readout->mask, blank); 74 } 75 if (readout->mask->numCols < numCols || readout->mask->numRows < numRows) { 76 psImage *newMask = psImageAlloc(numCols, numRows, PS_TYPE_MASK); 77 psImageInit(newMask, blank); 78 psImageOverlaySection(newMask, readout->mask, readout->col0, readout->row0, "="); 79 psFree(readout->mask); 80 readout->mask = newMask; 81 } 94 // XXX is this an error? 95 if (readout->mask) return false; 96 readout->mask = psImageAlloc(numCols, numRows, PS_TYPE_MASK); 97 psImageInit(readout->mask, blank); 82 98 } 83 99 84 100 if (weight) { 85 if (!readout->weight) { 86 readout->weight = psImageAlloc(numCols, numRows, PS_TYPE_F32); 87 psImageInit(readout->weight, NAN); 88 } 89 if (readout->weight->numCols < numCols || readout->weight->numRows < numRows) { 90 psImage *newWeight = psImageAlloc(numCols, numRows, PS_TYPE_F32); 91 psImageInit(newWeight, NAN); 92 psImageOverlaySection(newWeight, readout->weight, readout->col0, readout->row0, "="); 93 psFree(readout->weight); 94 readout->weight = newWeight; 95 } 101 // XXX is this an error? 102 if (readout->weight) return false; 103 readout->weight = psImageAlloc(numCols, numRows, PS_TYPE_F32); 104 psImageInit(readout->weight, NAN); 96 105 } 97 106 … … 99 108 } 100 109 101 bool pmReadoutStackValidate(int *minInputColsPtr, int *maxInputColsPtr, int *minInputRowsPtr, 102 int *maxInputRowsPtr, int *numColsPtr, int *numRowsPtr, 103 const psArray *inputs) 110 bool pmReadoutStackSetOutputSize(int *col0, int *row0, int *numCols, int *numRows, const psArray *inputs) 104 111 { 105 112 PS_ASSERT_ARRAY_NON_NULL(inputs, false); 106 PS_ASSERT_PTR_NON_NULL(minInputColsPtr, false); 107 PS_ASSERT_PTR_NON_NULL(maxInputColsPtr, false); 108 PS_ASSERT_PTR_NON_NULL(minInputRowsPtr, false); 109 PS_ASSERT_PTR_NON_NULL(maxInputRowsPtr, false); 110 PS_ASSERT_PTR_NON_NULL(numColsPtr, false); 111 PS_ASSERT_PTR_NON_NULL(numRowsPtr, false); 112 113 // Step through each readout in the input image list to determine how big of an output image is needed to 114 // combine these input images. 115 int maxInputCols = 0; // The largest input column value 116 int maxInputRows = 0; // The largest input row value 117 int minInputCols = INT_MAX; // The smallest input column value 118 int minInputRows = INT_MAX; // The smallest input row value 119 int xSize = 0, ySize = 0; // The size of the output image 113 PS_ASSERT_PTR_NON_NULL(col0, false); 114 PS_ASSERT_PTR_NON_NULL(row0, false); 115 PS_ASSERT_PTR_NON_NULL(numCols, false); 116 PS_ASSERT_PTR_NON_NULL(numRows, false); 117 118 // Step through each readout in the input image list to determine how big of an output 119 // image is needed to combine these input images. 120 120 121 121 int xMin = INT_MAX; … … 123 123 int xMax = 0; 124 124 int yMax = 0; 125 int xSize = 0; 126 int ySize = 0; // The size of the output image 125 127 126 128 bool valid = false; // Do we have a single valid input? … … 128 130 pmReadout *readout = inputs->data[i]; // Readout of interest 129 131 130 if (!readout) { 131 continue; 132 } 133 if (!readout->image) { 134 psError(PS_ERR_UNEXPECTED_NULL, true, "Input readout %ld has NULL image.\n", i); 135 return false; 136 } 132 if (!readout) continue; 137 133 138 134 // use the trimsec to define the max full range of the output pixels … … 150 146 yMax = PS_MAX(yMax, trimsec->y1); 151 147 } 148 valid = true; 149 psTrace("psModules.camera", 7, "Readout %ld: trimsec: %f,%f - %f,%f\n", i, trimsec->x0, trimsec->y0, trimsec->x1, trimsec->y1); 150 } 151 152 *col0 = xMin; 153 *row0 = yMin; 154 *numCols = xSize; 155 *numRows = ySize; 156 157 if (!valid) { 158 psError(PS_ERR_UNKNOWN, false, "No valid input readouts."); 159 } 160 return valid; 161 } 162 163 bool pmReadoutUpdateSize(pmReadout *readout, int minCols, int minRows, 164 int numCols, int numRows, bool mask, bool weight, 165 psMaskType blank) 166 { 167 PS_ASSERT_PTR_NON_NULL(readout, false); 168 169 if (readout->image) { 170 readout->col0 = PS_MIN(minCols, readout->col0); 171 readout->row0 = PS_MIN(minRows, readout->row0); 172 } else { 173 readout->col0 = minCols; 174 readout->row0 = minRows; 175 } 176 177 // (reAllocate the images 178 if (!readout->image) { 179 readout->image = psImageAlloc(numCols, numRows, PS_TYPE_F32); 180 psImageInit(readout->image, NAN); 181 } 182 if (readout->image->numCols < numCols || readout->image->numRows < numRows) { 183 // Generate the new output image by extending the current one, or making a whole new one 184 psImage *newImage = psImageAlloc(numCols, numRows, PS_TYPE_F32); 185 psImageInit(newImage, NAN); 186 psImageOverlaySection(newImage, readout->image, readout->col0, readout->row0, "="); 187 psFree(readout->image); 188 readout->image = newImage; 189 } 190 191 if (mask) { 192 if (!readout->mask) { 193 readout->mask = psImageAlloc(numCols, numRows, PS_TYPE_MASK); 194 psImageInit(readout->mask, blank); 195 } 196 if (readout->mask->numCols < numCols || readout->mask->numRows < numRows) { 197 psImage *newMask = psImageAlloc(numCols, numRows, PS_TYPE_MASK); 198 psImageInit(newMask, blank); 199 psImageOverlaySection(newMask, readout->mask, readout->col0, readout->row0, "="); 200 psFree(readout->mask); 201 readout->mask = newMask; 202 } 203 } 204 205 if (weight) { 206 if (!readout->weight) { 207 readout->weight = psImageAlloc(numCols, numRows, PS_TYPE_F32); 208 psImageInit(readout->weight, NAN); 209 } 210 if (readout->weight->numCols < numCols || readout->weight->numRows < numRows) { 211 psImage *newWeight = psImageAlloc(numCols, numRows, PS_TYPE_F32); 212 psImageInit(newWeight, NAN); 213 psImageOverlaySection(newWeight, readout->weight, readout->col0, readout->row0, "="); 214 psFree(readout->weight); 215 readout->weight = newWeight; 216 } 217 } 218 219 return true; 220 } 221 222 bool pmReadoutStackValidate(int *minInputColsPtr, int *maxInputColsPtr, int *minInputRowsPtr, 223 int *maxInputRowsPtr, int *numColsPtr, int *numRowsPtr, 224 const psArray *inputs) 225 { 226 PS_ASSERT_ARRAY_NON_NULL(inputs, false); 227 PS_ASSERT_PTR_NON_NULL(minInputColsPtr, false); 228 PS_ASSERT_PTR_NON_NULL(maxInputColsPtr, false); 229 PS_ASSERT_PTR_NON_NULL(minInputRowsPtr, false); 230 PS_ASSERT_PTR_NON_NULL(maxInputRowsPtr, false); 231 PS_ASSERT_PTR_NON_NULL(numColsPtr, false); 232 PS_ASSERT_PTR_NON_NULL(numRowsPtr, false); 233 234 // Step through each readout in the input image list to determine how big of an output image is needed to 235 // combine these input images. 236 int maxInputCols = 0; // The largest input column value 237 int maxInputRows = 0; // The largest input row value 238 int minInputCols = INT_MAX; // The smallest input column value 239 int minInputRows = INT_MAX; // The smallest input row value 240 int xSize = 0, ySize = 0; // The size of the output image 241 242 int xMin = INT_MAX; 243 int yMin = INT_MAX; 244 int xMax = 0; 245 int yMax = 0; 246 247 bool valid = false; // Do we have a single valid input? 248 for (long i = 0; i < inputs->n; i++) { 249 pmReadout *readout = inputs->data[i]; // Readout of interest 250 251 if (!readout) { 252 continue; 253 } 254 if (!readout->image) { 255 psError(PS_ERR_UNEXPECTED_NULL, true, "Input readout %ld has NULL image.\n", i); 256 return false; 257 } 258 259 // use the trimsec to define the max full range of the output pixels 260 pmCell *cell = readout->parent; // The parent cell 261 bool mdok = true; // Status of MD lookup 262 psRegion *trimsec = psMetadataLookupPtr(&mdok, cell->concepts, "CELL.TRIMSEC"); // Trim section 263 if (!mdok || !trimsec || psRegionIsNaN(*trimsec)) { 264 psWarning("CELL.TRIMSEC is not set for readout %ld --- ignored.\n", i); 265 } else { 266 xSize = PS_MAX(xSize, trimsec->x1 - trimsec->x0); 267 ySize = PS_MAX(ySize, trimsec->y1 - trimsec->y0); 268 xMin = PS_MIN(xMin, trimsec->x0); 269 xMax = PS_MAX(xMax, trimsec->x1); 270 yMin = PS_MIN(yMin, trimsec->y0); 271 yMax = PS_MAX(yMax, trimsec->y1); 272 } 152 273 153 274 valid = true; … … 158 279 minInputRows = PS_MAX(yMin, PS_MIN(minInputRows, readout->row0)); 159 280 maxInputRows = PS_MIN(yMax, PS_MAX(maxInputRows, readout->row0 + readout->image->numRows)); 160 psTrace("psModules.camera", 7, "Readout %ld: offset %d,%d; size %dx%d\n", i, 161 readout->col0, readout->row0, readout->image->numCols, readout->image->numRows);281 282 psTrace("psModules.camera", 7, "Readout %ld: offset %d,%d; size %dx%d\n", i, readout->col0, readout->row0, readout->image->numCols, readout->image->numRows); 162 283 } 163 284 -
trunk/psModules/src/camera/pmReadoutStack.h
r17228 r18830 24 24 ); 25 25 26 psImage *pmReadoutSetAnalysisImage(pmReadout *readout, // Readout containing image 27 const char *name, // Name of image in analysis metadata 28 int numCols, int numRows, // Expected size of image 29 psElemType type, // Expected type of image 30 double init // Initial value 31 ); 32 33 // retrieve the specified image 34 // XXX not sure why this should call psMemIncrRefCounter 35 psImage *pmReadoutGetAnalysisImage(pmReadout *readout, // Readout containing image 36 const char *name // Name of image in analysis metadata 37 ); 38 39 26 40 /// Return an image from analysis metadata, produced while stacking 27 41 psImage *pmReadoutAnalysisImage(pmReadout *readout, // Readout containing image … … 32 46 ); 33 47 48 // XXX for the moment, use col0, row0, numCols, numRows supplied from the outside 49 bool pmReadoutStackDefineOutput(pmReadout *readout, int col0, int row0, int numCols, int numRows, bool mask, bool weight, psMaskType blank); 50 51 bool pmReadoutStackSetOutputSize(int *col0, int *row0, int *numCols, int *numRows, const psArray *inputs); 52 34 53 #endif -
trunk/psModules/src/config/pmConfig.c
r18413 r18830 1627 1627 1628 1628 if (trunc) { 1629 if(truncate(filename, 0) != 0) { 1630 psError(PS_ERR_IO, true, "Failed to truncate file, %s\n", filename); 1631 nebServerFree(server); 1629 if(truncate(path, 0) != 0) { 1630 psError(PS_ERR_IO, true, "Failed to truncate Nebulous file %s (real name %s)\n", filename, path); 1632 1631 return NULL; 1633 1632 } -
trunk/psModules/src/imcombine/pmReadoutCombine.c
r17228 r18830 42 42 } 43 43 44 // check the input parameters and set up the output images 45 bool pmReadoutCombinePrepare(pmReadout *output, const psArray *inputs, const pmCombineParams *params) 46 { 47 // Check inputs 48 PS_ASSERT_PTR_NON_NULL(output, false); 49 PS_ASSERT_ARRAY_NON_NULL(inputs, false); 50 PS_ASSERT_PTR_NON_NULL(params, false); 51 PS_ASSERT_FLOAT_WITHIN_RANGE(params->fracLow, 0.0, 1.0, false); 52 PS_ASSERT_FLOAT_WITHIN_RANGE(params->fracHigh, 0.0, 1.0, false); 53 54 // valid combintion statistic? 55 bool valid = false; 56 valid |= (params->combine == PS_STAT_SAMPLE_MEAN); 57 valid |= (params->combine == PS_STAT_SAMPLE_MEDIAN); 58 valid |= (params->combine == PS_STAT_ROBUST_MEDIAN); 59 valid |= (params->combine == PS_STAT_FITTED_MEAN); 60 valid |= (params->combine == PS_STAT_CLIPPED_MEAN); 61 if (!valid) { 62 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Combination method is not SAMPLE_MEAN, SAMPLE_MEDIAN, " 63 "ROBUST_MEDIAN, FITTED_MEAN or CLIPPED_MEAN.\n"); 64 return false; 65 } 66 67 // weights exist if weights desired? 68 for (int i = 0; i < inputs->n; i++) { 69 pmReadout *readout = inputs->data[i]; // Readout of interest 70 if (params->weights && !readout->weight) { 71 psError(PS_ERR_UNEXPECTED_NULL, true, 72 "Rejection based on weights requested, but no weights supplied for image %d.\n", i); 73 return false; 74 } 75 } 76 77 pmHDU *hdu = pmHDUFromReadout(output); // Output HDU 78 if (!hdu) { 79 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find HDU for readout.\n"); 80 return false; 81 } 82 83 // set the output header metadata 84 psString comment = NULL; // Comment to add to header 85 psStringAppend(&comment, "Combining using statistic: %x", params->combine); 86 if (!hdu->header) { 87 hdu->header = psMetadataAlloc(); 88 } 89 psMetadataAddStr(hdu->header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK, comment, ""); 90 psFree(comment); 91 92 // note the clipping parameters, if used 93 if (params->combine == PS_STAT_CLIPPED_MEAN) { 94 psString comment = NULL; // Comment to add to header 95 psStringAppend(&comment, "Combination clipping: %d iterations, rejection at %f sigma", params->iter, params->rej); 96 psMetadataAddStr(hdu->header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK, comment, ""); 97 psFree(comment); 98 } 99 100 // note the use of weights 101 if (params->weights) { 102 psMetadataAddStr(hdu->header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK, 103 "Using input weights to combine images", ""); 104 } 105 106 // note the rejection fraction 107 float keepFrac = 1.0 - params->fracLow - params->fracHigh; // Fraction of pixels to keep 108 if (keepFrac != 1.0) { 109 psString comment = NULL; // Comment to add to header 110 psStringAppend(&comment, "Min/max rejection: %f high, %f low, keep %d", 111 params->fracHigh, params->fracLow, params->nKeep); 112 psMetadataAddStr(hdu->header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK, comment, ""); 113 psFree(comment); 114 } 115 116 // note the mask value actually used 117 psMaskType maskVal = params->maskVal; // The mask value 118 if (maskVal) { 119 psString comment = NULL; // Comment to add to header 120 psStringAppend(&comment, "Mask for combination: %x", maskVal); 121 psMetadataAddStr(hdu->header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK, comment, ""); 122 psFree(comment); 123 } 124 125 // determine the output image size based on the input images 126 int row0, col0, numCols, numRows; 127 if (!pmReadoutStackSetOutputSize(&col0, &row0, &numCols, &numRows, inputs)) { 128 psError(PS_ERR_UNKNOWN, false, "problem setting output readout size."); 129 return false; 130 } 131 132 // generate the required output images based on the specified sizes 133 pmReadoutStackDefineOutput(output, col0, row0, numCols, numRows, true, params->weights, params->blank); 134 psTrace("psModules.imcombine", 7, "Output minimum: %d,%d\n", output->col0, output->row0); 135 136 // these calls allocate and save the requested images on the output analysis metadata 137 psImage *counts = pmReadoutSetAnalysisImage(output, PM_READOUT_STACK_ANALYSIS_COUNT, numCols, numRows, PS_TYPE_U16, 0); 138 if (!counts) { 139 return false; 140 } 141 psImage *sigma = pmReadoutSetAnalysisImage(output, PM_READOUT_STACK_ANALYSIS_SIGMA, numCols, numRows, PS_TYPE_F32, NAN); 142 if (!sigma) { 143 return false; 144 } 145 146 // Update the "concepts" 147 psList *inputCells = psListAlloc(NULL); // List of cells 148 for (long i = 0; i < inputs->n; i++) { 149 pmReadout *readout = inputs->data[i]; // Readout of interest 150 psListAdd(inputCells, PS_LIST_TAIL, readout->parent); 151 } 152 bool success = pmConceptsAverageCells(output->parent, inputCells, NULL, NULL, true); 153 psFree(inputCells); 154 155 // set these even though the values are not yet set 156 output->data_exists = true; 157 output->parent->data_exists = true; 158 output->parent->parent->data_exists = true; 159 160 return success; 161 } 44 162 45 163 // XXX: Maybe add support for S16 and S32 types. Currently, only F32 supported. … … 61 179 PS_ASSERT_FLOAT_WITHIN_RANGE(params->fracLow, 0.0, 1.0, false); 62 180 PS_ASSERT_FLOAT_WITHIN_RANGE(params->fracHigh, 0.0, 1.0, false); 63 if (params->combine != PS_STAT_SAMPLE_MEAN && params->combine != PS_STAT_SAMPLE_MEDIAN &&64 params->combine != PS_STAT_ROBUST_MEDIAN && params->combine != PS_STAT_FITTED_MEAN &&65 params->combine != PS_STAT_CLIPPED_MEAN) {66 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Combination method is not SAMPLE_MEAN, SAMPLE_MEDIAN, "67 "ROBUST_MEDIAN, FITTED_MEAN or CLIPPED_MEAN.\n");68 return false;69 }70 for (int i = 0; i < inputs->n; i++) {71 pmReadout *readout = inputs->data[i]; // Readout of interest72 if (params->weights && !readout->weight) {73 psError(PS_ERR_UNEXPECTED_NULL, true,74 "Rejection based on weights requested, but no weights supplied for image %d.\n", i);75 return false;76 }77 }78 79 bool first = !output->image; // First pass through?80 181 81 182 pmHDU *hdu = pmHDUFromReadout(output); // Output HDU … … 85 186 } 86 187 87 if (first) { 88 psString comment = NULL; // Comment to add to header 89 psStringAppend(&comment, "Combining using statistic: %x", params->combine); 90 if (!hdu->header) { 91 hdu->header = psMetadataAlloc(); 92 } 93 psMetadataAddStr(hdu->header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK, comment, ""); 94 psFree(comment); 95 } 188 pthread_t id = pthread_self(); 189 char name[64]; 190 sprintf (name, "%x", (unsigned int) id); 191 psTimerStart (name); 96 192 97 193 psStatsOptions combineStdev = 0; // Statistics option for weights … … 118 214 stats->clipSigma = params->rej; 119 215 stats->clipIter = params->iter; 120 121 if (first) { 122 psString comment = NULL; // Comment to add to header 123 psStringAppend(&comment, "Combination clipping: %d iterations, rejection at %f sigma", 124 params->iter, params->rej); 125 psMetadataAddStr(hdu->header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK, comment, ""); 126 psFree(comment); 127 } 128 } 129 if (params->weights && first) { 130 psMetadataAddStr(hdu->header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK, 131 "Using input weights to combine images", ""); 132 } 216 } 217 218 psImage *counts = pmReadoutGetAnalysisImage(output, PM_READOUT_STACK_ANALYSIS_COUNT); 219 if (!counts) { 220 return false; 221 } 222 psImage *sigma = pmReadoutGetAnalysisImage(output, PM_READOUT_STACK_ANALYSIS_SIGMA); 223 if (!sigma) { 224 return false; 225 } 226 227 stats->options |= combineStdev; 133 228 134 229 int minInputCols, maxInputCols, minInputRows, maxInputRows; // Smallest and largest values to combine 135 230 int xSize, ySize; // Size of the output image 136 if (!pmReadoutStackValidate(&minInputCols, &maxInputCols, &minInputRows, &maxInputRows, &xSize, &ySize, 137 inputs)) { 231 if (!pmReadoutStackValidate(&minInputCols, &maxInputCols, &minInputRows, &maxInputRows, &xSize, &ySize, inputs)) { 138 232 psError(PS_ERR_UNKNOWN, false, "No valid input readouts."); 139 233 return false; 140 234 } 141 142 pmReadoutUpdateSize(output, minInputCols, minInputRows, xSize, ySize, true, params->weights,143 params->blank);144 psTrace("psModules.imcombine", 7, "Output minimum: %d,%d\n", output->col0, output->row0);145 146 psImage *counts = pmReadoutAnalysisImage(output, PM_READOUT_STACK_ANALYSIS_COUNT, xSize, ySize,147 PS_TYPE_U16, 0);148 if (!counts) {149 return false;150 }151 psImage *sigma = pmReadoutAnalysisImage(output, PM_READOUT_STACK_ANALYSIS_SIGMA, xSize, ySize,152 PS_TYPE_F32, NAN);153 if (!sigma) {154 psFree(counts);155 return false;156 }157 158 stats->options |= combineStdev;159 235 160 236 // We loop through each pixel in the output image. We loop through each input readout. We determine if … … 180 256 181 257 float keepFrac = 1.0 - params->fracLow - params->fracHigh; // Fraction of pixels to keep 182 if (keepFrac != 1.0 && first) {183 psString comment = NULL; // Comment to add to header184 psStringAppend(&comment, "Min/max rejection: %f high, %f low, keep %d",185 params->fracHigh, params->fracLow, params->nKeep);186 psMetadataAddStr(hdu->header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK, comment, "");187 psFree(comment);188 }189 190 258 psMaskType maskVal = params->maskVal; // The mask value 191 if (maskVal && first) {192 psString comment = NULL; // Comment to add to header193 psStringAppend(&comment, "Mask for combination: %x", maskVal);194 psMetadataAddStr(hdu->header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK, comment, "");195 psFree(comment);196 }197 259 198 260 #ifndef PS_NO_TRACE … … 226 288 int yOut = i - output->row0; // y position on output readout 227 289 #ifdef SHOW_BUSY 228 290 229 291 if (psTraceGetLevel("psModules.imcombine") > 9) { 230 292 printf("Processing row %d\r", i); … … 242 304 int xIn = j - readout->col0; // x position on input readout 243 305 psImage *image = readout->image; // The readout image 244 245 #if 0 // This should have been taken care of already:246 // Check bounds247 if (xIn < 0 || xIn >= image->numCols || yIn < 0 || yIn >= image->numRows) {248 continue;249 }250 #endif251 306 252 307 pixelsData[r] = image->data.F32[yIn][xIn]; … … 348 403 } 349 404 #endif 405 350 406 psFree(index); 351 407 psFree(pixels); … … 355 411 psFree(stats); 356 412 psFree(invScale); 357 psFree(counts); 358 psFree(sigma); 359 360 // Update the "concepts" 361 psList *inputCells = psListAlloc(NULL); // List of cells 362 for (long i = 0; i < inputs->n; i++) { 363 pmReadout *readout = inputs->data[i]; // Readout of interest 364 psListAdd(inputCells, PS_LIST_TAIL, readout->parent); 365 } 366 bool success = pmConceptsAverageCells(output->parent, inputCells, NULL, NULL, true); 367 psFree(inputCells); 368 369 output->data_exists = true; 370 output->parent->data_exists = true; 371 output->parent->parent->data_exists = true; 372 373 return success; 413 414 // fprintf (stderr, "done with combine %x : %f sec\n", (unsigned int) id, psTimerMark (name)); 415 return true; 374 416 } 375 417 -
trunk/psModules/src/imcombine/pmReadoutCombine.h
r17228 r18830 5 5 * @author Paul Price, IfA 6 6 * 7 * @version $Revision: 1.1 3$ $Name: not supported by cvs2svn $8 * @date $Date: 2008-0 3-29 03:10:17$7 * @version $Revision: 1.14 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2008-08-01 00:01:26 $ 9 9 * Copyright 2004-2006 Institute for Astronomy, University of Hawaii 10 10 */ … … 36 36 ); 37 37 38 // check the input parameters and set up the output images 39 bool pmReadoutCombinePrepare(pmReadout *output, const psArray *inputs, const pmCombineParams *params); 40 38 41 /// Combine multiple readouts, applying zero and scale, with optional minmax clipping 39 42 bool pmReadoutCombine(pmReadout *output,///< Output readout; altered and returned -
trunk/psModules/src/objects/Makefile.am
r15562 r18830 4 4 libpsmodulesobjects_la_LDFLAGS = -release $(PACKAGE_VERSION) 5 5 libpsmodulesobjects_la_SOURCES = \ 6 pmDetections.c \ 7 pmSpan.c \ 8 pmFootprint.c \ 9 pmFootprintArrayGrow.c \ 10 pmFootprintArraysMerge.c \ 11 pmFootprintAssignPeaks.c \ 12 pmFootprintFind.c \ 13 pmFootprintFindAtPoint.c \ 14 pmFootprintIDs.c \ 6 15 pmPeaks.c \ 7 16 pmMoments.c \ … … 45 54 46 55 pkginclude_HEADERS = \ 56 pmDetections.h \ 57 pmSpan.h \ 58 pmFootprint.h \ 47 59 pmPeaks.h \ 48 60 pmMoments.h \
Note:
See TracChangeset
for help on using the changeset viewer.
