def test_lazy_reader_leeway_compare(self):

        o1 = Leeway(loglevel=0)
        #o1.set_config('environment:fallback:land_binary_mask', 0)
        o1.required_variables = [r for r in o1.required_variables
                                 if r != 'land_binary_mask']
        o1.add_readers_from_list(reader_list, lazy=False)
        time = o1.readers['roms native'].start_time
        o1.seed_elements(lat=67.85, lon=14, time=time)
        o1.run(steps=5)

        o2 = Leeway(loglevel=20)
        #o2.set_config('environment:fallback:land_binary_mask', 0)
        o2.required_variables = [r for r in o1.required_variables
                                 if r != 'land_binary_mask']
        o2.add_readers_from_list(reader_list, lazy=True)
        o2.seed_elements(lat=67.85, lon=14, time=time)
        o2.run(steps=5)

        # Some differences in wind and current components
        # due to different coordinate system
        for var in o1.history.dtype.names:
            if var in ['x_wind', 'y_wind', 'x_sea_water_velocity',
                       'y_sea_water_velocity']:
                tolerance = 1
            else:
                tolerance = 5
            self.assertIsNone(np.testing.assert_array_almost_equal(
                o1.history[var], o2.history[var], tolerance))
    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)
Exemple #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.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)
Exemple #4
0
#!/usr/bin/env python
"""
Vietnam
==================================
"""

from datetime import datetime, timedelta
from opendrift.models.leeway import Leeway

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

# Adding readers for global Thredds datasets:
# - Ocean forecast from global Hycom
# - Weather forecast from NOAA/NCEP
o.add_readers_from_list([
    'https://tds.hycom.org/thredds/dodsC/GLBy0.08/latest',
    'https://pae-paha.pacioos.hawaii.edu/thredds/dodsC/ncep_global/NCEP_Global_Atmospheric_Model_best.ncd'])

# Seed some particles
objType = 26  # 26 = Life-raft, no ballast
o.seed_elements(lon=107.8, lat=10.0, radius=1000, number=1000,
                objectType=objType, time=datetime.now())

# Run model
o.run(duration=timedelta(days=3),
      time_step=timedelta(hours=1),
      time_step_output=timedelta(hours=3))

# Print and plot results
print(o)
o.plot(fast=True)
Exemple #5
0
for case in ['oil', 'leeway']:  # test two models
    for timestep in [900, -900]:  # forwards and backwards
        for z in [0, -200]:  # seeding at sea surface and at 200 m depth
            if case == 'oil':
                o = OpenOil3D(weathering_model='noaa')
                args = {'oiltype': 'IVAR AASEN 2012',
                #args = {'oiltype': 'WISTING',
                        'z': z}
            else:
                if z < 0:
                    continue  # Only surface seeding for Leeway
                o = Leeway()
                args = {'objectType': 32}

            o.add_readers_from_list(readers, timeout=5)
            print(o)

            #lons=[-0.8, 0.4]; lats=[59.9, 59.95] # NorKyst border
            #lons=[4.8, 5.1]; lats=[59.9, 59.95] # Western Norway coast
            #lons=[13.11, 13.13]; lats=[67.81, 67.80] # Lofoten
            #lons=[19.37, 19.33]; lats=[70.32, 70.34] # Troms
            lons=[3.8, 3.82]; lats=[59.6, 59.61] # North Sea

            o.seed_elements(lon=lons, lat=lats,
                            time=[datetime.now() - timedelta(hours=3),
                                  datetime.now()],
                            number=1000, radius = [0, 1000],
                            cone=True, **args)

            print(o)
Exemple #6
0
"""
Initialising reader from JSON string
====================================
"""

from datetime import datetime, timedelta
from opendrift.models.leeway import Leeway

o = Leeway()

#%%
# Adding a CMEMS reader as a JSON string, and NCEP winds from thredds URL.
# For CMEMS, username or password must be stored in a .netrc file under
# machine name "cmems", or provided explicitly instead of *null*
o.add_readers_from_list([
    '{"reader": "reader_cmems", "dataset": "global-analysis-forecast-phy-001-024-hourly-t-u-v-ssh", "cmems_user": null, "cmems_password": null}',
    'https://pae-paha.pacioos.hawaii.edu/thredds/dodsC/ncep_global/NCEP_Global_Atmospheric_Model_best.ncd'
])

o.seed_elements(time=datetime.utcnow(),
                lon=123,
                lat=-16.1,
                number=1000,
                radius=1000)

o.run(duration=timedelta(hours=72))

print(o)

o.animation(fast=False,
            skip=1,
            scale=10,
Exemple #7
0
for case in ['oil', 'leeway']:  # test two models
    for timestep in [900, -900]:  # forwards and backwards
        for z in [0, -200]:  # seeding at sea surface and at 200 m depth
            if case == 'oil':
                o = OpenOil3D(weathering_model='noaa')
                args = {'oiltype': 'IVAR AASEN',
                #args = {'oiltype': 'WISTING',
                        'z': z}
            else:
                if z < 0:
                    continue  # Only surface seeding for Leeway
                o = Leeway()
                args = {'objectType': 32}

            o.add_readers_from_list(readers, timeout=5)
            print o

            #lons=[-0.8, 0.4]; lats=[59.9, 59.95] # NorKyst border
            #lons=[4.8, 5.1]; lats=[59.9, 59.95] # Western Norway coast
            #lons=[13.11, 13.13]; lats=[67.81, 67.80] # Lofoten
            #lons=[19.37, 19.33]; lats=[70.32, 70.34] # Troms
            lons=[3.8, 3.82]; lats=[59.6, 59.61] # North Sea

            o.seed_elements(lon=lons, lat=lats,
                            time=[datetime.now() - timedelta(hours=3),
                                  datetime.now()],
                            number=1000, radius = [0, 1000],
                            cone=True, **args)

            print o
Exemple #8
0
    def run_opendrift(self):
        sys.stdout.write('running OpenDrift')
        try:
            self.budgetbutton.destroy()
        except Exception as e:
            print e
            pass
        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()))
        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=0)
            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=5000,
                            radius=radius, time=start_time,
                            objectType=ln + 1)
        if self.model.get() == 'OpenOil':
            o = OpenOil3D(weathering_model='noaa', loglevel=0)
            o.seed_elements(lon=lon, lat=lat, number=5000, radius=radius,
                            time=start_time, cone=cone,
                            oiltype=self.oljetype.get())

        readers = [  # Note that order (priority) is important!
            '/lustre/storeA/project/copernicus/sea/romsnorkyst/zdepths1h/*fc*.nc',
            'http://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be',
            '/lustre/storeA/project/copernicus/sea/romsnordic/zdepths1h/roms_nordic4_ZDEPTHS_hr.fc.*.nc',
            'http://thredds.met.no/thredds/dodsC/sea/nordic4km/zdepths1h/aggregate_be',
            '/lustre/storeA/project/metproduction/products/meps/symlinks/thredds/meps_det_pp_2_5km_latest.nc',
            'http://thredds.met.no/thredds/dodsC/meps25files/meps_det_pp_2_5km_latest.nc',
            '/lustre/storeA/project/metproduction/products/arome2_5_arctic/thredds/arome_arctic_pp_2_5km_latest.nc',
            'http://thredds.met.no/thredds/dodsC/aromearcticlatest/arome_arctic_pp_2_5km_latest.nc',
            '/lustre/storeA/project/copernicus/sea/mywavewam4/*fc*.nc',
            'http://thredds.met.no/thredds/dodsC/sea/mywavewam4/mywavewam4_be',
            'http://tds.hycom.org/thredds/dodsC/GLBu0.08/expt_91.2/uv3z',
            'http://oos.soest.hawaii.edu/thredds/dodsC/hioos/model/atm/ncep_global/NCEP_Global_Atmospheric_Model_best.ncd']
        o.add_readers_from_list(readers)
        o.set_config('general:basemap_resolution', 'h')

        time_step = 1800  # Half hour
        duration = int(self.durationhours.get())*3600/time_step
        if self.directionvar.get() == 'backwards':
            time_step = -time_step
        if self.has_diana is True:
            extra_args = {'outfile': self.outputdir + '/opendrift_' +                          self.model.get() + o.start_time.strftime(
                                '_%Y%m%d_%H%M.nc')}
        else:
            extra_args = {}

        mapres = self.mapresvar.get()[0]
        o.set_config('general:basemap_resolution', mapres)         

        o.run(steps=duration, time_step=time_step,
              time_step_output=time_step, **extra_args)
        print o

        if self.has_diana is True:
            diana_filename = self.dianadir + '/opendrift_' + \
                self.model.get() + o.start_time.strftime(
                                '_%Y%m%d_%H%M.nc')
            o.write_netcdf_density_map(diana_filename)
            tk.Button(self.master, text='Show in Diana',
                      command=lambda: os.system('diana &')
                      ).grid(row=8, column=2, sticky=tk.W, pady=4)
        tk.Button(self.master, text='Animation',
                  command=o.animation).grid(row=8, column=3,
                                            sticky=tk.W, pady=4)
        if self.model.get() == 'OpenOil':
            self.budgetbutton = tk.Button(self.master,
                text='Oil Budget', command=o.plot_oil_budget)
            self.budgetbutton.grid(row=8, column=4, sticky=tk.W, pady=4)
Exemple #9
0
    def run_opendrift(self):
        sys.stdout.write('running OpenDrift')
        try:
            self.budgetbutton.destroy()
        except Exception as e:
            print e
            pass
        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()))
        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=0)
            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=5000,
                            radius=radius,
                            time=start_time,
                            objectType=ln + 1)
        if self.model.get() == 'OpenOil':
            o = OpenOil3D(weathering_model='noaa', loglevel=0)
            o.seed_elements(lon=lon,
                            lat=lat,
                            number=5000,
                            radius=radius,
                            time=start_time,
                            cone=cone,
                            oiltype=self.oljetype.get())

        readers = [  # Note that order (priority) is important!
            '/lustre/storeA/project/copernicus/sea/romsnorkyst/zdepths1h/*fc*.nc',
            'http://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be',
            '/lustre/storeA/project/copernicus/sea/romsnordic/zdepths1h/roms_nordic4_ZDEPTHS_hr.fc.*.nc',
            'http://thredds.met.no/thredds/dodsC/sea/nordic4km/zdepths1h/aggregate_be',
            '/lustre/storeA/project/metproduction/products/meps/symlinks/thredds/meps_det_pp_2_5km_latest.nc',
            'http://thredds.met.no/thredds/dodsC/meps25files/meps_det_pp_2_5km_latest.nc',
            '/lustre/storeA/project/metproduction/products/arome2_5_arctic/thredds/arome_arctic_pp_2_5km_latest.nc',
            'http://thredds.met.no/thredds/dodsC/aromearcticlatest/arome_arctic_pp_2_5km_latest.nc',
            '/lustre/storeA/project/copernicus/sea/mywavewam4/*fc*.nc',
            'http://thredds.met.no/thredds/dodsC/sea/mywavewam4/mywavewam4_be',
            'http://tds.hycom.org/thredds/dodsC/GLBu0.08/expt_91.2/uv3z',
            'http://oos.soest.hawaii.edu/thredds/dodsC/hioos/model/atm/ncep_global/NCEP_Global_Atmospheric_Model_best.ncd'
        ]
        o.add_readers_from_list(readers)
        o.set_config('general:basemap_resolution', 'h')

        time_step = 1800  # Half hour
        duration = int(self.durationhours.get()) * 3600 / time_step
        if self.directionvar.get() == 'backwards':
            time_step = -time_step
        if self.has_diana is True:
            extra_args = {
                'outfile':
                self.outputdir + '/opendrift_' + self.model.get() +
                o.start_time.strftime('_%Y%m%d_%H%M.nc')
            }
        else:
            extra_args = {}

        mapres = self.mapresvar.get()[0]
        o.set_config('general:basemap_resolution', mapres)

        o.run(steps=duration,
              time_step=time_step,
              time_step_output=time_step,
              **extra_args)
        print o

        if self.has_diana is True:
            diana_filename = self.dianadir + '/opendrift_' + \
                self.model.get() + o.start_time.strftime(
                                '_%Y%m%d_%H%M.nc')
            o.write_netcdf_density_map(diana_filename)
            tk.Button(self.seed,
                      text='Show in Diana',
                      command=lambda: os.system('diana &')).grid(row=8,
                                                                 column=2,
                                                                 sticky=tk.W,
                                                                 pady=4)
        tk.Button(self.seed, text='Animation',
                  command=o.animation).grid(row=8,
                                            column=3,
                                            sticky=tk.W,
                                            pady=4)
        if self.model.get() == 'OpenOil':
            self.budgetbutton = tk.Button(self.seed,
                                          text='Oil Budget',
                                          command=o.plot_oil_budget)
            self.budgetbutton.grid(row=8, column=4, sticky=tk.W, pady=4)
#!/usr/bin/env python
"""
Vietnam
==================================
"""

from datetime import datetime, timedelta
from opendrift.models.leeway import Leeway

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

# Adding readers for global Thredds datasets:
# - Ocean forecast from global Hycom
# - Weather forecast from NOAA/NCEP
o.add_readers_from_list([
    'http://tds.hycom.org/thredds/dodsC/GLBy0.08/latest',
    'http://oos.soest.hawaii.edu/thredds/dodsC/hioos/model/atm/ncep_global/NCEP_Global_Atmospheric_Model_best.ncd'
])

# Seed some particles
objType = 26  # 26 = Life-raft, no ballast
o.seed_elements(lon=107.8,
                lat=10.0,
                radius=1000,
                number=1000,
                objectType=objType,
                time=datetime.now())

# Run model
o.run(duration=timedelta(days=3),
      time_step=timedelta(hours=1),
      time_step_output=timedelta(hours=3))