Ejemplo n.º 1
0
def test_environment_mapping(test_data):

    # Wind from NE
    r = reader_constant.Reader({
        'wind_speed': 5,
        'wind_from_direction': 45,
        'land_binary_mask': 0
    })
    o = OceanDrift(loglevel=50)
    o.set_config('general:use_auto_landmask', False)
    o.add_reader(r)
    o.seed_elements(lon=4, lat=60, time=datetime.now())
    o.run(steps=15)
    np.testing.assert_almost_equal(o.elements.lon, 3.932, 3)
    np.testing.assert_almost_equal(o.elements.lat, 59.966, 3)
    # Wind from SW
    r = reader_constant.Reader({
        'wind_speed': 5,
        'wind_from_direction': 225,
        'land_binary_mask': 0
    })
    o = OceanDrift(loglevel=50)
    o.set_config('general:use_auto_landmask', False)
    o.add_reader(r)
    o.seed_elements(lon=4, lat=60, time=datetime.now())
    o.run(steps=15)
    np.testing.assert_almost_equal(o.elements.lon, 4.068, 3)
    np.testing.assert_almost_equal(o.elements.lat, 60.034, 3)
Ejemplo n.º 2
0
 def test_constant_reader(self):
     o = OpenOil(loglevel=0)
     cw = reader_constant.Reader({'x_wind':5, 'y_wind': 6})
     cc = reader_constant.Reader({'x_sea_water_velocity':0, 'y_sea_water_velocity': .2})
     cs = reader_constant.Reader({'sea_water_temperature': 278})
     r = reader_netCDF_CF_generic.Reader(o.test_data_folder() +
         '16Nov2015_NorKyst_z_surface/norkyst800_subset_16Nov2015.nc')
     o.add_reader([cw, cc, r])
     # TODO: should check why adding constant reader with
     #   sea_water_temperature gives Deprecated warning
     #o.add_reader([cw, cc, cs, r])
     o.seed_elements(lon=4, lat=60, time=r.start_time, number=5)
     o.run(steps=3)
Ejemplo n.º 3
0
    def test_constant_and_lazy_reader_leeway(self):
        cw = reader_constant.Reader({'x_wind':5, 'y_wind': 6})
        cc = reader_constant.Reader({'x_sea_water_velocity':0,
                                     'y_sea_water_velocity': .2})

        o = Leeway(loglevel=20)
        o.add_reader([cw, cc])
        o.add_readers_from_list(reader_list)
        o.set_config('environment:fallback:x_sea_water_velocity', 0.0)
        o.set_config('environment:fallback:y_sea_water_velocity', 0.1)
        time = datetime(2016,2,2,12)
        o.seed_elements(lat=67.85, lon=14, time=time)
        o.run(steps=2)
        self.assertAlmostEqual(o.elements.lat[0], 67.8548, 3)
Ejemplo n.º 4
0
 def test_shipdrift(self):
     """Sintef case study"""
     s = ShipDrift(loglevel=50)
     s.set_config('drift:current_uncertainty', 0)
     s.set_config('drift:wind_uncertainty', 0)
     c = reader_constant.Reader({
         'sea_surface_wave_significant_height':
         5,
         'sea_surface_wave_mean_period_from_variance_spectral_density_second_frequency_moment':
         11,
         'x_wind':
         14.14213562,
         'y_wind':
         -14.14213562,
         'x_sea_water_velocity':
         0.05656854249,
         'y_sea_water_velocity':
         -0.05656854249
     })
     s.fallback_values['land_binary_mask'] = 0
     s.add_reader(c)
     s.seed_elements(lon=2,
                     lat=60,
                     time=datetime.now(),
                     number=1,
                     length=80,
                     beam=14,
                     height=25,
                     draft=5)
     s.run(time_step=600, duration=timedelta(hours=4))
     self.assertIsNone(
         np.testing.assert_array_almost_equal(s.elements.lon, 2.25267706))
     self.assertIsNone(
         np.testing.assert_array_almost_equal(s.elements.lat, 59.87694775))
Ejemplo n.º 5
0
 def test_shipdrift_backwards(self):
     """Case above, reversed"""
     s = ShipDrift(loglevel=50)
     c = reader_constant.Reader({
         'sea_surface_wave_significant_height':
         5,
         'sea_surface_wave_mean_period_from_variance_spectral_density_second_frequency_moment':
         11,
         'x_wind':
         14.14213562,
         'y_wind':
         -14.14213562,
         'x_sea_water_velocity':
         0.05656854249,
         'y_sea_water_velocity':
         -0.05656854249
     })
     s.set_config('environment:fallback:land_binary_mask', 0)
     s.add_reader(c)
     s.seed_elements(lon=2.25267706,
                     lat=59.87694775,
                     time=datetime.now(),
                     number=1,
                     length=80,
                     beam=14,
                     height=25,
                     draft=5)
     s.run(time_step=-600, duration=timedelta(hours=4))
     self.assertIsNone(
         np.testing.assert_array_almost_equal(s.elements.lon, 2.0, 3))
     self.assertIsNone(
         np.testing.assert_array_almost_equal(s.elements.lat, 60, 3))
Ejemplo n.º 6
0
 def test_shipdrift(self):
     """Sintef case study"""
     s = ShipDrift(loglevel=50)
     s.set_config('drift:horizontal_diffusivity', 0)
     c = reader_constant.Reader({
         'sea_surface_wave_significant_height':
         5,
         'sea_surface_wave_mean_period_from_variance_spectral_density_second_frequency_moment':
         11,
         'x_wind':
         14.14213562,
         'y_wind':
         -14.14213562,
         'x_sea_water_velocity':
         0.05656854249,
         'y_sea_water_velocity':
         -0.05656854249
     })
     s.set_config('environment:fallback:land_binary_mask', 0)
     s.add_reader(c)
     s.list_configspec('seed')
     s.set_config('seed:orientation', 'left')
     s.seed_elements(lon=2,
                     lat=60,
                     time=datetime.now(),
                     number=3,
                     length=80,
                     beam=14,
                     height=25,
                     draft=5)
     s.run(time_step=600, duration=timedelta(hours=4))
     self.assertIsNone(
         np.testing.assert_array_almost_equal(s.elements.lon, 2.254, 3))
     self.assertIsNone(
         np.testing.assert_array_almost_equal(s.elements.lat, 59.873, 3))
Ejemplo n.º 7
0
    def test_constant_and_lazy_reader_leeway(self):
        cw = reader_constant.Reader({'x_wind': 5, 'y_wind': 6})
        cc = reader_constant.Reader({
            'x_sea_water_velocity': 0,
            'y_sea_water_velocity': .2
        })

        o = Leeway(loglevel=20)
        o.set_config('general:basemap_resolution', 'c')
        o.add_reader([cw, cc])
        o.add_readers_from_list(reader_list)
        o.fallback_values['x_sea_water_velocity'] = 0.0
        o.fallback_values['y_sea_water_velocity'] = 0.1
        time = datetime(2016, 2, 2, 12)
        o.seed_elements(lat=67.85, lon=14, time=time)
        o.run(steps=2)
        self.assertAlmostEqual(o.elements.lat[0], 67.8548, 3)
Ejemplo n.º 8
0
 def test_seed_seafloor(self):
     # Check that seed:seafloor overrides z to 'seafloor'
     o = OceanDrift(loglevel=50)
     from opendrift.readers import reader_constant
     r = reader_constant.Reader({'sea_floor_depth_below_sea_level': 200})
     o.add_reader(r)
     o.set_config('seed:seafloor', True)
     o.seed_elements(lon=4, lat=60, time=datetime.now())
     self.assertAlmostEqual(o.elements_scheduled.z[0], -200)
Ejemplo n.º 9
0
    def test_lazy_reader_oildrift(self):
        o = OpenOil3D(loglevel=20)
        reader_constant_wind = \
            reader_constant.Reader({'x_wind':5, 'y_wind': 6})
        o.add_reader(reader_constant_wind)

        o.add_readers_from_list(reader_list, lazy=True)

        self.assertEqual(len(o._lazy_readers()), 4)
        o.set_config('general:basemap_resolution', 'c')
        o.seed_elements(lon=14, lat=67.85, time=datetime(2016, 2, 2, 12))
        o.run(steps=5)
        self.assertEqual(len(o._lazy_readers()), 2)
        self.assertEqual(len(o.discarded_readers), 1)
Ejemplo n.º 10
0
def test_environment_mapping(test_data):

    # Wind from NE
    r = reader_constant.Reader({
        'wind_speed': 5,
        'wind_from_direction': 45,
        'land_binary_mask': 0
    })
    o = OceanDrift(loglevel=50)
    o.set_config('general:use_auto_landmask', False)
    o.add_reader(r)
    o.seed_elements(lon=4, lat=60, time=datetime.now())
    o.run(steps=15)
    np.testing.assert_almost_equal(o.elements.lon, 3.932, 3)
    np.testing.assert_almost_equal(o.elements.lat, 59.966, 3)
    # Wind from SW
    r = reader_constant.Reader({
        'wind_speed': 5,
        'wind_from_direction': 225,
        'land_binary_mask': 0
    })
    o = OceanDrift(loglevel=50)
    o.set_config('general:use_auto_landmask', False)
    o.add_reader(r)
    o.seed_elements(lon=4, lat=60, time=datetime.now())
    o.run(steps=15)
    np.testing.assert_almost_equal(o.elements.lon, 4.068, 3)
    np.testing.assert_almost_equal(o.elements.lat, 60.034, 3)

    # land_binary_mask mapped from sea_floor_depth_below_sea_level
    r = reader_netCDF_CF_generic.Reader(
        o.test_data_folder() +
        '14Jan2016_NorKyst_z_3d/NorKyst-800m_ZDEPTHS_his_00_3Dsubset.nc')
    assert 'land_binary_mask' not in r.derived_variables  # Disabled by default
    r.activate_environment_mapping('land_binary_mask_from_ocean_depth')
    assert 'land_binary_mask' in r.derived_variables
Ejemplo n.º 11
0
 def test_shipdrift_defaults(self):
     s = ShipDrift(loglevel=0)
     #s.list_configspec()
     s.set_config('environment:fallback:land_binary_mask', 0)
     c = reader_constant.Reader({
         'sea_surface_wave_significant_height': 5,
         'sea_surface_wave_mean_period_from_variance_spectral_density_second_frequency_moment': 11,
         'x_wind': 14.14213562,
         'y_wind': -14.14213562,
         'x_sea_water_velocity': 0.05656854249,
         'y_sea_water_velocity': -0.05656854249})
     s.add_reader(c)
     s.set_config('seed:height', 14)
     s.seed_elements(lon=2, lat=60, time=datetime.now(), number=1)
     s.run(duration=timedelta(hours=4))
     #self.assertAlmostEqual(s.elements.lon.max(), 2.1273, 3)  # Without setting config
     self.assertAlmostEqual(s.elements.lon.max(), 2.1990, 3)
Ejemplo n.º 12
0
    def test_lazy_reader_oildrift(self):
        o = OpenOil3D(loglevel=0)
        reader_constant_wind = \
            reader_constant.Reader({'x_wind':5, 'y_wind': 6,
                                    'sea_ice_area_fraction': 0})
        # Added ice area to prevent problems with masking
        # with older versions of netCDF library
        o.add_reader(reader_constant_wind)

        o.add_readers_from_list(reader_list, lazy=True)

        self.assertEqual(len(o._lazy_readers()), 4)
        o.seed_elements(lon=14, lat=67.85, time=datetime(2016, 2, 2, 12))
        o.run(steps=5)
        print(o)  # Debug, this fails for old libraries
        self.assertEqual(len(o._lazy_readers()), 2)
        self.assertEqual(len(o.discarded_readers), 1)
Ejemplo n.º 13
0
#!/usr/bin/env python
"""
Openoil sample output netCDF file
==================================
"""

import os
from datetime import timedelta
from opendrift.readers import reader_netCDF_CF_generic
from opendrift.readers import reader_constant
from opendrift.models.openoil import OpenOil

o = OpenOil(loglevel=20, weathering_model='noaa')

rc = reader_constant.Reader({'x_wind': 5,
                             'y_wind': 4})

# Arome
reader_arome = reader_netCDF_CF_generic.Reader(o.test_data_folder() +
    '16Nov2015_NorKyst_z_surface/arome_subset_16Nov2015.nc')

# Norkyst
reader_norkyst = reader_netCDF_CF_generic.Reader(o.test_data_folder() +
    '16Nov2015_NorKyst_z_surface/norkyst800_subset_16Nov2015.nc')

o.add_reader([rc, reader_norkyst, reader_arome])

#%%
# Seed oil elements at defined position and time
time = [reader_arome.start_time,
        reader_arome.start_time + timedelta(hours=1)]