IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 3, 2006, 5:57:32 PM (20 years ago)
Author:
Paul Price
Message:

Updates for ppMerge

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/detrend/pmFlatNormalize.c

    r6999 r7060  
    77
    88
    9 // Estimate the flat-field normalisation
    10 bool pmFlatNormalize(psVector *sourceFlux, // The source flux in each image; modified for return
    11                      psVector *chipGains, // Initial guess of the chip gains; modified for return
    12                      psImage *fluxLevels, // Fluxes for each integration (row) and chip (col); modified
    13                      unsigned int maxIter, // Maximum number of iterations
    14                      double tolerance   // Tolerance level before dying
    15                     )
     9// Estimate the flat-field normalisation; return the source flux in each integration
     10psVector *pmFlatNormalize(bool *converge, // Did we converge?
     11                          psVector *chipGains, // Initial guess of the chip gains; modified for return
     12                          const psImage *fluxLevels, // Fluxes for each integration (row) and chip (col)
     13                          unsigned int maxIter, // Maximum number of iterations
     14                          double tolerance   // Tolerance level before dying
     15                         )
    1616{
    17     int numSources = sourceFlux->n;     // Number of measurements made
    18     int numChips = chipGains->n;        // Number of chips with which each measurement is made
     17    int numSources = fluxLevels->numRows; // Number of integrations
     18    int numChips = fluxLevels->numCols; // Number of chips with which each integration is made
    1919
    2020    // Sanity checks
    21     assert(fluxLevels->numCols == numSources);
    22     assert(fluxLevels->numRows == numChips);
    23     assert(sourceFlux->type.type == PS_TYPE_F64);
     21    assert(chipGains->n == numChips);
    2422    assert(chipGains->type.type == PS_TYPE_F64);
    25     assert(fluxLevels->type.type == PS_TYPE_F64);
    2623    assert(maxIter >= 1);
    2724    assert(tolerance > 0);
    2825
    2926    // Take the logarithms
     27    psImage *flux = psImageCopy(NULL, fluxLevels, PS_TYPE_F64); // Copy of the input flux levels matrix
    3028    psImage *fluxMask = psImageAlloc(numSources, numChips, PS_TYPE_U8); // Mask for bad measurements
    3129    psImageInit(fluxMask, 0);
     
    4442
    4543        for (int j = 0; j < numSources; j++) {
    46             if (isfinite(fluxLevels->data.F64[j][i]) && fluxLevels->data.F64[j][i] > 0) {
    47                 fluxLevels->data.F64[j][i] = log(fluxLevels->data.F64[j][i]);
     44            if (isfinite(flux->data.F64[j][i]) && flux->data.F64[j][i] > 0) {
     45                flux->data.F64[j][i] = log(flux->data.F64[j][i]);
    4846            } else {
    4947                // Blank out this measurement
    5048                fluxMask->data.U8[j][i] = 1;
    51                 fluxLevels->data.F64[j][i] = NAN;
     49                flux->data.F64[j][i] = NAN;
    5250            }
    5351        }
    5452    }
    55     // Don't need to initialise sourceFlux, since that is changed immediately
    5653
    5754
    5855    double diff = INFINITY;             // Difference from previous iteration
     56    psVector *sourceFlux = psVectorAlloc(numSources, PS_TYPE_F64); // The flux in each integration
     57    // Don't need to initialise sourceFlux, since that is changed immediately
    5958    for (int iter = 0; iter < maxIter && diff > tolerance; iter++) {
    6059        diff = 0.0;
     
    7069            for (int j = 0; j < numChips; j++) {
    7170                if (!gainMask->data.U8[j] && !fluxMask->data.U8[i][j]) {
    72                     sum += fluxLevels->data.F64[i][j] - chipGains->data.F64[j];
     71                    sum += flux->data.F64[i][j] - chipGains->data.F64[j];
    7372                    number++;
    7473                }
     
    9392            for (int j = 0; j < numSources; j++) {
    9493                if (!fluxMask->data.U8[j][i]) {
    95                     sum += fluxLevels->data.F64[j][i] - sourceFlux->data.F64[j];
     94                    sum += flux->data.F64[j][i] - sourceFlux->data.F64[j];
    9695                    number++;
    9796                }
     
    106105        }
    107106    }
     107    psFree(flux);
    108108    psFree(fluxMask);
    109109
    110     // Un-log everything
     110    // Un-log the vectors
    111111    for (int i = 0; i < numChips; i++) {
    112112        if (!gainMask->data.U8[i]) {
     
    122122    psFree(sourceMask);
    123123
    124     return (diff <= tolerance);         // Did we converge?
     124    if (converge) {
     125        *converge = (diff < tolerance); // Did we converge?
     126    }
     127
     128    return sourceFlux;
    125129}
Note: See TracChangeset for help on using the changeset viewer.