Changeset 8926 for trunk/psModules/src/detrend/pmShutterCorrection.c
- Timestamp:
- Sep 24, 2006, 3:06:28 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/detrend/pmShutterCorrection.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/detrend/pmShutterCorrection.c
r8886 r8926 101 101 // XXX we could examine the top 2 or 3 values and decide if we 102 102 // extended exptime enough or median clip. 103 pars->scale = counts->data.F 64[N-1];103 pars->scale = counts->data.F32[N-1]; 104 104 105 105 // fit a line to the lowest three points and extrapolate to 0.0 106 tmpX = psVectorAlloc (2, PS_TYPE_F64); 107 tmpY = psVectorAlloc (2, PS_TYPE_F64); 108 109 tmpX->data.F64[0] = exptime->data.F64[0]; 110 tmpX->data.F64[1] = exptime->data.F64[1]; 111 tmpY->data.F64[0] = counts->data.F64[0]; 112 tmpY->data.F64[1] = counts->data.F64[1]; 106 tmpX = psVectorAlloc (2, PS_TYPE_F32); 107 tmpY = psVectorAlloc (2, PS_TYPE_F32); 108 tmpX->n = tmpY->n = 2; 109 110 tmpX->data.F32[0] = exptime->data.F32[0]; 111 tmpX->data.F32[1] = exptime->data.F32[1]; 112 tmpY->data.F32[0] = counts->data.F32[0]; 113 tmpY->data.F32[1] = counts->data.F32[1]; 113 114 114 115 // fit a line and extrapolate the fit to 0.0 … … 125 126 float value = pars->scale * (1 + ratio) / 2.0; 126 127 127 int Nm = psVectorBracket (exptime, value, (ratio < 1.0)); 128 int Np = (Nm == N - 1) ? Nm - 1 : Nm + 1; 129 130 tmpX->data.F64[0] = counts->data.F64[Nm]; 131 tmpX->data.F64[1] = counts->data.F64[Np]; 132 tmpY->data.F64[0] = exptime->data.F64[Nm]; 133 tmpY->data.F64[1] = exptime->data.F64[Np]; 128 int Np; 129 if (ratio < 1.0) { 130 Np = psVectorBracket (counts, value, true); 131 } else { 132 Np = psVectorBracketDescend (counts, value, true); 133 } 134 int Nm = (Np == 0) ? 1 : Np - 1; 135 136 tmpX->data.F32[0] = counts->data.F32[Nm]; 137 tmpX->data.F32[1] = counts->data.F32[Np]; 138 tmpY->data.F32[0] = exptime->data.F32[Nm]; 139 tmpY->data.F32[1] = exptime->data.F32[Np]; 134 140 135 141 // fit a line and extrapolate the fit to counts = A (1 + dTk/dTo) : exptime = dTo … … 146 152 147 153 // linear fit to the counts and exptime, given a value for offref 148 pmShutterCorrPars *pmShutterCorrectionLinFit (psVector *exptime, psVector *counts, float offref)154 pmShutterCorrPars *pmShutterCorrectionLinFit (psVector *exptime, psVector *counts, psVector *cntError, float offref) 149 155 { 150 156 … … 152 158 psVector *x = psVectorAlloc (exptime->n, PS_TYPE_F32); 153 159 psVector *y = psVectorAlloc (exptime->n, PS_TYPE_F32); 160 x->n = y->n = exptime->n; 154 161 155 162 for (int i = 0; i < exptime->n; i++) { … … 167 174 line->coeff[1][1] = 0; 168 175 169 psVectorFitPolynomial2D (line, NULL, 0, counts, NULL, x, y);176 psVectorFitPolynomial2D (line, NULL, 0, counts, cntError, x, y); 170 177 171 178 pmShutterCorrPars *pars = pmShutterCorrParsAlloc (); … … 174 181 pars->scale = line->coeff[1][0]; 175 182 pars->offset = line->coeff[0][1] / line->coeff[1][0]; 183 184 psFree (x); 185 psFree (y); 186 psFree (line); 176 187 177 188 return (pars); … … 196 207 197 208 // non-linear fit to the counts and exptime, given a guess for the three parameters 198 pmShutterCorrPars *pmShutterCorrectionFullFit (psVector *exptime, psVector *counts, p mShutterCorrPars *guess)209 pmShutterCorrPars *pmShutterCorrectionFullFit (psVector *exptime, psVector *counts, psVector *cntError, pmShutterCorrPars *guess) 199 210 { 200 211 … … 221 232 // construct the coordinate and value entries (y is counts) 222 233 psArray *x = psArrayAlloc(exptime->n); 223 psVector *y = counts; 224 psVector *yErr = psVectorAlloc(exptime->n, PS_TYPE_F32); 225 x->n = yErr->n = exptime->n; 234 x->n = exptime->n; 226 235 227 236 for (int i = 0; i < exptime->n; i++) { 228 237 psVector *coord = psVectorAlloc(1, PS_TYPE_F32); 229 238 coord->n = 1; 230 231 239 coord->data.F32[0] = exptime->data.F32[i]; 232 233 240 x->data[i] = coord; 234 yErr->data.F32[i] = sqrt(y->data.F32[i]); 235 } 236 237 psMinimizeLMChi2(myMin, covar, params, constrain, x, y, yErr, pmShutterCorrectionModel); 241 } 242 243 psMinimizeLMChi2(myMin, covar, params, constrain, x, counts, cntError, pmShutterCorrectionModel); 238 244 239 245 pmShutterCorrPars *pars = pmShutterCorrParsAlloc (); … … 243 249 pars->offref = params->data.F32[2]; 244 250 245 return (pars); 246 } 251 psFree (myMin); 252 psFree (params); 253 psFree (x); 254 255 return (pars); 256 }
Note:
See TracChangeset
for help on using the changeset viewer.
