예제 #1
0
    def test_density(self):
        """Test density"""
        outfile = 'test_xarray.nc'
        analysis_file = 'test_xarray_analysis.nc'
        o = OceanDrift(loglevel=20)
        o.set_config('environment:fallback:land_binary_mask', 0)
        t1 = datetime.now()
        t2 = t1 + timedelta(hours=6)
        o.seed_elements(time=t1, lon=4, lat=60, number=100, origin_marker=0)
        o.seed_elements(time=[t1, t2],
                        lon=4.2,
                        lat=60.2,
                        number=100,
                        origin_marker=1)
        o.seed_elements(time=[t1, t2],
                        lon=4.1,
                        lat=60.1,
                        number=100,
                        origin_marker=2)
        reader_x = reader_oscillating.Reader('x_sea_water_velocity',
                                             amplitude=1,
                                             zero_time=t1)
        reader_y = reader_oscillating.Reader('y_sea_water_velocity',
                                             amplitude=1,
                                             zero_time=t2)
        o.add_reader([reader_x, reader_y])
        o.set_config('drift:horizontal_diffusivity', 10)
        o.run(duration=timedelta(hours=12), time_step=1800, outfile=outfile)
        #o.plot(fast=True)
        density_pixelsize_m = 5000
        H, Hsub, Hsurf, lon_array, lat_array = o.get_density_array(
            pixelsize_m=density_pixelsize_m)

        ox = opendrift.open_xarray(outfile, analysis_file=analysis_file)
        Hx, lon_arrayx, lat_arrayx = ox.get_density_xarray(
            pixelsize_m=density_pixelsize_m)
        Hx = Hx[0]  # Presently only for origin_marker = 0
        self.assertAlmostEqual(lon_array[0], 3.94, 1)
        self.assertAlmostEqual(lon_array[-1], 4.76, 1)
        self.assertAlmostEqual(lon_arrayx[0], 3.90, 1)
        self.assertAlmostEqual(lon_arrayx[-1], 4.67, 1)
        self.assertEqual(Hx.shape, H.shape)
        Hsum = H.sum(axis=1).sum(axis=1)
        Hxsum = Hx.sum(axis=1).sum(axis=1)
        self.assertEqual(Hsum[0], 118)
        self.assertEqual(Hxsum[0], 118)
        self.assertEqual(Hsum[-1], 300)
        self.assertEqual(Hxsum[-1], 300)
        os.remove(outfile)
        os.remove(analysis_file)
예제 #2
0
    def test_stranding_options(self):
        reader_osc = reader_oscillating.Reader('x_sea_water_velocity',
                                               amplitude=1,
                                               zero_time=datetime.now())

        reader_global = reader_global_landmask.Reader()

        # Three different stranding options, with
        # expected final status and position
        options = ['stranding', 'previous', 'none']
        status = ['stranded', 'active', 'active']
        lons = [12.930, 13.348, 12.444]

        for i, option in enumerate(options):
            o = OceanDrift(loglevel=00)
            o.set_config('general:coastline_action', option)
            o.add_reader([reader_osc, reader_global])
            # Adding northwards drift
            o.fallback_values['y_sea_water_velocity'] = .2
            o.seed_elements(lon=12.2,
                            lat=67.7,
                            radius=0,
                            time=reader_osc.zero_time)
            o.run(steps=28, time_step=3600 * 2)
            #o.plot()
            print('Testing stranding: %s' % option)
            if len(o.elements) == 1:
                el = o.elements
            else:
                el = o.elements_deactivated
            # o.plot ()
            self.assertEqual(o.status_categories[int(el.status)], status[i])
            self.assertIsNone(
                np.testing.assert_array_almost_equal(el.lon, lons[i], 2))
예제 #3
0
 def test_outside_domain(self):
     o = OceanDrift(loglevel=50)
     reader_osc_x = reader_oscillating.Reader(
             'x_sea_water_velocity', amplitude=1,
             zero_time=datetime.now())
     reader_osc_y = reader_oscillating.Reader(
             'y_sea_water_velocity', amplitude=1,
             zero_time=datetime.now())
     o.add_reader([reader_osc_x, reader_osc_y])
     o.set_config('drift:deactivate_east_of', 2.1)
     o.set_config('drift:deactivate_west_of', 1.9)
     o.set_config('drift:deactivate_south_of', 59.9)
     o.set_config('drift:deactivate_north_of', 60.1)
     o.fallback_values['land_binary_mask'] = 0
     o.seed_elements(lon=2, lat=60, number=1000,
                     time=datetime.now(), radius=10000)
     o.run(duration=timedelta(hours=5))
     self.assertEqual(o.num_elements_deactivated(), 768)
     self.assertEqual(o.num_elements_active(), 232)
예제 #4
0
    def test_stranding_options(self):
        reader_osc = reader_oscillating.Reader('x_sea_water_velocity',
                                               amplitude=.5,
                                               period_seconds=3600 * 6,
                                               zero_time=datetime.now())

        reader_global = reader_global_landmask.Reader()

        # Three different stranding options, with
        # expected final status and position
        options = ['stranding', 'previous', 'none']
        status = ['stranded', 'active', 'active']
        lons_backward = [16.157, 16.087, 16.167]
        lons_forward = [16.198, 16.115, 16.167]

        for i, option in enumerate(options):
            for direction in ['forward', 'backward']:
                if direction == 'forward':
                    lons = lons_forward
                    time_step = 900
                else:
                    lons = lons_backward
                    time_step = -900
                o = OceanDrift(loglevel=50)
                o.set_config('general:coastline_action', option)
                o.add_reader([reader_osc, reader_global])
                # Adding northwards drift
                o.set_config('environment:constant:y_sea_water_velocity', .1)
                #o.seed_elements(lon=13.35, lat=68.0, radius=0,
                o.seed_elements(lon=16.12,
                                lat=68.5,
                                radius=0,
                                time=reader_osc.zero_time)
                o.run(duration=timedelta(hours=22), time_step=time_step)
                #o.animation()
                #o.plot ()
                print('Testing stranding: %s, %s' % (option, direction))
                if len(o.elements) == 1:
                    el = o.elements
                else:
                    el = o.elements_deactivated
                self.assertEqual(o.status_categories[int(el.status)],
                                 status[i])
                self.assertIsNone(
                    np.testing.assert_array_almost_equal(el.lon, lons[i], 3))
예제 #5
0
#%%
# First make a simulation with two seedings, marked by *origin_marker*
o = OceanDrift(loglevel=50)
t1 = datetime.now()
t2 = t1 + timedelta(hours=6)
number = 10000
outfile = 'simulation.nc'  # Raw simulation output
o.seed_elements(time=t1, lon=4, lat=60, number=number, origin_marker=0)
o.seed_elements(time=[t1, t2],
                lon=4.2,
                lat=60.4,
                number=number,
                origin_marker=1)

reader_x = reader_oscillating.Reader('x_sea_water_velocity',
                                     amplitude=1,
                                     zero_time=t1)
reader_y = reader_oscillating.Reader('y_sea_water_velocity',
                                     amplitude=1,
                                     zero_time=t2)
o.add_reader([reader_x, reader_y])
o.set_config('drift:horizontal_diffusivity', 10)
o.run(duration=timedelta(hours=24),
      time_step=900,
      time_step_output=1800,
      outfile=outfile)

#%%
# Opening the output file lazily with Xarray.
# This will work even if the file is too large to fit in memory, as it
# will read and process data chuck-by-chunk directly from file using Dask.
"""
Coastline with options
======================

Example to illustrate stranding options using an artificial
east-west oscillating current field
Knut-Frode Dagestad, Feb 2017
"""

from datetime import datetime
from opendrift.readers import reader_oscillating
from opendrift.models.oceandrift import OceanDrift

o = OceanDrift(loglevel=50)  # Set loglevel to 0 for debug information

reader_osc = reader_oscillating.Reader('x_sea_water_velocity', amplitude=1,
                                       zero_time=datetime.now())
o.add_reader([reader_osc])  # Oscillating east-west current component

o.fallback_values['y_sea_water_velocity'] = .2  # Adding northwards drift

#%%
# Try different options: 'previous', 'stranding', 'none'
o.set_config('general:coastline_action', 'previous')

o.seed_elements(lon=12.2, lat=67.7, radius=5000, number=25, time=reader_osc.zero_time)

o.run(steps=36*4, time_step=900, time_step_output=1800)

#%%
# Print and plot results
print(o)
예제 #7
0
#!/usr/bin/env python
"""
Sediment drift with resuspension
================================
"""

from datetime import timedelta, datetime
from opendrift.readers import reader_oscillating
from opendrift.models.sedimentdrift import SedimentDrift

#%%
# Constructing an artificial current field where x- and y-components are oscilating with different amplitude and period
reader_oscx = reader_oscillating.Reader('x_sea_water_velocity',
                                        amplitude=0.6,
                                        zero_time=datetime.utcnow())
reader_oscy = reader_oscillating.Reader('y_sea_water_velocity',
                                        amplitude=.3,
                                        period_seconds=3600 * 5,
                                        zero_time=datetime.utcnow())

o = SedimentDrift(loglevel=50)  # 0 for debug output

#%%
# Seeding sediments
o.seed_elements(
    lon=4.65,
    lat=60,
    number=10000,
    time=[datetime.utcnow(),
          datetime.utcnow() + timedelta(hours=6)],
    terminal_velocity=-.01)  # 1 cm/s settling speed
예제 #8
0
from opendrift.readers import reader_ROMS_native
from opendrift.readers import reader_oscillating

from opendrift.models.oceandrift import OceanDrift

o = OceanDrift(loglevel=0)  # Set loglevel to 0 for debug information

# Adding nordic reader for coastline
reader_nordic = reader_ROMS_native.Reader(
    o.test_data_folder() +
    '2Feb2016_Nordic_sigma_3d/Nordic-4km_SLEVELS_avg_00_subset2Feb2016.nc')
reader_nordic.variables = ['land_binary_mask']

reader_osc = reader_oscillating.Reader('x_sea_water_velocity',
                                       amplitude=1,
                                       zero_time=reader_nordic.start_time)
o.add_reader([reader_osc])  # Oscillating east-west current component

o.fallback_values['y_sea_water_velocity'] = .2  # Adding northwards drift
o.set_config('general:basemap_resolution', 'i')

##########################################################
# Try different options: 'previous', 'stranding', 'none'
o.set_config('general:coastline_action', 'previous')
##########################################################

time = reader_osc.zero_time
lon = 12.2
lat = 67.7
o.seed_elements(lon, lat, radius=5000, number=15, time=time)
예제 #9
0
t1 = datetime.now()
t2 = t1 + timedelta(hours=48)
number = 25000
o.seed_elements(time=[t1, t2],
                lon=9.017931,
                lat=58.562702,
                number=number,
                origin_marker=0)  # River 1
o.seed_elements(time=[t1, t2],
                lon=8.824815,
                lat=58.425648,
                number=number,
                origin_marker=1)  # River 2

reader_x = reader_oscillating.Reader('x_sea_water_velocity',
                                     period_seconds=3600 * 24,
                                     amplitude=1,
                                     zero_time=t1)
reader_y = reader_oscillating.Reader('y_sea_water_velocity',
                                     period_seconds=3600 * 72,
                                     amplitude=.5,
                                     zero_time=t2)
o.add_reader([reader_x, reader_y])
o.set_config('drift:horizontal_diffusivity', 300)
o.set_config('general:coastline_action', 'previous')
o.run(duration=timedelta(hours=48),
      time_step=1800,
      time_step_output=3600,
      outfile=outfile)

#%%
# Opening the output file lazily with Xarray.
# - 'lift_to_seafloor': particles are lifted vertically to seafloor level
#
# This is controlled by the config setting:
# o.set_config('general:seafloor_action', <action>)


from datetime import timedelta
from opendrift.readers import reader_netCDF_CF_generic
from opendrift.models.oceandrift import OceanDrift
from opendrift.readers import reader_oscillating


# readers
o = OceanDrift(loglevel=50)
reader_norkyst = reader_netCDF_CF_generic.Reader(o.test_data_folder() + '14Jan2016_NorKyst_z_3d/NorKyst-800m_ZDEPTHS_his_00_3Dsubset.nc')
reader_osc = reader_oscillating.Reader('x_sea_water_velocity', amplitude=10, period_seconds=3600)

runs = []
seafloor_actions = ['previous', 'deactivate', 'lift_to_seafloor']

for seafloor_action in seafloor_actions:

    o = OceanDrift(loglevel=50)  # Set loglevel to 0 for debug information
    o.max_speed = 10

    o.add_reader([reader_osc, reader_norkyst])

    o.set_config('drift:horizontal_diffusivity', 0)
    o.set_config('environment:constant:y_sea_water_velocity', 0)
    o.set_config('environment:constant:land_binary_mask', 0)
    o.set_config('general:use_auto_landmask', False)