- Timestamp:
- May 3, 2010, 8:45:22 AM (16 years ago)
- Location:
- branches/simmosaic_branches
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
ppImage/src/ppImageDetrendFringe.c (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/simmosaic_branches
- Property svn:mergeinfo changed
-
branches/simmosaic_branches/ppImage/src/ppImageDetrendFringe.c
r24838 r27839 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 … … 192 224 } 193 225 assert(fringes->readouts->n == solution->nFringeFrames); 226 227 psImageMaskType maskVal = options->flatMask; 194 228 195 229 bool mdok; // Status of MD lookup … … 231 265 232 266 # if (0) 233 // write metadata header value234 // XXX this is measured per cell, but we only have headers per chip235 psString keyword = NULL;236 psStringAppend (&keyword, "FRNG_%02dV", i);237 psMetadataAddF32(hdu->header, PS_LIST_TAIL, keyword, PS_META_REPLACE, "Fringe Amplitude", solution->coeff->data.F32[i + 1]);238 psFree (keyword);239 240 keyword = NULL;241 psStringAppend (&keyword, "FRNG_%02dE", i);242 psMetadataAddF32(hdu->header, PS_LIST_TAIL, keyword, PS_META_REPLACE, "Fringe Amplitude error", solution->coeffErr->data.F32[i + 1]);243 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); 244 278 # endif 245 279 … … 257 291 } 258 292 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 259 303 // XXX: Make generic, so subregions may be subtracted as well 260 if (!psBinaryOp(readout->image, readout->image, "-", sumFringe)) {261 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to subtract fringe.\n");262 return false;263 }264 265 // measure residual fringe amplitude. results go to FRINGE.RESIDUALS266 ppImageDetrendFringeMeasure (readout, fringes, true, options);304 // if (!psBinaryOp(readout->image, readout->image, "-", sumFringe)) { 305 // psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to subtract fringe.\n"); 306 // return false; 307 // } 308 309 // measure residual fringe amplitude. results go to FRINGE.RESIDUALS 310 ppImageDetrendFringeMeasure (readout, fringes, true, options); 267 311 } 268 312 psFree(sumFringe); … … 276 320 psFree(timeString); 277 321 278 return sumFringe;322 return true; 279 323 } 280 324 … … 294 338 pmChip *fringe = pmFPAfileThisChip(config->files, view, "PPIMAGE.FRINGE"); 295 339 if (!fringe) { 296 psError(PS_ERR_UNKNOWN, false, "missing fringe reference data.\n");297 psFree (view);298 return false;340 psError(PS_ERR_UNKNOWN, false, "missing fringe reference data.\n"); 341 psFree (view); 342 return false; 299 343 } 300 344 301 345 // Solve the fringe system 302 346 if (!ppImageDetrendFringeSolve(chip, fringe, false, options)) { 303 psError(PS_ERR_UNKNOWN, false, "failed to solve the fringe system.\n");304 psFree (view);305 return false;347 psError(PS_ERR_UNKNOWN, false, "failed to solve the fringe system.\n"); 348 psFree (view); 349 return false; 306 350 } 307 351 … … 309 353 view->cell = view->readout = -1; 310 354 while ((cell = pmFPAviewNextCell(view, chip->parent, 1)) != NULL) { 311 if (!cell->process || !cell->file_exists) {312 continue;313 }314 315 // Apply the fringe correction316 psTrace("ppImage", 3, "Applying fringe correction...\n");317 pmCell *fringeCell = pmFPAfileThisCell(config->files, view, "PPIMAGE.FRINGE");318 if (!fringeCell) {319 psError(PS_ERR_UNKNOWN, false, "missing fringe reference data.\n");320 psFree (view);321 return false;322 }323 324 // XXX for now, skip the video cells (cell->readouts->n > 1)325 if (cell->readouts->n > 1) {326 psWarning ("Skipping Video Cell for ppImageDetrendFringeApply");327 continue;328 }329 330 if (!ppImageDetrendFringeGenerate(cell, fringeCell, options)) {331 psError(PS_ERR_UNKNOWN, false, "failed to apply fringe image.\n");332 psFree (view);333 return false;334 }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 } 335 379 } 336 380 337 381 // Solve the residual fringe system 338 382 if (!ppImageDetrendFringeSolve(chip, fringe, true, options)) { 339 psError(PS_ERR_UNKNOWN, false, "failed to solve the residual fringe system.\n");340 psFree (view);341 return false;383 psError(PS_ERR_UNKNOWN, false, "failed to solve the residual fringe system.\n"); 384 psFree (view); 385 return false; 342 386 } 343 387
Note:
See TracChangeset
for help on using the changeset viewer.
