IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 24, 2006, 3:06:28 PM (20 years ago)
Author:
magnier
Message:

finished, tested pmShutterCorrection

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/detrend/pmShutterCorrection.c

    r8886 r8926  
    101101    // XXX we could examine the top 2 or 3 values and decide if we
    102102    // extended exptime enough or median clip.
    103     pars->scale = counts->data.F64[N-1];
     103    pars->scale = counts->data.F32[N-1];
    104104
    105105    // 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];
    113114
    114115    // fit a line and extrapolate the fit to 0.0
     
    125126    float value = pars->scale * (1 + ratio) / 2.0;
    126127
    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];
    134140
    135141    // fit a line and extrapolate the fit to counts = A (1 + dTk/dTo) : exptime = dTo
     
    146152
    147153// linear fit to the counts and exptime, given a value for offref
    148 pmShutterCorrPars *pmShutterCorrectionLinFit (psVector *exptime, psVector *counts, float offref)
     154pmShutterCorrPars *pmShutterCorrectionLinFit (psVector *exptime, psVector *counts, psVector *cntError, float offref)
    149155{
    150156
     
    152158    psVector *x = psVectorAlloc (exptime->n, PS_TYPE_F32);
    153159    psVector *y = psVectorAlloc (exptime->n, PS_TYPE_F32);
     160    x->n = y->n = exptime->n;
    154161
    155162    for (int i = 0; i < exptime->n; i++) {
     
    167174    line->coeff[1][1] = 0;
    168175
    169     psVectorFitPolynomial2D (line, NULL, 0, counts, NULL, x, y);
     176    psVectorFitPolynomial2D (line, NULL, 0, counts, cntError, x, y);
    170177
    171178    pmShutterCorrPars *pars = pmShutterCorrParsAlloc ();
     
    174181    pars->scale  = line->coeff[1][0];
    175182    pars->offset = line->coeff[0][1] / line->coeff[1][0];
     183
     184    psFree (x);
     185    psFree (y);
     186    psFree (line);
    176187
    177188    return (pars);
     
    196207
    197208// non-linear fit to the counts and exptime, given a guess for the three parameters
    198 pmShutterCorrPars *pmShutterCorrectionFullFit (psVector *exptime, psVector *counts, pmShutterCorrPars *guess)
     209pmShutterCorrPars *pmShutterCorrectionFullFit (psVector *exptime, psVector *counts, psVector *cntError, pmShutterCorrPars *guess)
    199210{
    200211
     
    221232    // construct the coordinate and value entries (y is counts)
    222233    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;
    226235
    227236    for (int i = 0; i < exptime->n; i++) {
    228237        psVector *coord = psVectorAlloc(1, PS_TYPE_F32);
    229238        coord->n = 1;
    230 
    231239        coord->data.F32[0] = exptime->data.F32[i];
    232 
    233240        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);
    238244
    239245    pmShutterCorrPars *pars = pmShutterCorrParsAlloc ();
     
    243249    pars->offref = params->data.F32[2];
    244250
    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.