Changeset 26755
- Timestamp:
- Feb 1, 2010, 3:06:21 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/20091201/ppImage/src/ppImageDetrendFringe.c
r25930 r26755 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 … … 85 85 psArray *fringes = psArrayAlloc(cells->n); // Fringes, to return 86 86 int video_cell_zero = 0; 87 87 88 88 for (int i = 0; i < cells->n; i++) { 89 89 fringes->data[i] = NULL; … … 91 91 pmCell *cell = cells->data[i]; // Cell of interest 92 92 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 }117 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 } 117 118 118 fringes->data[i] = psMemIncrRefCounter(psMetadataLookupPtr(NULL, cell->analysis, source)); 119 119 } … … 123 123 pmFringeStats *fringe = pmFringeStatsAlloc(prevFringe->regions); 124 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;125 fringe->f->data.F32[j] = NAN; 126 fringe->df->data.F32[j] = 1.0; 127 127 } 128 128 fringes->data[0] = fringe; 129 129 } 130 130 131 131 return fringes; 132 132 } … … 143 143 psArray *science = NULL; 144 144 if (isResidual) { 145 science = getFringes(scienceChip, "FRINGE.RESIDUALS"); // Fringe residuals on science chip145 science = getFringes(scienceChip, "FRINGE.RESIDUALS"); // Fringe residuals on science chip 146 146 } else { 147 science = getFringes(scienceChip, "FRINGE.MEASUREMENTS"); // Fringe measurements on science chip147 science = getFringes(scienceChip, "FRINGE.MEASUREMENTS"); // Fringe measurements on science chip 148 148 } 149 149 … … 160 160 for (int j = 0; j < references->n; j++) { // Iterate over cells 161 161 psArray *ref = references->data[j]; // Array of references for this cell 162 162 163 163 refs->data[j] = psMemIncrRefCounter(ref->data[i]); 164 164 } 165 referencesCat->data[i] = pmFringeStatsConcatenate(refs, NULL, NULL);165 referencesCat->data[i] = pmFringeStatsConcatenate(refs, NULL, NULL); 166 166 psFree(refs); 167 167 } … … 174 174 175 175 if (isResidual) { 176 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); 177 177 } else { 178 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); 179 179 } 180 180 … … 184 184 pmHDU *hdu = pmHDUFromCell(science);// HDU of interest 185 185 for (int i = 0; i < solution->nFringeFrames; i++) { 186 // write metadata header value187 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);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); 204 204 } 205 205 # endif … … 265 265 266 266 # if (0) 267 // write metadata header value268 // XXX this is measured per cell, but we only have headers per chip269 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);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); 278 278 # endif 279 279 … … 291 291 } 292 292 293 // subtract fringe and update mask if fringe value is NAN294 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 }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 } 302 302 303 303 // XXX: Make generic, so subregions may be subtracted as well … … 307 307 // } 308 308 309 // measure residual fringe amplitude. results go to FRINGE.RESIDUALS310 ppImageDetrendFringeMeasure (readout, fringes, true, options);309 // measure residual fringe amplitude. results go to FRINGE.RESIDUALS 310 ppImageDetrendFringeMeasure (readout, fringes, true, options); 311 311 } 312 312 psFree(sumFringe); … … 320 320 psFree(timeString); 321 321 322 return sumFringe;322 return true; 323 323 } 324 324 … … 338 338 pmChip *fringe = pmFPAfileThisChip(config->files, view, "PPIMAGE.FRINGE"); 339 339 if (!fringe) { 340 psError(PS_ERR_UNKNOWN, false, "missing fringe reference data.\n");341 psFree (view);342 return false;340 psError(PS_ERR_UNKNOWN, false, "missing fringe reference data.\n"); 341 psFree (view); 342 return false; 343 343 } 344 344 345 345 // Solve the fringe system 346 346 if (!ppImageDetrendFringeSolve(chip, fringe, false, options)) { 347 psError(PS_ERR_UNKNOWN, false, "failed to solve the fringe system.\n");348 psFree (view);349 return false;347 psError(PS_ERR_UNKNOWN, false, "failed to solve the fringe system.\n"); 348 psFree (view); 349 return false; 350 350 } 351 351 … … 353 353 view->cell = view->readout = -1; 354 354 while ((cell = pmFPAviewNextCell(view, chip->parent, 1)) != NULL) { 355 if (!cell->process || !cell->file_exists) {356 continue;357 }358 359 // Apply the fringe correction360 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 }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 } 379 379 } 380 380 381 381 // Solve the residual fringe system 382 382 if (!ppImageDetrendFringeSolve(chip, fringe, true, options)) { 383 psError(PS_ERR_UNKNOWN, false, "failed to solve the residual fringe system.\n");384 psFree (view);385 return false;383 psError(PS_ERR_UNKNOWN, false, "failed to solve the residual fringe system.\n"); 384 psFree (view); 385 return false; 386 386 } 387 387
Note:
See TracChangeset
for help on using the changeset viewer.
