IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 26755


Ignore:
Timestamp:
Feb 1, 2010, 3:06:21 PM (16 years ago)
Author:
eugene
Message:

fix return value (true, not sumFringe)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/20091201/ppImage/src/ppImageDetrendFringe.c

    r25930 r26755  
    1414    psArray *references = psMemIncrRefCounter(psMetadataLookupPtr(NULL, fringe->analysis, "FRINGE.MEASUREMENTS"));
    1515    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;
    1818    }
    1919
     
    4040    char *scienceFringes = NULL;
    4141    if (isResidual) {
    42         scienceFringes = psStringCopy ("FRINGE.RESIDUALS");
     42        scienceFringes = psStringCopy ("FRINGE.RESIDUALS");
    4343    } else {
    44         scienceFringes = psStringCopy ("FRINGE.MEASUREMENTS");
     44        scienceFringes = psStringCopy ("FRINGE.MEASUREMENTS");
    4545    }
    4646
     
    8585    psArray *fringes = psArrayAlloc(cells->n); // Fringes, to return
    8686    int video_cell_zero = 0;
    87    
     87
    8888    for (int i = 0; i < cells->n; i++) {
    8989        fringes->data[i] = NULL;
     
    9191        pmCell *cell = cells->data[i];  // Cell of interest
    9292
    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
    118118        fringes->data[i] = psMemIncrRefCounter(psMetadataLookupPtr(NULL, cell->analysis, source));
    119119    }
     
    123123      pmFringeStats *fringe     = pmFringeStatsAlloc(prevFringe->regions);
    124124      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;
    127127      }
    128128      fringes->data[0] = fringe;
    129129    }
    130    
     130
    131131    return fringes;
    132132}
     
    143143    psArray *science = NULL;
    144144    if (isResidual) {
    145         science = getFringes(scienceChip,  "FRINGE.RESIDUALS"); // Fringe residuals on science chip
     145        science = getFringes(scienceChip,  "FRINGE.RESIDUALS"); // Fringe residuals on science chip
    146146    } else {
    147         science = getFringes(scienceChip, "FRINGE.MEASUREMENTS"); // Fringe measurements on science chip
     147        science = getFringes(scienceChip, "FRINGE.MEASUREMENTS"); // Fringe measurements on science chip
    148148    }
    149149
     
    160160        for (int j = 0; j < references->n; j++) {     // Iterate over cells
    161161            psArray *ref = references->data[j];       // Array of references for this cell
    162            
     162
    163163            refs->data[j] = psMemIncrRefCounter(ref->data[i]);
    164164        }
    165         referencesCat->data[i] = pmFringeStatsConcatenate(refs, NULL, NULL);
     165        referencesCat->data[i] = pmFringeStatsConcatenate(refs, NULL, NULL);
    166166        psFree(refs);
    167167    }
     
    174174
    175175    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);
    177177    } 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);
    179179    }
    180180
     
    184184    pmHDU *hdu = pmHDUFromCell(science);// HDU  of interest
    185185    for (int i = 0; i < solution->nFringeFrames; i++) {
    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);
     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);
    204204    }
    205205# endif
     
    265265
    266266# if (0)
    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);
     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);
    278278# endif
    279279
     
    291291        }
    292292
    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         }
     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        }
    302302
    303303        // XXX: Make generic, so subregions may be subtracted as well
     
    307307        // }
    308308
    309         // measure residual fringe amplitude. results go to FRINGE.RESIDUALS
    310         ppImageDetrendFringeMeasure (readout, fringes, true, options);
     309        // measure residual fringe amplitude. results go to FRINGE.RESIDUALS
     310        ppImageDetrendFringeMeasure (readout, fringes, true, options);
    311311    }
    312312    psFree(sumFringe);
     
    320320    psFree(timeString);
    321321
    322     return sumFringe;
     322    return true;
    323323}
    324324
     
    338338    pmChip *fringe = pmFPAfileThisChip(config->files, view, "PPIMAGE.FRINGE");
    339339    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;
    343343    }
    344344
    345345    // Solve the fringe system
    346346    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;
    350350    }
    351351
     
    353353    view->cell = view->readout = -1;
    354354    while ((cell = pmFPAviewNextCell(view, chip->parent, 1)) != NULL) {
    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         }
     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        }
    379379    }
    380380
    381381    // Solve the residual fringe system
    382382    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;
    386386    }
    387387
Note: See TracChangeset for help on using the changeset viewer.