Changeset 8866 for trunk/psModules/src/detrend/pmShutterCorrection.c
- Timestamp:
- Sep 20, 2006, 4:18:19 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/detrend/pmShutterCorrection.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/detrend/pmShutterCorrection.c
r8842 r8866 51 51 */ 52 52 53 static void pmShutterCorrParsFree (pmShutterCorrPars *pars) 54 { 55 if (pars == NULL) 56 return; 57 return; 58 } 59 60 pmShutterCorrPars *pmShutterCorrParsAlloc () 61 { 62 63 pmShutterCorrPars *pars = (pmShutterCorrPars *) psAlloc(sizeof(pmShutterCorrPars)); 64 psMemSetDeallocator(pars, (psFreeFunc) pmShutterCorrParsFree); 65 pars->scale = 0.0; 66 pars->offset = 0.0; 67 pars->offref = 0.0; 68 return (pars); 69 } 70 53 71 // use interpolation to guess shutter correction parameters given a set of exposures times and normalized 54 72 // counts (divided by the reference counts for each image) … … 62 80 63 81 N = exptime->n; 82 // ASSERT (N >> 5) 64 83 65 // NOTE: vectors must be sorted on input it is expensive to sort or check this here, but it is easy to66 // arrange by sorting the images before generating these vectors.84 // NOTE: vectors must be sorted on input. It is expensive to sort or check this here, but 85 // it is easy to arrange by sorting the images before generating these vectors. 67 86 68 87 // choose the highest exptime point as the guess for the scale: … … 72 91 73 92 // fit a line to the lowest three points and extrapolate to 0.0 74 tmpX = psVector Recycle (tmpX, 3, PS_TYPE_F64);75 tmpY = psVector Recycle (tmpY, 3, PS_TYPE_F64);93 tmpX = psVectorAlloc (2, PS_TYPE_F64); 94 tmpY = psVectorAlloc (2, PS_TYPE_F64); 76 95 77 tmpX->data.F64[0] = exptime->data.F64[N-3]; 78 tmpX->data.F64[1] = exptime->data.F64[N-2]; 79 tmpX->data.F64[2] = exptime->data.F64[N-1]; 80 tmpY->data.F64[0] = counts->data.F64[N-3]; 81 tmpY->data.F64[1] = counts->data.F64[N-2]; 82 tmpY->data.F64[2] = counts->data.F64[N-1]; 96 tmpX->data.F64[0] = exptime->data.F64[0]; 97 tmpX->data.F64[1] = exptime->data.F64[1]; 98 tmpY->data.F64[0] = counts->data.F64[0]; 99 tmpY->data.F64[1] = counts->data.F64[1]; 83 100 84 // fit a line to use for interpolation101 // fit a line and extrapolate the fit to 0.0 85 102 psPolynomial1D *line = psPolynomial1DAlloc (PS_POLYNOMIAL_ORD, 1); 86 103 line = psVectorFitPolynomial1D (line, NULL, 0, tmpY, NULL, tmpX); 104 ratio = psPolynomial1DEval (line, 0.0) / pars->scale; 87 105 88 106 // XXX we need a sanity check: … … 92 110 // then the slope should be positive. 93 111 94 // extrapolate the fit to 0.095 ratio = psPolynomial1DEval (line, 0.0);112 // find two points bracketing the value counts = A (1 + dTk/dTo) / 2 = pars->scale (1 + ratio) / 2 113 value = pars->scale * (1 + ratio) / 2.0; 96 114 115 Nm = psVectorBracket (exptime, value, (ratio < 1.0)); 116 Np = (Nm == N - 1) ? Nm - 1 : Nm + 1; 117 118 tmpX->data.F64[0] = counts->data.F64[Nm]; 119 tmpX->data.F64[1] = counts->data.F64[Np]; 120 tmpY->data.F64[0] = exptime->data.F64[Nm]; 121 tmpY->data.F64[1] = exptime->data.F64[Np]; 122 123 // fit a line and extrapolate the fit to counts = A (1 + dTk/dTo) : exptime = dTo 124 psPolynomial1D *line = psPolynomial1DAlloc (PS_POLYNOMIAL_ORD, 1); 125 line = psVectorFitPolynomial1D (line, NULL, 0, tmpY, NULL, tmpX); 126 pars->offref = psPolynomial1DEval (line, value); 127 pars->offset = ratio * pars->offref; 128 129 psFree (line); 130 psFree (tmpX); 131 psFree (tmpY); 132 133 return (pars); 97 134 }
Note:
See TracChangeset
for help on using the changeset viewer.
