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/test/detrend/tap_pmShutterCorrection.c

    r8919 r8926  
    1313
    1414    // test allocation, free of pmShutterCorrPars
     15    diag("pmShutterCorrParsAlloc tests");
    1516    {
    1617        psMemId id = psMemGetId();
     
    2526    }
    2627
    27     // test parameter guess (linearly spaced exptimes)
     28    // test parameter guess (linearly spaced exptimes, TK/TO < 1)
     29    diag("pmShutterCorrectionGuess tests : coarse linear-spaced exptimes");
    2830    {
    2931        psMemId id = psMemGetId();
     
    3739        exptime->n = counts->n = NPTS;
    3840
    39         for (int i = 0; i < exptime->n; i++)
    40         {
    41             exptime->data.F32[i] = i;
    42             counts->data.F32[i] = AK*(exptime->data.F32[i] + TK) / (exptime->data.F32[i] + TO);
    43         }
    44 
    45         pmShutterCorrPars *pars = pmShutterCorrectionGuess (exptime, counts);
    46 
    47         ok(pars != NULL, "pmShutterCorrPars successfully allocated");
    48         skip_start(pars == NULL, 0, "Skipping tests because pmShutterCorrParsAlloc() failed");
    49         ok(pars->scale == AK, "got the right scale (got %f vs %f)", pars->scale, AK);
    50         ok(pars->offset == TK, "got the right offset (got %f vs %f)", pars->offset, TK);
    51         ok(pars->offref == TO, "got the right offref (got %f vs %f)", pars->offref, TO);
    52         skip_end();
    53 
    54         psFree(pars);
    55         psFree(exptime);
    56         psFree(counts);
     41        for (int i = 0; i < exptime->n; i++) {
     42            exptime->data.F32[i] = i*0.25;
     43            counts->data.F32[i] = AK*(exptime->data.F32[i] + TK) / (exptime->data.F32[i] + TO);
     44        }
     45
     46        pmShutterCorrPars *pars = pmShutterCorrectionGuess (exptime, counts);
     47
     48        ok(pars != NULL, "pmShutterCorrPars successfully allocated");
     49        skip_start(pars == NULL, 0, "Skipping tests because pmShutterCorrParsAlloc() failed");
     50
     51        // with coarse linearly-spaced times large compared to TO and TK,
     52        // we can't expect very accurate guesses.  the exptime guess is fairly good because
     53        // the largest exptime is much longer than TK or TO
     54        ok(fabs(pars->scale  - AK) < 0.5, "scale guess is close enough (got %f vs %f)",  pars->scale, AK);
     55        ok(fabs(pars->offset - TK) < 0.5, "offset guess is close enough (got %f vs %f)", pars->offset, TK);
     56        ok(fabs(pars->offref - TO) < 0.5, "offref guess is close enough (got %f vs %f)", pars->offref, TO);
     57        skip_end();
     58
     59        psFree(pars);
     60        psFree(exptime);
     61        psFree(counts);
     62        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     63    }
     64
     65    // test parameter guess (linearly spaced exptimes, TK/TO < 1)
     66    diag("pmShutterCorrectionGuess tests : fine linear-spaced exptimes");
     67    {
     68        psMemId id = psMemGetId();
     69
     70        int NPTS = 20;
     71        float AK = 5.0;
     72        float TK = 0.1;
     73        float TO = 0.2;
     74        psVector *exptime = psVectorAlloc (NPTS, PS_TYPE_F32);
     75        psVector *counts  = psVectorAlloc (NPTS, PS_TYPE_F32);
     76        exptime->n = counts->n = NPTS;
     77
     78        for (int i = 0; i < exptime->n; i++) {
     79            exptime->data.F32[i] = i*0.1;
     80            counts->data.F32[i] = AK*(exptime->data.F32[i] + TK) / (exptime->data.F32[i] + TO);
     81        }
     82
     83        pmShutterCorrPars *pars = pmShutterCorrectionGuess (exptime, counts);
     84
     85        ok(pars != NULL, "pmShutterCorrPars successfully allocated");
     86        skip_start(pars == NULL, 0, "Skipping tests because pmShutterCorrParsAlloc() failed");
     87
     88        // with fine linearly-spaced times large compared to TO and TK,
     89        // we get a good guess to TK and TO, but since the largest exptime is not
     90        // many times larger than TO, we don't do very well with the AK
     91        ok(fabs(pars->scale  - AK) < 0.5, "scale guess is close enough (got %f vs %f)",  pars->scale, AK);
     92        ok(fabs(pars->offset - TK) < 0.05, "offset guess is close enough (got %f vs %f)", pars->offset, TK);
     93        ok(fabs(pars->offref - TO) < 0.05, "offref guess is close enough (got %f vs %f)", pars->offref, TO);
     94        skip_end();
     95
     96        psFree(pars);
     97        psFree(exptime);
     98        psFree(counts);
     99        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     100    }
     101
     102    // test parameter guess (log spaced exptimes, TK/TO < 1)
     103    diag("pmShutterCorrectionGuess tests : log-spaced exptimes");
     104    {
     105        psMemId id = psMemGetId();
     106
     107        int NPTS = 40;
     108        float AK = 5.0;
     109        float TK = 0.1;
     110        float TO = 0.2;
     111        psVector *exptime = psVectorAlloc (NPTS, PS_TYPE_F32);
     112        psVector *counts  = psVectorAlloc (NPTS, PS_TYPE_F32);
     113        exptime->n = counts->n = NPTS;
     114
     115        for (int i = 0; i < exptime->n; i++) {
     116            exptime->data.F32[i] = pow(10.0, -2 + i*0.1);
     117            counts->data.F32[i] = AK*(exptime->data.F32[i] + TK) / (exptime->data.F32[i] + TO);
     118        }
     119
     120        pmShutterCorrPars *pars = pmShutterCorrectionGuess (exptime, counts);
     121
     122        // with fine log-spaced times well-sampling TO and TK,
     123        // we can expect accurate guesses
     124        ok(pars != NULL, "pmShutterCorrPars successfully allocated");
     125        skip_start(pars == NULL, 0, "Skipping tests because pmShutterCorrParsAlloc() failed");
     126        ok(fabs(pars->scale  - AK) < 0.01, "scale guess is close enough (got %f vs %f)",  pars->scale, AK);
     127        ok(fabs(pars->offset - TK) < 0.01, "offset guess is close enough (got %f vs %f)", pars->offset, TK);
     128        ok(fabs(pars->offref - TO) < 0.01, "offref guess is close enough (got %f vs %f)", pars->offref, TO);
     129        skip_end();
     130
     131        psFree(pars);
     132        psFree(exptime);
     133        psFree(counts);
     134        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     135    }
     136
     137
     138    // test parameter guess (linearly spaced exptimes, TK/TO > 1)
     139    diag("pmShutterCorrectionGuess tests : coarse linear-spaced exptimes, TK/TO > 1");
     140    {
     141        psMemId id = psMemGetId();
     142
     143        int NPTS = 10;
     144        float AK = 5.0;
     145        float TK = 0.2;
     146        float TO = 0.1;
     147        psVector *exptime = psVectorAlloc (NPTS, PS_TYPE_F32);
     148        psVector *counts  = psVectorAlloc (NPTS, PS_TYPE_F32);
     149        exptime->n = counts->n = NPTS;
     150
     151        for (int i = 0; i < exptime->n; i++) {
     152            exptime->data.F32[i] = i*0.25;
     153            counts->data.F32[i] = AK*(exptime->data.F32[i] + TK) / (exptime->data.F32[i] + TO);
     154        }
     155
     156        pmShutterCorrPars *pars = pmShutterCorrectionGuess (exptime, counts);
     157
     158        ok(pars != NULL, "pmShutterCorrPars successfully allocated");
     159        skip_start(pars == NULL, 0, "Skipping tests because pmShutterCorrParsAlloc() failed");
     160
     161        // with coarse linearly-spaced times large compared to TO and TK,
     162        // we can't expect very accurate guesses.  the exptime guess is fairly good because
     163        // the largest exptime is much longer than TK or TO
     164        ok(fabs(pars->scale  - AK) < 0.5, "scale guess is close enough (got %f vs %f)",  pars->scale, AK);
     165        ok(fabs(pars->offset - TK) < 0.5, "offset guess is close enough (got %f vs %f)", pars->offset, TK);
     166        ok(fabs(pars->offref - TO) < 0.5, "offref guess is close enough (got %f vs %f)", pars->offref, TO);
     167        skip_end();
     168
     169        psFree(pars);
     170        psFree(exptime);
     171        psFree(counts);
     172        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     173    }
     174
     175    // test parameter guess (linearly spaced exptimes, TK/TO > 1)
     176    diag("pmShutterCorrectionGuess tests : fine linear-spaced exptimes, TK/TO > 1");
     177    {
     178        psMemId id = psMemGetId();
     179
     180        int NPTS = 20;
     181        float AK = 5.0;
     182        float TK = 0.2;
     183        float TO = 0.1;
     184        psVector *exptime = psVectorAlloc (NPTS, PS_TYPE_F32);
     185        psVector *counts  = psVectorAlloc (NPTS, PS_TYPE_F32);
     186        exptime->n = counts->n = NPTS;
     187
     188        for (int i = 0; i < exptime->n; i++) {
     189            exptime->data.F32[i] = i*0.1;
     190            counts->data.F32[i] = AK*(exptime->data.F32[i] + TK) / (exptime->data.F32[i] + TO);
     191        }
     192
     193        pmShutterCorrPars *pars = pmShutterCorrectionGuess (exptime, counts);
     194
     195        ok(pars != NULL, "pmShutterCorrPars successfully allocated");
     196        skip_start(pars == NULL, 0, "Skipping tests because pmShutterCorrParsAlloc() failed");
     197
     198        // with fine linearly-spaced times large compared to TO and TK,
     199        // we get a good guess to TK and TO, but since the largest exptime is not
     200        // many times larger than TO, we don't do very well with the AK
     201        ok(fabs(pars->scale  - AK) < 0.5, "scale guess is close enough (got %f vs %f)",  pars->scale, AK);
     202        ok(fabs(pars->offset - TK) < 0.05, "offset guess is close enough (got %f vs %f)", pars->offset, TK);
     203        ok(fabs(pars->offref - TO) < 0.05, "offref guess is close enough (got %f vs %f)", pars->offref, TO);
     204        skip_end();
     205
     206        psFree(pars);
     207        psFree(exptime);
     208        psFree(counts);
     209        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     210    }
     211
     212    // test parameter guess (log spaced exptimes, TK/TO > 1)
     213    diag("pmShutterCorrectionGuess tests : log-spaced exptimes, TK/TO > 1");
     214    {
     215        psMemId id = psMemGetId();
     216
     217        int NPTS = 40;
     218        float AK = 5.0;
     219        float TK = 0.2;
     220        float TO = 0.1;
     221        psVector *exptime = psVectorAlloc (NPTS, PS_TYPE_F32);
     222        psVector *counts  = psVectorAlloc (NPTS, PS_TYPE_F32);
     223        exptime->n = counts->n = NPTS;
     224
     225        for (int i = 0; i < exptime->n; i++) {
     226            exptime->data.F32[i] = pow(10.0, -2 + i*0.1);
     227            counts->data.F32[i] = AK*(exptime->data.F32[i] + TK) / (exptime->data.F32[i] + TO);
     228        }
     229
     230        pmShutterCorrPars *pars = pmShutterCorrectionGuess (exptime, counts);
     231
     232        // with fine log-spaced times well-sampling TO and TK,
     233        // we can expect accurate guesses
     234        ok(pars != NULL, "pmShutterCorrPars successfully allocated");
     235        skip_start(pars == NULL, 0, "Skipping tests because pmShutterCorrParsAlloc() failed");
     236        ok(fabs(pars->scale  - AK) < 0.01, "scale guess is close enough (got %f vs %f)",  pars->scale, AK);
     237        ok(fabs(pars->offset - TK) < 0.01, "offset guess is close enough (got %f vs %f)", pars->offset, TK);
     238        ok(fabs(pars->offref - TO) < 0.01, "offref guess is close enough (got %f vs %f)", pars->offref, TO);
     239        skip_end();
     240
     241        psFree(pars);
     242        psFree(exptime);
     243        psFree(counts);
     244        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     245    }
     246
     247    // test non-linear fitting
     248    diag("pmShutterCorrectionFullFit tests : linear-spaced exptimes");
     249    {
     250        psMemId id = psMemGetId();
     251
     252        int NPTS = 20;
     253        float FL = 10000.0;
     254        float AK = 5.0;
     255        float TK = 0.2;
     256        float TO = 0.1;
     257        psVector *exptime = psVectorAlloc (NPTS, PS_TYPE_F32);
     258        psVector *counts  = psVectorAlloc (NPTS, PS_TYPE_F32);
     259        psVector *cntErr  = psVectorAlloc (NPTS, PS_TYPE_F32);
     260        exptime->n = counts->n = cntErr->n = NPTS;
     261
     262        for (int i = 0; i < exptime->n; i++) {
     263            exptime->data.F32[i] = i*0.1;
     264            counts->data.F32[i] = AK*(exptime->data.F32[i] + TK) / (exptime->data.F32[i] + TO);
     265            cntErr->data.F32[i] = AK*sqrt(FL*(exptime->data.F32[i] + TK)) / (exptime->data.F32[i] + TO);
     266        }
     267
     268        pmShutterCorrPars *guess = pmShutterCorrectionGuess (exptime, counts);
     269        skip_start(guess == NULL, 0, "Skipping tests because pmShutterCorrectionGuess() failed");
     270        pmShutterCorrPars *pars = pmShutterCorrectionFullFit (exptime, counts, cntErr, guess);
     271
     272        // with fine log-spaced times well-sampling TO and TK,
     273        // we can expect accurate guesses
     274        ok(pars != NULL, "pmShutterCorrPars successfully allocated by FullFit");
     275        skip_start(pars == NULL, 0, "Skipping tests because pmShutterCorrParsAlloc() failed");
     276        ok(fabs(pars->scale  - AK) < 0.01, "scale fit is close enough (got %f vs %f)",  pars->scale, AK);
     277        ok(fabs(pars->offset - TK) < 0.01, "offset fit is close enough (got %f vs %f)", pars->offset, TK);
     278        ok(fabs(pars->offref - TO) < 0.01, "offref fit is close enough (got %f vs %f)", pars->offref, TO);
     279        skip_end();
     280
     281        psFree(pars);
     282        skip_end();
     283
     284        psFree(guess);
     285        psFree(exptime);
     286        psFree(counts);
     287        psFree(cntErr);
     288        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     289    }
     290
     291    // test non-linear fitting
     292    diag("pmShutterCorrectionFullFit tests : log-spaced exptimes");
     293    {
     294        psMemId id = psMemGetId();
     295
     296        int NPTS = 40;
     297        float FL = 10000.0;
     298        float AK = 1.0;
     299        float TK = 0.2;
     300        float TO = 0.1;
     301        psVector *exptime = psVectorAlloc (NPTS, PS_TYPE_F32);
     302        psVector *counts  = psVectorAlloc (NPTS, PS_TYPE_F32);
     303        psVector *cntErr  = psVectorAlloc (NPTS, PS_TYPE_F32);
     304        exptime->n = counts->n = cntErr->n = NPTS;
     305
     306        for (int i = 0; i < exptime->n; i++) {
     307            exptime->data.F32[i] = pow(10.0, -2 + i*0.1);
     308            counts->data.F32[i] = AK*(exptime->data.F32[i] + TK) / (exptime->data.F32[i] + TO);
     309            cntErr->data.F32[i] = AK*sqrt(FL*(exptime->data.F32[i] + TK)) / (exptime->data.F32[i] + TO);
     310        }
     311
     312        pmShutterCorrPars *guess = pmShutterCorrectionGuess (exptime, counts);
     313        skip_start(guess == NULL, 0, "Skipping tests because pmShutterCorrectionGuess() failed");
     314        pmShutterCorrPars *pars = pmShutterCorrectionFullFit (exptime, counts, cntErr, guess);
     315
     316        // with fine log-spaced times well-sampling TO and TK,
     317        // we can expect accurate guesses
     318        ok(pars != NULL, "pmShutterCorrPars successfully allocated by FullFit");
     319        skip_start(pars == NULL, 0, "Skipping tests because pmShutterCorrParsAlloc() failed");
     320        ok(fabs(pars->scale  - AK) < 0.01, "scale fit is close enough (got %f vs %f)",  pars->scale, AK);
     321        ok(fabs(pars->offset - TK) < 0.01, "offset fit is close enough (got %f vs %f)", pars->offset, TK);
     322        ok(fabs(pars->offref - TO) < 0.01, "offref fit is close enough (got %f vs %f)", pars->offref, TO);
     323        skip_end();
     324
     325        psFree(pars);
     326        skip_end();
     327
     328        psFree(guess);
     329        psFree(exptime);
     330        psFree(counts);
     331        psFree(cntErr);
     332        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     333    }
     334
     335    // XXX should add tests with the input counts scattered with GaussDev...
     336
     337    // test linear fitting
     338    diag("pmShutterCorrectionLinFit tests : linear-spaced exptimes");
     339    {
     340        psMemId id = psMemGetId();
     341
     342        int NPTS = 20;
     343        float FL = 10000.0;
     344        float AK = 5.0;
     345        float TK = 0.2;
     346        float TO = 0.1;
     347        psVector *exptime = psVectorAlloc (NPTS, PS_TYPE_F32);
     348        psVector *counts  = psVectorAlloc (NPTS, PS_TYPE_F32);
     349        psVector *cntErr  = psVectorAlloc (NPTS, PS_TYPE_F32);
     350        exptime->n = counts->n = cntErr->n = NPTS;
     351
     352        for (int i = 0; i < exptime->n; i++) {
     353            exptime->data.F32[i] = i*0.1;
     354            counts->data.F32[i] = AK*(exptime->data.F32[i] + TK) / (exptime->data.F32[i] + TO);
     355            cntErr->data.F32[i] = AK*sqrt(FL*(exptime->data.F32[i] + TK)) / (exptime->data.F32[i] + TO);
     356        }
     357
     358        pmShutterCorrPars *guess = pmShutterCorrectionGuess (exptime, counts);
     359        skip_start(guess == NULL, 0, "Skipping tests because pmShutterCorrectionGuess() failed");
     360        pmShutterCorrPars *full = pmShutterCorrectionFullFit (exptime, counts, cntErr, guess);
     361        pmShutterCorrPars *pars = pmShutterCorrectionLinFit (exptime, counts, cntErr, full->offref);
     362
     363        // with fine log-spaced times well-sampling TO and TK,
     364        // we can expect accurate guesses
     365        ok(pars != NULL, "pmShutterCorrPars successfully allocated by FullFit");
     366        skip_start(pars == NULL, 0, "Skipping tests because pmShutterCorrParsAlloc() failed");
     367        ok(fabs(pars->scale  - AK) < 0.01, "scale fit is close enough (got %f vs %f)",  pars->scale, AK);
     368        ok(fabs(pars->offset - TK) < 0.01, "offset fit is close enough (got %f vs %f)", pars->offset, TK);
     369        ok(fabs(pars->offref - TO) < 0.01, "offref fit is close enough (got %f vs %f)", pars->offref, TO);
     370        skip_end();
     371
     372        psFree(pars);
     373        psFree(full);
     374        skip_end();
     375
     376        psFree(guess);
     377        psFree(exptime);
     378        psFree(counts);
     379        psFree(cntErr);
     380        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     381    }
     382
     383    // test linear fitting
     384    diag("pmShutterCorrectionLinFit tests : log-spaced exptimes");
     385    {
     386        psMemId id = psMemGetId();
     387
     388        int NPTS = 40;
     389        float FL = 10000.0;
     390        float AK = 1.0;
     391        float TK = 0.2;
     392        float TO = 0.1;
     393        psVector *exptime = psVectorAlloc (NPTS, PS_TYPE_F32);
     394        psVector *counts  = psVectorAlloc (NPTS, PS_TYPE_F32);
     395        psVector *cntErr  = psVectorAlloc (NPTS, PS_TYPE_F32);
     396        exptime->n = counts->n = cntErr->n = NPTS;
     397
     398        for (int i = 0; i < exptime->n; i++) {
     399            exptime->data.F32[i] = pow(10.0, -2 + i*0.1);
     400            counts->data.F32[i] = AK*(exptime->data.F32[i] + TK) / (exptime->data.F32[i] + TO);
     401            cntErr->data.F32[i] = AK*sqrt(FL*(exptime->data.F32[i] + TK)) / (exptime->data.F32[i] + TO);
     402        }
     403
     404        pmShutterCorrPars *guess = pmShutterCorrectionGuess (exptime, counts);
     405        skip_start(guess == NULL, 0, "Skipping tests because pmShutterCorrectionGuess() failed");
     406        pmShutterCorrPars *full = pmShutterCorrectionFullFit (exptime, counts, cntErr, guess);
     407        pmShutterCorrPars *pars = pmShutterCorrectionLinFit (exptime, counts, cntErr, full->offref);
     408
     409        // with fine log-spaced times well-sampling TO and TK,
     410        // we can expect accurate guesses
     411        ok(pars != NULL, "pmShutterCorrPars successfully allocated by FullFit");
     412        skip_start(pars == NULL, 0, "Skipping tests because pmShutterCorrParsAlloc() failed");
     413        ok(fabs(pars->scale  - AK) < 0.01, "scale fit is close enough (got %f vs %f)",  pars->scale, AK);
     414        ok(fabs(pars->offset - TK) < 0.01, "offset fit is close enough (got %f vs %f)", pars->offset, TK);
     415        ok(fabs(pars->offref - TO) < 0.01, "offref fit is close enough (got %f vs %f)", pars->offref, TO);
     416        skip_end();
     417
     418        psFree(pars);
     419        psFree(full);
     420        skip_end();
     421
     422        psFree(guess);
     423        psFree(exptime);
     424        psFree(counts);
     425        psFree(cntErr);
    57426        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
    58427    }
Note: See TracChangeset for help on using the changeset viewer.