コード例 #1
0
def test_upper_righ_corner():  #  off grid
    positions = np.array(((10.0, 5.0), ), np.float32)
    mass = np.array((1.0, ), np.float32)
    flags = np.zeros_like(mass, dtype=np.uint8)

    mass_grid = comp_volume(positions, mass, flags, grid)
    assert np.alltrue(mass_grid == 0)  # nothing on the grid
コード例 #2
0
def test_on_edge_right(): # right edge is off grid
    positions = np.array(( (10.0, 0.0), ), np.float32)
    mass = np.array( (1.0,), np.float32 )
    flags = np.zeros_like(mass, dtype=np.uint8)
        
    mass_grid = comp_volume(positions, mass, flags, grid)
    assert np.alltrue(mass_grid == 0) # nothing on the grid
コード例 #3
0
def test_multiple_flags_off_map():
    # don't ignore it this time
    positions = np.array(( ( 1.5,  2.5),
                           ( 100, 10  ),
                           ( 9.0,  4.0),
                           ( 0.0,  0.0),
                           ( 0.0, -4.0),
                           ( 5.0,  2.0),
                           (-6.0,  1.0)
                           
                           ), np.float32)
    mass = np.array(  (1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 5.0 ), np.float32 )
    flags = np.array( (  0,   1,   2,   4,   8,  16,   0 ), dtype=np.uint8)
    bitmask = 1 + 4 + 16
        
    mass_grid = comp_volume(positions, mass, flags, grid, flag_bitmask_to_ignore = bitmask)
    assert mass_grid[5, 3] == mass[0] # should be full mass in the one grid box 
    assert mass_grid[0, 0] == 0       # should be full mass in the one grid box 
    assert mass_grid[9, 4] == mass[2] # should be full mass in the one grid box 
    assert mass_grid[5, 2] == 0       # should be full mass in the one grid box 
    assert mass_grid[5, 0] == mass[4] # should be full mass in the one grid box 
    assert mass_grid[7, 3] == 0       # should be full mass in the one grid box 
    assert mass_grid[2, 3] == mass[6] # should be full mass in the one grid box 
    print mass_grid.sum()
    assert mass_grid.sum() == 14.0   # mass conserved (w/out flagged oil)
コード例 #4
0
def test_upper_righ_corner(): #  off grid
    positions = np.array(( (10.0, 5.0), ), np.float32)
    mass = np.array( (1.0,), np.float32 )
    flags = np.zeros_like(mass, dtype=np.uint8)
        
    mass_grid = comp_volume(positions, mass, flags, grid)
    assert np.alltrue(mass_grid == 0) # nothing on the grid
コード例 #5
0
def test_on_edge_right():  # right edge is off grid
    positions = np.array(((10.0, 0.0), ), np.float32)
    mass = np.array((1.0, ), np.float32)
    flags = np.zeros_like(mass, dtype=np.uint8)

    mass_grid = comp_volume(positions, mass, flags, grid)
    assert np.alltrue(mass_grid == 0)  # nothing on the grid
コード例 #6
0
def test_multiple_flags_off_map():
    # don't ignore it this time
    positions = np.array(((1.5, 2.5), (100, 10), (9.0, 4.0), (0.0, 0.0),
                          (0.0, -4.0), (5.0, 2.0), (-6.0, 1.0)), np.float32)
    mass = np.array((1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 5.0), np.float32)
    flags = np.array((0, 1, 2, 4, 8, 16, 0), dtype=np.uint8)
    bitmask = 1 + 4 + 16

    mass_grid = comp_volume(positions,
                            mass,
                            flags,
                            grid,
                            flag_bitmask_to_ignore=bitmask)
    assert mass_grid[5,
                     3] == mass[0]  # should be full mass in the one grid box
    assert mass_grid[0, 0] == 0  # should be full mass in the one grid box
    assert mass_grid[9,
                     4] == mass[2]  # should be full mass in the one grid box
    assert mass_grid[5, 2] == 0  # should be full mass in the one grid box
    assert mass_grid[5,
                     0] == mass[4]  # should be full mass in the one grid box
    assert mass_grid[7, 3] == 0  # should be full mass in the one grid box
    assert mass_grid[2,
                     3] == mass[6]  # should be full mass in the one grid box
    print mass_grid.sum()
    assert mass_grid.sum() == 14.0  # mass conserved (w/out flagged oil)
コード例 #7
0
def test_off_grid_left():
    positions = np.array(((-11, 3), ), np.float32)
    mass = np.array((1.0, ), np.float32)
    flags = np.zeros_like(mass, dtype=np.uint8)

    mass_grid = comp_volume(positions, mass, flags, grid)
    assert np.alltrue(mass_grid == 0)  # nothing on the grid
コード例 #8
0
def test_one_particle():
    from batch_gnome import cy_tap_comp_volume
    # set up a grid:
    grid = tap_mod.Grid(min_long=-10,
                        max_long=10,
                        min_lat=-5,
                        max_lat=5,
                        num_lat=5,
                        num_long=10)
    LE_positions = np.array(((1.5, 2.5), ), np.float32)
    Vol1 = tap_mod.CompThicknessCubeTimestepOld(grid, LE_positions)
    # reshape:
    print Vol1
    assert Vol1[5, 3] == 1  # should be full mass in the one grid box
    assert Vol1.sum() == 1  # mass conserved

    NumLEs = len(LE_positions)
    LE_mass = np.ones((NumLEs, ), dtype=np.float32)
    flags = flags = np.zeros((NumLEs), dtype=np.uint8)
    Vol2 = cy_tap_comp_volume.comp_volume(LE_positions, LE_mass, flags, grid)
    # reshape:
    print Vol2
    assert Vol2[5, 3] == 1  # should be full mass in the one grid box
    assert Vol2.sum() == 1  # mass conserved

    assert np.array_equal(Vol1, Vol2)
コード例 #9
0
def test_off_grid_downright():
    positions = np.array(( (1100, -200), ), np.float32)
    mass = np.array( (1.0,), np.float32 )
    flags = np.zeros_like(mass, dtype=np.uint8)
        
    mass_grid = comp_volume(positions, mass, flags, grid)
    assert np.alltrue(mass_grid == 0) # nothing on the grid
コード例 #10
0
def test_two_particles_one_cell():
    positions = np.array(( (1.5, 2.5), (1.0, 2.0)), np.float32)
    mass = np.array( (1.0, 2.0), np.float32 )
    flags = np.zeros_like(mass, dtype=np.uint8)
        
    mass_grid = comp_volume(positions, mass, flags, grid)
    assert mass_grid[5, 3] == mass[0] + mass[1] # should be full mass in the one grid box 
    assert mass_grid.sum() == mass.sum() # mass conserved
コード例 #11
0
def test_on_edge_left():  # left edge is on grid
    positions = np.array(((-10.0, 0.0), ), np.float32)
    mass = np.array((1.0, ), np.float32)
    flags = np.zeros_like(mass, dtype=np.uint8)

    mass_grid = comp_volume(positions, mass, flags, grid)
    assert mass_grid[0, 2] == mass[0]
    assert mass_grid.sum() == mass.sum()  # conserve mass
コード例 #12
0
def test_on_edge_left(): # left edge is on grid
    positions = np.array(( (-10.0, 0.0), ), np.float32)
    mass = np.array( (1.0,), np.float32 )
    flags = np.zeros_like(mass, dtype=np.uint8)
        
    mass_grid = comp_volume(positions, mass, flags, grid)
    assert mass_grid[0, 2] == mass[0]
    assert mass_grid.sum() == mass.sum() # conserve mass
コード例 #13
0
def test_lower_left_corner():  #  on grid
    positions = np.array(((-10.0, -5.0), ), np.float32)
    mass = np.array((1.0, ), np.float32)
    flags = np.zeros_like(mass, dtype=np.uint8)

    mass_grid = comp_volume(positions, mass, flags, grid)
    assert mass_grid[0, 0] == mass[0]
    assert mass_grid.sum() == mass.sum()  # conserve mass
コード例 #14
0
def test_lower_left_corner(): #  on grid
    positions = np.array(( (-10.0, -5.0), ), np.float32)
    mass = np.array( (1.0,), np.float32 )
    flags = np.zeros_like(mass, dtype=np.uint8)
        
    mass_grid = comp_volume(positions, mass, flags, grid)
    assert mass_grid[0, 0] == mass[0]
    assert mass_grid.sum() == mass.sum() # conserve mass
コード例 #15
0
def test_two_particles_one_cell():
    positions = np.array(((1.5, 2.5), (1.0, 2.0)), np.float32)
    mass = np.array((1.0, 2.0), np.float32)
    flags = np.zeros_like(mass, dtype=np.uint8)

    mass_grid = comp_volume(positions, mass, flags, grid)
    assert mass_grid[
        5, 3] == mass[0] + mass[1]  # should be full mass in the one grid box
    assert mass_grid.sum() == mass.sum()  # mass conserved
コード例 #16
0
def test_flag_offMap():
    # don't ignore it this time
    positions = np.array(((1.5, 2.5), (-9.0, -4.0)), np.float32)
    mass = np.array((1.0, 2.0), np.float32)
    flags = np.array((0, 4), dtype=np.uint8)  # 4 is the offMap flag

    mass_grid = comp_volume(positions, mass, flags, grid)
    assert mass_grid[5,
                     3] == mass[0]  # should be full mass in the one grid box
    assert mass_grid[0, 0] == 0  # should be full mass in the one grid box
    assert mass_grid.sum() == mass[0]  # mass conserved (w/out flagged oil)
コード例 #17
0
def test_beached_flag():
    
    positions = np.array(( (1.5, 2.5),
                           (-9.0, -4.0)
                           ), np.float32)
    mass = np.array( (1.0, 2.0), np.float32 )
    flags = np.array( (0, 2) , dtype=np.uint8)
        
    mass_grid = comp_volume(positions, mass, flags, grid)
    assert mass_grid[5, 3] == mass[0] # should be full mass in the one grid box 
    assert mass_grid[0, 0] == mass[1] # should be full mass in the one grid box 
    assert mass_grid.sum() == mass.sum() # mass conserved
コード例 #18
0
def test_beached_flag2():
    # don't ignore it this time
    positions = np.array(( (1.5, 2.5),
                           (-9.0, -4.0)
                           ), np.float32)
    mass = np.array( (1.0, 2.0), np.float32 )
    flags = np.array( (0, 2) , dtype=np.uint8)
        
    mass_grid = comp_volume(positions, mass, flags, grid, flag_bitmask_to_ignore = 2)
    assert mass_grid[5, 3] == mass[0] # should be full mass in the one grid box 
    assert mass_grid[0, 0] == 0 # should be full mass in the one grid box 
    assert mass_grid.sum() == mass[0] # mass conserved (w/out beached oil)
コード例 #19
0
def test_flag_offMap():
    # don't ignore it this time
    positions = np.array(( (1.5, 2.5),
                           (-9.0, -4.0)
                           ), np.float32)
    mass = np.array( (1.0, 2.0), np.float32 )
    flags = np.array( (0, 4) , dtype=np.uint8) # 4 is the offMap flag
        
    mass_grid = comp_volume(positions, mass, flags, grid)
    assert mass_grid[5, 3] == mass[0] # should be full mass in the one grid box 
    assert mass_grid[0, 0] == 0 # should be full mass in the one grid box 
    assert mass_grid.sum() == mass[0] # mass conserved (w/out flagged oil)
コード例 #20
0
def test_beached_flag():

    positions = np.array(((1.5, 2.5), (-9.0, -4.0)), np.float32)
    mass = np.array((1.0, 2.0), np.float32)
    flags = np.array((0, 2), dtype=np.uint8)

    mass_grid = comp_volume(positions, mass, flags, grid)
    assert mass_grid[5,
                     3] == mass[0]  # should be full mass in the one grid box
    assert mass_grid[0,
                     0] == mass[1]  # should be full mass in the one grid box
    assert mass_grid.sum() == mass.sum()  # mass conserved
コード例 #21
0
def test_flag_noOnSurface():
    # don't ignore it this time
    positions = np.array(( (1.5, 2.5),
                           (-9.0, -4.0),
                           ), np.float32)
    mass = np.array( (1.0, 2.0), np.float32 )
    flags = np.array( (16, 0) , dtype=np.uint8) # 16 is the notOnSurface: flag
        
    mass_grid = comp_volume(positions, mass, flags, grid)
    assert mass_grid[5, 3] == 0 # should be full mass in the one grid box 
    assert mass_grid[0, 0] == mass[1] # should be full mass in the one grid box 
    assert mass_grid.sum() == mass[1] # mass conserved (w/out flagged oil)
コード例 #22
0
def test_flag_noOnSurface():
    # don't ignore it this time
    positions = np.array((
        (1.5, 2.5),
        (-9.0, -4.0),
    ), np.float32)
    mass = np.array((1.0, 2.0), np.float32)
    flags = np.array((16, 0), dtype=np.uint8)  # 16 is the notOnSurface: flag

    mass_grid = comp_volume(positions, mass, flags, grid)
    assert mass_grid[5, 3] == 0  # should be full mass in the one grid box
    assert mass_grid[0,
                     0] == mass[1]  # should be full mass in the one grid box
    assert mass_grid.sum() == mass[1]  # mass conserved (w/out flagged oil)
コード例 #23
0
def test_beached_flag2():
    # don't ignore it this time
    positions = np.array(((1.5, 2.5), (-9.0, -4.0)), np.float32)
    mass = np.array((1.0, 2.0), np.float32)
    flags = np.array((0, 2), dtype=np.uint8)

    mass_grid = comp_volume(positions,
                            mass,
                            flags,
                            grid,
                            flag_bitmask_to_ignore=2)
    assert mass_grid[5,
                     3] == mass[0]  # should be full mass in the one grid box
    assert mass_grid[0, 0] == 0  # should be full mass in the one grid box
    assert mass_grid.sum() == mass[0]  # mass conserved (w/out beached oil)
コード例 #24
0
def test_one_particle():
    from batch_gnome import cy_tap_comp_volume
    # set up a grid:
    grid = tap_mod.Grid(min_long=-10, max_long=10, min_lat=-5, max_lat=5,num_lat=5,num_long=10)
    LE_positions = np.array(( (1.5, 2.5), ), np.float32)
    Vol1= tap_mod.CompThicknessCubeTimestepOld( grid, LE_positions )
    # reshape:
    print Vol1
    assert Vol1[5, 3] == 1 # should be full mass in the one grid box 
    assert Vol1.sum() == 1  # mass conserved

    NumLEs = len(LE_positions)
    LE_mass = np.ones((NumLEs,), dtype = np.float32)
    flags = flags = np.zeros((NumLEs), dtype = np.uint8)
    Vol2= cy_tap_comp_volume.comp_volume( LE_positions, LE_mass, flags, grid )
    # reshape:
    print Vol2
    assert Vol2[5, 3] == 1 # should be full mass in the one grid box 
    assert Vol2.sum() == 1  # mass conserved

    assert np.array_equal(Vol1, Vol2)
コード例 #25
0
def test_multiple_LEs():
    # don't ignore it this time
    positions = np.array(((1.5, 2.5), (-9.0, -4.0), (9.0, 4.0), (0.0, 0.0),
                          (0.0, -4.0), (5.0, 2.0), (-6.0, 1.0)), np.float32)
    mass = np.array((1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 5.0), np.float32)
    flags = np.zeros_like(mass, dtype=np.uint8)
    #    flags = np.array( (16, 0) , dtype=np.uint8) # 16 is the notOnSurface: flag

    mass_grid = comp_volume(positions, mass, flags, grid)
    assert mass_grid[5,
                     3] == mass[0]  # should be full mass in the one grid box
    assert mass_grid[0,
                     0] == mass[1]  # should be full mass in the one grid box
    assert mass_grid[9,
                     4] == mass[2]  # should be full mass in the one grid box
    assert mass_grid[5,
                     2] == mass[3]  # should be full mass in the one grid box
    assert mass_grid[5,
                     0] == mass[4]  # should be full mass in the one grid box
    assert mass_grid[7,
                     3] == mass[5]  # should be full mass in the one grid box
    assert mass_grid[2,
                     3] == mass[6]  # should be full mass in the one grid box
    assert mass_grid.sum() == mass.sum()  # mass conserved (w/out flagged oil)
コード例 #26
0
def test_multiple_LEs():
    # don't ignore it this time
    positions = np.array(( ( 1.5,  2.5),
                           (-9.0, -4.0),
                           ( 9.0,  4.0),
                           ( 0.0,  0.0),
                           ( 0.0, -4.0),
                           ( 5.0,  2.0),
                           (-6.0,  1.0)
                           
                           ), np.float32)
    mass = np.array( (1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 5.0 ), np.float32 )
    flags = np.zeros_like(mass, dtype=np.uint8)
#    flags = np.array( (16, 0) , dtype=np.uint8) # 16 is the notOnSurface: flag
        
    mass_grid = comp_volume(positions, mass, flags, grid)
    assert mass_grid[5, 3] == mass[0] # should be full mass in the one grid box 
    assert mass_grid[0, 0] == mass[1] # should be full mass in the one grid box 
    assert mass_grid[9, 4] == mass[2] # should be full mass in the one grid box 
    assert mass_grid[5, 2] == mass[3] # should be full mass in the one grid box 
    assert mass_grid[5, 0] == mass[4] # should be full mass in the one grid box 
    assert mass_grid[7, 3] == mass[5] # should be full mass in the one grid box 
    assert mass_grid[2, 3] == mass[6] # should be full mass in the one grid box 
    assert mass_grid.sum() == mass.sum() # mass conserved (w/out flagged oil)