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
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 |
# File 'lib/numru/gphys/gphys_dim_op.rb', line 315 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
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 |
# File 'lib/numru/gphys/gphys_dim_op.rb', line 338 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
356 357 358 359 360 361 362 |
# File 'lib/numru/gphys/gphys_dim_op.rb', line 356 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
364 365 366 367 368 369 370 |
# File 'lib/numru/gphys/gphys_dim_op.rb', line 364 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
372 373 374 375 376 377 378 379 380 |
# File 'lib/numru/gphys/gphys_dim_op.rb', line 372 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
382 383 384 385 386 387 388 389 390 |
# File 'lib/numru/gphys/gphys_dim_op.rb', line 382 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
392 393 394 395 396 397 398 399 |
# File 'lib/numru/gphys/gphys_dim_op.rb', line 392 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
401 402 403 404 405 406 407 408 409 |
# File 'lib/numru/gphys/gphys_dim_op.rb', line 401 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 |