Changeset 13970 for trunk/ppImage/src/ppImageDetrendFringe.c
- Timestamp:
- Jun 25, 2007, 2:27:15 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/ppImage/src/ppImageDetrendFringe.c (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note:
See TracChangeset
for help on using the changeset viewer.
