IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 7178


Ignore:
Timestamp:
May 22, 2006, 5:17:19 PM (20 years ago)
Author:
Paul Price
Message:

Normalising source fluxes by the mean

File:
1 edited

Legend:

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

    r7060 r7178  
    2626    // Take the logarithms
    2727    psImage *flux = psImageCopy(NULL, fluxLevels, PS_TYPE_F64); // Copy of the input flux levels matrix
    28     psImage *fluxMask = psImageAlloc(numSources, numChips, PS_TYPE_U8); // Mask for bad measurements
     28    psImage *fluxMask = psImageAlloc(numChips, numSources, PS_TYPE_U8); // Mask for bad measurements
    2929    psImageInit(fluxMask, 0);
    3030    psVector *gainMask = psVectorAlloc(numChips, PS_TYPE_U8); // Mask for bad gains
     31    gainMask->n = numChips;
    3132    psVectorInit(gainMask, 0);
    3233    psVector *sourceMask = psVectorAlloc(numSources, PS_TYPE_U8); // Mask for bad integrations
     34    sourceMask->n = numSources;
    3335    psVectorInit(sourceMask, 0);
    3436    for (int i = 0; i < numChips; i++) {
     
    3638            chipGains->data.F64[i] = log(chipGains->data.F64[i]);
    3739        } else {
     40            chipGains->data.F64[i] = 0.0; // Take a wild guess
     41            #if 0
    3842            // Blank out this chip
    3943            gainMask->data.U8[i] = 1;
    4044            chipGains->data.F64[i] = NAN;
     45            #endif
     46
    4147        }
    4248
     
    5258    }
    5359
    54 
    5560    double diff = INFINITY;             // Difference from previous iteration
    5661    psVector *sourceFlux = psVectorAlloc(numSources, PS_TYPE_F64); // The flux in each integration
    57     // Don't need to initialise sourceFlux, since that is changed immediately
     62    sourceFlux->n = numSources;
     63    psVector *oldSourceFlux = psVectorAlloc(numSources, PS_TYPE_F64); // The fluxes in the previous iteration
     64    oldSourceFlux->n = numSources;
     65    psVectorInit(oldSourceFlux, 0.0);
    5866    for (int iter = 0; iter < maxIter && diff > tolerance; iter++) {
    5967        diff = 0.0;
    6068
     69
    6170        // Improve on the fluxes
     71        double sumFlux = 0.0;           // Total fluxes
     72        long numFluxes = 0;             // Number of fluxes
    6273        for (int i = 0; i < numSources; i++) {
    6374            if (sourceMask->data.U8[i]) {
     75                psTrace(__func__, 7, "Flux for exposure %d is masked.\n", i);
    6476                continue;
    6577            }
    66             double previous = sourceFlux->data.F64[i]; // Value from previous iteration
     78            numFluxes++;
    6779            double sum = 0.0;           // Sum of F_ij - G_j
    6880            int number = 0;             // Number of chips contributing
     
    7587            if (number > 0) {
    7688                sourceFlux->data.F64[i] = sum / (double)number;
    77                 diff += abs((sourceFlux->data.F64[i] - previous) / sourceFlux->data.F64[i]);
    7889            } else {
    7990                sourceMask->data.U8[i] = 1;
    8091                sourceFlux->data.F64[i] = NAN;
    8192            }
     93            sumFlux += exp(sourceFlux->data.F64[i]);
     94            psTrace(__func__, 7, "Flux for exposure %d is %f\n", i, exp(sourceFlux->data.F64[i]));
     95        }
     96        // Normalise the mean to unity
     97        sumFlux /= (double)numFluxes;
     98        sumFlux = log(sumFlux);
     99        for (int i = 0; i < numSources; i++) {
     100            if (sourceMask->data.U8[i]) {
     101                continue;
     102            }
     103            sourceFlux->data.F64[i] -= sumFlux;
     104            diff += abs((sourceFlux->data.F64[i] - oldSourceFlux->data.F64[i]) / sourceFlux->data.F64[i]);
    82105        }
    83106
     
    87110                continue;
    88111            }
    89             double previous = chipGains->data.F64[i]; // Value from previous iteration
    90112            double sum = 0.0;           // Sum of F_ji - S_j
    91113            int number = 0;             // Numer of sources contributing
     
    98120            if (number > 0) {
    99121                chipGains->data.F64[i] = sum / (double)number;
    100                 diff += abs((chipGains->data.F64[i] - previous) / chipGains->data.F64[i]);
    101122            } else {
    102123                gainMask->data.U8[i] = 1;
    103124                chipGains->data.F64[i] = NAN;
    104125            }
     126            psTrace(__func__, 7, "Gain for chip %d is %f\n", i, exp(chipGains->data.F64[i]));
    105127        }
     128
     129        psTrace(__func__, 2, "Iteration %d: difference is %f\n", iter, diff);
     130
     131        // Switch the old and new
     132        psVector *temp = sourceFlux;
     133        sourceFlux = oldSourceFlux;
     134        oldSourceFlux = temp;
    106135    }
    107136    psFree(flux);
    108137    psFree(fluxMask);
     138    psFree(oldSourceFlux);
    109139
    110140    // Un-log the vectors
Note: See TracChangeset for help on using the changeset viewer.