Exemplo n.º 1
0
class TestLeeway(unittest.TestCase):
    """Tests for Leeway module."""

    def test_leewayprop(self):
        """Check that Leeway properties are properly read."""
        self.objectType = 85  # MED-WASTE-7
        self.lee = Leeway(loglevel=20)
        objectType = self.objectType
        self.assertEqual(self.lee.leewayprop[objectType]
                         ['Description'],
                         '>>Medical waste, syringes, small')
        self.assertEqual(self.lee.leewayprop[objectType]['DWSLOPE'], 1.79)

    def test_leewayrun(self):
        """Test the expected Leeway left/right split."""
        self.lee = Leeway(loglevel=30)
        self.objectType = 50  # FISHING-VESSEL-1
        self.reader_basemap = reader_basemap_landmask.Reader(
            llcrnrlon=3, llcrnrlat=59.8, projection='merc',
            urcrnrlon=6, urcrnrlat=60.5, resolution='i')
        self.lee.add_reader([self.reader_basemap])
        self.lee.seed_elements(lon=4.5, lat=60, number=100,
                               objectType=self.objectType,
                               time=datetime(2015, 1, 1))
        self.lee.fallback_values['x_wind'] = 0
        self.lee.fallback_values['y_wind'] = 10
        self.lee.fallback_values['x_sea_water_velocity'] = 0
        self.lee.fallback_values['y_sea_water_velocity'] = 0
        # Check that 7 out of 100 elements strand towards coast
        self.lee.run(steps=24, time_step=3600)
        self.assertEqual(self.lee.num_elements_scheduled(), 0)
        self.assertEqual(self.lee.num_elements_active(), 97)
        self.assertEqual(self.lee.num_elements_deactivated(), 3)  # stranded
        self.lee.export_ascii('leeway_ascii.txt')
        os.remove('leeway_ascii.txt')
Exemplo n.º 2
0
 def test_leeway_global_one_month_ago(self):
     o = Leeway(loglevel=0)
     o.add_readers_from_file(o.test_data_folder() +
         '../../opendrift/scripts/data_sources.txt')
     o.seed_elements(lon=50, lat=29, number=100, radius=1000,
                     time=datetime.now() - timedelta(days=30))
     o.run(steps=15)
     o.export_ascii('leeway_ascii.txt')
     os.remove('leeway_ascii.txt')
     print (o)
     self.assertEqual(o.steps_calculation, 15)
Exemplo n.º 3
0
 def test_leeway_yesterday(self):
     o = Leeway(loglevel=0)
     o.add_readers_from_file(o.test_data_folder() +
                             '../../opendrift/scripts/data_sources.txt')
     o.set_config('general:basemap_resolution', 'i')
     o.seed_elements(lon=14,
                     lat=67.85,
                     number=100,
                     radius=1000,
                     time=datetime.now() - timedelta(days=1))
     o.run(steps=15)
     o.export_ascii('leeway_ascii.txt')
     os.remove('leeway_ascii.txt')
     print o
     self.assertEqual(o.steps_calculation, 15)
Exemplo n.º 4
0
class TestLeeway(unittest.TestCase):
    """Tests for Leeway module."""
    def test_leewayprop(self):
        """Check that Leeway properties are properly read."""
        self.objectType = 85  # MED-WASTE-7
        self.lee = Leeway(loglevel=20)
        objectType = self.objectType
        self.assertEqual(self.lee.leewayprop[objectType]['Description'],
                         '>>Medical waste, syringes, small')
        self.assertEqual(self.lee.leewayprop[objectType]['DWSLOPE'], 1.79)

    def test_leeway_config_object(self):
        """Check that correct object type is fetched from config"""
        l = Leeway(loglevel=20)
        l.set_config('seed:object_type', 'Surf board with person')
        l.seed_elements(lon=4.5, lat=60, number=100, time=datetime(2015, 1, 1))
        objType = l.elements_scheduled.objectType
        self.assertEqual(l.leewayprop[objType]['Description'],
                         'Surf board with person')
        self.assertEqual(l.leewayprop[objType]['OBJKEY'],
                         'PERSON-POWERED-VESSEL-2')

    def test_leewayrun(self):
        """Test the expected Leeway left/right split."""
        self.lee = Leeway(loglevel=30)
        self.objectType = 50  # FISHING-VESSEL-1
        self.reader_landmask = reader_global_landmask.Reader(llcrnrlon=3,
                                                             llcrnrlat=59.8,
                                                             urcrnrlon=6,
                                                             urcrnrlat=60.5)
        self.lee.add_reader([self.reader_landmask])
        self.lee.seed_elements(lon=4.5,
                               lat=60,
                               number=100,
                               objectType=self.objectType,
                               time=datetime(2015, 1, 1))
        self.lee.fallback_values['x_wind'] = 0
        self.lee.fallback_values['y_wind'] = 10
        self.lee.fallback_values['x_sea_water_velocity'] = 0
        self.lee.fallback_values['y_sea_water_velocity'] = 0
        # Check that 7 out of 100 elements strand towards coast
        self.lee.run(steps=24, time_step=3600)
        self.assertEqual(self.lee.num_elements_scheduled(), 0)
        self.assertEqual(self.lee.num_elements_active(), 96)
        self.assertEqual(self.lee.num_elements_deactivated(), 4)  # stranded
        self.lee.export_ascii('leeway_ascii.txt')
        os.remove('leeway_ascii.txt')
Exemplo n.º 5
0
def test_leewayrun(tmpdir):
    """Test the expected Leeway left/right split."""
    lee = Leeway(loglevel=30)
    objectType = 50  # FISHING-VESSEL-1
    reader_landmask = reader_global_landmask.Reader(extent=[ 3, 59.8, 6, 60.5 ])
    lee.add_reader([reader_landmask])
    lee.seed_elements(lon=4.5, lat=60, number=100,
                            objectType=objectType,
                            time=datetime(2015, 1, 1))
    lee.fallback_values['x_wind'] = 0
    lee.fallback_values['y_wind'] = 10
    lee.fallback_values['x_sea_water_velocity'] = 0
    lee.fallback_values['y_sea_water_velocity'] = 0
    # Check that 7 out of 100 elements strand towards coast
    lee.run(steps=24, time_step=3600)
    assert lee.num_elements_scheduled() == 0
    assert lee.num_elements_active() == 96
    assert lee.num_elements_deactivated() == 4  # stranded
    lee.export_ascii(tmpdir + '/leeway_ascii.txt')
Exemplo n.º 6
0
def test_leewayrun(tmpdir, test_data):
    """Test the expected Leeway left/right split."""
    lee = Leeway(loglevel=20)
    object_type = 50  # FISHING-VESSEL-1
    reader_landmask = reader_global_landmask.Reader(extent=[ 3, 59.8, 6, 60.5 ])
    lee.add_reader([reader_landmask])
    lee.seed_cone(lon=[4.5, 4.7], lat=[60.1, 60], number=100,
                  object_type=object_type,
                  time=[datetime(2015, 1, 1, 0), datetime(2015, 1, 1, 6)])
    lee.set_config('environment:fallback:x_wind', 0)
    lee.set_config('environment:fallback:y_wind', 10)
    lee.set_config('environment:fallback:x_sea_water_velocity', 0)
    lee.set_config('environment:fallback:y_sea_water_velocity', 0)
    # Check that 10 out of 100 elements strand towards coast
    lee.run(steps=24, time_step=3600)
    assert lee.num_elements_scheduled() == 0
    assert lee.num_elements_active() == 88
    assert lee.num_elements_deactivated() == 12  # stranded

    asciif = tmpdir + '/leeway_ascii.txt'
    lee.export_ascii(asciif)
    asciitarget = test_data + "/generated/test_leewayrun_export_ascii.txt"
    import filecmp
    assert filecmp.cmp(asciif, asciitarget)