IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 3, 2010, 8:50:52 AM (16 years ago)
Author:
eugene
Message:

updates from trunk

Location:
branches/simtest_nebulous_branches
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/simtest_nebulous_branches

  • branches/simtest_nebulous_branches/ppImage/src/ppImageDetrendFringe.c

    r24911 r27840  
    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
     
    8484    psArray *cells = chip->cells;       // Component cells
    8585    psArray *fringes = psArrayAlloc(cells->n); // Fringes, to return
     86    int video_cell_zero = 0;
     87
    8688    for (int i = 0; i < cells->n; i++) {
    8789        fringes->data[i] = NULL;
     
    8991        pmCell *cell = cells->data[i];  // Cell of interest
    9092
    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        }
    96117
    97118        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;
    98129    }
    99130
     
    112143    psArray *science = NULL;
    113144    if (isResidual) {
    114         science = getFringes(scienceChip, "FRINGE.RESIDUALS"); // Fringe residuals on science chip
     145        science = getFringes(scienceChip, "FRINGE.RESIDUALS"); // Fringe residuals on science chip
    115146    } else {
    116         science = getFringes(scienceChip, "FRINGE.MEASUREMENTS"); // Fringe measurements on science chip
     147        science = getFringes(scienceChip, "FRINGE.MEASUREMENTS"); // Fringe measurements on science chip
    117148    }
    118149
     
    124155    psArray *references = getFringes(refChip, "FRINGE.MEASUREMENTS"); // Fringe measurements on reference chip
    125156    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
    131163            refs->data[j] = psMemIncrRefCounter(ref->data[i]);
    132164        }
     
    142174
    143175    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);
    145177    } 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);
    147179    }
    148180
     
    152184    pmHDU *hdu = pmHDUFromCell(science);// HDU  of interest
    153185    for (int i = 0; i < solution->nFringeFrames; i++) {
    154         // write metadata header value
    155         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);
    172204    }
    173205# endif
     
    233265
    234266# if (0)
    235         // write metadata header value
    236         // XXX this is measured per cell, but we only have headers per chip
    237         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);
    246278# endif
    247279
     
    259291        }
    260292
    261         // subtract fringe and update mask if fringe value is NAN
    262         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        }
    270302
    271303        // XXX: Make generic, so subregions may be subtracted as well
     
    275307        // }
    276308
    277         // measure residual fringe amplitude. results go to FRINGE.RESIDUALS
    278         ppImageDetrendFringeMeasure (readout, fringes, true, options);
     309        // measure residual fringe amplitude. results go to FRINGE.RESIDUALS
     310        ppImageDetrendFringeMeasure (readout, fringes, true, options);
    279311    }
    280312    psFree(sumFringe);
     
    288320    psFree(timeString);
    289321
    290     return sumFringe;
     322    return true;
    291323}
    292324
     
    306338    pmChip *fringe = pmFPAfileThisChip(config->files, view, "PPIMAGE.FRINGE");
    307339    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;
    311343    }
    312344
    313345    // Solve the fringe system
    314346    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;
    318350    }
    319351
     
    321353    view->cell = view->readout = -1;
    322354    while ((cell = pmFPAviewNextCell(view, chip->parent, 1)) != NULL) {
    323         if (!cell->process || !cell->file_exists) {
    324             continue;
    325         }
    326 
    327         // Apply the fringe correction
    328         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        }
    347379    }
    348380
    349381    // Solve the residual fringe system
    350382    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;
    354386    }
    355387
Note: See TracChangeset for help on using the changeset viewer.