Beispiel #1
0
    def test_stranding_options(self):

        reader_osc = reader_oscillating.Reader(
                'x_sea_water_velocity', amplitude=1,
                zero_time=datetime.now())

        reader_basemap = reader_basemap_landmask.Reader(
                    llcrnrlon=12, llcrnrlat=67.6,
                    urcrnrlon=13.6, urcrnrlat=68.1,
                    resolution='i', projection='merc')
 
        # 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=30)
            o.set_config('general:coastline_action', option)
            o.add_reader([reader_osc, reader_basemap])
            # 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)
            print 'Testing stranding: %s' % option
            if len(o.elements) == 1:
                el = o.elements
            else:
                el = o.elements_deactivated
            self.assertEqual(o.status_categories[int(el.status)], status[i])
            self.assertAlmostEqual(el.lon, lons[i], 2)
Beispiel #2
0
    def test_reader_order(self):
        # Check that we get the same output indepenently of reader order
        o = OceanDrift(loglevel=50)
        norkyst = reader_netCDF_CF_generic.Reader(o.test_data_folder() +
            '16Nov2015_NorKyst_z_surface/norkyst800_subset_16Nov2015.nc')
        arome = reader_netCDF_CF_generic.Reader(o.test_data_folder() +
            '16Nov2015_NorKyst_z_surface/arome_subset_16Nov2015.nc')
        basemap = reader_basemap_landmask.Reader(
            llcrnrlon=2, llcrnrlat=59.8, urcrnrlon=6, urcrnrlat=61,
            resolution='c', projection='merc')
        lon=4.; lat=60.

        # First run
        o.add_reader([basemap, norkyst, arome])
        o.seed_elements(lon, lat, time=norkyst.start_time)
        o.run(steps=30)
        # Second run
        # Check that we get almost identical results with other projection
        o1 = OceanDrift(loglevel=50)
        o1.add_reader([norkyst, arome, basemap])
        o1.seed_elements(lon, lat, time=norkyst.start_time)
        o1.run(steps=30)
        self.assertAlmostEqual(o.elements.lon, o1.elements.lon, 2)
        self.assertAlmostEqual(o.elements.lat, o1.elements.lat, 2)
        # Third run
        # Check that this is identical to run 1 if projection set equal
        o2 = OceanDrift(loglevel=50)
        o2.add_reader([norkyst, arome, basemap])
        o2.seed_elements(lon, lat, time=norkyst.start_time)
        o2.set_projection(basemap.proj4)
        o2.run(steps=30)
        self.assertEqual(o.elements.lon, o2.elements.lon)
Beispiel #3
0
 def test_buffer_length_stranding(self):
     o1 = OceanDrift(loglevel=30)
     norkyst = reader_netCDF_CF_generic.Reader(o1.test_data_folder() +
         '16Nov2015_NorKyst_z_surface/norkyst800_subset_16Nov2015.nc')
     basemap = reader_basemap_landmask.Reader(
         llcrnrlon=4.5, llcrnrlat=60.1,
         urcrnrlon=6.0, urcrnrlat=60.4,
         resolution='c', projection='merc')
     o1.add_reader([basemap])
     o1.fallback_values['x_sea_water_velocity'] = 0.8  # onshore drift
     o1.seed_elements(4.8, 60.2, radius=5000, number=100,
                     time=norkyst.start_time)
     o1.run(steps=100,
            time_step=900,
            time_step_output=3600,
            export_buffer_length=10)
     # Without buffer
     o2 = OceanDrift(loglevel=30)
     o2.add_reader([basemap])
     o2.fallback_values['x_sea_water_velocity'] = 0.8  # onshore drift
     o2.seed_elements(4.8, 60.2, radius=5000, number=100,
                     time=norkyst.start_time)
     o2.run(steps=100,
            time_step=900,
            time_step_output=3600,
            outfile='test_buffer_length_stranding.nc')
     self.assertItemsEqual(o1.history['lon'].compressed(),
                           o2.history['lon'].compressed())
     self.assertItemsEqual(o1.history['status'].compressed(),
                           o2.history['status'].compressed())
     os.remove('test_buffer_length_stranding.nc')
Beispiel #4
0
    def test_openberg(self):
        """Check if weighting array is set correctly
        and if model returns expected positions"""
        o = OpenBerg(loglevel=50)

        reader_current = reader_netCDF_CF_generic.Reader(
            o.test_data_folder() +
            '14Jan2016_NorKyst_z_3d/NorKyst-800m_ZDEPTHS_his_00_3Dsubset.nc')

        reader_basemap = reader_basemap_landmask.Reader(llcrnrlon=3.,
                                                        llcrnrlat=60.,
                                                        urcrnrlon=5.,
                                                        urcrnrlat=63.5,
                                                        resolution='c',
                                                        projection='gall')
        # reader_basemap = reader_basemap_landmask.Reader(llcrnrlon=-1.5, llcrnrlat=59, urcrnrlon=7, urcrnrlat=64, resolution='c')

        o.add_reader([reader_current, reader_basemap])
        o.seed_elements(4., 62., time=reader_current.start_time)
        o.run(steps=1)

        arr = [
            0.16072658, 0.16466097, 0.17384121, 0.17325179, 0.1715925,
            0.15592695
        ]

        for indx in range(len(arr)):
            self.assertAlmostEqual(o.uw_weighting[indx], arr[indx], 8)

        self.assertAlmostEqual(o.history['lon'].data[0][1], 3.9921231, 3)
        self.assertAlmostEqual(o.history['lat'].data[0][1], 62.0108299, 3)
Beispiel #5
0
    def test_adding_readers(self):
        o = OceanDrift()
        basemap = reader_basemap_landmask.Reader(llcrnrlon=-1.5,
                                                 llcrnrlat=59,
                                                 urcrnrlon=7,
                                                 urcrnrlat=64,
                                                 resolution='c')
        r = reader_ROMS_native.Reader(
            o.test_data_folder() +
            '2Feb2016_Nordic_sigma_3d/Nordic-4km_SLEVELS_avg_00_subset2Feb2016.nc'
        )
        o.add_reader([r, basemap])
        self.assertEqual(o.priority_list['land_binary_mask'],
                         ['roms native', 'basemap_landmask'])
        self.assertEqual(o.priority_list['x_sea_water_velocity'],
                         ['roms native'])
        # Switch order
        o = OceanDrift()
        o.add_reader([basemap, r])
        self.assertEqual(o.priority_list['land_binary_mask'],
                         ['basemap_landmask', 'roms native'])
        self.assertEqual(o.priority_list['x_sea_water_velocity'],
                         ['roms native'])

        # Test add_readers_from_list
        o = OceanDrift()
        o.add_readers_from_list(reader_list, lazy=False)
        self.assertEqual(o.priority_list['x_sea_water_velocity'],
                         ['roms native'])
        self.assertEqual(o.priority_list['x_wind'], [
            o.test_data_folder() +
            '2Feb2016_Nordic_sigma_3d/AROME_MetCoOp_00_DEF.nc_20160202_subset'
        ])
Beispiel #6
0
 def test_seed_outside_coverage(self):
     """Test seeding"""
     o = OpenOil3D(loglevel=0)
     norkyst = reader_netCDF_CF_generic.Reader(
         o.test_data_folder() +
         '14Jan2016_NorKyst_z_3d/NorKyst-800m_ZDEPTHS_his_00_3Dsubset.nc')
     basemap = reader_basemap_landmask.Reader(llcrnrlon=4,
                                              llcrnrlat=60,
                                              urcrnrlon=6,
                                              urcrnrlat=64,
                                              resolution='c',
                                              projection='merc')
     o.add_reader([basemap, norkyst])
     o.fallback_values['x_wind'] = 0
     o.fallback_values['y_wind'] = 0
     o.set_config('seed:oil_type', 'SNORRE B')
     o.seed_elements(5,
                     63,
                     number=5,
                     time=norkyst.start_time - 24 * timedelta(hours=24))
     # Check that the oiltype is taken from config
     self.assertEqual(o.oil_name, o.get_config('seed:oil_type'))
     self.assertEqual(o.oil_name, 'SNORRE B')
     with self.assertRaises(ValueError):
         o.run(steps=3, time_step=timedelta(minutes=15))
Beispiel #7
0
 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')
Beispiel #8
0
    def get(self):

        parser = reqparse.RequestParser()
        parser.add_argument('latitude', type=float, help='Latitude of the object')
        parser.add_argument('longitude', type=float, help='Longitude of object')
        args = parser.parse_args(strict=True)
        if args['latitude'] is not None and args['longitude'] is not None:
            if abs(args['latitude']) > 90 :
                abort(404, message="latitude is out of range of -90 <= latitude <= 90")
            
            if abs(args['longitude']) > 180:
                abort(404, message='longitude is out of range of -180 <= longitude <= 180')
            
            latitude = args['latitude']
            longitude = args['longitude']
            lw = Leeway()  # Set loglevel to 0 for debug information

            # Arome
            #reader_arome = reader_netCDF_CF_generic.Reader('http://thredds.met.no/thredds/dodsC/arome25/arome_metcoop_default2_5km_latest.nc')
            reader_arome = reader_netCDF_CF_generic.Reader(lw.test_data_folder() + 
                '16Nov2015_NorKyst_z_surface/arome_subset_16Nov2015.nc')

            reader_norkyst = reader_netCDF_CF_generic.Reader('http://tds.hycom.org/thredds/dodsC/GLBu0.08/expt_91.2/uv3z')

            # Landmask (Basemap)
            reader_basemap = reader_basemap_landmask.Reader(
                                llcrnrlon=longitude-2, llcrnrlat=latitude-2,
                                urcrnrlon=longitude+2, urcrnrlat=latitude+2, resolution='h',
                                projection='merc')
            
            #lw.add_reader([reader_norkyst, reader_arome, reader_basemap])
            # Adding readers succesively, and specifying which variables they 
            # shall provide. This way, order of adding readers does not matter,
            # except for small rounding differences due to different projection
            lw.add_reader(reader_norkyst,
                        variables=['x_sea_water_velocity', 'y_sea_water_velocity'])
            lw.add_reader(reader_arome,
                        variables=['x_wind', 'y_wind'])
            lw.add_reader(reader_basemap,
                        variables=['land_binary_mask'])

            # Seed leeway elements at defined position and time
            objType = 26  # 26 = Life-raft, no ballast
            lw.seed_elements(longitude, latitude, radius=100, number=30,
                            time=reader_arome.start_time, objectType=objType)

            lw.set_projection('+proj=merc')

            lw.run(steps=60*4, time_step=900)
            
            lp = lw.plot(show=False)
            img = StringIO.StringIO()
            lp[1].savefig(img,format='png')
            img.seek(0)
            response=make_response(img.buf)
            response.headers['Content-Type'] = 'image/png'
            return response
        else:
            abort(404, message="Requires latitude and longitude but none were given.")
Beispiel #9
0
 def make_OceanDrift_object(self):
     self.o = OceanDrift(loglevel=30)
     self.fake_eddy = reader_ArtificialOceanEddy.Reader(2, 62)
     self.o.use_block = False
     self.reader_basemap = reader_basemap_landmask.Reader(
         llcrnrlon=-1.5, llcrnrlat=59,
         urcrnrlon=7, urcrnrlat=64, resolution='c')
     self.o.add_reader([self.fake_eddy, self.reader_basemap])
Beispiel #10
0
 def test_output_time_step(self):
     o1 = OceanDrift(loglevel=30)
     norkyst = reader_netCDF_CF_generic.Reader(o1.test_data_folder() +
         '16Nov2015_NorKyst_z_surface/norkyst800_subset_16Nov2015.nc')
     basemap = reader_basemap_landmask.Reader(
         llcrnrlon=4.5, llcrnrlat=60.0,
         urcrnrlon=5.2, urcrnrlat=60.5,
         resolution='i', projection='merc')
     o1.add_reader([basemap, norkyst])
     o1.seed_elements(4.96, 60.1, radius=3000, number=100,
                     time=norkyst.start_time)
     o1.run(duration=timedelta(hours=12),
                time_step=timedelta(minutes=30),
                time_step_output=timedelta(minutes=30),
                outfile='test_time_step30.nc')
     # Check length of time array and output array
     time = o1.get_time_array()[0]
     self.assertEqual(o1.history.shape[1], len(time))
     self.assertEqual(o1.start_time, time[0])
     self.assertEqual(o1.time, time[-1])
     # Second run, with larger output time step
     o2 = OceanDrift(loglevel=30)
     o2.add_reader([basemap, norkyst])
     o2.seed_elements(4.96, 60.1, radius=3000, number=100,
                     time=norkyst.start_time)
     o2.run(duration=timedelta(hours=12),
                time_step=timedelta(minutes=30),
                time_step_output=timedelta(minutes=60),
                outfile='test_time_step60.nc')
     self.assertEqual(o1.history.shape, (100,25))
     self.assertEqual(o2.history.shape, (100,13))
     # Check that start and end conditions (longitudes) are idential
     self.assertItemsEqual(o1.history['lon'][:,24].compressed(), 
                           o2.history['lon'][:,12].compressed())
     self.assertItemsEqual(o1.history['lon'][:,0].compressed(),
                           o2.history['lon'][:,0].compressed())
     # Check that also run imported from file is identical
     o1i = OceanDrift(loglevel=20)
     o1i.io_import_file('test_time_step30.nc')
     o2i = OceanDrift(loglevel=20)
     o2i.io_import_file('test_time_step60.nc')
     os.remove('test_time_step30.nc')
     os.remove('test_time_step60.nc')
     self.assertItemsEqual(o2i.history['lon'][:,12].compressed(),
                           o2.history['lon'][:,12].compressed())
     # Check number of activated elements
     self.assertEqual(o1.num_elements_total(), o2.num_elements_total())
     self.assertEqual(o1.num_elements_total(), o1i.num_elements_total())
     self.assertEqual(o1.num_elements_total(), o2i.num_elements_total())
     # Check number of deactivated elements
     self.assertEqual(o1.num_elements_deactivated(),
                      o2.num_elements_deactivated())
     self.assertEqual(o1.num_elements_deactivated(),
                      o1i.num_elements_deactivated())
     self.assertEqual(o1.num_elements_deactivated(),
                      o2i.num_elements_deactivated())
Beispiel #11
0
def test_basemap_global_matches(test_data):
    reader_global = reader_global_landmask.Reader()
    reader_basemap = reader_basemap_landmask.Reader(llcrnrlon=4,
                                                    llcrnrlat=59,
                                                    urcrnrlon=18,
                                                    urcrnrlat=68.1,
                                                    resolution='i',
                                                    projection='merc')

    reader_nordic = reader_ROMS_native.Reader(
        test_data +
        '2Feb2016_Nordic_sigma_3d/Nordic-4km_SLEVELS_avg_00_subset2Feb2016.nc')

    land = (np.array([15.]), np.array([65.6]))
    ocean = (np.array([5.]), np.array([65.6]))

    # basemap
    ob = OceanDrift(loglevel=00)
    ob.add_reader([reader_nordic, reader_basemap])

    en, en_prof, missing = ob.get_environment(['land_binary_mask'],
                                              reader_nordic.start_time,
                                              land[0], land[1], np.array([0]),
                                              None)

    assert en.land_binary_mask == np.array([True])

    en, en_prof, missing = ob.get_environment(['land_binary_mask'],
                                              reader_nordic.start_time,
                                              ocean[0], ocean[1],
                                              np.array([0]), None)

    assert en.land_binary_mask == np.array([False])
    assert len(ob.readers) == 2

    # global landmask
    oc = OceanDrift(loglevel=00)
    oc.add_reader([reader_nordic, reader_global])
    en, en_prof, missing = oc.get_environment(['land_binary_mask'],
                                              reader_nordic.start_time,
                                              land[0], land[1], np.array([0]),
                                              None)

    assert en.land_binary_mask == np.array([True])

    en, en_prof, missing = oc.get_environment(['land_binary_mask'],
                                              reader_nordic.start_time,
                                              ocean[0], ocean[1],
                                              np.array([0]), None)

    assert en.land_binary_mask == np.array([False])
    assert len(
        oc.readers) == 2  # make sure opendrift doesn't add default basemap
Beispiel #12
0
    def test_MFDataset(self):

        reader_basemap = reader_basemap_landmask.Reader(llcrnrlon=13.5,
                                                        llcrnrlat=67.1,
                                                        urcrnrlon=14.6,
                                                        urcrnrlat=67.7,
                                                        resolution='i',
                                                        projection='merc')

        o = OceanDrift3D(loglevel=0)
        o.set_config('general:basemap_resolution', 'i')
        nordicMF = reader_ROMS_native.Reader(
            o.test_data_folder() +
            '2Feb2016_Nordic_sigma_3d/Nordic_subset_day*.nc')
        nordicMF_all = reader_ROMS_native.Reader(
            o.test_data_folder() + '2Feb2016_Nordic_sigma_3d/Nordic_subset.nc')
        lon = 14.0
        lat = 67.3
        #nordic3d = reader_ROMS_native.Reader(o.test_data_folder() +
        #    '2Feb2016_Nordic_sigma_3d/Nordic-4km_SLEVELS_avg_00_subset2Feb2016.nc')
        #o.add_reader(nordic3d)  # Slightly different results
        # Subset is made with ncks, and should give identical result
        # e0=0, e1=20, x0=40, x1=70
        # ncks -d eta_rho,0,$e1 -d eta_psi,0,$e1 -d eta_v,0,$e1 -d eta_u,0,$e1 -d xi_rho,$x0,$x1 -d xi_psi,$x0,$x1 -d xi_v,$x0,$x1 -d xi_u,$x0,$x1 Nordic-4km_SLEVELS_avg_00_subset2Feb2016.nc Nordic_subset.nc -O --fl_fmt=netcdf4_classic
        # ncks -O -d ocean_time,0 Nordic_subset.nc Nordic_subset_day1.nc
        o.add_reader([reader_basemap, nordicMF_all])
        o.seed_elements(lon,
                        lat,
                        number=100,
                        radius=5000,
                        time=nordicMF_all.start_time)
        o.run(steps=48, time_step=3600)

        # Same run, with multi-file dataset
        o2 = OceanDrift3D(loglevel=30)
        o2.set_config('general:basemap_resolution', 'i')
        o2.add_reader([reader_basemap, nordicMF])
        o2.seed_elements(lon,
                         lat,
                         number=100,
                         radius=5000,
                         time=nordicMF_all.start_time)
        o2.run(steps=48, time_step=3600)

        #o.plot(filename='o1.png', background='sea_floor_depth_below_sea_level')
        #o2.plot(filename='o2.png', background='sea_floor_depth_below_sea_level')

        self.assertEqual(o.num_elements_active(), 67)
        self.assertEqual(o2.num_elements_active(), 67)
        self.assertEqual(o.num_elements_deactivated(), 33)
        self.assertEqual(o2.num_elements_deactivated(), 33)
        self.assertEqual(o.elements.lon[0], o2.elements.lon[0])
Beispiel #13
0
    def setUp(self):
        self.objectType = 50  # FISHING-VESSEL-1
        self.lee = Leeway(loglevel=20)
        #print self.lee.leewayprop.values()[0]

        #self.lee = WindBlow(loglevel=0)
        self.reader_basemap = reader_basemap_landmask.Reader(llcrnrlon=3,
                                                             llcrnrlat=59,
                                                             projection='merc',
                                                             urcrnrlon=6,
                                                             urcrnrlat=61,
                                                             resolution='i')
        self.lee.add_reader([self.reader_basemap])
        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
Beispiel #14
0
    def test_interact_coastline_basemap(self):
        reader_basemap = reader_basemap_landmask.Reader(llcrnrlon=4.5,
                                                        llcrnrlat=60.4,
                                                        urcrnrlon=6,
                                                        urcrnrlat=60.6,
                                                        resolution='c',
                                                        projection='merc')

        o = OceanDrift(loglevel=00)
        o.set_config('general:coastline_action', 'previous')
        o.add_reader(reader_basemap)
        o.fallback_values['x_sea_water_velocity'] = .7
        o.seed_elements(lon=5, lat=60.5, time=datetime.now())
        o.run(time_step=3600, steps=30)
        lons = o.history['lon'][0]
        self.assertAlmostEqual(lons[0], 5, 2)
        self.assertAlmostEqual(lons[-2], 5.366, 2)
        self.assertAlmostEqual(lons[-1], 5.366, 2)
Beispiel #15
0
 def test_seed_outside_coverage(self):
     """Test seeding"""
     o = OpenOil3D(loglevel=0)
     norkyst = reader_netCDF_CF_generic.Reader(
         o.test_data_folder() +
         '14Jan2016_NorKyst_z_3d/NorKyst-800m_ZDEPTHS_his_00_3Dsubset.nc')
     basemap = reader_basemap_landmask.Reader(llcrnrlon=4,
                                              llcrnrlat=60,
                                              urcrnrlon=6,
                                              urcrnrlat=64,
                                              resolution='c',
                                              projection='merc')
     o.add_reader([basemap, norkyst])
     o.seed_elements(5,
                     63,
                     number=5,
                     time=norkyst.start_time - 24 * timedelta(hours=24))
     o.run(steps=3, time_step=timedelta(minutes=15))
Beispiel #16
0
def test_performance_basemap(benchmark):
    print("setting up basemap")
    reader_basemap = reader_basemap_landmask.Reader(
                        llcrnrlon=18.64, llcrnrlat=69.537,
                        urcrnrlon=19.37, urcrnrlat=69.81, resolution = 'f')


    x = np.linspace(18.641, 19.369, 100)
    y = np.linspace(69.538, 69.80, 100)

    xx, yy = np.meshgrid(x,y)
    xx = xx.ravel()
    yy = yy.ravel()

    # warmup
    reader_basemap.__on_land__(xx, yy)

    print ("masking against basemap")
    benchmark(reader_basemap.__on_land__, xx, yy)
Beispiel #17
0
#######################
# Preparing readers
#######################

base = 'results'
baseout = 'figures'
hexagon = False
startdate = '01062015'
enddate = '30122015'
experiment = 1
filename = "results/MarMine_molusc_opendrift_" + str(startdate) + "_to_" + str(
    enddate) + "_novertical.nc"
print(filename)
reader_basemap = reader_basemap_landmask.Reader(llcrnrlon=2,
                                                llcrnrlat=65.,
                                                urcrnrlon=20,
                                                urcrnrlat=75,
                                                resolution='i',
                                                projection='merc')
o.add_reader(reader_basemap)

plotfilenameAnime = 'Figures/test.mp4'
plotfilenameColor = 'Figures/test_color.png'
plotfilename = 'Figures/test.png'

if os.path.exists(filename):
    print("=> Opening input file: {}".format(filename))
    o.io_import_file(filename)
    # o.add_reader([reader_basemap]) #Do not include basemap when stranding is deactivated

    # o.plot_vertical_distribution()
    o.plot(linecolor='z', lvmin=-150, lvmax=0, filename=plotfilenameColor)
Beispiel #18
0
lw = Leeway(loglevel=0)  # Set loglevel to 0 for debug information

# Arome
#reader_arome = reader_netCDF_CF_generic.Reader('http://thredds.met.no/thredds/dodsC/meps25files/meps_det_extracted_2_5km_latest.nc')
reader_arome = reader_netCDF_CF_generic.Reader(lw.test_data_folder() + 
    '16Nov2015_NorKyst_z_surface/arome_subset_16Nov2015.nc')

# Norkyst
#reader_norkyst = reader_netCDF_CF_generic.Reader('http://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be')
reader_norkyst = reader_netCDF_CF_generic.Reader(lw.test_data_folder() + 
    '16Nov2015_NorKyst_z_surface/norkyst800_subset_16Nov2015.nc')

# Landmask (Basemap)
reader_basemap = reader_basemap_landmask.Reader(
                    llcrnrlon=3.3, llcrnrlat=59.5,
                    urcrnrlon=5.5, urcrnrlat=62.5, resolution='h',
                    projection='merc')

#lw.add_reader([reader_norkyst, reader_arome, reader_basemap])
# Adding readers succesively, and specifying which variables they 
# shall provide. This way, order of adding readers does not matter,
# except for small rounding differences due to different projection
lw.add_reader(reader_norkyst,
              variables=['x_sea_water_velocity', 'y_sea_water_velocity'])
lw.add_reader(reader_arome,
              variables=['x_wind', 'y_wind'])
lw.add_reader(reader_basemap,
              variables=['land_binary_mask'])
lw.fallback_values['x_sea_water_velocity'] = 0
lw.fallback_values['y_sea_water_velocity'] = 0
Beispiel #19
0
from datetime import timedelta

import numpy as np

from opendrift.readers import reader_basemap_landmask
from opendrift.readers import reader_netCDF_CF_generic
from opendrift.models.oceandrift import OceanDrift

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

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

# Landmask (Basemap)
reader_basemap = reader_basemap_landmask.Reader(
                    llcrnrlon=4.0, llcrnrlat=59.9,
                    urcrnrlon=5.5, urcrnrlat=61.2,
                    resolution='h', projection='merc')

o.add_reader([reader_basemap, reader_norkyst])

# Seeding some particles
lons = np.linspace(4.4, 4.6, 10)
lats = np.linspace(60.0, 60.1, 10)
lons, lats = np.meshgrid(lons, lats)
lons = lons.ravel()
lats = lats.ravel()

# Seed oil elements on a grid at regular time interval
start_time = reader_norkyst.start_time
time_step = timedelta(hours=6)
num_steps = 10
Beispiel #20
0
import unittest
from datetime import datetime, timedelta

import numpy as np

from opendrift.models.oceandrift import OceanDrift
from opendrift.readers import reader_netCDF_CF_generic
from opendrift.readers import reader_ROMS_native
from opendrift.readers import reader_basemap_landmask
from opendrift.models.pelagicegg import PelagicEggDrift


o = OceanDrift()
basemap = reader_basemap_landmask.Reader(
            llcrnrlon=-1.5, llcrnrlat=59,
            urcrnrlon=7, urcrnrlat=64, resolution='c')

class TestReaders(unittest.TestCase):
    """Tests for readers"""

    def test_adding_readers(self):
        o = OceanDrift()
        r = reader_ROMS_native.Reader(o.test_data_folder() +
            '2Feb2016_Nordic_sigma_3d/Nordic-4km_SLEVELS_avg_00_subset2Feb2016.nc')
        o.add_reader([r, basemap])
        self.assertEqual(o.priority_list['land_binary_mask'],
                         ['roms native', 'basemap_landmask'])
        self.assertEqual(o.priority_list['x_sea_water_velocity'],
                         ['roms native'])
        # Switch order
Beispiel #21
0
o = Leeway(loglevel=0)  # Set loglevel to 0 for debug information

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

# Making customised, full resolution landmask (Basemap)
reader_basemap = reader_basemap_landmask.Reader(llcrnrlon=5.5,
                                                llcrnrlat=61.05,
                                                urcrnrlon=6.65,
                                                urcrnrlat=61.21,
                                                resolution='f',
                                                projection='merc')

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

# Seed elements
lat = 61.117594
lon = 6.55
#time = [reader_arome.start_time,
#        reader_arome.start_time + timedelta(hours=5)]
time = reader_arome.start_time
objType = 1  # 1: Person-in-water (PIW), unknown state (mean values)
o.seed_elements(lon,
                lat,
                radius=50,
Beispiel #22
0
#reader_hycom = reader_netCDF_CF_generic.Reader('http://tds.hycom.org/thredds/dodsC/GLBu0.08/expt_19.1/2010/3hrly')
#print(reader_hycom0)
reader_globcurrent = reader_netCDF_CF_generic.Reader(
    'http://tds0.ifremer.fr/thredds/dodsC/CLS-L4-CUREUL_HS-ALT_SUM-V02.0_FULL_TIME_SERIE'
)  # Total

reader_oceanwind = reader_netCDF_CF_generic.Reader(
    'http://tds0.ifremer.fr/thredds/dodsC/CERSAT-GLO-CLIM_WIND_L4-OBS_FULL_TIME_SERIE'
)
#print(reader_oceanwind)

# For longer simulations, it is better to pre-generate a basemap:
# Landmask (Basemap)
reader_basemap = reader_basemap_landmask.Reader(llcrnrlon=-94,
                                                llcrnrlat=20,
                                                urcrnrlon=-80,
                                                urcrnrlat=32,
                                                resolution='i')

# Add readers
#o.add_reader([reader_basemap, reader_hycom, reader_oceanwind])
o.add_reader([reader_basemap, reader_globcurrent, reader_oceanwind])

# Seed some particles
lon = -88.387161
lat = 28.736669  # Macondo location
starttime = datetime(2010, 4, 21, 6, 0, 0)  # 4 hours after explosion
time = [starttime, starttime + timedelta(hours=24 * 40)]
o.seed_elements(lon, lat, radius=0, number=5000, time=time)

# Run model
Beispiel #23
0
o = OpenOil(loglevel=0)  # Set loglevel to 0 for debug information

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

# Landmask (Basemap)
reader_basemap = reader_basemap_landmask.Reader(llcrnrlon=3.0,
                                                llcrnrlat=60.4,
                                                urcrnrlon=6,
                                                urcrnrlat=61.8,
                                                resolution='h',
                                                projection='merc')

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

############################################################
# Seed oil particles within contour detected from satellite
############################################################
o.seed_from_gml(
    o.test_data_folder() +
    'radarsat_oil_satellite_observation/RS2_20151116_002619_0127_SCNB_HH_SGF_433012_9730_12182143_Oil.gml',
    num_elements=2000)
############################################################
# Additional continous point release, lasting 24 hours
############################################################
Beispiel #24
0
from opendrift.models.openoil import OpenOil

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

# HYCOM
#reader_hycom = reader_netCDF_CF_generic.Reader('http://tds.hycom.org/thredds/dodsC/GLBu0.08/expt_19.1/2010/3hrly')
#print reader_hycom

reader_globcurrent = reader_netCDF_CF_generic.Reader(
    'http://tds0.ifremer.fr/thredds/dodsC/CLS-L4-CUREUL_HS-ALT_SUM-V02.0_FULL_TIME_SERIE'
)

# Landmask (Basemap)
reader_basemap = reader_basemap_landmask.Reader(llcrnrlon=100,
                                                llcrnrlat=5,
                                                urcrnrlon=120,
                                                urcrnrlat=15,
                                                resolution='h')

# OceanWind
try:
    reader_oceanwind = reader_netCDF_CF_generic.Reader(
        'http://www.ncdc.noaa.gov/thredds/dodsC/oceanwinds6hr')
    print reader_oceanwind
    o.add_reader([reader_globcurrent, reader_oceanwind, reader_basemap])
except:
    o.add_reader([reader_globcurrent, reader_basemap])

# Seed some particles
lat = 10.228248
lon = 106.973337
Beispiel #25
0
from opendrift.readers import reader_basemap_landmask
from opendrift.readers import reader_netCDF_CF_generic

from opendrift.models.oceandrift import OceanDrift

ncfile = 'backandforth.nc'

o = OceanDrift(loglevel=0)  # Set loglevel to 0 for debug information
reader_norkyst = reader_netCDF_CF_generic.Reader(
    o.test_data_folder() +
    '16Nov2015_NorKyst_z_surface/norkyst800_subset_16Nov2015.nc')
#reader_norkyst = reader_netCDF_CF_generic.Reader('http://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be')

reader_basemap = reader_basemap_landmask.Reader(llcrnrlon=3,
                                                llcrnrlat=59,
                                                urcrnrlon=6,
                                                urcrnrlat=62,
                                                resolution='h')

o.add_reader([reader_norkyst, reader_basemap])

################
# Forward run
################
# Seeding some particles
lon = 4.2
lat = 60.1
time = reader_norkyst.start_time
o.seed_elements(lon, lat, radius=1000, number=100, time=time)

o.run(steps=50 * 4, time_step=900, outfile=ncfile)
############################################
# Preparing Readers
############################################

reader_current = reader_netCDF_CF_generic.Reader(
    o.test_data_folder() +
    '16Nov2015_NorKyst_z_surface/norkyst800_subset_16Nov2015.nc')

reader_wind = reader_netCDF_CF_generic.Reader(
    o.test_data_folder() +
    '16Nov2015_NorKyst_z_surface/arome_subset_16Nov2015.nc')

reader_basemap = reader_basemap_landmask.Reader(llcrnrlon=2.9,
                                                llcrnrlat=59.7,
                                                urcrnrlon=4.9,
                                                urcrnrlat=61.5,
                                                resolution='l',
                                                projection='gall')
o.add_reader([reader_current, reader_wind, reader_basemap])

#######################
# Seeding elements
#######################

# Icebergs are moved with the ocean current as per Barker et al (2004),
# in addition to a fraction of the wind speed (wind_drift_factor).
# This factor depends on the properties of the elements.
# Default empirical values are:
# - Wind drift fraction: 0.018 (1.8 %) (Garret 1985)
# - Iceberg size: 	Keel dept = 60m
#					Waterline length = 90.5m
    def run_opendrift(self):
        sys.stdout.write('running OpenDrift')
        month = np.int(self.months.index(self.monthvar.get()) + 1)
        start_time = datetime(np.int(self.yearvar.get()), month,
                              np.int(self.datevar.get()),
                              np.int(self.hourvar.get()),
                              np.int(self.minutevar.get()))
        if start_time > self.current.end_time:
            sys.stdout.write('Start time after end of current data!')
            start_time = self.current.start_time
        emonth = np.int(self.months.index(self.emonthvar.get()) + 1)
        end_time = datetime(np.int(self.eyearvar.get()), emonth,
                            np.int(self.edatevar.get()),
                            np.int(self.ehourvar.get()),
                            np.int(self.eminutevar.get()))
        sys.stdout.flush()
        lon = np.float(self.lon.get())
        lat = np.float(self.lat.get())
        radius = np.float(self.radius.get())
        elon = np.float(self.elon.get())
        elat = np.float(self.elat.get())
        eradius = np.float(self.eradius.get())
        if lon != elon or lat != elat or start_time != end_time:
            lon = [lon, elon]
            lat = [lat, elat]
            radius = [radius, eradius]
            start_time = [start_time, end_time]
            cone = True
        else:
            cone = False
        if self.model.get() == 'Leeway':
            o = Leeway(loglevel=20)
            for ln, lc in enumerate(self.leewaycategories):
                if self.oljetype.get() == lc.strip().replace('>', ''):
                    print 'Leeway object category: ' + lc
                    break
            o.seed_elements(lon=lon,
                            lat=lat,
                            number=2000,
                            radius=radius,
                            time=start_time,
                            objectType=ln + 1)
        if self.model.get() == 'OpenOil':
            o = OpenOil(loglevel=20)
            o.seed_elements(lon=lon,
                            lat=lat,
                            number=2000,
                            radius=radius,
                            time=start_time,
                            cone=cone,
                            oiltype=self.oljetype.get())

        print 'Making Basemap...'
        lons = o.elements_scheduled.lon
        lats = o.elements_scheduled.lat
        bufferlat = 2
        basemap = reader_basemap_landmask.Reader(
            llcrnrlon=lons.min() - bufferlat,
            llcrnrlat=lats.min() - bufferlat,
            urcrnrlon=lons.max() + bufferlat,
            urcrnrlat=lats.max() + bufferlat,
            resolution='h',
            projection='merc',
            minimise_whitespace=True)
        o.add_reader([basemap, self.current, self.wind])

        time_step = 1800  # Half hour
        duration = int(self.durationhours.get()) * 3600 / time_step
        if self.directionvar.get() == 'backwards':
            time_step = -time_step
        o.run(steps=duration, time_step=time_step)
        print o

        tk.Button(self.master, text='Animation',
                  command=o.animation).grid(row=7,
                                            column=2,
                                            sticky=tk.W,
                                            pady=4)
        if self.model.get() == 'OpenOil':
            tk.Button(self.master,
                      text='Oil Budget',
                      command=o.plot_oil_budget).grid(row=7,
                                                      column=3,
                                                      sticky=tk.W,
                                                      pady=4)

        o.plot()
Beispiel #28
0
print o.oiltypes  # Print available oil types

# Arome
reader_arome = reader_netCDF_CF_generic.Reader(o.test_data_folder() + 
    '16Nov2015_NorKyst_z_surface/arome_subset_16Nov2015.nc')
#reader_arome = reader_netCDF_CF_generic.Reader('http://thredds.met.no/thredds/dodsC/arome25/arome_metcoop_default2_5km_latest.nc')

# Norkyst
reader_norkyst = reader_netCDF_CF_generic.Reader(o.test_data_folder() + 
    '16Nov2015_NorKyst_z_surface/norkyst800_subset_16Nov2015.nc')
#reader_norkyst = reader_netCDF_CF_generic.Reader('http://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be')

# Landmask (Basemap)
reader_basemap = reader_basemap_landmask.Reader(
                    llcrnrlon=4.4, llcrnrlat=60.0,
                    urcrnrlon=5.6, urcrnrlat=60.9,
                    resolution='h', projection='merc',
                    minimise_whitespace=True)

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

# Seeding some particles
lon = 4.9; lat = 60.1; # Outside Bergen

#time = [reader_arome.start_time,
#        reader_arome.start_time + timedelta(hours=30)]
time = reader_arome.start_time

# Seed oil elements at defined position and time
o.seed_elements(lon, lat, radius=3000, number=500, time=time, z=0,
                #oiltype='GULLFAKS, EXXON')
Beispiel #29
0
o = OpenOil3D(loglevel=0)

# Arome
reader_arome = reader_netCDF_CF_generic.Reader(o.test_data_folder() + 
    '16Nov2015_NorKyst_z_surface/arome_subset_16Nov2015.nc')
#reader_arome = reader_netCDF_CF_generic.Reader('http://thredds.met.no/thredds/dodsC/arome25/arome_metcoop_default2_5km_latest.nc')

# Norkyst
#reader_norkyst = reader_netCDF_CF_generic.Reader(o.test_data_folder() + 
#    '16Nov2015_NorKyst_z_surface/norkyst800_subset_16Nov2015.nc')
#reader_norkyst = reader_netCDF_CF_generic.Reader('http://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be')

# Landmask (Basemap)
reader_basemap = reader_basemap_landmask.Reader(
                    llcrnrlon=4, llcrnrlat=59.7,
                    urcrnrlon=7, urcrnrlat=61.5,
                    resolution='h', projection='merc')

#o.add_reader([reader_basemap, reader_norkyst, reader_arome])
o.fallback_values['x_wind'] = 7
o.fallback_values['x_sea_water_velocity'] = .7
o.fallback_values['y_sea_water_velocity'] = .3
#o.fallback_values['land_binary_mask'] = 0
#o.add_reader([reader_basemap, reader_norkyst])
o.add_reader([reader_basemap])

# Seeding some particles
lon = 4.8; lat = 60.0; # Outside Bergen

#time = [reader_arome.start_time,
#        reader_arome.start_time + timedelta(hours=30)]
Beispiel #30
0
# Arome
#reader_arome = reader_netCDF_CF_generic.Reader('http://thredds.met.no/thredds/dodsC/arome25/arome_metcoop_default2_5km_latest.nc')
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('http://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be')
reader_norkyst = reader_netCDF_CF_generic.Reader(
    o.test_data_folder() +
    '16Nov2015_NorKyst_z_surface/norkyst800_subset_16Nov2015.nc')

# Landmask (Basemap)
reader_basemap = reader_basemap_landmask.Reader(llcrnrlon=2,
                                                llcrnrlat=59,
                                                urcrnrlon=6,
                                                urcrnrlat=62,
                                                resolution='i',
                                                projection='merc')

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

# Seeding some particles
lon = [3.6, 5.1]
lat = [61., 59.6]
# Outside Bergen

# Seed elements along cone, e.g. ship track with
# increasing uncertainty in position
time = [reader_arome.start_time, reader_arome.start_time + timedelta(hours=30)]
#time = reader_arome.start_time