- Timestamp:
- May 3, 2010, 8:50:52 AM (16 years ago)
- Location:
- branches/simtest_nebulous_branches
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
ppImage/src/ppImageDetrendFringe.c (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/simtest_nebulous_branches
- Property svn:mergeinfo changed
-
branches/simtest_nebulous_branches/ppImage/src/ppImageDetrendFringe.c
r24911 r27840 14 14 psArray *references = psMemIncrRefCounter(psMetadataLookupPtr(NULL, fringe->analysis, "FRINGE.MEASUREMENTS")); 15 15 if (!references) { 16 psError(PS_ERR_IO, false, "Unable to find fringe references.\n");17 return false;16 psError(PS_ERR_IO, false, "Unable to find fringe references.\n"); 17 return false; 18 18 } 19 19 … … 40 40 char *scienceFringes = NULL; 41 41 if (isResidual) { 42 scienceFringes = psStringCopy ("FRINGE.RESIDUALS");42 scienceFringes = psStringCopy ("FRINGE.RESIDUALS"); 43 43 } else { 44 scienceFringes = psStringCopy ("FRINGE.MEASUREMENTS");44 scienceFringes = psStringCopy ("FRINGE.MEASUREMENTS"); 45 45 } 46 46 … … 84 84 psArray *cells = chip->cells; // Component cells 85 85 psArray *fringes = psArrayAlloc(cells->n); // Fringes, to return 86 int video_cell_zero = 0; 87 86 88 for (int i = 0; i < cells->n; i++) { 87 89 fringes->data[i] = NULL; … … 89 91 pmCell *cell = cells->data[i]; // Cell of interest 90 92 91 // XXX for now, skip the video cells (cell->readouts->n > 1) 92 if (cell->readouts->n > 1) { 93 psWarning ("Skipping Video Cell (%d) for ppImageDetrendFringe.c:getFringes", i); 94 continue; 95 } 93 psTrace("psModules.detrend",7,"Readouts: Cell %d chip: %ld\n",i,cell->readouts->n); 94 // XXX for now, skip the video cells (cell->readouts->n > 1) 95 // CZW: This mess creates a fake set of fringe stats by stealing the previous one. 96 // We let the fitting code know that this is all lies by scaling the weights by a crazy amount. 97 98 if ( (cell->readouts->n > 1) ) { 99 psTrace("psModules.detrend",7,"Should be skipping scichip: %d\n",i); 100 psWarning ("Skipping Video Cell (%d) for ppImageDetrendFringe.c:getFringes", i); 101 102 if (i == 0) { 103 video_cell_zero = 1; 104 } 105 else { 106 pmFringeStats *prevFringe = fringes->data[i-1]; 107 pmFringeStats *fringe = pmFringeStatsAlloc(prevFringe->regions); 108 for (int j = 0; j < fringe->regions->nRequested; j++) { 109 fringe->f->data.F32[j] = prevFringe->f->data.F32[j]; 110 fringe->df->data.F32[j] = prevFringe->df->data.F32[j] / 1e6; 111 } 112 fringes->data[i] = fringe; 113 } 114 115 continue; 116 } 96 117 97 118 fringes->data[i] = psMemIncrRefCounter(psMetadataLookupPtr(NULL, cell->analysis, source)); 119 } 120 121 if (video_cell_zero == 1) { 122 pmFringeStats *prevFringe = fringes->data[1]; 123 pmFringeStats *fringe = pmFringeStatsAlloc(prevFringe->regions); 124 for (int j = 0; j < fringe->regions->nRequested; j++) { 125 fringe->f->data.F32[j] = NAN; 126 fringe->df->data.F32[j] = 1.0; 127 } 128 fringes->data[0] = fringe; 98 129 } 99 130 … … 112 143 psArray *science = NULL; 113 144 if (isResidual) { 114 science = getFringes(scienceChip,"FRINGE.RESIDUALS"); // Fringe residuals on science chip145 science = getFringes(scienceChip, "FRINGE.RESIDUALS"); // Fringe residuals on science chip 115 146 } else { 116 science = getFringes(scienceChip, "FRINGE.MEASUREMENTS"); // Fringe measurements on science chip147 science = getFringes(scienceChip, "FRINGE.MEASUREMENTS"); // Fringe measurements on science chip 117 148 } 118 149 … … 124 155 psArray *references = getFringes(refChip, "FRINGE.MEASUREMENTS"); // Fringe measurements on reference chip 125 156 int numRefs = ((psArray*)references->data[0])->n; // Number of reference fringes 126 psArray *referencesCat = psArrayAlloc(numRefs); // Reference fringes 127 for (int i = 0; i < numRefs; i++) { // Iterate over fringes 128 psArray *refs = psArrayAlloc(references->n); // Array of fringes for each cell 129 for (int j = 0; j < references->n; j++) { // Iterate over cells 130 psArray *ref = references->data[j]; // Array of references for this cell 157 psArray *referencesCat = psArrayAlloc(numRefs); // Reference fringes 158 for (int i = 0; i < numRefs; i++) { // Iterate over fringes 159 psArray *refs = psArrayAlloc(references->n); // Array of fringes for each cell 160 for (int j = 0; j < references->n; j++) { // Iterate over cells 161 psArray *ref = references->data[j]; // Array of references for this cell 162 131 163 refs->data[j] = psMemIncrRefCounter(ref->data[i]); 132 164 } … … 142 174 143 175 if (isResidual) { 144 psMetadataAdd(scienceChip->analysis, PS_LIST_TAIL, "FRINGE.RESIDUAL.SOLUTION", PS_DATA_UNKNOWN, "Fringe solution", solution);176 psMetadataAdd(scienceChip->analysis, PS_LIST_TAIL, "FRINGE.RESIDUAL.SOLUTION", PS_DATA_UNKNOWN, "Fringe solution", solution); 145 177 } else { 146 psMetadataAdd(scienceChip->analysis, PS_LIST_TAIL, "FRINGE.SOLUTION", PS_DATA_UNKNOWN, "Fringe solution", solution);178 psMetadataAdd(scienceChip->analysis, PS_LIST_TAIL, "FRINGE.SOLUTION", PS_DATA_UNKNOWN, "Fringe solution", solution); 147 179 } 148 180 … … 152 184 pmHDU *hdu = pmHDUFromCell(science);// HDU of interest 153 185 for (int i = 0; i < solution->nFringeFrames; i++) { 154 // write metadata header value155 psString keyword = NULL;156 if (isResidual) {157 psStringAppend (&keyword, "FRES_%02dV", i);158 } else {159 psStringAppend (&keyword, "FRNG_%02dV", i);160 }161 psMetadataAddF32(hdu->header, PS_LIST_TAIL, keyword, PS_META_REPLACE, "Fringe Amplitude", solution->coeff->data.F32[i + 1]);162 psFree (keyword);163 164 keyword = NULL;165 if (isResidual) {166 psStringAppend (&keyword, "FRES_%02dE", i);167 } else {168 psStringAppend (&keyword, "FRNG_%02dE", i);169 }170 psMetadataAddF32(hdu->header, PS_LIST_TAIL, keyword, PS_META_REPLACE, "Fringe Amplitude error", solution->coeffErr->data.F32[i + 1]);171 psFree (keyword);186 // write metadata header value 187 psString keyword = NULL; 188 if (isResidual) { 189 psStringAppend (&keyword, "FRES_%02dV", i); 190 } else { 191 psStringAppend (&keyword, "FRNG_%02dV", i); 192 } 193 psMetadataAddF32(hdu->header, PS_LIST_TAIL, keyword, PS_META_REPLACE, "Fringe Amplitude", solution->coeff->data.F32[i + 1]); 194 psFree (keyword); 195 196 keyword = NULL; 197 if (isResidual) { 198 psStringAppend (&keyword, "FRES_%02dE", i); 199 } else { 200 psStringAppend (&keyword, "FRNG_%02dE", i); 201 } 202 psMetadataAddF32(hdu->header, PS_LIST_TAIL, keyword, PS_META_REPLACE, "Fringe Amplitude error", solution->coeffErr->data.F32[i + 1]); 203 psFree (keyword); 172 204 } 173 205 # endif … … 233 265 234 266 # if (0) 235 // write metadata header value236 // XXX this is measured per cell, but we only have headers per chip237 psString keyword = NULL;238 psStringAppend (&keyword, "FRNG_%02dV", i);239 psMetadataAddF32(hdu->header, PS_LIST_TAIL, keyword, PS_META_REPLACE, "Fringe Amplitude", solution->coeff->data.F32[i + 1]);240 psFree (keyword);241 242 keyword = NULL;243 psStringAppend (&keyword, "FRNG_%02dE", i);244 psMetadataAddF32(hdu->header, PS_LIST_TAIL, keyword, PS_META_REPLACE, "Fringe Amplitude error", solution->coeffErr->data.F32[i + 1]);245 psFree (keyword);267 // write metadata header value 268 // XXX this is measured per cell, but we only have headers per chip 269 psString keyword = NULL; 270 psStringAppend (&keyword, "FRNG_%02dV", i); 271 psMetadataAddF32(hdu->header, PS_LIST_TAIL, keyword, PS_META_REPLACE, "Fringe Amplitude", solution->coeff->data.F32[i + 1]); 272 psFree (keyword); 273 274 keyword = NULL; 275 psStringAppend (&keyword, "FRNG_%02dE", i); 276 psMetadataAddF32(hdu->header, PS_LIST_TAIL, keyword, PS_META_REPLACE, "Fringe Amplitude error", solution->coeffErr->data.F32[i + 1]); 277 psFree (keyword); 246 278 # endif 247 279 … … 259 291 } 260 292 261 // subtract fringe and update mask if fringe value is NAN262 for (int iy = 0; iy < readout->image->numRows; iy++) {263 for (int ix = 0; ix < readout->image->numCols; ix++) {264 readout->image->data.F32[iy][ix] -= sumFringe->data.F32[iy][ix];265 if (!isfinite(sumFringe->data.F32[iy][ix]) && readout->mask) {266 readout->mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= maskVal;267 } 268 }269 }293 // subtract fringe and update mask if fringe value is NAN 294 for (int iy = 0; iy < readout->image->numRows; iy++) { 295 for (int ix = 0; ix < readout->image->numCols; ix++) { 296 readout->image->data.F32[iy][ix] -= sumFringe->data.F32[iy][ix]; 297 if (!isfinite(sumFringe->data.F32[iy][ix]) && readout->mask) { 298 readout->mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= maskVal; 299 } 300 } 301 } 270 302 271 303 // XXX: Make generic, so subregions may be subtracted as well … … 275 307 // } 276 308 277 // measure residual fringe amplitude. results go to FRINGE.RESIDUALS278 ppImageDetrendFringeMeasure (readout, fringes, true, options);309 // measure residual fringe amplitude. results go to FRINGE.RESIDUALS 310 ppImageDetrendFringeMeasure (readout, fringes, true, options); 279 311 } 280 312 psFree(sumFringe); … … 288 320 psFree(timeString); 289 321 290 return sumFringe;322 return true; 291 323 } 292 324 … … 306 338 pmChip *fringe = pmFPAfileThisChip(config->files, view, "PPIMAGE.FRINGE"); 307 339 if (!fringe) { 308 psError(PS_ERR_UNKNOWN, false, "missing fringe reference data.\n");309 psFree (view);310 return false;340 psError(PS_ERR_UNKNOWN, false, "missing fringe reference data.\n"); 341 psFree (view); 342 return false; 311 343 } 312 344 313 345 // Solve the fringe system 314 346 if (!ppImageDetrendFringeSolve(chip, fringe, false, options)) { 315 psError(PS_ERR_UNKNOWN, false, "failed to solve the fringe system.\n");316 psFree (view);317 return false;347 psError(PS_ERR_UNKNOWN, false, "failed to solve the fringe system.\n"); 348 psFree (view); 349 return false; 318 350 } 319 351 … … 321 353 view->cell = view->readout = -1; 322 354 while ((cell = pmFPAviewNextCell(view, chip->parent, 1)) != NULL) { 323 if (!cell->process || !cell->file_exists) {324 continue;325 }326 327 // Apply the fringe correction328 psTrace("ppImage", 3, "Applying fringe correction...\n");329 pmCell *fringeCell = pmFPAfileThisCell(config->files, view, "PPIMAGE.FRINGE");330 if (!fringeCell) {331 psError(PS_ERR_UNKNOWN, false, "missing fringe reference data.\n");332 psFree (view);333 return false;334 }335 336 // XXX for now, skip the video cells (cell->readouts->n > 1)337 if (cell->readouts->n > 1) {338 psWarning ("Skipping Video Cell for ppImageDetrendFringeApply");339 continue;340 }341 342 if (!ppImageDetrendFringeGenerate(cell, fringeCell, options)) {343 psError(PS_ERR_UNKNOWN, false, "failed to apply fringe image.\n");344 psFree (view);345 return false;346 }355 if (!cell->process || !cell->file_exists) { 356 continue; 357 } 358 359 // Apply the fringe correction 360 psTrace("ppImage", 3, "Applying fringe correction...\n"); 361 pmCell *fringeCell = pmFPAfileThisCell(config->files, view, "PPIMAGE.FRINGE"); 362 if (!fringeCell) { 363 psError(PS_ERR_UNKNOWN, false, "missing fringe reference data.\n"); 364 psFree (view); 365 return false; 366 } 367 368 // XXX for now, skip the video cells (cell->readouts->n > 1) 369 if (cell->readouts->n > 1) { 370 psWarning ("Skipping Video Cell for ppImageDetrendFringeApply"); 371 continue; 372 } 373 374 if (!ppImageDetrendFringeGenerate(cell, fringeCell, options)) { 375 psError(PS_ERR_UNKNOWN, false, "failed to apply fringe image.\n"); 376 psFree (view); 377 return false; 378 } 347 379 } 348 380 349 381 // Solve the residual fringe system 350 382 if (!ppImageDetrendFringeSolve(chip, fringe, true, options)) { 351 psError(PS_ERR_UNKNOWN, false, "failed to solve the residual fringe system.\n");352 psFree (view);353 return false;383 psError(PS_ERR_UNKNOWN, false, "failed to solve the residual fringe system.\n"); 384 psFree (view); 385 return false; 354 386 } 355 387
Note:
See TracChangeset
for help on using the changeset viewer.
