IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 17, 2007, 10:17:21 AM (19 years ago)
Author:
magnier
Message:

added errors to psImageMap, NaN for unconstrained pixels in output map

File:
1 edited

Legend:

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

    r14863 r14864  
    2525# define TEST_9PT_3 1
    2626# define TEST_9PT_4 1
     27# define TEST_9PT_5 1
    2728
    2829int main (void)
    2930{
    3031
    31     plan_tests(1);
     32    plan_tests(219);
    3233   
    3334    // *** tests to demonstrate the validity of the algorithm or concept ***
     35
     36    // test with unconstrained cell: 3x3 grid fitted to 8 points with simple slope and scale difference
     37    # if (TEST_9PT_5)
     38    {
     39        psMemId id = psMemGetId();
     40
     41        psImageBinning *binning = psImageBinningAlloc();
     42        binning->nXfine = 6;
     43        binning->nYfine = 6;
     44        binning->nXruff = 3;
     45        binning->nYruff = 3;
     46
     47        // generate a grid of test data points
     48        psVector *x = psVectorAlloc (50, PS_TYPE_F32);
     49        psVector *y = psVectorAlloc (50, PS_TYPE_F32);
     50        psVector *f = psVectorAlloc (50, PS_TYPE_F32);
     51
     52        // the underlying field is f = ix + iy, where ix,iy are fine pixel coordinates
     53        // place the measurement points exactly on the ruff reference pixel centers
     54        int n = 0;
     55        for (float ix = 1.0; ix < 6.0; ix += 2.0) {
     56            for (float iy = 1.0; iy < 6.0; iy += 2.0) {
     57                if ((ix == 1.0) && (iy == 1.0)) continue;
     58                x->data.F32[n] = ix;
     59                y->data.F32[n] = iy;
     60                f->data.F32[n] = x->data.F32[n] + y->data.F32[n];
     61                n++;
     62            }
     63        }
     64        x->n = n;
     65        y->n = n;
     66        f->n = n;
     67
     68        psImage *field = psImageAlloc(6, 6, PS_TYPE_F32);
     69        for (int ix = 0; ix < 6; ix++) {
     70            for (int iy = 0; iy < 6; iy++) {
     71                field->data.F32[iy][ix] = (ix + 0.5) + (iy + 0.5);
     72            }
     73        }
     74
     75        psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN);
     76
     77        // scale defines both field and map image sizes (nXfine, nXruff)
     78        psImageMap *map = psImageMapAlloc (NULL, binning, stats);
     79
     80        // fit the data to the map
     81        psImageMapFit (map, x, y, f, NULL);
     82
     83        psImage *model = psImageAlloc(field->numCols, field->numRows, PS_TYPE_F32);
     84        for (int ix = 0; ix < model->numCols; ix++) {
     85            for (int iy = 0; iy < model->numRows; iy++) {
     86                model->data.F32[iy][ix] = psImageUnbinPixel_V2 (ix + 0.5, iy + 0.5, map->map, map->binning);
     87                if ((ix < 3) && (iy < 3)) {
     88                    is_float (model->data.F32[iy][ix], NAN, "model matches expected NaN");
     89                } else {
     90                    is_float_tol (model->data.F32[iy][ix], field->data.F32[iy][ix], 1e-5, "model matches inputs");
     91                }
     92            }
     93        }
     94
     95        SaveImage (NULL, map->map, "map.fits");
     96        SaveImage (NULL, field, "field.fits");
     97        SaveImage (NULL, model, "model.fits");
     98
     99        psFree (model);
     100        psFree (binning);
     101        psFree (map);
     102        psFree (stats);
     103        psFree (field);
     104        psFree (x);
     105        psFree (y);
     106        psFree (f);
     107        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     108    }
     109    # endif
    34110
    35111    // test for more points: 3x3 grid fitted to 9 points with simple slope and scale difference
Note: See TracChangeset for help on using the changeset viewer.