Changeset 13657 for trunk/ppStats/src/ppStatsLoop.c
- Timestamp:
- Jun 5, 2007, 3:06:50 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/ppStats/src/ppStatsLoop.c (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppStats/src/ppStatsLoop.c
r13640 r13657 69 69 70 70 static psExit cellStats(psMetadata *chipResults, // Metadata holding the chip results 71 pmCell *cell, // Cell for which to get statistics72 psFits *fits, // FITS file handle73 ppStatsData *data,// The data74 const pmConfig *config // Configuration71 pmCell *cell, // Cell for which to get statistics 72 psFits *fits, // FITS file handle 73 ppStatsData *data,// The data 74 const pmConfig *config // Configuration 75 75 ) 76 76 { 77 77 assert(chipResults); 78 78 assert(cell); 79 assert(fits);80 79 assert(data); 81 80 assert(config); … … 96 95 97 96 if (psListLength(data->headers) > 0 && cell->hdu) { 98 if ( !pmCellReadHeader(cell, fits)) {97 if (fits && !pmCellReadHeader(cell, fits)) { 99 98 psError (PS_ERR_IO, false, "trouble reading cell header\n"); 100 return PS_EXIT_DATA_ERROR; 99 psFree(cellResults); 100 return PS_EXIT_DATA_ERROR; 101 101 } 102 102 pmHDU *hdu = cell->hdu; // HDU for headers … … 104 104 } 105 105 if (psListLength(data->concepts) > 0) { 106 if ( !pmCellReadHeader(cell, fits)) {106 if (fits && !pmCellReadHeader(cell, fits)) { 107 107 psError (PS_ERR_IO, false, "trouble reading cell header\n"); 108 return PS_EXIT_DATA_ERROR; 108 psFree(cellResults); 109 return PS_EXIT_DATA_ERROR; 109 110 } 110 111 pmConceptsReadCell(cell, PM_CONCEPT_SOURCE_ALL, false, config->database); … … 123 124 pmHDU *hdu = pmHDUFromCell(cell); // HDU for cell 124 125 if (!hdu || hdu->blankPHU) { 125 psError (PS_ERR_UNKNOWN, false, "trouble finding HDU for cell\n"); 126 return PS_EXIT_CONFIG_ERROR; 127 } 128 129 if (!pmCellRead(cell, fits, config->database)) { 130 psError (PS_ERR_IO, false, "trouble reading cell data\n"); 131 return PS_EXIT_DATA_ERROR; 126 psError (PS_ERR_UNKNOWN, false, "trouble finding HDU for cell\n"); 127 psFree(cellResults); 128 return PS_EXIT_CONFIG_ERROR; 129 } 130 131 if (fits && !pmCellRead(cell, fits, config->database)) { 132 psError (PS_ERR_IO, false, "trouble reading cell data\n"); 133 psFree(cellResults); 134 return PS_EXIT_DATA_ERROR; 132 135 } 133 136 … … 147 150 } 148 151 149 // Measure basic image statistics (means, stdevs, etc). 152 // Measure basic image statistics (means, stdevs, etc). 150 153 if (data->sample <= 0.0) { 151 154 if (!psImageStats(data->stats, readout->image, readout->mask, data->maskVal)) { … … 205 208 206 209 // measure other types of statistics tests 207 210 208 211 statsDone: 209 212 // count saturated pixels 210 if (psListLength(data->summary) > 0) { 211 bool get_nSatPixels = false;212 bool get_fSatPixels = false;213 if (psListLength(data->summary) > 0) { 214 bool get_nSatPixels = false; 215 bool get_fSatPixels = false; 213 216 214 217 psListIterator *iterator = psListIteratorAlloc(data->summary, PS_LIST_HEAD, false); 215 psString choice; 218 psString choice; 216 219 while ((choice = psListGetAndIncrement(iterator))) { 217 if (!strcasecmp (choice, "SAT_PIXEL_NUM")) get_nSatPixels = true;218 if (!strcasecmp (choice, "SAT_PIXEL_FRAC")) get_fSatPixels = true;219 } 220 221 if (!get_nSatPixels && !get_fSatPixels) {222 goto cellDone;223 }224 225 // Get the "concepts" of interest226 float saturation = psMetadataLookupF32(&mdok, cell->concepts, "CELL.SATURATION"); // Saturation level227 if (!mdok || isnan(saturation)) {228 psLogMsg(__func__, PS_LOG_WARN, "CELL.SATURATION is not set --- unable to measure N_SAT_PIXELS.\n");229 if (get_nSatPixels) psMetadataAddS32(cellResults, PS_LIST_TAIL, "SAT_PIXEL_NUM", 0, NULL, 0);230 if (get_fSatPixels) psMetadataAddF32(cellResults, PS_LIST_TAIL, "SAT_PIXEL_FRAC", 0, NULL, NAN);231 goto cellDone;232 }233 234 int nSatPixels = 0;235 for (int j = 0; j < readout->image->numRows; j++) {236 for (int i = 0; i < readout->image->numCols; i++) {237 if (readout->image->data.F32[j][i] >= saturation) {238 nSatPixels ++;239 }240 }241 }242 if (get_nSatPixels) psMetadataAddS32(cellResults, PS_LIST_TAIL, "SAT_PIXEL_NUM", 0, NULL, nSatPixels);243 if (get_fSatPixels) psMetadataAddF32(cellResults, PS_LIST_TAIL, "SAT_PIXEL_FRAC", 0, NULL, nSatPixels / (double)(readout->image->numRows * readout->image->numCols));220 if (!strcasecmp (choice, "SAT_PIXEL_NUM")) get_nSatPixels = true; 221 if (!strcasecmp (choice, "SAT_PIXEL_FRAC")) get_fSatPixels = true; 222 } 223 224 if (!get_nSatPixels && !get_fSatPixels) { 225 goto cellDone; 226 } 227 228 // Get the "concepts" of interest 229 float saturation = psMetadataLookupF32(&mdok, cell->concepts, "CELL.SATURATION"); // Saturation level 230 if (!mdok || isnan(saturation)) { 231 psLogMsg(__func__, PS_LOG_WARN, "CELL.SATURATION is not set --- unable to measure N_SAT_PIXELS.\n"); 232 if (get_nSatPixels) psMetadataAddS32(cellResults, PS_LIST_TAIL, "SAT_PIXEL_NUM", 0, NULL, 0); 233 if (get_fSatPixels) psMetadataAddF32(cellResults, PS_LIST_TAIL, "SAT_PIXEL_FRAC", 0, NULL, NAN); 234 goto cellDone; 235 } 236 237 int nSatPixels = 0; 238 for (int j = 0; j < readout->image->numRows; j++) { 239 for (int i = 0; i < readout->image->numCols; i++) { 240 if (readout->image->data.F32[j][i] >= saturation) { 241 nSatPixels ++; 242 } 243 } 244 } 245 if (get_nSatPixels) psMetadataAddS32(cellResults, PS_LIST_TAIL, "SAT_PIXEL_NUM", 0, NULL, nSatPixels); 246 if (get_fSatPixels) psMetadataAddF32(cellResults, PS_LIST_TAIL, "SAT_PIXEL_FRAC", 0, NULL, nSatPixels / (double)(readout->image->numRows * readout->image->numCols)); 244 247 } 245 248 … … 247 250 // Add the cell results to the chip 248 251 addToHierarchy(cellResults, chipResults, cellName, "Results for cell"); 249 pmCellFreeData(cell); 252 if (fits) { 253 pmCellFreeData(cell); 254 } 250 255 return PS_EXIT_SUCCESS; 251 256 } 252 257 253 258 static psExit chipStats(psMetadata *fpaResults, // Metadata holding the fpa results 254 pmChip *chip, // Chip for which to get statistics255 psFits *fits, // FITS file handle256 pmFPAview *view, // View for analysis257 ppStatsData *data,// The data258 const pmConfig *config // Configuration259 pmChip *chip, // Chip for which to get statistics 260 psFits *fits, // FITS file handle 261 pmFPAview *view, // View for analysis 262 ppStatsData *data,// The data 263 const pmConfig *config // Configuration 259 264 ) 260 265 { 261 266 assert(fpaResults); 262 267 assert(chip); 263 assert(fits);264 268 assert(view); 265 269 assert(data); … … 279 283 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Desired cell view (%d) doesn't match " 280 284 "number of cells (%ld)\n", view->cell, cells->n); 281 return PS_EXIT_CONFIG_ERROR;285 return PS_EXIT_CONFIG_ERROR; 282 286 } 283 287 … … 290 294 291 295 if (psListLength(data->headers) > 0 && chip->hdu) { 292 if ( !pmChipReadHeader(chip, fits)) {296 if (fits && !pmChipReadHeader(chip, fits)) { 293 297 psError (PS_ERR_IO, false, "trouble reading chip header\n"); 294 return PS_EXIT_DATA_ERROR; 298 psFree(chipResults); 299 return PS_EXIT_DATA_ERROR; 295 300 } 296 301 pmHDU *hdu = chip->hdu; // HDU for headers … … 298 303 } 299 304 if (psListLength(data->concepts) > 0) { 300 if ( !pmChipReadHeader(chip, fits)) {305 if (fits && !pmChipReadHeader(chip, fits)) { 301 306 psError (PS_ERR_IO, false, "trouble reading chip header\n"); 302 return PS_EXIT_DATA_ERROR; 307 psFree(chipResults); 308 return PS_EXIT_DATA_ERROR; 303 309 } 304 310 pmConceptsReadChip(chip, PM_CONCEPT_SOURCE_ALL, false, false, config->database); … … 309 315 pmCell *cell = cells->data[view->cell]; // Cell of interest 310 316 result = cellStats(chipResults, cell, fits, data, config); 311 if (result != PS_EXIT_SUCCESS) { 312 psError (PS_ERR_IO, false, "trouble with cell stats for %d\n", view->cell); 313 pmChipFreeData(chip); 314 return result; 315 } 316 addToHierarchy(chipResults, fpaResults, chipName, "Results for chip"); 317 pmChipFreeData(chip); 318 return PS_EXIT_SUCCESS; 317 if (result != PS_EXIT_SUCCESS) { 318 psError (PS_ERR_IO, false, "trouble with cell stats for %d\n", view->cell); 319 if (fits) { 320 pmChipFreeData(chip); 321 } 322 psFree(chipResults); 323 return result; 324 } 325 addToHierarchy(chipResults, fpaResults, chipName, "Results for chip"); 326 if (fits) { 327 pmChipFreeData(chip); 328 } 329 psFree(chipResults); 330 return PS_EXIT_SUCCESS; 319 331 } 320 332 … … 323 335 pmCell *cell = cells->data[i]; // Cell of interest 324 336 result = cellStats(chipResults, cell, fits, data, config); 325 if (result != PS_EXIT_SUCCESS) { 326 psError (PS_ERR_IO, false, "trouble with cell stats for %d\n", i); 327 pmChipFreeData(chip); 328 return result; 329 } 337 if (result != PS_EXIT_SUCCESS) { 338 psError (PS_ERR_IO, false, "trouble with cell stats for %d\n", i); 339 if (fits) { 340 pmChipFreeData(chip); 341 } 342 psFree(chipResults); 343 return result; 344 } 330 345 } 331 346 332 347 addToHierarchy(chipResults, fpaResults, chipName, "Results for chip"); 333 pmChipFreeData(chip); 348 if (fits) { 349 pmChipFreeData(chip); 350 } 334 351 return PS_EXIT_SUCCESS; 335 352 } 336 353 337 354 psMetadata *ppStatsLoop(psExit *result, 338 psMetadata *fpaResults, // Metadata to hold the FPA results355 psMetadata *fpaResults, // Metadata to hold the FPA results 339 356 ppStatsData *data, // The data 340 357 const pmConfig *config // Configuration … … 345 362 psFits *fits = data->fits; // FITS file handle 346 363 PS_ASSERT_PTR_NON_NULL(fpa, NULL); 347 PS_ASSERT_PTR_NON_NULL(fits, NULL);348 364 349 365 *result = PS_EXIT_SUCCESS; … … 353 369 354 370 // allocate a new one if needed 355 psMetadata *newResults = psMemIncrRefCounter(fpaResults);371 psMetadata *newResults = fpaResults; 356 372 if (!newResults) { 357 newResults = psMetadataAlloc();373 newResults = psMetadataAlloc(); 358 374 } 359 375 360 376 // Iterate through the FPA 361 377 if (psListLength(data->headers) > 0 && fpa->hdu) { 362 pmFPAReadHeader(fpa, fits); 378 if (fits && !pmFPAReadHeader(fpa, fits)) { 379 psError(PS_ERR_IO, false, "Unable to read header for FPA."); 380 psFree(view); 381 psFree(newResults); 382 return NULL; 383 } 363 384 pmHDU *hdu = fpa->hdu; // HDU for headers 364 385 getMetadata(newResults, hdu->header, data->headers); 365 386 } 366 387 if (psListLength(data->concepts) > 0) { 367 pmFPAReadHeader(fpa, fits); 388 if (fits && !pmFPAReadHeader(fpa, fits)) { 389 psError(PS_ERR_IO, false, "Unable to read header for FPA."); 390 psFree(view); 391 psFree(newResults); 392 return NULL; 393 } 368 394 pmConceptsReadFPA(fpa, PM_CONCEPT_SOURCE_ALL, false, config->database); 369 395 getMetadata(newResults, fpa->concepts, data->concepts); … … 373 399 if (view->chip >= 0) { 374 400 pmChip *chip = chips->data[view->chip]; // Chip of interest 375 *result = chipStats(newResults, chip, fits, view, data, config);401 *result = chipStats(newResults, chip, fits, view, data, config); 376 402 if (*result != PS_EXIT_SUCCESS) { 377 psError(PS_ERR_UNKNOWN, false, "trouble with stats for cell %d\n", view->cell); 378 psFree (view); 379 psFree (newResults); 380 return NULL; 381 } 382 pmFPAFreeData(fpa); 383 psFree(view); 384 return newResults; 403 psError(PS_ERR_UNKNOWN, false, "trouble with stats for cell %d\n", view->cell); 404 psFree (view); 405 psFree (newResults); 406 return NULL; 407 } 408 if (fits) { 409 pmFPAFreeData(fpa); 410 } 411 psFree(view); 412 return newResults; 385 413 } 386 414 … … 389 417 pmChip *chip = chips->data[i]; // Chip of interest 390 418 *result = chipStats(newResults, chip, fits, view, data, config); 391 if (*result != PS_EXIT_SUCCESS) { 392 psError(PS_ERR_UNKNOWN, false, "trouble with stats for chip %d\n", i); 393 psFree (view); 394 psFree (newResults); 395 return NULL; 396 } 397 } 398 399 pmFPAFreeData(fpa); 419 if (*result != PS_EXIT_SUCCESS) { 420 psError(PS_ERR_UNKNOWN, false, "trouble with stats for chip %d\n", i); 421 psFree (view); 422 psFree (newResults); 423 return NULL; 424 } 425 } 426 427 if (fits) { 428 pmFPAFreeData(fpa); 429 } 400 430 psFree(view); 431 401 432 return newResults; 402 433 }
Note:
See TracChangeset
for help on using the changeset viewer.
