IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 14860


Ignore:
Timestamp:
Sep 16, 2007, 9:16:39 AM (19 years ago)
Author:
magnier
Message:

fixed bugs in test

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20070830/psLib/test/imageops/tap_psImageMapFit.c

    r14859 r14860  
    1919# define TEST_4PT_3 0
    2020
     21# define TEST_6PT_0 0
     22
    2123# define TEST_9PT_0 0
    2224# define TEST_9PT_1 0
    23 # define TEST_9PT_2 0
    24 
    25 # define TEST_6PT_0 1
     25# define TEST_9PT_2 1
    2626
    2727# define TEST1 0
     
    5858        int n = 0;
    5959        for (float ix = 0.5; ix < 3.0; ix += 1.0) {
    60             for (int iy = 0.5; iy < 2.0; iy += 1.0) {
    61                 x->data.F32[n] = ix;
    62                 y->data.F32[n] = iy;
    63                 # if (0)
     60            for (float iy = 0.5; iy < 2.0; iy += 1.0) {
     61                // x->data.F32[n] = ix;
     62                // y->data.F32[n] = iy;
     63                if ((ix == 0.5) && (iy == 0.5)) {
     64                    x->data.F32[n] = ix + 0.0;
     65                    y->data.F32[n] = iy + 0.1; // add in both points. 
     66                    // f->data.F32[n] = x->data.F32[n] + y->data.F32[n];
     67                    // n++;
     68                    // x->data.F32[n] = ix + 0.0;
     69                    // y->data.F32[n] = iy - 0.1;
     70                } else {
     71                    x->data.F32[n] = ix;
     72                    y->data.F32[n] = iy;
     73                }
     74                f->data.F32[n] = x->data.F32[n] + y->data.F32[n];
     75                n++;
     76            }
     77        }
     78        x->n = n;
     79        y->n = n;
     80        f->n = n;
     81
     82        psImage *field = psImageAlloc(3, 2, PS_TYPE_F32);
     83        for (int ix = 0; ix < 3; ix++) {
     84            for (int iy = 0; iy < 2; iy++) {
     85                field->data.F32[iy][ix] = (ix + 0.5) + (iy + 0.5);
     86            }
     87        }
     88
     89        psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN);
     90
     91        // scale defines both field and map image sizes (nXfine, nXruff)
     92        psImageMap *map = psImageMapAlloc (NULL, binning, stats);
     93
     94        // fit the data to the map
     95        psImageMapFit (map, x, y, f, NULL);
     96        psFree (binning);
     97
     98        SaveImage (NULL, map->map, "map.fits");
     99       
     100        SaveImage (NULL, field, "field.fits");
     101
     102        psImage *model = psImageAlloc(field->numCols, field->numRows, PS_TYPE_F32);
     103        for (int ix = 0; ix < model->numCols; ix++) {
     104            for (int iy = 0; iy < model->numRows; iy++) {
     105                model->data.F32[iy][ix] = psImageUnbinPixel_V2 (ix + 0.5, iy + 0.5, map->map, map->binning);
     106                is_float_tol (model->data.F32[iy][ix], field->data.F32[iy][ix], FLT_EPSILON, "model matches inputs");
     107            }
     108        }
     109        SaveImage (NULL, model, "model.fits");
     110        // ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     111    }
     112    # endif
     113
     114    // test for more points: 3x3 grid fitted to 9 points with simple slope and scale difference
     115    # if (TEST_9PT_2)
     116    {
     117        psImageBinning *binning = psImageBinningAlloc();
     118        binning->nXfine = 6;
     119        binning->nYfine = 6;
     120        binning->nXruff = 3;
     121        binning->nYruff = 3;
     122
     123        // generate a grid of test data points
     124        psVector *x = psVectorAlloc (50, PS_TYPE_F32);
     125        psVector *y = psVectorAlloc (50, PS_TYPE_F32);
     126        psVector *f = psVectorAlloc (50, PS_TYPE_F32);
     127
     128        // the underlying field is f = ix + iy, where ix,iy are fine pixel coordinates
     129        // place the measurement points exactly on the ruff reference pixel centers
     130        int n = 0;
     131        for (float ix = 1.0; ix < 6; ix += 2.0) {
     132            for (float iy = 1.0; iy < 6; iy += 2.0) {
    64133                if ((ix == 3.0) && (iy == 1.0)) {
    65134                    x->data.F32[n] = ix + 0.0;
    66135                    y->data.F32[n] = iy + 0.1; // add in both points. 
    67                     f->data.F32[n] = ix + iy;
     136                    f->data.F32[n] = x->data.F32[n] + y->data.F32[n];
    68137                    n++;
    69138                    x->data.F32[n] = ix + 0.0;
     
    73142                    y->data.F32[n] = iy;
    74143                }
    75                 # endif
    76                 f->data.F32[n] = ix + iy;
     144                f->data.F32[n] = x->data.F32[n] + y->data.F32[n];
    77145                n++;
    78146            }
     
    82150        f->n = n;
    83151
    84         psImage *field = psImageAlloc(3, 2, PS_TYPE_F32);
    85         for (int ix = 0; ix < 3; ix++) {
    86             for (int iy = 0; iy < 2; iy++) {
     152        psImage *field = psImageAlloc(6, 6, PS_TYPE_F32);
     153        for (int ix = 0; ix < 6; ix++) {
     154            for (int iy = 0; iy < 6; iy++) {
    87155                field->data.F32[iy][ix] = (ix + 0.5) + (iy + 0.5);
    88156            }
     
    114182    # endif
    115183
    116     // test for more points: 3x3 grid fitted to 9 points with simple slope and scale difference
    117     # if (TEST_9PT_2)
     184    // still a simple test: 3x3 grid fitted to 9 points with simple slope and scale difference
     185    # if (TEST_9PT_1)
    118186    {
    119187        psImageBinning *binning = psImageBinningAlloc();
     
    124192
    125193        // generate a grid of test data points
    126         psVector *x = psVectorAlloc (50, PS_TYPE_F32);
    127         psVector *y = psVectorAlloc (50, PS_TYPE_F32);
    128         psVector *f = psVectorAlloc (50, PS_TYPE_F32);
    129 
    130         // the underlying field is f = ix + iy, where ix,iy are fine pixel coordinates
    131         // place the measurement points exactly on the ruff reference pixel centers
    132         int n = 0;
    133         for (float ix = 1.0; ix < 6; ix += 2.0) {
    134             for (int iy = 1.0; iy < 6; iy += 2.0) {
    135                 if ((ix == 3.0) && (iy == 1.0)) {
    136                     x->data.F32[n] = ix + 0.0;
    137                     y->data.F32[n] = iy + 0.1; // add in both points. 
    138                     f->data.F32[n] = ix + iy;
    139                     n++;
    140                     x->data.F32[n] = ix + 0.0;
    141                     y->data.F32[n] = iy - 0.1;
    142                 } else {
    143                     x->data.F32[n] = ix;
    144                     y->data.F32[n] = iy;
    145                 }
    146                 f->data.F32[n] = ix + iy;
    147                 n++;
    148             }
    149         }
    150         x->n = n;
    151         y->n = n;
    152         f->n = n;
    153 
    154         psImage *field = psImageAlloc(6, 6, PS_TYPE_F32);
    155         for (int ix = 0; ix < 6; ix++) {
    156             for (int iy = 0; iy < 6; iy++) {
    157                 field->data.F32[iy][ix] = (ix + 0.5) + (iy + 0.5);
    158             }
    159         }
    160 
    161         psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN);
    162 
    163         // scale defines both field and map image sizes (nXfine, nXruff)
    164         psImageMap *map = psImageMapAlloc (NULL, binning, stats);
    165 
    166         // fit the data to the map
    167         psImageMapFit (map, x, y, f, NULL);
    168         psFree (binning);
    169 
    170         SaveImage (NULL, map->map, "map.fits");
    171        
    172         SaveImage (NULL, field, "field.fits");
    173 
    174         psImage *model = psImageAlloc(field->numCols, field->numRows, PS_TYPE_F32);
    175         for (int ix = 0; ix < model->numCols; ix++) {
    176             for (int iy = 0; iy < model->numRows; iy++) {
    177                 model->data.F32[iy][ix] = psImageUnbinPixel_V2 (ix + 0.5, iy + 0.5, map->map, map->binning);
    178                 is_float_tol (model->data.F32[iy][ix], field->data.F32[iy][ix], FLT_EPSILON, "model matches inputs");
    179             }
    180         }
    181         SaveImage (NULL, model, "model.fits");
    182         // ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
    183     }
    184     # endif
    185 
    186     // still a simple test: 3x3 grid fitted to 9 points with simple slope and scale difference
    187     # if (TEST_9PT_1)
    188     {
    189         psImageBinning *binning = psImageBinningAlloc();
    190         binning->nXfine = 6;
    191         binning->nYfine = 6;
    192         binning->nXruff = 3;
    193         binning->nYruff = 3;
    194 
    195         // generate a grid of test data points
    196194        psVector *x = psVectorAlloc (9, PS_TYPE_F32);
    197195        psVector *y = psVectorAlloc (9, PS_TYPE_F32);
     
    205203                x->data.F32[n] = ix;
    206204                y->data.F32[n] = iy;
    207                 f->data.F32[n] = ix + iy;
     205                f->data.F32[n] = x->data.F32[n] + y->data.F32[n];
    208206                n++;
    209207            }
     
    263261                x->data.F32[n] = ix + 0.5;
    264262                y->data.F32[n] = iy + 0.5;
    265                 f->data.F32[n] = ix + iy;
     263                f->data.F32[n] = x->data.F32[n] + y->data.F32[n];
    266264                field->data.F32[iy][ix] = f->data.F32[n];
    267265                n++;
     
    377375            for (int iy = 0; iy < 2; iy++) {
    378376                // add in one extra point on the surface
     377                if (!ix && !iy) {
     378                    x->data.F32[n] = ix + 0.5;
     379                    y->data.F32[n] = iy + 0.5 + 0.1;
     380                } else {
     381                    x->data.F32[n] = ix + 0.5;
     382                    y->data.F32[n] = iy + 0.5;
     383                }
     384                # if (0)
    379385                if (ix) {
    380386                    x->data.F32[n] = ix + 0.5 - 0.1;
     
    387393                    y->data.F32[n] = iy + 0.5 + 0.1;
    388394                }
     395                # endif
    389396                f->data.F32[n] = x->data.F32[n] + y->data.F32[n];
    390397                field->data.F32[iy][ix] = ix + 0.5 + iy + 0.5;
     
    439446                x->data.F32[n] = ix;
    440447                y->data.F32[n] = iy;
    441                 f->data.F32[n] = ix + iy;
     448                f->data.F32[n] = x->data.F32[n] + y->data.F32[n];
    442449                n++;
    443450            }
Note: See TracChangeset for help on using the changeset viewer.