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
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
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)
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
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
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)
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
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)
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
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
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
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
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
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
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
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)
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
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)
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)
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
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)
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)
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)
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)
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)
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)