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
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/numru/gphys/gphys_dim_op.rb', line 234 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
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
# File 'lib/numru/gphys/gphys_dim_op.rb', line 257 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
275 276 277 278 279 280 281 |
# File 'lib/numru/gphys/gphys_dim_op.rb', line 275 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
283 284 285 286 287 288 289 |
# File 'lib/numru/gphys/gphys_dim_op.rb', line 283 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
291 292 293 294 295 296 297 298 299 |
# File 'lib/numru/gphys/gphys_dim_op.rb', line 291 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
301 302 303 304 305 306 307 308 309 |
# File 'lib/numru/gphys/gphys_dim_op.rb', line 301 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
311 312 313 314 315 316 317 318 |
# File 'lib/numru/gphys/gphys_dim_op.rb', line 311 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
320 321 322 323 324 325 326 327 328 |
# File 'lib/numru/gphys/gphys_dim_op.rb', line 320 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 |