Changeset 29471
- Timestamp:
- Oct 17, 2010, 12:18:12 PM (16 years ago)
- Location:
- branches/eam_branches/ipp-20100823/psModules/test/objects
- Files:
-
- 2 edited
-
Makefile.am (modified) (1 diff)
-
tap_pmSourceMoments.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20100823/psModules/test/objects/Makefile.am
r15985 r29471 24 24 tap_pmSourceExtendedPars \ 25 25 tap_pmSourceSky \ 26 tap_pmSourceMoments \ 26 27 tap_pmSourceIO_PS1_DEV_0 \ 27 28 tap_pmSourceIO_PS1_DEV_1 \ -
branches/eam_branches/ipp-20100823/psModules/test/objects/tap_pmSourceMoments.c
r29444 r29471 9 9 #define ERR_TRACE_LEVEL 0 10 10 11 # define GAIN 1.0 12 # define RDNOISE 10.0 13 11 14 float Gaussian(float Io, float sigma, float Xc, float Yc, int ix, int iy); 15 bool MakeGaussian (pmSource *source, float Io, float sigma, float Xc, float Yc); 16 bool MakeGaussianNoNoise (pmSource *source, float Io, float sigma, float Xc, float Yc); 17 double ppSimRandomGaussianNorm (void); 18 double ppSimRandomGaussian (double mean, double sigma); 19 20 bool GaussiansWindowsAndTopHatsNoNoise (pmSource *source, float Io, float sigma, float Xc, float Yc); 21 bool GaussiansWindowsAndTopHats (pmSource *source, float Io, float sigma, float Xc, float Yc); 22 bool CentroidWithGuessOffset (pmSource *source, float Io, float sigma, float Xc, float Yc, float dX, float dY); 23 bool CentroidWithGuessOffsetIterate (pmSource *source, float Io, float sigma, float Xc, float Yc, float dX, float dY); 12 24 13 25 int main(int argc, char* argv[]) … … 19 31 20 32 // ---------------------------------------------------------------------- 21 // pmSourceMomentsGetCentroid() tests 33 // pmSourceMomentsGetCentroid() tests (no noise) 22 34 { 23 35 psMemId id = psMemGetId(); … … 27 39 ok(source, "source allocated"); 28 40 41 bool status = true; 42 29 43 // need to have: peak, pixels, variance, 30 44 int Nx = 100; … … 32 46 float Xc = 52.0; 33 47 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); 37 52 source->moments = pmMomentsAlloc(); 38 53 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; 45 70 } 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"); 48 82 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 49 83 } 50 84 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 116 bool 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 136 bool 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 151 bool 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 188 bool 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 225 bool 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 242 bool 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; 51 258 } 52 259 … … 59 266 return value; 60 267 } 268 269 /// **** this stuff should be in psLib -- it is too useful... 270 271 static int Ngaussint = 0; 272 static double *gaussint = NULL; 273 274 extern double drand48(); 275 276 double 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 286 void ppSimRandomGaussianFree() 287 { 288 psFree (gaussint); 289 return; 290 } 291 292 void 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 */ 299 void 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 338 double 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 356 double 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.
