def test_land_cross_array(self): """ test a few LEs """ gmap = RasterMap(refloat_halflife=6, raster=self.raster, map_bounds=((-50, -30), (-50, 30), (50, 30), (50, -30)), projection=NoProjection()) # one left to right # one right to left # one diagonal upper left to lower right # one diagonal upper right to lower left spill = sample_sc_release(4) spill['positions'] = np.array( ((5.0, 5.0, 0.), (15.0, 5.0, 0.), (0., 0., 0.), (19.0, 0., 0.)), dtype=np.float64) spill['next_positions'] = np.array( ((15.0, 5.0, 0.), (5.0, 5.0, 0.), (10.0, 5.0, 0.), (0., 9.0, 0.)), dtype=np.float64) gmap.beach_elements(spill) assert np.array_equal(spill['next_positions'], ((10.0, 5.0, 0.), (10.0, 5.0, 0.), (10.0, 5.0, 0.), (10.0, 4.0, 0.))) assert np.array_equal(spill['last_water_positions'], ((9.0, 5.0, 0.), (11.0, 5.0, 0.), (9.0, 4.0, 0.), (11.0, 4.0, 0.))) assert np.alltrue(spill['status_codes'] == oil_status.on_land)
def test_some_cross_array(self): """ test a few LEs """ gmap = RasterMap(refloat_halflife=6, bitmap_array=self.raster, map_bounds=((-50, -30), (-50, 30), (50, 30), (50, -30)), projection=NoProjection()) # hours # one left to right # one right to left # diagonal that doesn't hit # diagonal that does hit spill = sample_sc_release(4) spill['positions'] = np.array(((5.0, 5.0, 0.), (15.0, 5.0, 0.), (0., 0., 0.), (19.0, 0., 0.)), dtype=np.float64) spill['next_positions'] = np.array(((9.0, 5.0, 0.), (11.0, 5.0, 0.), (9.0, 9.0, 0.), (0., 9.0, 0.)), dtype=np.float64) gmap.beach_elements(spill) assert np.array_equal(spill['next_positions'], ((9.0, 5.0, 0.), (11.0, 5.0, 0.), (9.0, 9.0, 0.), (10.0, 4.0, 0.))) # just the beached ones assert np.array_equal((spill['last_water_positions'])[3:], ((11.0, 4.0, 0.), )) assert np.array_equal((spill['status_codes'])[3:], (oil_status.on_land, ))
def test_starts_on_land(self): """ try a single LE that starts on land it last water position should be the same point. """ gmap = RasterMap(refloat_halflife=6, raster=self.raster, map_bounds=((-50, -30), (-50, 30), (50, 30), (50, -30)), projection=NoProjection()) spill = sample_sc_release(1) spill['positions'] = np.array(((10.0, 5.0, 0.), ), dtype=np.float64) spill['last_water_positions'] = np.array(((0.0, 0.0, 0.), ), dtype=np.float64) spill['next_positions'] = np.array(((15.0, 5.0, 0.), ), dtype=np.float64) spill['status_codes'] = np.array((oil_status.in_water, ), dtype=status_code_type) gmap.beach_elements(spill) # next position gets set to land location assert np.array_equal(spill['next_positions'][0], (10.0, 5.0, 0.)) assert np.array_equal(spill['last_water_positions'][0], (10.0, 5.0, 0.)) assert spill['status_codes'][0] == oil_status.on_land
def test_land_cross(self): """ try a single LE that should be crossing land """ gmap = RasterMap(refloat_halflife=6, bitmap_array=self.raster, map_bounds=((-50, -30), (-50, 30), (50, 30), (50, -30)), projection=NoProjection()) # hours spill = sample_sc_release(1) spill['positions'] = np.array(((5.0, 5.0, 0.), ), dtype=np.float64) spill['next_positions'] = np.array(((15.0, 5.0, 0.), ), dtype=np.float64) spill['status_codes'] = np.array((oil_status.in_water, ), dtype=status_code_type) gmap.beach_elements(spill) assert np.array_equal(spill['next_positions'][0], (10.0, 5.0, 0.)) assert np.array_equal(spill['last_water_positions'][0], (9.0, 5.0, 0.)) assert spill['status_codes'][0] == oil_status.on_land
def test_land_cross_array(self): """ test a few LEs """ gmap = RasterMap(refloat_halflife=6, bitmap_array=self.raster, map_bounds=((-50, -30), (-50, 30), (50, 30), (50, -30)), projection=NoProjection()) # hours # one left to right # one right to left # one diagonal upper left to lower right # one diagonal upper right to lower left spill = sample_sc_release(4) spill['positions'] = np.array(((5.0, 5.0, 0.), (15.0, 5.0, 0.), (0., 0., 0.), (19.0, 0., 0.)), dtype=np.float64) spill['next_positions'] = np.array(((15.0, 5.0, 0.), (5.0, 5.0, 0.), (10.0, 5.0, 0.), (0., 9.0, 0.)), dtype=np.float64) gmap.beach_elements(spill) assert np.array_equal(spill['next_positions'], ((10.0, 5.0, 0.), (10.0, 5.0, 0.), (10.0, 5.0, 0.), (10.0, 4.0, 0.))) assert np.array_equal(spill['last_water_positions'], ((9.0, 5.0, 0.), (11.0, 5.0, 0.), (9.0, 4.0, 0.), (11.0, 4.0, 0.))) assert np.alltrue(spill['status_codes'] == oil_status.on_land)
def test_starts_on_land(self): """ try a single LE that starts on land it last water position should be the same point. """ gmap = RasterMap(refloat_halflife=6, bitmap_array=self.raster, map_bounds=((-50, -30), (-50, 30), (50, 30), (50, -30)), projection=NoProjection()) # hours spill = sample_sc_release(1) spill['positions'] = np.array(((10.0, 5.0, 0.), ), dtype=np.float64) spill['last_water_positions'] = np.array(((0.0, 0.0, 0.), ), dtype=np.float64) spill['next_positions'] = np.array(((15.0, 5.0, 0.), ), dtype=np.float64) spill['status_codes'] = np.array((oil_status.in_water, ), dtype=status_code_type) gmap.beach_elements(spill) ## next position gets set to land location assert np.array_equal(spill['next_positions'][0], (10.0, 5.0, 0.)) assert np.array_equal(spill['last_water_positions'][0], (10.0, 5.0, 0.)) assert spill['status_codes'][0] == oil_status.on_land
def test_some_off_map(self): """ Test LEs that go off the map should get off_map flag - no longer setting to_be_removed flag. map simply sets the off_maps flag. """ gmap = RasterMap(refloat_halflife=6, bitmap_array=self.raster, map_bounds=((-50, -30), (-50, 30), (50, 30), (50, -30)), projection=NoProjection()) # hours spill = sample_sc_release(8) spill['positions'] = np.array(( (45.0, 25.0, 0.), (45.0, 25.0, 0.), (45.0, -25.0, 0.), (45.0, -25.0, 0.), (-45.0, -25.0, 0.), (-45.0, -25.0, 0.), (-45.0, 25.0, 0.), (-45.0, 25.0, 0.), ), dtype=np.float64) spill['next_positions'] = np.array(( # off # still on # off # still on # off # still on # off # still on (55.0, 25.0, 0.), (49.0, 25.0, 0.), (45.0, -35.0, 0.), (45.0, -29.0, 0.), (-55.0, -25.0, 0.), (-49.0, -25.0, 0.), (-45.0, 35.0, 0.), (-45.0, 29.0, 0.), ), dtype=np.float64) gmap.beach_elements(spill) off = np.ones(4,) * oil_status.off_maps # off = np.ones(4) * oil_status.to_be_removed assert np.array_equal(spill['status_codes'][0::2], off) on = np.ones(4) * oil_status.in_water assert np.array_equal(spill['status_codes'][1::2], on)
def test_outside_raster(self): """ test LEs starting form outside the raster bounds """ gmap = RasterMap(refloat_halflife=6, bitmap_array=self.raster, map_bounds=((-50, -30), (-50, 30), (50, 30), (50, -30)), projection=NoProjection()) # hours # one left to right # one right to left # diagonal that doesn't hit # diagonal that does hit # spill = gnome.spill.Spill(num_LEs=4) spill = sample_sc_release(4) spill['positions'] = np.array(((30.0, 5.0, 0.), (-5.0, 5.0, 0.), (5.0, -5.0, 0.), (-5.0, -5.0, 0.)), dtype=np.float64) # outside right # outside left # outside top # outside upper left spill['next_positions'] = np.array(((15.0, 5.0, 0.), (5.0, 5.0, 0.), (5.0, 15.0, 0.), (25.0, 15.0, 0.)), dtype=np.float64) gmap.beach_elements(spill) assert np.array_equal(spill['next_positions'], ((15.0, 5.0, 0.), (5.0, 5.0, 0.), (5.0, 15.0, 0.), (10.0, 5.0, 0.))) # just the beached ones assert np.array_equal((spill['last_water_positions'])[3:], ((9.0, 4.0, 0.), )) assert np.array_equal((spill['status_codes'])[3:], (oil_status.on_land, ))