def check_seeding(self):
        print('#' * 50)
        print('Hang on, plot is comming in a few seconds...')
        print('#' * 50)
        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

        so = Leeway(loglevel=50)
        so.seed_elements(lon=lon, lat=lat, radius=radius, time=start_time)
        so.plot(buffer=.5, fast=True)
        del so
示例#2
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.")
示例#3
0
    def check_seeding(self):
        print('#' * 50)
        print('Hang on, plot is comming in a few seconds...')
        mapres = self.mapresvar.get()[0]
        if mapres == 'f':
            print(
                '...actually more like 30 seconds for full resolution coastline....'
            )
            if self.has_diana is True:
                print('Du far ta deg ein liten trall mens du ventar.')
        print('#' * 50)
        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

        so = Leeway(loglevel=50)
        so.seed_elements(lon=lon,
                         lat=lat,
                         number=5000,
                         radius=radius,
                         time=start_time)
        so.set_config('general:basemap_resolution', mapres)
        so.plot(buffer=.5)
        del so
示例#4
0
    def check_seeding(self):
        print '#'*50
        print 'Hang on, plot is comming in a few seconds...'
        mapres = self.mapresvar.get()[0]
        if mapres == 'f':
            print '...actually more like 30 seconds for full resolution coastline....'
            if self.has_diana is True:
                print 'Du far ta deg ein liten trall mens du ventar.'
        print '#'*50
        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

        so = Leeway(loglevel=50)
        so.seed_elements(lon=lon, lat=lat, number=5000,
                         radius=radius, time=start_time)
        so.set_config('general:basemap_resolution', mapres)         
        so.plot(buffer=.5)
        del so
示例#5
0
    def check_seeding(self):
        print('#'*50)
        print('Hang on, plot is comming in a few seconds...')
        print('#'*50)
        month = int(self.months.index(self.monthvar.get()) + 1)
        start_time = datetime(int(self.yearvar.get()), month,
                              int(self.datevar.get()),
                              int(self.hourvar.get()),
                              int(self.minutevar.get()))
        emonth = int(self.months.index(self.emonthvar.get()) + 1)
        end_time = datetime(int(self.eyearvar.get()), emonth,
                            int(self.edatevar.get()),
                            int(self.ehourvar.get()),
                            int(self.eminutevar.get()))
        sys.stdout.flush()
        lon = float(self.lon.get())
        lat = float(self.lat.get())
        radius = float(self.radius.get())
        elon = float(self.elon.get())
        elat = float(self.elat.get())
        eradius = 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

        so = Leeway(loglevel=50)
        for k,v in self.GUI_config.items():
            try:
                so.set_config(k, v)
            except:
                pass
        so.seed_cone(lon=lon, lat=lat, radius=radius, time=start_time)
        so.plot(buffer=.5, fast=True)
        del so
示例#6
0
# 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

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

# Seed leeway elements at defined position and time
objType = 26  # 26 = Life-raft, no ballast
lw.seed_elements(lon, lat, radius=1000, number=3000,
                 time=reader_arome.start_time, objectType=objType)

lw.set_projection('+proj=merc')

# Running model (until end of driver data)
lw.run(steps=60*4, time_step=900)

# Print and plot results
print(lw)
lw.animation()
#lw.animation(filename='leeway.gif')
lw.plot()
示例#7
0
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)
o.animation(fast=True)
示例#8
0
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,
                number=5000,
                time=time,
                objectType=objType)

# Running model for 66 hours
o.run(steps=66 * 12, time_step=300)

# Print and plot results
print o
o.plot()
o.animation()
示例#9
0
                    continue  # Only surface seeding for Leeway
                o = Leeway()
                args = {'objectType': 32}

            #o.add_readers_from_list(readers, timeout=5)
            o.add_halo_readers()
            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
            o.run(duration=timedelta(hours=24), time_step=timestep,
                  time_step_output=1800, outfile='halo_test.nc')

            print o
            o.animation()
            if case == 'oil':
                o.plot()
                o.plot_oil_budget()
                o.plot_property('water_fraction')
                o.animation_profile()
              variables=['x_sea_water_velocity', 'y_sea_water_velocity'])
lw.add_reader(reader_arome, variables=['x_wind', 'y_wind'])
lw.set_config('environment:fallback:x_sea_water_velocity', 0)
lw.set_config('environment:fallback:y_sea_water_velocity', 0)

#%%
# Seed leeway elements at defined position and time
object_type = 26  # 26 = Life-raft, no ballast
lw.seed_elements(lon=4.5, lat=59.6, radius=100, number=1000,
                 time=reader_arome.start_time, object_type=object_type)

#%%
# Running model
lw.run(duration=timedelta(hours=48), time_step=900, time_step_output=3600)

#%%
# Print and plot results
print(lw)

#%%
# Animation with current as background.
# Note that drift is also depending on wind, which is not shown.
lw.animation(background=['x_sea_water_velocity', 'y_sea_water_velocity'],
             skip=5,  # show every 5th vector
             cmap=cmocean.cm.speed, vmin=0, vmax=.8, bgalpha=.7, land_color='#666666', fast=True)

#%%
# .. image:: /gallery/animations/example_leeway_0.gif

lw.plot(fast=True)
示例#11
0
    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()
    '16Nov2015_NorKyst_z_surface/norkyst800_subset_16Nov2015.nc')

#%%
# Adding readers successively, and specifying which variables they
# shall provide. This way, order of adding readers does not matter
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.set_config('environment:fallback:x_sea_water_velocity', 0)
lw.set_config('environment:fallback:y_sea_water_velocity', 0)

#%%
# Seed leeway elements at defined position and time
object_type = 26  # 26 = Life-raft, no ballast
lw.seed_elements(lon=4.5,
                 lat=59.6,
                 radius=100,
                 number=1000,
                 time=reader_arome.start_time,
                 object_type=object_type)

#%%
# Running model
lw.run(duration=timedelta(hours=48), time_step=900, time_step_output=3600)

#%%
# Print and plot results
print(lw)

lw.plot(fast=True, filename='test.png')
示例#13
0
              variables=['x_sea_water_velocity', 'y_sea_water_velocity'])
lw.add_reader(reader_arome, variables=['x_wind', 'y_wind'])
lw.add_reader(reader_landmask, variables=['land_binary_mask'])
lw.fallback_values['x_sea_water_velocity'] = 0
lw.fallback_values['y_sea_water_velocity'] = 0

#%%
# Seed leeway elements at defined position and time
objType = 26  # 26 = Life-raft, no ballast
lw.seed_elements(lon=4.5,
                 lat=60.0,
                 radius=1000,
                 number=3000,
                 time=reader_arome.start_time,
                 objectType=objType)

#%%
# Running model (until end of driver data)
lw.run(duration=timedelta(hours=60), time_step=900, time_step_output=3600)

#%%
# Print and plot results
print(lw)
# lw.animation()
lw.animation(background=['x_sea_water_velocity', 'y_sea_water_velocity'])

#%%
# .. image:: /gallery/animations/example_leeway_0.gif

lw.plot(fast=True, background=['x_sea_water_velocity', 'y_sea_water_velocity'])
示例#14
0
    '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=2.5, llcrnrlat=59.3,
                    urcrnrlon=5.8, urcrnrlat=62.5, resolution='i')

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

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

objType = 26  # 26 = Life-raft, no ballast
lw.seed_elements(lon, lat, radius=[1000, 10000], number=5000,
                 time=time, objectType=objType)

# Running model (until end of driver data)
lw.run(steps=66*4, time_step=900)

# Print and plot results
print lw
lw.plot()
lw.animation()
示例#15
0
    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()