Changeset 7060 for trunk/psModules/src/detrend/pmFlatNormalize.c
- Timestamp:
- May 3, 2006, 5:57:32 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/detrend/pmFlatNormalize.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/detrend/pmFlatNormalize.c
r6999 r7060 7 7 8 8 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 return12 psImage *fluxLevels, // Fluxes for each integration (row) and chip (col); modified13 unsigned int maxIter, // Maximum number of iterations14 double tolerance // Tolerance level before dying15 )9 // Estimate the flat-field normalisation; return the source flux in each integration 10 psVector *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 ) 16 16 { 17 int numSources = sourceFlux->n; // Number of measurements made18 int numChips = chipGains->n; // Number of chips with which each measurementis made17 int numSources = fluxLevels->numRows; // Number of integrations 18 int numChips = fluxLevels->numCols; // Number of chips with which each integration is made 19 19 20 20 // 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); 24 22 assert(chipGains->type.type == PS_TYPE_F64); 25 assert(fluxLevels->type.type == PS_TYPE_F64);26 23 assert(maxIter >= 1); 27 24 assert(tolerance > 0); 28 25 29 26 // Take the logarithms 27 psImage *flux = psImageCopy(NULL, fluxLevels, PS_TYPE_F64); // Copy of the input flux levels matrix 30 28 psImage *fluxMask = psImageAlloc(numSources, numChips, PS_TYPE_U8); // Mask for bad measurements 31 29 psImageInit(fluxMask, 0); … … 44 42 45 43 for (int j = 0; j < numSources; j++) { 46 if (isfinite(flux Levels->data.F64[j][i]) && fluxLevels->data.F64[j][i] > 0) {47 flux Levels->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]); 48 46 } else { 49 47 // Blank out this measurement 50 48 fluxMask->data.U8[j][i] = 1; 51 flux Levels->data.F64[j][i] = NAN;49 flux->data.F64[j][i] = NAN; 52 50 } 53 51 } 54 52 } 55 // Don't need to initialise sourceFlux, since that is changed immediately56 53 57 54 58 55 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 59 58 for (int iter = 0; iter < maxIter && diff > tolerance; iter++) { 60 59 diff = 0.0; … … 70 69 for (int j = 0; j < numChips; j++) { 71 70 if (!gainMask->data.U8[j] && !fluxMask->data.U8[i][j]) { 72 sum += flux Levels->data.F64[i][j] - chipGains->data.F64[j];71 sum += flux->data.F64[i][j] - chipGains->data.F64[j]; 73 72 number++; 74 73 } … … 93 92 for (int j = 0; j < numSources; j++) { 94 93 if (!fluxMask->data.U8[j][i]) { 95 sum += flux Levels->data.F64[j][i] - sourceFlux->data.F64[j];94 sum += flux->data.F64[j][i] - sourceFlux->data.F64[j]; 96 95 number++; 97 96 } … … 106 105 } 107 106 } 107 psFree(flux); 108 108 psFree(fluxMask); 109 109 110 // Un-log everything110 // Un-log the vectors 111 111 for (int i = 0; i < numChips; i++) { 112 112 if (!gainMask->data.U8[i]) { … … 122 122 psFree(sourceMask); 123 123 124 return (diff <= tolerance); // Did we converge? 124 if (converge) { 125 *converge = (diff < tolerance); // Did we converge? 126 } 127 128 return sourceFlux; 125 129 }
Note:
See TracChangeset
for help on using the changeset viewer.
