Changeset 13970 for trunk/ppImage/src/ppImageLoop.c
- Timestamp:
- Jun 25, 2007, 2:27:15 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/ppImage/src/ppImageLoop.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppImage/src/ppImageLoop.c
r13924 r13970 3 3 #endif 4 4 5 #include <ppStats.h>6 5 #include "ppImage.h" 7 6 #include "ppImageDetrendFringe.h" … … 10 9 bool ppImageLoop (pmConfig *config, ppImageOptions *options) { 11 10 12 bool mdok; // Status of MD lookup13 11 bool status; 14 12 pmChip *chip; 15 13 pmCell *cell; 16 14 pmReadout *readout; 17 psMetadata *stats = NULL;18 19 const char *statsName = psMetadataLookupStr(&mdok, config->arguments, "STATS"); // Filename for statistics20 FILE *statsFile = NULL; // File stream for statistics21 if (mdok && statsName && strlen(statsName) > 0) {22 psString resolved = pmConfigConvertFilename(statsName, config, true); // Resolved filename23 statsFile = fopen(resolved, "w");24 if (!statsFile) {25 psError(PS_ERR_IO, true, "Unable to open statistics file %s for writing.\n", resolved);26 psFree(resolved);27 return false;28 }29 stats = psMetadataAlloc();30 psFree(resolved);31 }32 15 33 16 pmFPAfile *input = psMetadataLookupPtr(&status, config->files, "PPIMAGE.INPUT"); … … 96 79 } 97 80 98 // Solve the fringe system81 // Apply the fringe correction 99 82 if (options->doFringe) { 100 pmChip *fringe = pmFPAfileThisChip(config->files, view, "PPIMAGE.FRINGE"); 101 if (!ppImageDetrendFringeSolve(chip, fringe, options)) { 83 if (!ppImageDetrendFringeApply (config, chip, view, options)) { 102 84 psFree (view); 103 85 return false; 104 86 } 105 } 106 107 // Go back over the cells to apply the fringe and do statistics 108 view->cell = view->readout = -1; 109 while ((cell = pmFPAviewNextCell(view, input->fpa, 1)) != NULL) { 110 if (!cell->process || !cell->file_exists) { 111 continue; 112 } 113 114 // Apply the fringe correction 115 if (options->doFringe) { 116 psTrace("ppImage", 3, "Applying fringe correction...\n"); 117 pmCell *fringeCell = pmFPAfileThisCell(config->files, view, "PPIMAGE.FRINGE"); 118 if (!ppImageDetrendFringeGenerate(cell, fringeCell)) { 119 psFree (view); 120 return false; 121 } 122 } 123 124 // Perform statistics on the detrended cell 125 if (stats) { 126 bool mdok; // Status of MD lookup 127 pmFPAfile *output = psMetadataLookupPtr(&mdok, config->files, "PPIMAGE.OUTPUT"); 128 if (!mdok || !output) { 129 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find file PPIMAGE.OUTPUT."); 130 psFree (view); 131 return false; 132 } 133 134 if (!ppStats(stats, output->fpa, view, 135 options->satMask | options->badMask | options->maskValue, 136 config)) { 137 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to generate stats for image."); 138 psFree(stats); 139 psFree(view); 140 return false; 141 } 142 143 if (options->doFringe && !ppStatsFringe(stats, chip, "FRINGE.SOLUTION")) { 144 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to extract fringe solution for image."); 145 psFree(stats); 146 psFree(view); 147 return false; 148 } 149 } 150 151 // Add MD5 information for cell 152 pmHDU *hdu = pmHDUFromCell(cell); // HDU that owns the cell 153 while ((readout = pmFPAviewNextReadout(view, input->fpa, 1)) != NULL) { 154 const char *chipName = psMetadataLookupStr(NULL, chip->concepts, "CHIP.NAME"); 155 const char *cellName = psMetadataLookupStr(NULL, cell->concepts, "CELL.NAME"); 156 157 psString headerName = NULL; // Header name for MD5 158 psStringAppend(&headerName, "MD5_%s_%s_%d", chipName, cellName, view->readout); 159 160 psVector *md5 = psImageMD5(readout->image); // md5 hash 161 psString md5string = psMD5toString(md5); // String 162 psFree(md5); 163 psMetadataAddStr(hdu->header, PS_LIST_TAIL, headerName, PS_META_REPLACE, 164 "Image MD5", md5string); 165 psFree(md5string); 166 psFree(headerName); 167 } 168 } 87 } 88 89 // measure various statistics for this image 90 if (!ppImageStats (config, chip, view, options)) { 91 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to measures stats for image"); 92 psFree (view); 93 return false; 94 } 169 95 170 96 if (!ppImageMosaicChip(config, options, view, "PPIMAGE.CHIP", "PPIMAGE.OUTPUT")) { … … 214 140 215 141 // Write out summary statistics 216 if (stats) { 217 char *statsMDC = psMetadataConfigFormat(stats); 218 if (!statsMDC || strlen(statsMDC) == 0) { 219 psError(PS_ERR_IO, false, "Unable to get statistics MDC file.\n"); 220 } else { 221 fprintf(statsFile, "%s", statsMDC); 222 } 223 psFree(statsMDC); 224 fclose(statsFile); 225 psFree(stats); 142 if (!ppImageStatsOutput (config, input->fpa, options)) { 143 psError(PS_ERR_UNKNOWN, false, "Unable to write statistics file.\n"); 144 psFree (view); 145 return false; 226 146 } 227 147
Note:
See TracChangeset
for help on using the changeset viewer.
