Changeset 13970
- Timestamp:
- Jun 25, 2007, 2:27:15 PM (19 years ago)
- Location:
- trunk/ppImage/src
- Files:
-
- 1 added
- 8 edited
-
Makefile.am (modified) (2 diffs)
-
ppImage.h (modified) (1 diff)
-
ppImageDetrendFringe.c (modified) (13 diffs)
-
ppImageDetrendFringe.h (modified) (3 diffs)
-
ppImageDetrendReadout.c (modified) (1 diff)
-
ppImageLoop.c (modified) (4 diffs)
-
ppImageOptions.c (modified) (2 diffs)
-
ppImageOptions.h (modified) (1 diff)
-
ppImageStats.c (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppImage/src/Makefile.am
r13528 r13970 26 26 ppImageAstrom.c \ 27 27 ppImageAddstar.c \ 28 ppImageStats.c \ 28 29 ppImageDefineFile.c \ 29 30 ppImageVersion.c … … 48 49 ppImageAstrom.c \ 49 50 ppImageAddstar.c \ 51 ppImageStats.c \ 50 52 ppImageDefineFile.c \ 51 53 ppImageVersion.c -
trunk/ppImage/src/ppImage.h
r13901 r13970 65 65 bool ppImageDefineFile (pmConfig *config, pmFPA *input, char *filerule, char *argname, pmFPAfileType fileType, pmDetrendType detrendType); 66 66 67 // calculate stats, including MD5 68 bool ppImageStats (pmConfig *config, pmChip *chip, const pmFPAview *inputView, const ppImageOptions *options); 69 70 // write stats to output file 71 bool ppImageStatsOutput (pmConfig *config, pmFPA *fpa, const ppImageOptions *options); 72 67 73 #endif -
trunk/ppImage/src/ppImageDetrendFringe.c
r13779 r13970 10 10 #include "ppImageDetrendFringe.h" 11 11 12 bool ppImageDetrendFringeMeasure(pmReadout *readout, pmCell *fringe, const ppImageOptions *options)12 bool ppImageDetrendFringeMeasure(pmReadout *readout, pmCell *fringe, const bool isResidual, const ppImageOptions *options) 13 13 { 14 14 PS_ASSERT_PTR_NON_NULL(readout, false); … … 49 49 psBinaryOp(measurements->df, measurements->df, "*", psScalarAlloc(expTime, PS_TYPE_F32)); 50 50 51 char *scienceFringes = NULL; 52 if (isResidual) { 53 scienceFringes = psStringCopy ("FRINGE.RESIDUALS"); 54 } else { 55 scienceFringes = psStringCopy ("FRINGE.MEASUREMENTS"); 56 } 57 51 58 // Science fringe measurements 52 pmFringeStats *previous = psMetadataLookupPtr(NULL, readout->parent->analysis, "FRINGE.MEASUREMENTS");59 pmFringeStats *previous = psMetadataLookupPtr(NULL, readout->parent->analysis, scienceFringes); 53 60 if (previous) { 54 61 // Multiple readouts: concatenate … … 73 80 } 74 81 75 psMetadataAdd(readout->parent->analysis, PS_LIST_TAIL, "FRINGE.MEASUREMENTS",82 psMetadataAdd(readout->parent->analysis, PS_LIST_TAIL, scienceFringes, 76 83 PS_DATA_UNKNOWN | PS_META_REPLACE, "Fringe measurements", measurements); 77 84 psFree(measurements); 78 85 psFree(scienceFringes); 79 86 psFree(references); 80 87 … … 84 91 85 92 // Pull the fringes out of the cell analysis FRINGE.MEASUREMENTS for a chip 86 static psArray *getFringes(const pmChip *chip // Chip of interest 87 )93 // XXX need some error checks 94 static psArray *getFringes(const pmChip *chip, const char *source) 88 95 { 89 96 psArray *cells = chip->cells; // Component cells … … 91 98 for (int i = 0; i < cells->n; i++) { 92 99 pmCell *cell = cells->data[i]; // Cell of interest 93 fringes->data[i] = psMemIncrRefCounter(psMetadataLookupPtr(NULL, cell->analysis, 94 "FRINGE.MEASUREMENTS")); 100 fringes->data[i] = psMemIncrRefCounter(psMetadataLookupPtr(NULL, cell->analysis, source)); 95 101 } 96 102 … … 101 107 // Solve the fringe system: we have science fringe measurements for each cell, and an array of reference 102 108 // fringe measurements for each cell. Need to concatenate these together first, and then solve. 103 bool ppImageDetrendFringeSolve(pmChip *scienceChip, const pmChip *refChip, const ppImageOptions *options)109 bool ppImageDetrendFringeSolve(pmChip *scienceChip, const pmChip *refChip, const bool isResidual, const ppImageOptions *options) 104 110 { 105 111 PS_ASSERT_PTR_NON_NULL(scienceChip, NULL); … … 107 113 PS_ASSERT_PTR_NON_NULL(options, NULL); 108 114 109 psArray *science = getFringes(scienceChip); // Fringe measurements on science chip 115 psArray *science = NULL; 116 if (isResidual) { 117 science = getFringes(scienceChip, "FRINGE.RESIDUALS"); // Fringe residuals on science chip 118 } else { 119 science = getFringes(scienceChip, "FRINGE.MEASUREMENTS"); // Fringe measurements on science chip 120 } 121 110 122 pmFringeStats *scienceCat = pmFringeStatsConcatenate(science, NULL, NULL); // Science fringes 111 123 psFree(science); … … 113 125 // Need to transform the array of cells each with an array of fringes --> array of fringes for the chip as 114 126 // a whole 115 psArray *references = getFringes(refChip ); // Fringe measurements on reference chip127 psArray *references = getFringes(refChip, "FRINGE.MEASUREMENTS"); // Fringe measurements on reference chip 116 128 int numRefs = ((psArray*)references->data[0])->n; // Number of reference fringes 117 129 psArray *referencesCat = psArrayAlloc(numRefs); // Reference fringes … … 132 144 options->fringeIter, options->fringeKeep); 133 145 134 psMetadataAdd(scienceChip->analysis, PS_LIST_TAIL, "FRINGE.SOLUTION", PS_DATA_UNKNOWN, 135 "Fringe solution", solution); 146 if (isResidual) { 147 psMetadataAdd(scienceChip->analysis, PS_LIST_TAIL, "FRINGE.RESIDUAL.SOLUTION", PS_DATA_UNKNOWN, "Fringe solution", solution); 148 } else { 149 psMetadataAdd(scienceChip->analysis, PS_LIST_TAIL, "FRINGE.SOLUTION", PS_DATA_UNKNOWN, "Fringe solution", solution); 150 } 151 152 # if (0) 153 // write the fringe amplitude or residual amplitude to the header 154 // XXX this is measured per cell, but we only have headers per chip 155 pmHDU *hdu = pmHDUFromCell(science);// HDU of interest 156 for (int i = 0; i < solution->nFringeFrames; i++) { 157 // write metadata header value 158 psString keyword = NULL; 159 if (isResidual) { 160 psStringAppend (&keyword, "FRES_%02dV", i); 161 } else { 162 psStringAppend (&keyword, "FRNG_%02dV", i); 163 } 164 psMetadataAddF32(hdu->header, PS_LIST_TAIL, keyword, PS_META_REPLACE, "Fringe Amplitude", solution->coeff->data.F32[i + 1]); 165 psFree (keyword); 166 167 keyword = NULL; 168 if (isResidual) { 169 psStringAppend (&keyword, "FRES_%02dE", i); 170 } else { 171 psStringAppend (&keyword, "FRNG_%02dE", i); 172 } 173 psMetadataAddF32(hdu->header, PS_LIST_TAIL, keyword, PS_META_REPLACE, "Fringe Amplitude error", solution->coeffErr->data.F32[i + 1]); 174 psFree (keyword); 175 } 176 # endif 177 136 178 psFree(solution); 137 179 psFree(scienceCat); … … 142 184 143 185 144 bool ppImageDetrendFringeGenerate(pmCell *science, pmCell *fringes )186 bool ppImageDetrendFringeGenerate(pmCell *science, pmCell *fringes, const ppImageOptions *options) 145 187 { 146 188 PS_ASSERT_PTR_NON_NULL(science, false); … … 191 233 psFree(md5string); 192 234 235 # if (0) 193 236 // write metadata header value 237 // XXX this is measured per cell, but we only have headers per chip 194 238 psString keyword = NULL; 195 psStringAppend (&keyword, "FRNG_%02d ", i);239 psStringAppend (&keyword, "FRNG_%02dV", i); 196 240 psMetadataAddF32(hdu->header, PS_LIST_TAIL, keyword, PS_META_REPLACE, "Fringe Amplitude", solution->coeff->data.F32[i + 1]); 197 241 psFree (keyword); 198 242 199 243 keyword = NULL; 200 psStringAppend (&keyword, "FRNG_%02d D", i);244 psStringAppend (&keyword, "FRNG_%02dE", i); 201 245 psMetadataAddF32(hdu->header, PS_LIST_TAIL, keyword, PS_META_REPLACE, "Fringe Amplitude error", solution->coeffErr->data.F32[i + 1]); 202 246 psFree (keyword); 247 # endif 248 203 249 } 204 250 if (expTime != 1.0) { … … 219 265 return false; 220 266 } 267 268 // measure residual fringe amplitude. results go to FRINGE.RESIDUALS 269 ppImageDetrendFringeMeasure (readout, fringes, true, options); 221 270 } 222 271 psFree(sumFringe); … … 233 282 } 234 283 284 bool ppImageDetrendFringeApply (pmConfig *config, pmChip *chip, const pmFPAview *inputView, const ppImageOptions *options) { 285 286 pmCell *cell = NULL; 287 288 assert (options->doFringe); // do not call if not needed 289 assert (inputView->chip != -1); 290 assert (inputView->cell == -1); 291 assert (inputView->readout == -1); 292 293 pmFPAview *view = pmFPAviewAlloc(0); // View for local processing 294 *view = *inputView; 295 296 // select the reference chip 297 pmChip *fringe = pmFPAfileThisChip(config->files, view, "PPIMAGE.FRINGE"); 298 if (!fringe) { 299 psError(PS_ERR_UNKNOWN, false, "missing fringe reference data.\n"); 300 psFree (view); 301 return false; 302 } 303 304 // Solve the fringe system 305 if (!ppImageDetrendFringeSolve(chip, fringe, false, options)) { 306 psError(PS_ERR_UNKNOWN, false, "failed to solve the fringe system.\n"); 307 psFree (view); 308 return false; 309 } 310 311 // Go back over the cells to apply the fringe correction 312 view->cell = view->readout = -1; 313 while ((cell = pmFPAviewNextCell(view, chip->parent, 1)) != NULL) { 314 if (!cell->process || !cell->file_exists) { 315 continue; 316 } 317 318 // Apply the fringe correction 319 psTrace("ppImage", 3, "Applying fringe correction...\n"); 320 pmCell *fringeCell = pmFPAfileThisCell(config->files, view, "PPIMAGE.FRINGE"); 321 if (!fringeCell) { 322 psError(PS_ERR_UNKNOWN, false, "missing fringe reference data.\n"); 323 psFree (view); 324 return false; 325 } 326 327 if (!ppImageDetrendFringeGenerate(cell, fringeCell, options)) { 328 psError(PS_ERR_UNKNOWN, false, "failed to apply fringe image.\n"); 329 psFree (view); 330 return false; 331 } 332 } 333 334 // Solve the residual fringe system 335 if (!ppImageDetrendFringeSolve(chip, fringe, true, options)) { 336 psError(PS_ERR_UNKNOWN, false, "failed to solve the residual fringe system.\n"); 337 psFree (view); 338 return false; 339 } 340 341 psFree (view); 342 return true; 343 } -
trunk/ppImage/src/ppImageDetrendFringe.h
r10335 r13970 9 9 bool ppImageDetrendFringeMeasure(pmReadout *readout, // Readout to measure 10 10 pmCell *fringe, // Fringe cell (each readout is a different component) 11 const bool isResidual, 11 12 const ppImageOptions *options // Options 12 13 ); … … 15 16 bool ppImageDetrendFringeSolve(pmChip *scienceChip, // Chip with science 16 17 const pmChip *refChip, // Chip with reference fringes 18 const bool isResidual, 17 19 const ppImageOptions *options // Options 18 20 ); … … 20 22 // Generate fringe frame 21 23 bool ppImageDetrendFringeGenerate(pmCell *science, // Science cell 22 pmCell *fringes // Fringe cell, one readout per fringe component 24 pmCell *fringes, // Fringe cell, one readout per fringe component 25 const ppImageOptions *options // Options 23 26 ); 24 27 25 28 29 bool ppImageDetrendFringeApply (pmConfig *config, // config 30 pmChip *chip, // science chip 31 const pmFPAview *inputView, // current view 32 const ppImageOptions *options // options 33 ); 34 26 35 #endif -
trunk/ppImage/src/ppImageDetrendReadout.c
r13812 r13970 88 88 if (options->doFringe) { 89 89 pmCell *fringe = pmFPAfileThisCell(config->files, detview, "PPIMAGE.FRINGE"); 90 if (!ppImageDetrendFringeMeasure(input, fringe, options)) {90 if (!ppImageDetrendFringeMeasure(input, fringe, false, options)) { 91 91 return false; 92 92 } -
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 -
trunk/ppImage/src/ppImageOptions.c
r13921 r13970 39 39 options->doAstromChip = false; // Astrometry 40 40 options->doAstromMosaic = false; // Astrometry 41 42 options->doStats = false; // Measure and save image statistics 41 43 42 44 options->BaseFITS = false; // create binned image (scale 1) … … 187 189 options->doShutter = psMetadataLookupBool(NULL, recipe, "SHUTTER"); 188 190 191 options->doStats = false; 192 char *statsName = psMetadataLookupStr(&status, config->arguments, "STATS"); // Filename for statistics 193 if (statsName) { 194 options->doStats = true; 195 } 196 189 197 // binned image options 190 198 options->xBin1 = psMetadataLookupS32(&status, recipe, "BIN1.XBIN"); -
trunk/ppImage/src/ppImageOptions.h
r13901 r13970 29 29 void *nonLinearSource; 30 30 31 bool doStats; 32 31 33 bool BaseFITS; 32 34 bool ChipFITS;
Note:
See TracChangeset
for help on using the changeset viewer.
