Changeset 7178
- Timestamp:
- May 22, 2006, 5:17:19 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
r7060 r7178 26 26 // Take the logarithms 27 27 psImage *flux = psImageCopy(NULL, fluxLevels, PS_TYPE_F64); // Copy of the input flux levels matrix 28 psImage *fluxMask = psImageAlloc(num Sources, numChips, PS_TYPE_U8); // Mask for bad measurements28 psImage *fluxMask = psImageAlloc(numChips, numSources, PS_TYPE_U8); // Mask for bad measurements 29 29 psImageInit(fluxMask, 0); 30 30 psVector *gainMask = psVectorAlloc(numChips, PS_TYPE_U8); // Mask for bad gains 31 gainMask->n = numChips; 31 32 psVectorInit(gainMask, 0); 32 33 psVector *sourceMask = psVectorAlloc(numSources, PS_TYPE_U8); // Mask for bad integrations 34 sourceMask->n = numSources; 33 35 psVectorInit(sourceMask, 0); 34 36 for (int i = 0; i < numChips; i++) { … … 36 38 chipGains->data.F64[i] = log(chipGains->data.F64[i]); 37 39 } else { 40 chipGains->data.F64[i] = 0.0; // Take a wild guess 41 #if 0 38 42 // Blank out this chip 39 43 gainMask->data.U8[i] = 1; 40 44 chipGains->data.F64[i] = NAN; 45 #endif 46 41 47 } 42 48 … … 52 58 } 53 59 54 55 60 double diff = INFINITY; // Difference from previous iteration 56 61 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); 58 66 for (int iter = 0; iter < maxIter && diff > tolerance; iter++) { 59 67 diff = 0.0; 60 68 69 61 70 // Improve on the fluxes 71 double sumFlux = 0.0; // Total fluxes 72 long numFluxes = 0; // Number of fluxes 62 73 for (int i = 0; i < numSources; i++) { 63 74 if (sourceMask->data.U8[i]) { 75 psTrace(__func__, 7, "Flux for exposure %d is masked.\n", i); 64 76 continue; 65 77 } 66 double previous = sourceFlux->data.F64[i]; // Value from previous iteration78 numFluxes++; 67 79 double sum = 0.0; // Sum of F_ij - G_j 68 80 int number = 0; // Number of chips contributing … … 75 87 if (number > 0) { 76 88 sourceFlux->data.F64[i] = sum / (double)number; 77 diff += abs((sourceFlux->data.F64[i] - previous) / sourceFlux->data.F64[i]);78 89 } else { 79 90 sourceMask->data.U8[i] = 1; 80 91 sourceFlux->data.F64[i] = NAN; 81 92 } 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]); 82 105 } 83 106 … … 87 110 continue; 88 111 } 89 double previous = chipGains->data.F64[i]; // Value from previous iteration90 112 double sum = 0.0; // Sum of F_ji - S_j 91 113 int number = 0; // Numer of sources contributing … … 98 120 if (number > 0) { 99 121 chipGains->data.F64[i] = sum / (double)number; 100 diff += abs((chipGains->data.F64[i] - previous) / chipGains->data.F64[i]);101 122 } else { 102 123 gainMask->data.U8[i] = 1; 103 124 chipGains->data.F64[i] = NAN; 104 125 } 126 psTrace(__func__, 7, "Gain for chip %d is %f\n", i, exp(chipGains->data.F64[i])); 105 127 } 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; 106 135 } 107 136 psFree(flux); 108 137 psFree(fluxMask); 138 psFree(oldSourceFlux); 109 139 110 140 // Un-log the vectors
Note:
See TracChangeset
for help on using the changeset viewer.
