Changeset 41341 for trunk/Ohana/src/opihi/cmd.data/test/medimage.sh
- Timestamp:
- Apr 16, 2020, 2:04:27 PM (6 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/cmd.data/test/medimage.sh (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/cmd.data/test/medimage.sh
r41340 r41341 1 1 2 macro go 3 mcreate a 30 30 4 for i 0 40 5 set a$i = zero(a) + $i 6 end 7 8 for i 0 40 9 medimage add t1 a$i 10 end 11 end 2 macro test.mean 3 4 $Nsample = 16 5 medimage delete -q t1 6 for i 0 $Nsample 7 mgaussdev t 50 50 0.0 1.0 8 medimage add t1 t 9 imhist -q t x y -range -10 10 -delta 0.1 10 11 $C0 = 0 12 $C1 = 1.5 13 $C2 = 400 14 $C3 = 0 15 vgauss -q x y con yf 16 # echo $C1 17 end 18 19 medimage calc t1 T -mean 20 21 imhist -q T x y -range -10 10 -delta 0.1 22 lim -n 1 x y; clear; box; plot -x hist x y 23 $C0 = 0 24 $C1 = 1.5 25 $C2 = 400 26 $C3 = 0 27 vgauss -q x y con yf 28 echo "expect {1/sqrt($Nsample)} : $C1" 29 plot -c red -x line x yf 30 end 31 32 macro test.median 33 34 $Nsample = 16 35 medimage delete -q t1 36 for i 0 $Nsample 37 mgaussdev t 50 50 0.0 1.0 38 medimage add t1 t 39 imhist -q t x y -range -10 10 -delta 0.1 40 41 $C0 = 0 42 $C1 = 1.5 43 $C2 = 400 44 $C3 = 0 45 vgauss -q x y con yf 46 end 47 48 # note that median of a gaussian distributed variable is not distributed with sigma' = sigma / sqrt(N) 49 # (somewhat higher scatter) 50 medimage calc t1 T 51 52 imhist -q T x y -range -10 10 -delta 0.1 53 lim -n 1 x y; clear; box; plot -x hist x y 54 $C0 = 0 55 $C1 = 1.5 56 $C2 = 400 57 $C3 = 0 58 vgauss -q x y con yf 59 echo "expect {1/sqrt($Nsample)} : $C1 (actually should be a bit higher)" 60 plot -c red -x line x yf 61 end 62 63 macro test.wtmean 64 65 $Nsample = 8 66 $sig1 = 1.0 67 $sig2 = 3.0 68 69 medimage delete -q t1 70 for i 0 $Nsample 71 mgaussdev t 50 50 0.0 $sig1 72 set v = $sig1^2 + zero(t) 73 medimage add t1 t -variance v 74 imhist -q t x y -range -10 10 -delta 0.1 75 76 $C0 = 0 77 $C1 = 1.5 78 $C2 = 400 79 $C3 = 0 80 vgauss -q x y con yf 81 # echo $C1 82 end 83 84 for i 0 $Nsample 85 mgaussdev t 50 50 0.0 $sig2 86 set v = $sig2^2 + zero(t) 87 medimage add t1 t -variance v 88 imhist -q t x y -range -10 10 -delta 0.1 89 90 $C0 = 0 91 $C1 = 1.5 92 $C2 = 400 93 $C3 = 0 94 vgauss -q x y con yf 95 # echo $C1 96 end 97 98 # note that median of a gaussian distributed variable is not distributed with sigma' = sigma / sqrt(N) 99 # (somewhat higher scatter) 100 medimage calc t1 T -wtmean 101 102 imhist -q T x y -range -10 10 -delta 0.1 103 lim -n 1 x y; clear; box; plot -x hist x y 104 $C0 = 0 105 $C1 = 1.5 106 $C2 = 400 107 $C3 = 0 108 vgauss -q x y con yf 109 $S1 = $Nsample / $sig1^2 + $Nsample / $sig2^2 110 echo "expect {1/sqrt($S1)} : $C1" 111 plot -c red -x line x yf 112 end 113 114 macro test.irls 115 medimage delete -q t1 116 $Nsample = 16 117 $sig = 1.0 118 for i 0 $Nsample 119 mgaussdev t 50 50 0.0 $sig 120 set v = $sig^2 + zero(t) 121 122 set bad = (rnd(t) < 0.05) ? 10*rnd(t) + 5 : zero(t) 123 set ts = t + bad 124 125 medimage add t1 ts -variance v 126 imhist -q t x y -range -10 10 -delta 0.1 127 128 $C0 = 0 129 $C1 = 1.5 130 $C2 = 400 131 $C3 = 0 132 vgauss -q x y con yf 133 # echo $C1 134 end 135 136 # get stats for straight mean: 137 medimage calc t1 Tm -mean 138 139 imhist -q Tm x y -range -10 10 -delta 0.1 140 lim -n 1 x y; clear; box; plot -x hist x y 141 $C0 = 0 142 $C1 = 1.5 143 $C2 = 400 144 $C3 = 0 145 vgauss -q x y con yf 146 echo "sigma from straight stdev: $C1" 147 # stats Tm 148 149 plot -c red -x line x yf 150 151 # get stats for irls 152 medimage calc t1 Ti -irls 153 154 imhist -q Ti x y -range -10 10 -delta 0.1 155 lim -n 2 x y; clear; box; plot -x hist x y 156 $C0 = 0 157 $C1 = 1.5 158 $C2 = 400 159 $C3 = 0 160 vgauss -q x y con yf 161 echo "sigma from irls: $C1 (ideal is {$sig/sqrt($Nsample)})" 162 # stats Ti 163 164 plot -c red -x line x yf 165 end 166 167 168 ###################33 169 170 171 macro test.mean.var 172 173 $Nsample = 64 174 $sig = 2.0 175 medimage delete -q t1 176 for i 0 $Nsample 177 mgaussdev t 100 100 0.0 $sig 178 medimage add t1 t 179 imhist -q t x y -range -10 10 -delta 0.1 180 181 $C0 = 0 182 $C1 = 1.5 183 $C2 = 400 184 $C3 = 0 185 vgauss -q x y con yf 186 # echo $C1 187 end 188 189 medimage calc t1 T -mean -variance Tv 190 191 imhist -q T x y -range -10 10 -delta 0.1 192 lim -n 1 x y; clear; box; plot -x hist x y 193 $C0 = 0 194 $C1 = 1.5 195 $C2 = 400 196 $C3 = 0 197 vgauss -q x y con yf 198 plot -c red -x line x yf 199 200 imhist Tv xv yv -range -1 4 -delta 0.1 201 lim -n 2 xv yv; clear; box; plot xv yv -x hist 202 203 stat Tv 204 echo "$C1 vs {sqrt($MEDIAN)} : expect {$sig/sqrt($Nsample)}" 205 end 206 207 macro test.median.var 208 209 $Nsample = 64 210 $sig = 2.0 211 medimage delete -q t1 212 for i 0 $Nsample 213 mgaussdev t 50 50 0.0 $sig 214 medimage add t1 t 215 imhist -q t x y -range -10 10 -delta 0.1 216 217 $C0 = 0 218 $C1 = 1.5 219 $C2 = 400 220 $C3 = 0 221 vgauss -q x y con yf 222 # echo $C1 223 end 224 225 # note that median of a gaussian distributed variable is not distributed with sigma' = sigma / sqrt(N) 226 # (somewhat higher scatter) 227 medimage calc t1 T -variance Tv 228 229 imhist -q T x y -range -10 10 -delta 0.1 230 lim -n 1 x y; clear; box; plot -x hist x y 231 $C0 = 0 232 $C1 = 1.5 233 $C2 = 400 234 $C3 = 0 235 vgauss -q x y con yf 236 plot -c red -x line x yf 237 238 imhist Tv xv yv -range -1 4 -delta 0.1 239 lim -n 2 xv yv; clear; box; plot xv yv -x hist 240 241 stat Tv 242 echo "$C1 vs {sqrt($MEDIAN)} : expect {$sig/sqrt($Nsample)}" 243 end 244 245 macro test.wtmean.var 246 247 $Nsample = 32 248 $sig1 = 1.0 249 $sig2 = 1.0 250 251 medimage delete -q t1 252 for i 0 $Nsample 253 mgaussdev t 50 50 0.0 $sig1 254 set v = $sig1^2 + zero(t) 255 medimage add t1 t -variance v 256 imhist -q t x y -range -10 10 -delta 0.1 257 258 $C0 = 0 259 $C1 = 1.5 260 $C2 = 400 261 $C3 = 0 262 vgauss -q x y con yf 263 # echo $C1 264 end 265 266 for i 0 $Nsample 267 mgaussdev t 50 50 0.0 $sig2 268 set v = $sig2^2 + zero(t) 269 medimage add t1 t -variance v 270 imhist -q t x y -range -10 10 -delta 0.1 271 272 $C0 = 0 273 $C1 = 1.5 274 $C2 = 400 275 $C3 = 0 276 vgauss -q x y con yf 277 # echo $C1 278 end 279 280 # note that median of a gaussian distributed variable is not distributed with sigma' = sigma / sqrt(N) 281 # (somewhat higher scatter) 282 medimage calc t1 T -wtmean -variance Tv 283 284 imhist -q T x y -range -10 10 -delta 0.1 285 lim -n 1 x y; clear; box; plot -x hist x y 286 $C0 = 0 287 $C1 = 1.5 288 $C2 = 400 289 $C3 = 0 290 vgauss -q x y con yf 291 plot -c red -x line x yf 292 293 stat -q Tv 294 $S1 = $Nsample / $sig1^2 + $Nsample / $sig2^2 295 echo $C1 vs {sqrt($MEDIAN)} : expect {1/sqrt($S1)} 296 end 297 298 macro test.irls.var 299 300 $Nsample = 16 301 $sig = 1.0 302 303 medimage delete -q t1 304 for i 0 $Nsample 305 mgaussdev t 50 50 0.0 $sig 306 set v = $sig^2 + zero(t) 307 308 set bad = (rnd(t) < 0.05) ? 10*rnd(t) + 5 : zero(t) 309 set ts = t + bad 310 311 medimage add t1 ts -variance v 312 imhist -q t x y -range -10 10 -delta 0.1 313 314 $C0 = 0 315 $C1 = 1.5 316 $C2 = 400 317 $C3 = 0 318 vgauss -q x y con yf 319 # echo $C1 320 end 321 322 # get stats for straight mean: 323 medimage calc t1 Tm -mean -variance Tv 324 325 imhist -q Tm x y -range -10 10 -delta 0.1 326 lim -n 1 x y; clear; box; plot -x hist x y 327 $C0 = 0 328 $C1 = 1.5 329 $C2 = 400 330 $C3 = 0 331 vgauss -q x y con yf 332 echo "sigma from straight stdev: $C1" 333 # stats Tm 334 335 plot -c red -x line x yf 336 337 # get stats for irls 338 medimage calc t1 Ti -irls -variance Tv 339 340 imhist -q Ti x y -range -10 10 -delta 0.1 341 lim -n 2 x y; clear; box; plot -x hist x y 342 $C0 = 0 343 $C1 = 1.5 344 $C2 = 400 345 $C3 = 0 346 vgauss -q x y con yf 347 echo "sigma from irls: $C1 (ideal is {$sig/sqrt($Nsample)})" 348 # stats Ti 349 350 plot -c red -x line x yf 351 352 set dTv = sqrt(Tv) 353 imhist dTv xv yv -range -1 4 -delta 0.02; lim -n 3 xv yv; clear; box; plot xv yv -x hist 354 355 stat -q Tv 356 echo $C1 vs {sqrt($MEDIAN)} (ideal is {$sig/sqrt($Nsample)})" 357 end 358 359 macro test.irls.boot.var 360 361 $Nsample = 64 362 $sig = 1.0 363 364 medimage delete -q t1 365 for i 0 $Nsample 366 mgaussdev t 200 200 0.0 $sig 367 set v = $sig^2 + zero(t) 368 369 set bad = (rnd(t) < 0.05) ? 10*rnd(t) + 5 : zero(t) 370 set ts = t + bad 371 372 mgaussdev noise 200 200 0.0 0.5 373 set ts = ts + noise 374 375 medimage add t1 ts -variance v 376 imhist -q t x y -range -10 10 -delta 0.1 377 378 $C0 = 0 379 $C1 = 1.5 380 $C2 = 400 381 $C3 = 0 382 vgauss -q x y con yf 383 # echo $C1 384 end 385 386 # get stats for straight mean: 387 medimage calc t1 Tm -mean -variance Tv 388 389 imhist -q Tm x y -range -10 10 -delta 0.02 390 lim -n 1 x y; clear; box; plot -x hist x y 391 peak -q x y 392 $C0 = $peakpos 393 $C1 = 1.5*$sig / sqrt($Nsample) 394 $C2 = $peakval 395 $C3 = 0 396 vgauss -q x y con yf 397 echo "sigma from straight stdev: $C1" 398 # stats Tm 399 400 plot -c red -x line x yf 401 402 # get stats for irls 403 date 404 medimage calc t1 Ti -irls -variance Tv -bootstrap-iter 100 405 date 406 407 imhist -q Ti x y -range -10 10 -delta 0.02 408 lim -n 2 x y; clear; box; plot -x hist x y 409 peak -q x y 410 $C0 = $peakpos 411 $C1 = 1.5*$sig / sqrt($Nsample) 412 $C2 = $peakval 413 $C3 = 0 414 vgauss -q x y con yf 415 echo "sigma from irls: $C1 (ideal is {$sig/sqrt($Nsample)})" 416 # stats Ti 417 418 plot -c red -x line x yf 419 420 set dTv = sqrt(Tv) 421 imhist dTv xv yv -range 0 {5*$sig/sqrt($Nsample)} -delta 0.02; lim -n 3 xv yv; clear; box; plot xv yv -x hist 422 423 stat -q Tv 424 echo $C1 vs {sqrt($MEDIAN)} (ideal is {$sig/sqrt($Nsample)})" 425 end 426 427 ############################## 428 macro test.irls.boot.test 429 430 $Nsample = 100 431 $sig1 = 1.0 432 433 medimage delete -q t1 434 for i 0 $Nsample 435 mgaussdev t 100 100 0.0 $sig1 436 set v = $sig1^2 + zero(t) 437 438 medimage add t1 t -variance v 439 end 440 441 # get stats for irls 442 medimage calc t1 Ti -irls -variance Tv -bootstrap 443 444 imhist -q Ti x y -range {-10*$sig1/sqrt($Nsample)} {10*$sig1/sqrt($Nsample)} -delta 0.01 445 lim -n 2 x y; clear; box; plot -x hist x y 446 peak -q x y 447 $C0 = $peakpos 448 $C1 = 1.5*$sig1/sqrt($Nsample) 449 $C2 = $peakval 450 $C3 = 0 451 vgauss x y con yf 452 echo "sigma from irls: $C1 (ideal is {$sig1/sqrt($Nsample)})" 453 # stats Ti 454 455 plot -c red -x line x yf 456 457 set dTv = sqrt(Tv) 458 imhist dTv xv yv -range 0 {5*$sig1/sqrt($Nsample)} -delta 0.02; lim -n 3 xv yv; clear; box; plot xv yv -x hist 459 460 stat -q irls_npt 461 $Npix = $MEAN 462 463 stat -q Tv 464 echo "sigma of irls average: $C1, sqrt(mean) of irls variance: {sqrt($MEAN)}, (ideal is {$sig1/sqrt($Npix)})" 465 end 466 467 macro test.irls.range.var 468 medimage delete -q t1 469 for i 0 8 470 mgaussdev t 50 50 0.0 1.0 471 set v = 1.0 + zero(t) 472 473 set bad = (rnd(t) < 0.05) ? 10*rnd(t) + 5 : zero(t) 474 set ts = t + bad 475 476 medimage add t1 ts -variance v 477 imhist -q t x y -range -10 10 -delta 0.1 478 479 $C0 = 0 480 $C1 = 1.5 481 $C2 = 400 482 $C3 = 0 483 vgauss -q x y con yf 484 echo $C1 485 end 486 487 for i 0 8 488 mgaussdev t 50 50 0.0 3.0 489 set v = 3.0 + zero(t) 490 491 set bad = (rnd(t) < 0.05) ? 10*rnd(t) + 5 : zero(t) 492 set ts = t + bad 493 494 medimage add t1 ts -variance v 495 imhist -q t x y -range -10 10 -delta 0.1 496 497 $C0 = 0 498 $C1 = 1.5 499 $C2 = 400 500 $C3 = 0 501 vgauss -q x y con yf 502 echo $C1 503 end 504 505 # get stats for straight mean: 506 medimage calc t1 Tm -mean -variance Tv 507 508 imhist -q Tm x y -range -10 10 -delta 0.1 509 lim -n 1 x y; clear; box; plot -x hist x y 510 $C0 = 0 511 $C1 = 1.5 512 $C2 = 400 513 $C3 = 0 514 vgauss -q x y con yf 515 echo $C1 516 stats Tm 517 518 plot -c red -x line x yf 519 520 # get stats for irls 521 medimage calc t1 Ti -irls -variance Tv 522 523 imhist -q Ti x y -range -10 10 -delta 0.1 524 lim -n 2 x y; clear; box; plot -x hist x y 525 $C0 = 0 526 $C1 = 1.5 527 $C2 = 400 528 $C3 = 0 529 vgauss -q x y con yf 530 echo $C1 531 stats Ti 532 533 plot -c red -x line x yf 534 535 stat -q Tv 536 echo $C1 vs {sqrt($MEDIAN)} 537 538 set dTv = sqrt(Tv) 539 imhist dTv xv yv -range -1 4 -delta 0.02; lim -n 3 xv yv; clear; box; plot xv yv -x hist 540 end
Note:
See TracChangeset
for help on using the changeset viewer.
