IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 13, 2006, 12:26:09 PM (19 years ago)
Author:
Paul Price
Message:

Doing fringe processing using the pmFPAfile framework, with FRINGE type for the reference fringes.

File:
1 edited

Legend:

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

    r9857 r9952  
    55#include "ppImageDetrendFringe.h"
    66
    7 bool ppImageDetrendFringeMeasure(pmFringeStats **science, // (Ptr to) science fringe measurements
    8                                  psArray *references, // Array of reference fringe measurements
    9                                  const pmReadout *readout, // Readout to measure
     7bool ppImageDetrendFringeMeasure(pmReadout *readout, // Readout to measure
     8                                 pmCell *fringe, // Fringe cell (each readout is a different component)
    109                                 const ppImageOptions *options // Options
    1110                                 )
    1211{
    13     assert(science);
    14     PS_ASSERT_ARRAY_NON_NULL(references, false);
     12    PS_ASSERT_PTR_NON_NULL(readout, false);
     13    PS_ASSERT_PTR_NON_NULL(fringe, false);
     14    PS_ASSERT_PTR_NON_NULL(options, false);
     15
     16    // Reference fringe measurements
     17    psArray *references = psMemIncrRefCounter(psMetadataLookupPtr(NULL, fringe->analysis,
     18                                                                  "FRINGE.MEASUREMENTS"));
     19    if (!references) {
     20        references = pmFringesParse(fringe); // Reference fringes
     21        if (!references) {
     22            psError(PS_ERR_IO, false, "Unable to find fringe references.\n");
     23            return false;
     24        }
     25        psMetadataAdd(fringe->analysis, PS_LIST_TAIL, "FRINGE.MEASUREMENTS", PS_DATA_UNKNOWN,
     26                      "Fringe measurements", references);
     27    }
    1528
    1629    pmFringeStats *reference = references->data[0]; // Take the first as representative
    1730    pmFringeRegions *regions = reference->regions; // Regions to measure
    18     pmFringeStats *fringe = pmFringeStatsMeasure(regions, readout, options->maskValue); // Fringe stats
     31    pmFringeStats *measurements = pmFringeStatsMeasure(regions, readout, options->maskValue); // Fringe stats
    1932
    2033    // Normalise measurements by the exposure time
     
    2336    if (!mdok || !isfinite(expTime)) {
    2437        psError(PS_ERR_UNKNOWN, false, "CELL.EXPOSURE is not set for --- can't normalise fringes\n");
    25         psFree(fringe);
     38        psFree(measurements);
    2639        return false;
    2740    }
     
    3043        expTime = 1.0;
    3144    }
    32     psBinaryOp(fringe->f, fringe->f, "*", psScalarAlloc(1.0 / expTime, PS_TYPE_F32));
    33     psBinaryOp(fringe->df, fringe->df, "*", psScalarAlloc(1.0 / expTime, PS_TYPE_F32));
     45    psBinaryOp(measurements->f, measurements->f, "*", psScalarAlloc(1.0 / expTime, PS_TYPE_F32));
     46    psBinaryOp(measurements->df, measurements->df, "*", psScalarAlloc(1.0 / expTime, PS_TYPE_F32));
    3447
    35     if (!*science) {
    36         // Only a single readout
    37         *science = fringe;
    38     } else {
     48    // Science fringe measurements
     49    pmFringeStats *previous = psMetadataLookupPtr(NULL, readout->parent->analysis, "FRINGE.MEASUREMENTS");
     50    if (previous) {
    3951        // Multiple readouts: concatenate
    4052        psArray *concatenate = psArrayAlloc(2); // Array to hold fringes
    4153
    4254        // Concatenate science measurements
    43         concatenate->data[0] = *science;
    44         concatenate->data[1] = fringe;
    45         pmFringeStats *sciNew = pmFringeStatsConcatenate(concatenate, NULL, NULL); // New measurements
    46         psFree(*science);
    47         *science = sciNew;
     55        concatenate->data[0] = previous;
     56        concatenate->data[1] = measurements;
     57        pmFringeStats *new = pmFringeStatsConcatenate(concatenate, NULL, NULL); // New measurements
     58        psFree(measurements);
     59        measurements = new;
    4860
    49         // Concatenate reference measurements
     61        // Concatenate reference measurements (duplication, so the science and reference line up)
    5062        for (int i = 0; i < references->n; i++) {
    5163            concatenate->data[0] = concatenate->data[1] = references->data[i];
     
    5466            references->data[i] = refNew;
    5567        }
    56 
    5768        concatenate->data[0] = concatenate->data[1] = NULL;
    5869        psFree(concatenate);
    5970    }
     71
     72    psMetadataAdd(readout->parent->analysis, PS_LIST_TAIL, "FRINGE.MEASUREMENTS",
     73                  PS_DATA_UNKNOWN | PS_META_REPLACE, "Fringe measurements", measurements);
     74    psFree(measurements);
     75
     76    psFree(references);
    6077
    6178    return true;
     
    6380
    6481
     82// Pull the fringes out of the cell analysis FRINGE.MEASUREMENTS for a chip
     83static psArray *getFringes(const pmChip *chip // Chip of interest
     84    )
     85{
     86    psArray *cells = chip->cells;       // Component cells
     87    psArray *fringes = psArrayAlloc(cells->n); // Fringes, to return
     88    for (int i = 0; i < cells->n; i++) {
     89        pmCell *cell = cells->data[i];  // Cell of interest
     90        fringes->data[i] = psMemIncrRefCounter(psMetadataLookupPtr(NULL, cell->analysis,
     91                                                                   "FRINGE.MEASUREMENTS"));
     92    }
     93
     94    return fringes;
     95}
     96
    6597
    6698// Solve the fringe system: we have science fringe measurements for each cell, and an array of reference
    6799// fringe measurements for each cell.  Need to concatenate these together first, and then solve.
    68 pmFringeScale *ppImageDetrendFringeSolve(psArray *science, // Science fringe measurements (per cell)
    69                                          psArray *references, // Array of array of fringe measurements
    70                                          const ppImageOptions *options // Options
     100bool ppImageDetrendFringeSolve(pmChip *scienceChip, // Chip with science
     101                               const pmChip *refChip, // Chip with reference fringes
     102                               const ppImageOptions *options // Options
    71103    )
    72104{
     105    PS_ASSERT_PTR_NON_NULL(scienceChip, NULL);
     106    PS_ASSERT_PTR_NON_NULL(refChip, NULL);
     107    PS_ASSERT_PTR_NON_NULL(options, NULL);
     108
     109    psArray *science = getFringes(scienceChip); // Fringe measurements on science chip
    73110    pmFringeStats *scienceCat = pmFringeStatsConcatenate(science, NULL, NULL); // Science fringes
     111    psFree(science);
    74112
    75113    // Need to transform the array of cells each with an array of fringes --> array of fringes for the chip as
    76114    // a whole
     115    psArray *references = getFringes(refChip); // Fringe measurements on reference chip
    77116    int numRefs = ((psArray*)references->data[0])->n; // Number of reference fringes
    78117    psArray *referencesCat = psArrayAlloc(numRefs); // Reference fringes
     
    86125        psFree(refs);
    87126    }
     127    psFree(references);
    88128
    89129    // Now we can solve
     
    92132                                                   options->fringeIter, options->fringeKeep);
    93133
     134    psMetadataAdd(scienceChip->analysis, PS_LIST_TAIL, "FRINGE.SOLUTION", PS_DATA_UNKNOWN,
     135                  "Fringe solution", solution);
     136    psFree(solution);
    94137    psFree(scienceCat);
    95138    psFree(referencesCat);
    96139
    97     return solution;
     140    return true;
    98141}
    99142
    100143
    101144psImage *ppImageDetrendFringeGenerate(pmCell *science, // Science cell
    102                                       pmCell *fringes, // Fringe cell, one readout per fringe component
    103                                       const pmFringeScale *solution // Fringe solution to apply
     145                                      pmCell *fringes // Fringe cell, one readout per fringe component
    104146    )
    105147{
    106148    PS_ASSERT_PTR_NON_NULL(science, false);
    107     PS_ASSERT_PTR_NON_NULL(solution, false);
     149    PS_ASSERT_PTR_NON_NULL(fringes, false);
     150
     151    pmFringeScale *solution = psMetadataLookupPtr(NULL, science->parent->analysis, "FRINGE.SOLUTION");
    108152    assert(fringes->readouts->n == solution->nFringeFrames);
    109153
Note: See TracChangeset for help on using the changeset viewer.