IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 29471


Ignore:
Timestamp:
Oct 17, 2010, 12:18:12 PM (16 years ago)
Author:
eugene
Message:

updates to tests

Location:
branches/eam_branches/ipp-20100823/psModules/test/objects
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20100823/psModules/test/objects/Makefile.am

    r15985 r29471  
    2424        tap_pmSourceExtendedPars \
    2525        tap_pmSourceSky \
     26        tap_pmSourceMoments \
    2627        tap_pmSourceIO_PS1_DEV_0 \
    2728        tap_pmSourceIO_PS1_DEV_1 \
  • branches/eam_branches/ipp-20100823/psModules/test/objects/tap_pmSourceMoments.c

    r29444 r29471  
    99#define ERR_TRACE_LEVEL         0
    1010
     11# define GAIN 1.0
     12# define RDNOISE 10.0
     13
    1114float Gaussian(float Io, float sigma, float Xc, float Yc, int ix, int iy);
     15bool MakeGaussian (pmSource *source, float Io, float sigma, float Xc, float Yc);
     16bool MakeGaussianNoNoise (pmSource *source, float Io, float sigma, float Xc, float Yc);
     17double ppSimRandomGaussianNorm (void);
     18double ppSimRandomGaussian (double mean, double sigma);
     19
     20bool GaussiansWindowsAndTopHatsNoNoise (pmSource *source, float Io, float sigma, float Xc, float Yc);
     21bool GaussiansWindowsAndTopHats (pmSource *source, float Io, float sigma, float Xc, float Yc);
     22bool CentroidWithGuessOffset (pmSource *source, float Io, float sigma, float Xc, float Yc, float dX, float dY);
     23bool CentroidWithGuessOffsetIterate (pmSource *source, float Io, float sigma, float Xc, float Yc, float dX, float dY);
    1224
    1325int main(int argc, char* argv[])
     
    1931
    2032    // ----------------------------------------------------------------------
    21     // pmSourceMomentsGetCentroid() tests
     33    // pmSourceMomentsGetCentroid() tests (no noise)
    2234    {
    2335        psMemId id = psMemGetId();
     
    2739        ok(source, "source allocated");
    2840       
     41        bool status = true;
     42
    2943        // need to have: peak, pixels, variance,
    3044        int Nx = 100;
     
    3246        float Xc = 52.0;
    3347        float Yc = 48.0;
    34         float Io = 1000.0;
    35 
    36         source->peak = pmPeakAlloc(Xc, Yc, Io, PS_PEAK_LONE);
     48        float Io = 100.0;
     49        float sigma = 4.0 / 2.35;
     50
     51        source->peak = pmPeakAlloc(Xc, Yc, Io, PM_PEAK_LONE);
    3752        source->moments = pmMomentsAlloc();
    3853        source->pixels = psImageAlloc(Nx, Ny, PS_TYPE_F32);
    39        
    40         // populate the pixels with an object (Gaussian with Io, sigma)
    41         for (int iy = 0; iy < source->pixels->numRows; iy++) {
    42           for (int ix = 0; ix < source->pixels->numCols; ix++) {
    43             source->pixels->data.F32[iy][ix] = Gaussian(Io, sigma, Xc, Yc, ix, iy);
    44           }
     54        source->variance = psImageAlloc(Nx, Ny, PS_TYPE_F32);
     55       
     56        // CentroidWithGuessOffset(source, Io, sigma, Xc, Yc, 0.0, 0.0);
     57        // CentroidWithGuessOffset(source, Io, sigma, Xc, Yc, 0.1, 0.0);
     58        // CentroidWithGuessOffset(source, Io, sigma, Xc, Yc, 0.0, 0.1);
     59        // CentroidWithGuessOffset(source, Io, sigma, Xc, Yc, 0.1, 0.1);
     60        // CentroidWithGuessOffset(source, Io, sigma, Xc, Yc, 0.3, 0.3);
     61        // CentroidWithGuessOffset(source, Io, sigma, Xc, Yc, 0.5, 0.5);
     62
     63        psVector *dX = psVectorAlloc(100, PS_TYPE_F32);
     64        psVector *dY = psVectorAlloc(100, PS_TYPE_F32);
     65
     66        for (int i = 0; i < dX->n; i++) {
     67            CentroidWithGuessOffsetIterate(source, Io, sigma, Xc, Yc, 1.0, 0.0);
     68            dX->data.F32[i] = Xc - source->moments->Mx;
     69            dY->data.F32[i] = Yc - source->moments->My;
    4570        }
    46 
    47         psFree(growthCurve);
     71        psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_STDEV);
     72
     73        psVectorStats (stats, dX, NULL, 0, 0);
     74        fprintf (stderr, "dX stats: %f +/- %f\n", stats->sampleMean, stats->sampleStdev);
     75        psStatsInit(stats);
     76       
     77        psVectorStats (stats, dY, NULL, 0, 0);
     78        fprintf (stderr, "dY stats: %f +/- %f\n", stats->sampleMean, stats->sampleStdev);
     79        psStatsInit(stats);
     80       
     81        ok(status, "measured centroid");
    4882        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
    4983    }
    5084
     85    // ----------------------------------------------------------------------
     86    // pmSourceMomentsGetCentroid() tests (standard noise)
     87    if (0) {
     88        psMemId id = psMemGetId();
     89
     90        // generate a sample source (no noise)
     91        pmSource *source = pmSourceAlloc();
     92        ok(source, "source allocated");
     93       
     94        bool status = true;
     95
     96        // need to have: peak, pixels, variance,
     97        int Nx = 100;
     98        int Ny = 100;
     99        float Xc = 52.0;
     100        float Yc = 48.0;
     101        float Io = 100000.0;
     102        float sigma = 4.0 / 2.35;
     103
     104        source->peak = pmPeakAlloc(Xc, Yc, Io, PM_PEAK_LONE);
     105        source->moments = pmMomentsAlloc();
     106        source->pixels = psImageAlloc(Nx, Ny, PS_TYPE_F32);
     107        source->variance = psImageAlloc(Nx, Ny, PS_TYPE_F32);
     108       
     109        GaussiansWindowsAndTopHats(source, Io, sigma, Xc + 0.0, Yc + 0.0);
     110
     111        ok(status, "measured centroid (window)");
     112        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     113    }
     114}
     115
     116bool CentroidWithGuessOffsetIterate (pmSource *source, float Io, float sigma, float Xc, float Yc, float dX, float dY) {
     117
     118    // pmSourceMomentsGetCentroid(source, radius, sigma, minSN, maskVal)
     119    source->peak->xf = Xc + dX;
     120    source->peak->yf = Yc + dY;
     121
     122    // MakeGaussianNoNoise (source, Io, sigma, Xc, Yc);
     123    MakeGaussian (source, Io, sigma, Xc, Yc);
     124
     125    // pmSourceMomentsGetCentroid(source, 10.0, 15.0 / 2.35, 0.0, 0);
     126    pmSourceMomentsGetCentroid(source, 8.0, 0.0, 0.0, 0);
     127    source->peak->xf = source->moments->Mx;
     128    source->peak->yf = source->moments->My;
     129    // fprintf (stderr, "%f,%f vs %f,%f : %f,%f -> %f,%f (SN = %f) ", Xc, Yc, source->moments->Mx, source->moments->My, dX, dY, Xc - source->moments->Mx, Yc - source->moments->My, source->moments->SN);
     130
     131    pmSourceMomentsGetCentroid(source, 10.0, 8.0/2.35, 0.0, 0);
     132    // fprintf (stderr, "  ---> %f,%f\n", Xc - source->moments->Mx, Yc - source->moments->My);
     133    return true;
     134}
     135
     136bool CentroidWithGuessOffset (pmSource *source, float Io, float sigma, float Xc, float Yc, float dX, float dY) {
     137
     138    // pmSourceMomentsGetCentroid(source, radius, sigma, minSN, maskVal)
     139    source->peak->xf = Xc + dX;
     140    source->peak->yf = Yc + dY;
     141
     142    // MakeGaussianNoNoise (source, Io, sigma, Xc, Yc);
     143    MakeGaussian (source, Io, sigma, Xc, Yc);
     144
     145    // pmSourceMomentsGetCentroid(source, 10.0, 15.0 / 2.35, 0.0, 0);
     146    pmSourceMomentsGetCentroid(source, 8.0, 0.0, 0.0, 0);
     147    fprintf (stderr, "%f,%f vs %f,%f : %f,%f -> %f,%f (SN = %f)\n", Xc, Yc, source->moments->Mx, source->moments->My, dX, dY, Xc - source->moments->Mx, Yc - source->moments->My, source->moments->SN);
     148    return true;
     149}
     150
     151bool GaussiansWindowsAndTopHatsNoNoise (pmSource *source, float Io, float sigma, float Xc, float Yc) {
     152
     153    // pmSourceMomentsGetCentroid(source, radius, sigma, minSN, maskVal)
     154    source->peak->xf = Xc;
     155    source->peak->yf = Yc;
     156
     157    MakeGaussianNoNoise (source, Io, sigma, Xc, Yc);
     158    pmSourceMomentsGetCentroid(source, 8.0, 0.0, 0.0, 0);
     159    fprintf (stderr, "%f,%f vs %f,%f = %f,%f\n", Xc, Yc, source->moments->Mx, source->moments->My, Xc - source->moments->Mx, Yc - source->moments->My);
     160
     161    pmSourceMomentsGetCentroid(source, 10.0, 0.0, 0.0, 0);
     162    fprintf (stderr, "%f,%f vs %f,%f = %f,%f\n", Xc, Yc, source->moments->Mx, source->moments->My, Xc - source->moments->Mx, Yc - source->moments->My);
     163
     164    pmSourceMomentsGetCentroid(source, 15.0, 0.0, 0.0, 0);
     165    fprintf (stderr, "%f,%f vs %f,%f = %f,%f\n", Xc, Yc, source->moments->Mx, source->moments->My, Xc - source->moments->Mx, Yc - source->moments->My);
     166
     167    pmSourceMomentsGetCentroid(source, 20.0, 0.0, 0.0, 0);
     168    fprintf (stderr, "%f,%f vs %f,%f = %f,%f\n", Xc, Yc, source->moments->Mx, source->moments->My, Xc - source->moments->Mx, Yc - source->moments->My);
     169
     170    ok(true, "measured centroid (tophat)");
     171
     172    pmSourceMomentsGetCentroid(source,  8.0, 8.0 / 2.35, 0.0, 0);
     173    fprintf (stderr, "%f,%f vs %f,%f = %f,%f\n", Xc, Yc, source->moments->Mx, source->moments->My, Xc - source->moments->Mx, Yc - source->moments->My);
     174
     175    pmSourceMomentsGetCentroid(source, 10.0, 8.0 / 2.35, 0.0, 0);
     176    fprintf (stderr, "%f,%f vs %f,%f = %f,%f\n", Xc, Yc, source->moments->Mx, source->moments->My, Xc - source->moments->Mx, Yc - source->moments->My);
     177
     178    pmSourceMomentsGetCentroid(source, 15.0, 8.0 / 2.35, 0.0, 0);
     179    fprintf (stderr, "%f,%f vs %f,%f = %f,%f\n", Xc, Yc, source->moments->Mx, source->moments->My, Xc - source->moments->Mx, Yc - source->moments->My);
     180
     181    pmSourceMomentsGetCentroid(source, 20.0, 8.0 / 2.35, 0.0, 0);
     182    fprintf (stderr, "%f,%f vs %f,%f = %f,%f\n", Xc, Yc, source->moments->Mx, source->moments->My, Xc - source->moments->Mx, Yc - source->moments->My);
     183
     184    ok(true, "measured centroid (window)");
     185    return true;
     186}
     187
     188bool GaussiansWindowsAndTopHats (pmSource *source, float Io, float sigma, float Xc, float Yc) {
     189
     190    // pmSourceMomentsGetCentroid(source, radius, sigma, minSN, maskVal)
     191    source->peak->xf = Xc;
     192    source->peak->yf = Yc;
     193
     194    MakeGaussian (source, Io, sigma, Xc, Yc);
     195    pmSourceMomentsGetCentroid(source, 8.0, 0.0, 0.0, 0);
     196    fprintf (stderr, "%f,%f vs %f,%f = %f,%f\n", Xc, Yc, source->moments->Mx, source->moments->My, Xc - source->moments->Mx, Yc - source->moments->My);
     197
     198    pmSourceMomentsGetCentroid(source, 10.0, 0.0, 0.0, 0);
     199    fprintf (stderr, "%f,%f vs %f,%f = %f,%f\n", Xc, Yc, source->moments->Mx, source->moments->My, Xc - source->moments->Mx, Yc - source->moments->My);
     200
     201    pmSourceMomentsGetCentroid(source, 15.0, 0.0, 0.0, 0);
     202    fprintf (stderr, "%f,%f vs %f,%f = %f,%f\n", Xc, Yc, source->moments->Mx, source->moments->My, Xc - source->moments->Mx, Yc - source->moments->My);
     203
     204    pmSourceMomentsGetCentroid(source, 20.0, 0.0, 0.0, 0);
     205    fprintf (stderr, "%f,%f vs %f,%f = %f,%f\n", Xc, Yc, source->moments->Mx, source->moments->My, Xc - source->moments->Mx, Yc - source->moments->My);
     206
     207    ok(true, "measured centroid (tophat)");
     208
     209    pmSourceMomentsGetCentroid(source,  8.0, 8.0 / 2.35, 0.0, 0);
     210    fprintf (stderr, "%f,%f vs %f,%f = %f,%f\n", Xc, Yc, source->moments->Mx, source->moments->My, Xc - source->moments->Mx, Yc - source->moments->My);
     211
     212    pmSourceMomentsGetCentroid(source, 10.0, 8.0 / 2.35, 0.0, 0);
     213    fprintf (stderr, "%f,%f vs %f,%f = %f,%f\n", Xc, Yc, source->moments->Mx, source->moments->My, Xc - source->moments->Mx, Yc - source->moments->My);
     214
     215    pmSourceMomentsGetCentroid(source, 15.0, 8.0 / 2.35, 0.0, 0);
     216    fprintf (stderr, "%f,%f vs %f,%f = %f,%f\n", Xc, Yc, source->moments->Mx, source->moments->My, Xc - source->moments->Mx, Yc - source->moments->My);
     217
     218    pmSourceMomentsGetCentroid(source, 20.0, 8.0 / 2.35, 0.0, 0);
     219    fprintf (stderr, "%f,%f vs %f,%f = %f,%f\n", Xc, Yc, source->moments->Mx, source->moments->My, Xc - source->moments->Mx, Yc - source->moments->My);
     220
     221    ok(true, "measured centroid (window)");
     222    return true;
     223}
     224
     225bool MakeGaussianNoNoise (pmSource *source, float Io, float sigma, float Xc, float Yc) {
     226
     227  psImageInit(source->pixels, 0.0);
     228  psImageInit(source->variance, 0.0);
     229
     230  // populate the pixels with an object (Gaussian with Io, sigma)
     231  for (int iy = 0; iy < source->pixels->numRows; iy++) {
     232    for (int ix = 0; ix < source->pixels->numCols; ix++) {
     233      source->pixels->data.F32[iy][ix] = Gaussian(Io * GAIN, sigma, Xc, Yc, ix, iy);
     234      source->variance->data.F32[iy][ix] = source->pixels->data.F32[iy][ix] + PS_SQR(RDNOISE); // RDNOISE and initial signal in electrons
     235      source->pixels->data.F32[iy][ix] /= GAIN;
     236      source->variance->data.F32[iy][ix] /= GAIN;
     237    }
     238  }
     239  return true;
     240}
     241
     242bool MakeGaussian (pmSource *source, float Io, float sigma, float Xc, float Yc) {
     243
     244  psImageInit(source->pixels, 0.0);
     245  psImageInit(source->variance, 0.0);
     246
     247  // populate the pixels with an object (Gaussian with Io, sigma)
     248  for (int iy = 0; iy < source->pixels->numRows; iy++) {
     249    for (int ix = 0; ix < source->pixels->numCols; ix++) {
     250      source->pixels->data.F32[iy][ix] = Gaussian(Io * GAIN, sigma, Xc, Yc, ix, iy);
     251      source->variance->data.F32[iy][ix] = source->pixels->data.F32[iy][ix] + PS_SQR(RDNOISE); // RDNOISE and initial signal in electrons
     252      source->pixels->data.F32[iy][ix] += sqrtf(source->variance->data.F32[iy][ix]) * ppSimRandomGaussianNorm();
     253      source->pixels->data.F32[iy][ix] /= GAIN;
     254      source->variance->data.F32[iy][ix] /= GAIN;
     255    }
     256  }
     257  return true;
    51258}
    52259
     
    59266  return value;
    60267}
     268
     269/// **** this stuff should be in psLib -- it is too useful...
     270
     271static int Ngaussint = 0;
     272static double *gaussint = NULL;
     273
     274extern double drand48();
     275
     276double p_ppSimGaussian (double x, double mean, double sigma) {
     277
     278  double f;
     279
     280  f = exp (-0.5 * PS_SQR(x - mean) / PS_SQR(sigma)) / sqrt(2 * M_PI * PS_SQR(sigma));
     281
     282  return (f);
     283
     284}
     285
     286void ppSimRandomGaussianFree()
     287{
     288    psFree (gaussint);
     289    return;
     290}
     291
     292void ppSimRandomGaussianAlloc (int Nbin) {
     293
     294    gaussint = (double *) psAlloc(Nbin*sizeof(double));
     295    return;
     296}
     297
     298/* integrate a gaussian from -5 sigma to +5 sigma */
     299void p_ppSimRandomGaussianInit (void) {
     300
     301  int i;
     302  long A, B;
     303  double val, x, dx, dx1, dx2, dx3, df;
     304  double mean, sigma;
     305
     306  /* no need to generate this if it already exists */
     307  if (gaussint) return;
     308
     309  A = time(NULL);
     310  for (B = 0; A == time(NULL); B++);
     311  srand48(B);
     312
     313  Ngaussint = 0x1000;
     314  ppSimRandomGaussianAlloc (Ngaussint + 1);
     315
     316  val = 0;
     317  dx = 1.0 / Ngaussint;
     318  dx1 = dx / 3.0;
     319  dx2 = 2.0*dx/3.0;
     320  dx3 = dx;
     321  mean = 0.0;
     322  sigma = 1.0;
     323
     324  for (i = 0, x = -7.0; (i < Ngaussint) && (x < 7.0); x += dx)  {
     325    df = (3.0*p_ppSimGaussian(x    , mean, sigma) +
     326          9.0*p_ppSimGaussian(x+dx1, mean, sigma) +
     327          9.0*p_ppSimGaussian(x+dx2, mean, sigma) +
     328          3.0*p_ppSimGaussian(x+dx3, mean, sigma)) * (dx1/8.0);
     329    val += df;
     330    if (val > (i + 0.5) / (double) Ngaussint) {
     331      gaussint[i] = x + dx / 2.0;
     332      i++;
     333    }
     334  }
     335}
     336
     337// XXX we are using drand48() rather than the random var supplied by rnd
     338double ppSimRandomGaussian (double mean, double sigma) {
     339
     340  int i;
     341  double y;
     342
     343  if (gaussint == NULL) {
     344      p_ppSimRandomGaussianInit ();
     345  }
     346
     347  y = drand48();
     348  i = Ngaussint*y;
     349  y = gaussint[i]*sigma + mean;
     350
     351  return (y);
     352
     353}
     354
     355// XXX we are using drand48() rather than the random var supplied by rnd
     356double ppSimRandomGaussianNorm (void) {
     357
     358  int i;
     359  double y;
     360
     361  if (gaussint == NULL) {
     362      p_ppSimRandomGaussianInit ();
     363  }
     364
     365  y = drand48();
     366  i = Ngaussint*y;
     367  y = gaussint[i];
     368
     369  return (y);
     370}
Note: See TracChangeset for help on using the changeset viewer.