Class: TC_GPhys_grid_op
- Inherits:
-
Test::Unit::TestCase
- Object
- Test::Unit::TestCase
- TC_GPhys_grid_op
- Includes:
- NumRu
- Defined in:
- lib/numru/gphys/gphys_dim_op.rb
Constant Summary
Constants included from NumRu
Instance Method Summary collapse
- #setup ⇒ Object
- #test_0_0_running_mean ⇒ Object
- #test_0_1_running_mean ⇒ Object
- #test_0_2_running_mean ⇒ Object
- #test_1_0_bin_mean ⇒ Object
- #test_1_1_bin_mean ⇒ Object
- #test_2_0_bin_sum ⇒ Object
- #test_2_1_bin_sum ⇒ Object
Methods included from NumRu
#linear_reg_slope_error, #linear_regression
Instance Method Details
#setup ⇒ Object
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 |
# File 'lib/numru/gphys/gphys_dim_op.rb', line 378 def setup nx = 11 ny = 5 vx = VArray.new( NArray.float(nx).indgen! ).rename("x") vy = VArray.new( NArray.float(ny).indgen! ).rename("y") xax = Axis.new().set_pos(vx) yax = Axis.new().set_pos(vy) grid = Grid.new(xax, yax) z = VArray.new( na = NArray.float(nx, ny).indgen! % 5, nil, "z" ) zu = VArray.new( NArray.float(nx, ny).fill(3.0), nil, "z" ) @gp = GPhys.new(grid,z) @gpu = GPhys.new(grid,zu) nam = NArrayMiss.to_nam(na) nam.invalidation(1,1) nam.invalidation(2,2) (1..4).each{|i| nam.invalidation(i,3)} zm = VArray.new( nam, nil, "zm" ) @gpm = GPhys.new(grid,zm) end |
#test_0_0_running_mean ⇒ Object
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 |
# File 'lib/numru/gphys/gphys_dim_op.rb', line 401 def test_0_0_running_mean puts "*** running_mean: basic ***" p(v0 = @gp.val) p(v = @gp.running_mean(0,3).val) assert_in_delta(v[4,0], 2.33333, 1e-4) p(v = @gp.running_mean(1,3,GPhys::BC_TRIM).val) assert_in_delta(v[2,1], 2.33333, 1e-4) p(v = @gpu.running_mean(0,3,GPhys::BC_TRIM).val) assert_in_delta(v[0,0], 3.0, 1e-4) assert_equal(v.shape[0], v0.shape[0]-2) p(v = @gp[0..9,true].running_mean(0,5,GPhys::BC_CYCLIC).val) assert_in_delta(v[0,0], 2.0, 1e-4) end |
#test_0_1_running_mean ⇒ Object
419 420 421 422 423 424 425 |
# File 'lib/numru/gphys/gphys_dim_op.rb', line 419 def test_0_1_running_mean puts "*** running_mean: weight ***" wgt = NArray[1.0, 2.0, 1.0] p @gp.val p(v = @gp.running_mean(0,wgt).val) assert_in_delta(v[4,0], (3.0+4.0*2)/4, 1e-4) end |
#test_0_2_running_mean ⇒ Object
427 428 429 430 431 432 433 |
# File 'lib/numru/gphys/gphys_dim_op.rb', line 427 def test_0_2_running_mean puts "*** running_mean: with data missing ***" p @gpm.val p(v = @gpm.running_mean(0,3).val) assert_in_delta(v[2,2], 1.5, 1e-4) assert(v[2,3] > 1e30) # missing value end |
#test_1_0_bin_mean ⇒ Object
435 436 437 438 439 440 441 442 443 |
# File 'lib/numru/gphys/gphys_dim_op.rb', line 435 def test_1_0_bin_mean puts "*** bin_mean ***" p @gp.val b = @gp.bin_mean(0,3) v = b.val p v, b.coord(0).val, b.coord(1).val assert_in_delta(b.val[1,1], 5.0/3.0, 1e-4) assert_in_delta(b.coord(0).val[1], 4.0, 1e-4) end |
#test_1_1_bin_mean ⇒ Object
445 446 447 448 449 450 451 452 453 |
# File 'lib/numru/gphys/gphys_dim_op.rb', line 445 def test_1_1_bin_mean puts "*** bin_mean: with data missing ***" p @gpm.val b = @gpm.bin_mean(0,3,2) v = b.val p v, b.coord(0).val, b.coord(1).val assert_in_delta(v[0,2], 2.5, 1e-4) assert(v[0,3] > 1e30) # missing value end |
#test_2_0_bin_sum ⇒ Object
455 456 457 458 459 460 461 462 |
# File 'lib/numru/gphys/gphys_dim_op.rb', line 455 def test_2_0_bin_sum puts "*** bin_sum ***" p @gp.val b = @gp.bin_sum(0,3) v = b.val p v, b.coord(0).val, b.coord(1).val assert_in_delta(b.val[1,1], 5.0, 1e-4) end |
#test_2_1_bin_sum ⇒ Object
464 465 466 467 468 469 470 471 472 |
# File 'lib/numru/gphys/gphys_dim_op.rb', line 464 def test_2_1_bin_sum puts "*** bin_sum: with data missing ***" p @gpm.val b = @gpm.bin_sum(0,3,2) v = b.val p v, b.coord(0).val, b.coord(1).val assert_in_delta(v[0,2], 5.0, 1e-4) assert(v[0,3] > 1e30) # missing value end |