IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 25, 2007, 2:27:15 PM (19 years ago)
Author:
eugene
Message:

adding fringe residual measurement in addition to fringe amplitude; clean up ppImageLoop calls to stats and fringe

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppImage/src/ppImageDetrendFringe.c

    r13779 r13970  
    1010#include "ppImageDetrendFringe.h"
    1111
    12 bool ppImageDetrendFringeMeasure(pmReadout *readout, pmCell *fringe, const ppImageOptions *options)
     12bool ppImageDetrendFringeMeasure(pmReadout *readout, pmCell *fringe, const bool isResidual, const ppImageOptions *options)
    1313{
    1414    PS_ASSERT_PTR_NON_NULL(readout, false);
     
    4949    psBinaryOp(measurements->df, measurements->df, "*", psScalarAlloc(expTime, PS_TYPE_F32));
    5050
     51    char *scienceFringes = NULL;
     52    if (isResidual) {
     53        scienceFringes = psStringCopy ("FRINGE.RESIDUALS");
     54    } else {
     55        scienceFringes = psStringCopy ("FRINGE.MEASUREMENTS");
     56    }
     57
    5158    // Science fringe measurements
    52     pmFringeStats *previous = psMetadataLookupPtr(NULL, readout->parent->analysis, "FRINGE.MEASUREMENTS");
     59    pmFringeStats *previous = psMetadataLookupPtr(NULL, readout->parent->analysis, scienceFringes);
    5360    if (previous) {
    5461        // Multiple readouts: concatenate
     
    7380    }
    7481
    75     psMetadataAdd(readout->parent->analysis, PS_LIST_TAIL, "FRINGE.MEASUREMENTS",
     82    psMetadataAdd(readout->parent->analysis, PS_LIST_TAIL, scienceFringes,
    7683                  PS_DATA_UNKNOWN | PS_META_REPLACE, "Fringe measurements", measurements);
    7784    psFree(measurements);
    78 
     85    psFree(scienceFringes);
    7986    psFree(references);
    8087
     
    8491
    8592// Pull the fringes out of the cell analysis FRINGE.MEASUREMENTS for a chip
    86 static psArray *getFringes(const pmChip *chip // Chip of interest
    87     )
     93// XXX need some error checks
     94static psArray *getFringes(const pmChip *chip, const char *source)
    8895{
    8996    psArray *cells = chip->cells;       // Component cells
     
    9198    for (int i = 0; i < cells->n; i++) {
    9299        pmCell *cell = cells->data[i];  // Cell of interest
    93         fringes->data[i] = psMemIncrRefCounter(psMetadataLookupPtr(NULL, cell->analysis,
    94                                                                    "FRINGE.MEASUREMENTS"));
     100        fringes->data[i] = psMemIncrRefCounter(psMetadataLookupPtr(NULL, cell->analysis, source));
    95101    }
    96102
     
    101107// Solve the fringe system: we have science fringe measurements for each cell, and an array of reference
    102108// fringe measurements for each cell.  Need to concatenate these together first, and then solve.
    103 bool ppImageDetrendFringeSolve(pmChip *scienceChip, const pmChip *refChip, const ppImageOptions *options)
     109bool ppImageDetrendFringeSolve(pmChip *scienceChip, const pmChip *refChip, const bool isResidual, const ppImageOptions *options)
    104110{
    105111    PS_ASSERT_PTR_NON_NULL(scienceChip, NULL);
     
    107113    PS_ASSERT_PTR_NON_NULL(options, NULL);
    108114
    109     psArray *science = getFringes(scienceChip); // Fringe measurements on science chip
     115    psArray *science = NULL;
     116    if (isResidual) {
     117        science = getFringes(scienceChip, "FRINGE.RESIDUALS"); // Fringe residuals on science chip
     118    } else {
     119        science = getFringes(scienceChip, "FRINGE.MEASUREMENTS"); // Fringe measurements on science chip
     120    }
     121
    110122    pmFringeStats *scienceCat = pmFringeStatsConcatenate(science, NULL, NULL); // Science fringes
    111123    psFree(science);
     
    113125    // Need to transform the array of cells each with an array of fringes --> array of fringes for the chip as
    114126    // a whole
    115     psArray *references = getFringes(refChip); // Fringe measurements on reference chip
     127    psArray *references = getFringes(refChip, "FRINGE.MEASUREMENTS"); // Fringe measurements on reference chip
    116128    int numRefs = ((psArray*)references->data[0])->n; // Number of reference fringes
    117129    psArray *referencesCat = psArrayAlloc(numRefs); // Reference fringes
     
    132144                                                   options->fringeIter, options->fringeKeep);
    133145
    134     psMetadataAdd(scienceChip->analysis, PS_LIST_TAIL, "FRINGE.SOLUTION", PS_DATA_UNKNOWN,
    135                   "Fringe solution", solution);
     146    if (isResidual) {
     147        psMetadataAdd(scienceChip->analysis, PS_LIST_TAIL, "FRINGE.RESIDUAL.SOLUTION", PS_DATA_UNKNOWN, "Fringe solution", solution);
     148    } else {
     149        psMetadataAdd(scienceChip->analysis, PS_LIST_TAIL, "FRINGE.SOLUTION", PS_DATA_UNKNOWN, "Fringe solution", solution);
     150    }
     151
     152# if (0)
     153    // write the fringe amplitude or residual amplitude to the header
     154    // XXX this is measured per cell, but we only have headers per chip
     155    pmHDU *hdu = pmHDUFromCell(science);// HDU  of interest
     156    for (int i = 0; i < solution->nFringeFrames; i++) {
     157        // write metadata header value
     158        psString keyword = NULL;
     159        if (isResidual) {
     160            psStringAppend (&keyword, "FRES_%02dV", i);
     161        } else {
     162            psStringAppend (&keyword, "FRNG_%02dV", i);
     163        }
     164        psMetadataAddF32(hdu->header, PS_LIST_TAIL, keyword, PS_META_REPLACE, "Fringe Amplitude", solution->coeff->data.F32[i + 1]);
     165        psFree (keyword);
     166
     167        keyword = NULL;
     168        if (isResidual) {
     169            psStringAppend (&keyword, "FRES_%02dE", i);
     170        } else {
     171            psStringAppend (&keyword, "FRNG_%02dE", i);
     172        }
     173        psMetadataAddF32(hdu->header, PS_LIST_TAIL, keyword, PS_META_REPLACE, "Fringe Amplitude error", solution->coeffErr->data.F32[i + 1]);
     174        psFree (keyword);
     175    }
     176# endif
     177
    136178    psFree(solution);
    137179    psFree(scienceCat);
     
    142184
    143185
    144 bool ppImageDetrendFringeGenerate(pmCell *science, pmCell *fringes)
     186bool ppImageDetrendFringeGenerate(pmCell *science, pmCell *fringes, const ppImageOptions *options)
    145187{
    146188    PS_ASSERT_PTR_NON_NULL(science, false);
     
    191233        psFree(md5string);
    192234
     235# if (0)
    193236        // write metadata header value
     237        // XXX this is measured per cell, but we only have headers per chip
    194238        psString keyword = NULL;
    195         psStringAppend (&keyword, "FRNG_%02d", i);
     239        psStringAppend (&keyword, "FRNG_%02dV", i);
    196240        psMetadataAddF32(hdu->header, PS_LIST_TAIL, keyword, PS_META_REPLACE, "Fringe Amplitude", solution->coeff->data.F32[i + 1]);
    197241        psFree (keyword);
    198242
    199243        keyword = NULL;
    200         psStringAppend (&keyword, "FRNG_%02dD", i);
     244        psStringAppend (&keyword, "FRNG_%02dE", i);
    201245        psMetadataAddF32(hdu->header, PS_LIST_TAIL, keyword, PS_META_REPLACE, "Fringe Amplitude error", solution->coeffErr->data.F32[i + 1]);
    202246        psFree (keyword);
     247# endif
     248
    203249    }
    204250    if (expTime != 1.0) {
     
    219265            return false;
    220266        }
     267
     268        // measure residual fringe amplitude. results go to FRINGE.RESIDUALS
     269        ppImageDetrendFringeMeasure (readout, fringes, true, options);
    221270    }
    222271    psFree(sumFringe);
     
    233282}
    234283
     284bool ppImageDetrendFringeApply (pmConfig *config, pmChip *chip, const pmFPAview *inputView, const ppImageOptions *options) {
     285
     286    pmCell *cell = NULL;
     287
     288    assert (options->doFringe); // do not call if not needed
     289    assert (inputView->chip != -1);
     290    assert (inputView->cell == -1);
     291    assert (inputView->readout == -1);
     292
     293    pmFPAview *view = pmFPAviewAlloc(0); // View for local processing
     294    *view = *inputView;
     295
     296    // select the reference chip
     297    pmChip *fringe = pmFPAfileThisChip(config->files, view, "PPIMAGE.FRINGE");
     298    if (!fringe) {
     299        psError(PS_ERR_UNKNOWN, false, "missing fringe reference data.\n");
     300        psFree (view);
     301        return false;
     302    }
     303
     304    // Solve the fringe system
     305    if (!ppImageDetrendFringeSolve(chip, fringe, false, options)) {
     306        psError(PS_ERR_UNKNOWN, false, "failed to solve the fringe system.\n");
     307        psFree (view);
     308        return false;
     309    }
     310
     311    // Go back over the cells to apply the fringe correction
     312    view->cell = view->readout = -1;
     313    while ((cell = pmFPAviewNextCell(view, chip->parent, 1)) != NULL) {
     314        if (!cell->process || !cell->file_exists) {
     315            continue;
     316        }
     317
     318        // Apply the fringe correction
     319        psTrace("ppImage", 3, "Applying fringe correction...\n");
     320        pmCell *fringeCell = pmFPAfileThisCell(config->files, view, "PPIMAGE.FRINGE");
     321        if (!fringeCell) {
     322            psError(PS_ERR_UNKNOWN, false, "missing fringe reference data.\n");
     323            psFree (view);
     324            return false;
     325        }
     326
     327        if (!ppImageDetrendFringeGenerate(cell, fringeCell, options)) {
     328            psError(PS_ERR_UNKNOWN, false, "failed to apply fringe image.\n");
     329            psFree (view);
     330            return false;
     331        }
     332    }
     333
     334    // Solve the residual fringe system
     335    if (!ppImageDetrendFringeSolve(chip, fringe, true, options)) {
     336        psError(PS_ERR_UNKNOWN, false, "failed to solve the residual fringe system.\n");
     337        psFree (view);
     338        return false;
     339    }
     340
     341    psFree (view);
     342    return true;
     343}
Note: See TracChangeset for help on using the changeset viewer.