Changeset 7179
- Timestamp:
- May 22, 2006, 5:19:26 PM (20 years ago)
- Location:
- trunk/psModules/src/detrend
- Files:
-
- 2 edited
-
pmFlatNormalize.c (modified) (9 diffs)
-
pmFlatNormalize.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/detrend/pmFlatNormalize.c
r7178 r7179 12 12 const psImage *fluxLevels, // Fluxes for each integration (row) and chip (col) 13 13 unsigned int maxIter, // Maximum number of iterations 14 doubletolerance // Tolerance level before dying14 float tolerance // Tolerance level before dying 15 15 ) 16 16 { … … 20 20 // Sanity checks 21 21 assert(chipGains->n == numChips); 22 assert(chipGains->type.type == PS_TYPE_F 64);22 assert(chipGains->type.type == PS_TYPE_F32); 23 23 assert(maxIter >= 1); 24 24 assert(tolerance > 0); 25 25 26 26 // Take the logarithms 27 psImage *flux = psImageCopy(NULL, fluxLevels, PS_TYPE_F 64); // Copy of the input flux levels matrix27 psImage *flux = psImageCopy(NULL, fluxLevels, PS_TYPE_F32); // Copy of the input flux levels matrix 28 28 psImage *fluxMask = psImageAlloc(numChips, numSources, PS_TYPE_U8); // Mask for bad measurements 29 29 psImageInit(fluxMask, 0); … … 35 35 psVectorInit(sourceMask, 0); 36 36 for (int i = 0; i < numChips; i++) { 37 if (isfinite(chipGains->data.F 64[i]) && chipGains->data.F64[i] > 0) {38 chipGains->data.F 64[i] = log(chipGains->data.F64[i]);37 if (isfinite(chipGains->data.F32[i]) && chipGains->data.F32[i] > 0) { 38 chipGains->data.F32[i] = log(chipGains->data.F32[i]); 39 39 } else { 40 chipGains->data.F 64[i] = 0.0; // Take a wild guess40 chipGains->data.F32[i] = 0.0; // Take a wild guess 41 41 #if 0 42 42 // Blank out this chip 43 43 gainMask->data.U8[i] = 1; 44 chipGains->data.F 64[i] = NAN;44 chipGains->data.F32[i] = NAN; 45 45 #endif 46 46 … … 48 48 49 49 for (int j = 0; j < numSources; j++) { 50 if (isfinite(flux->data.F 64[j][i]) && flux->data.F64[j][i] > 0) {51 flux->data.F 64[j][i] = log(flux->data.F64[j][i]);50 if (isfinite(flux->data.F32[j][i]) && flux->data.F32[j][i] > 0) { 51 flux->data.F32[j][i] = log(flux->data.F32[j][i]); 52 52 } else { 53 53 // Blank out this measurement 54 54 fluxMask->data.U8[j][i] = 1; 55 flux->data.F 64[j][i] = NAN;55 flux->data.F32[j][i] = NAN; 56 56 } 57 57 } 58 58 } 59 59 60 doublediff = INFINITY; // Difference from previous iteration61 psVector *sourceFlux = psVectorAlloc(numSources, PS_TYPE_F 64); // The flux in each integration60 float diff = INFINITY; // Difference from previous iteration 61 psVector *sourceFlux = psVectorAlloc(numSources, PS_TYPE_F32); // The flux in each integration 62 62 sourceFlux->n = numSources; 63 psVector *oldSourceFlux = psVectorAlloc(numSources, PS_TYPE_F 64); // The fluxes in the previous iteration63 psVector *oldSourceFlux = psVectorAlloc(numSources, PS_TYPE_F32); // The fluxes in the previous iteration 64 64 oldSourceFlux->n = numSources; 65 65 psVectorInit(oldSourceFlux, 0.0); … … 69 69 70 70 // Improve on the fluxes 71 doublesumFlux = 0.0; // Total fluxes71 float sumFlux = 0.0; // Total fluxes 72 72 long numFluxes = 0; // Number of fluxes 73 73 for (int i = 0; i < numSources; i++) { … … 77 77 } 78 78 numFluxes++; 79 doublesum = 0.0; // Sum of F_ij - G_j79 float sum = 0.0; // Sum of F_ij - G_j 80 80 int number = 0; // Number of chips contributing 81 81 for (int j = 0; j < numChips; j++) { 82 82 if (!gainMask->data.U8[j] && !fluxMask->data.U8[i][j]) { 83 sum += flux->data.F 64[i][j] - chipGains->data.F64[j];83 sum += flux->data.F32[i][j] - chipGains->data.F32[j]; 84 84 number++; 85 85 } 86 86 } 87 87 if (number > 0) { 88 sourceFlux->data.F 64[i] = sum / (double)number;88 sourceFlux->data.F32[i] = sum / (float)number; 89 89 } else { 90 90 sourceMask->data.U8[i] = 1; 91 sourceFlux->data.F 64[i] = NAN;91 sourceFlux->data.F32[i] = NAN; 92 92 } 93 sumFlux += exp(sourceFlux->data.F 64[i]);94 psTrace(__func__, 7, "Flux for exposure %d is %f\n", i, exp(sourceFlux->data.F 64[i]));93 sumFlux += exp(sourceFlux->data.F32[i]); 94 psTrace(__func__, 7, "Flux for exposure %d is %f\n", i, exp(sourceFlux->data.F32[i])); 95 95 } 96 96 // Normalise the mean to unity 97 sumFlux /= ( double)numFluxes;97 sumFlux /= (float)numFluxes; 98 98 sumFlux = log(sumFlux); 99 99 for (int i = 0; i < numSources; i++) { … … 101 101 continue; 102 102 } 103 sourceFlux->data.F 64[i] -= sumFlux;104 diff += abs((sourceFlux->data.F 64[i] - oldSourceFlux->data.F64[i]) / sourceFlux->data.F64[i]);103 sourceFlux->data.F32[i] -= sumFlux; 104 diff += abs((sourceFlux->data.F32[i] - oldSourceFlux->data.F32[i]) / sourceFlux->data.F32[i]); 105 105 } 106 106 … … 110 110 continue; 111 111 } 112 doublesum = 0.0; // Sum of F_ji - S_j112 float sum = 0.0; // Sum of F_ji - S_j 113 113 int number = 0; // Numer of sources contributing 114 114 for (int j = 0; j < numSources; j++) { 115 115 if (!fluxMask->data.U8[j][i]) { 116 sum += flux->data.F 64[j][i] - sourceFlux->data.F64[j];116 sum += flux->data.F32[j][i] - sourceFlux->data.F32[j]; 117 117 number++; 118 118 } 119 119 } 120 120 if (number > 0) { 121 chipGains->data.F 64[i] = sum / (double)number;121 chipGains->data.F32[i] = sum / (float)number; 122 122 } else { 123 123 gainMask->data.U8[i] = 1; 124 chipGains->data.F 64[i] = NAN;124 chipGains->data.F32[i] = NAN; 125 125 } 126 psTrace(__func__, 7, "Gain for chip %d is %f\n", i, exp(chipGains->data.F 64[i]));126 psTrace(__func__, 7, "Gain for chip %d is %f\n", i, exp(chipGains->data.F32[i])); 127 127 } 128 128 … … 141 141 for (int i = 0; i < numChips; i++) { 142 142 if (!gainMask->data.U8[i]) { 143 chipGains->data.F 64[i] = exp(chipGains->data.F64[i]);143 chipGains->data.F32[i] = exp(chipGains->data.F32[i]); 144 144 } 145 145 } 146 146 for (int i = 0; i < numSources; i++) { 147 147 if (!sourceMask->data.U8[i]) { 148 sourceFlux->data.F 64[i] = exp(sourceFlux->data.F64[i]);148 sourceFlux->data.F32[i] = exp(sourceFlux->data.F32[i]); 149 149 } 150 150 } -
trunk/psModules/src/detrend/pmFlatNormalize.h
r7060 r7179 2 2 #define PM_FLAT_NORMALIZE_H 3 3 4 #include "pslib.h" 4 5 5 6 // Normalise the flat-field measurements (f_ij = g_i s_j where f_ij is the flux recorded for chip i and … … 10 11 const psImage *fluxLevels, // Fluxes for each integration (row) and chip (col) 11 12 unsigned int maxIter, // Maximum number of iterations 12 double tolerance// Tolerance level before dying13 float tolerance // Tolerance level before dying 13 14 ); 14 15
Note:
See TracChangeset
for help on using the changeset viewer.
