Exemplo n.º 1
0
 def test_plot_animation(self):
     o = OceanDrift(loglevel=0)
     o.set_config('general:basemap_resolution', 'c')
     o.fallback_values['x_sea_water_velocity'] = .5
     o.fallback_values['y_sea_water_velocity'] = .3
     o.seed_elements(lon=3,
                     lat=60,
                     radius=1000,
                     time=datetime.now(),
                     number=100)
     o.run(steps=5)
     o.plot(filename='test_plot.png')
     o.animation(filename='test_plot.mp4')
     assert os.path.exists('test_plot.png')
     assert os.path.exists('test_plot.mp4')
     os.remove('test_plot.png')
     os.remove('test_plot.mp4')
Exemplo n.º 2
0
# - 0.01  (1 %) for CODE drifters partly submerged ~0.5 m
# As there are large uncertainties, it makes sense to provide a statistical
# distribution of wind_drift_factors
#
# Using a constant value for all elements:
#wind_drift_factor = 0.03
#
# Giving each element a unique (random) wind_drift_factor
wind_drift_factor = np.random.uniform(0, 0.06, 2000)
o.seed_elements(4.7,
                59.9,
                radius=3000,
                number=2000,
                time=reader_current.start_time,
                wind_drift_factor=wind_drift_factor)

#%%
# Running model
o.run(time_step=timedelta(minutes=15), time_step_output=timedelta(minutes=60))

#%%
# Print and plot results
print(o)
o.animation(color='wind_drift_factor', fast=True)

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

# Plot trajectories, colored by the wind_drift_factor of each element
o.plot(linecolor='wind_drift_factor', fast=True)
from datetime import datetime, timedelta

from opendrift.readers import reader_double_gyre
from opendrift.models.oceandrift import OceanDrift

o = OceanDrift(loglevel=20)  # Set loglevel to 0 for debug information
o.fallback_values['land_binary_mask'] = 0
o.set_config('drift:scheme', 'runge-kutta4')

double_gyre = reader_double_gyre.Reader(epsilon=.25, omega=0.628, A=0.1)
print(double_gyre)

o.add_reader(double_gyre)

x = [.9]
y = [.5]
lon, lat = double_gyre.xy2lonlat(x, y)

o.seed_elements(lon,
                lat,
                radius=.1,
                number=1000,
                time=double_gyre.initial_time)

o.run(duration=timedelta(seconds=10), time_step=0.1)
o.animation(buffer=0, filename='double_gyre.gif')

#%%
# .. image:: /gallery/animations/double_gyre.gif
Exemplo n.º 4
0
reader_landmask = reader_global_landmask.Reader(llcrnrlon=4,
                                                llcrnrlat=59.9,
                                                urcrnrlon=5.5,
                                                urcrnrlat=61.5)

o.add_reader([reader_norkyst, reader_landmask])
lon = 4.5
lat = 60.0

#%%
# First run, with Euler scheme:
o.set_config('drift:scheme', 'euler')
o.seed_elements(lon, lat, radius=0, number=1, time=time)
o.run(steps=66 * 2, time_step=1800)

#%%
# Second run, with Runge-Kutta scheme:
o2 = OceanDrift(loglevel=20)  # Set loglevel to 0 for debug information
o2.add_reader([reader_norkyst, reader_landmask])
o2.set_config('drift:scheme', 'runge-kutta')
o2.seed_elements(lon, lat, radius=0, number=1, time=time)
o2.run(steps=66 * 2, time_step=1800)

#%%
# Animate and compare the two runs
o.animation(compare=o2, legend=['Euler scheme', 'Runge-Kutta scheme'])

#%%
# .. image:: /gallery/animations/example_rungekutta_norkyst_0.gif
Exemplo n.º 5
0
# Seeding particles in a checkerboard pattern
di = 5  # Horizontal number of particles per square
dj = 5  # Vertical number of particles per square
lons = np.linspace(3.5, 5.0, 100)
lats = np.linspace(60, 61, 100)

ii = np.arange(len(lons)) // di
jj = np.arange(len(lats)) // dj
ii, jj = np.meshgrid(ii, jj)
board = (ii + jj) % 2 > 0

lons, lats = np.meshgrid(lons, lats)

lons = lons[board].ravel()
lats = lats[board].ravel()

# Seed oil elements at defined position and time
o.seed_elements(lons,
                lats,
                radius=0,
                number=10000,
                time=reader_norkyst.start_time)

# Running model (until end of driver data)
o.run(steps=66 * 2, time_step=1800)

# Print and plot results
print o
o.animation(filename="example_checkerboard_anim.gif")
#o.plot()
                                       lats=drifterlats,
                                       times=driftertimes)
o.add_reader(r)

#%%
# We seed elements within polygon, as could have been extracted
# from remote sensing imagery
lons = [2.39, 2.391, 2.392, 2.393, 2.394, 2.393, 2.392, 2.391, 2.39]
lats = [60.02, 60.02, 60.019, 60.02, 60.021, 60.022, 60.021, 60.021, 60.02]
o.seed_within_polygon(lons=lons, lats=lats, number=1000, time=r.start_time)

#%%
# Finally running simulation
o.run(end_time=r.end_time, time_step=r.time_step)

o.animation(buffer=.01, fast=True)

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

#%%
# Drifter track is shown in red, and simulated trajectories are shown in gray. Oil spill is displaced relative to drifter, but drifter current is assumed to be spatially homogeneous.
o.plot(buffer=.01,
       fast=True,
       trajectory_dict={
           'lon': drifterlons,
           'lat': drifterlats,
           'time': driftertimes,
           'linestyle': 'r-'
       })
Exemplo n.º 7
0
#%%
# Using live data from Thredds
o.add_readers_from_list([
    'https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be'])

#%%
# Seed 1000 elements at random depths
z = -np.random.rand(2000)*50
o.seed_elements(lon=4.8, lat=60.0, z=z, radius=0, number=2000,
                time=datetime.utcnow())

print(o)

#%%
# Adding some diffusion
o.set_config('drift:horizontal_diffusivity', 10)  # m2/s

#%%
# Running model
o.run(duration=timedelta(hours=24), time_step=1800)

#%%
# Plot results with lines and particles colored by depth
print(o)
o.plot(linecolor='z', buffer=.1, show_particles=False, fast=False)
o.animation(color='z', buffer=.1, fast=True)

#%%
# .. image:: /gallery/animations/example_depth_0.gif
Exemplo n.º 8
0
    proj4=proj)
o.add_reader(fvcom)
print(fvcom)

# Seed elements at defined positions, depth and time
N = 1000
z = -10 * np.random.uniform(0, 1, N)
o.seed_elements(lon=18.0,
                lat=69.8,
                radius=2000,
                number=N,
                z=z,
                time=fvcom.start_time)

#%%
# Running model
o.run(time_step=1800, duration=timedelta(hours=12))

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

#%%
# Animation (current as background not yet working).
o.animation(color='z')

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

o.plot(fast=True, buffer=1.)
Exemplo n.º 9
0
from opendrift.readers import reader_ROMS_native
from opendrift.models.oceandrift import OceanDrift

lon = 14.75; lat = 68.1

o = OceanDrift(loglevel=0)

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

# First run, with landmask from Basemap
o.add_reader([reader_nordic])
time = reader_nordic.start_time
o.seed_elements(lon, lat, radius=3000, number=1000, time=time)
o.set_config('general:use_basemap_landmask', True)
o.run(end_time=reader_nordic.end_time, time_step=1800)

# Second run, with landmask from ocean model
o2 = OceanDrift(loglevel=0)
o2.add_reader([reader_nordic])
lon = 14.75; lat = 68.1
o2.seed_elements(lon, lat, radius=3000, number=1000, time=time)
o2.set_config('general:use_basemap_landmask', False)
o2.run(end_time=reader_nordic.end_time, time_step=1800)


# Animation illustrating that red particles strand at ocean model land cells, and black particles strand at Basemap land polygons
o.animation(compare=o2, background='land_binary_mask',
            legend=['Basemap landmask', 'Ocean model landmask'])
Exemplo n.º 10
0
lat = 60.0
# Outside Bergen
time = [reader_arome.start_time, reader_arome.start_time + timedelta(hours=30)]

#%%
# Seed oil elements at defined position and time
o.seed_elements(lon, lat, radius=50, number=5000, time=time)

#%%
# Using windspeed relative to moving ocean (current)
o.set_config('drift:relative_wind', False)

o.run(steps=48 * 2, time_step=1800, time_step_output=3600 * 2)

#%%
# Second run, for comparison
o2 = OceanDrift(loglevel=20)  # Set loglevel to 0 for debug information
o2.add_reader([reader_norkyst, reader_arome])
o2.seed_elements(lon, lat, radius=50, number=5000, time=time)
o2.set_config('drift:relative_wind', True)
o2.run(steps=48 * 2, time_step=1800, time_step_output=3600 * 2)

#%%
# Animate and compare the two runs
o.animation(compare=o2, legend=['Absolute wind', 'Relative wind'])

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

o.plot(compare=o2, legend=['Absolute wind', 'Relative wind'], fast=True)
Exemplo n.º 11
0
    "['x_sea_water_velocity', 'y_sea_water_velocity']"].data_dict[
        'x_sea_water_velocity']

plt.subplot(2, 1, 1)
plt.imshow(original_current, interpolation='nearest')
plt.title('Original current field (x-component)')
clim = plt.gci().get_clim()
plt.colorbar()
plt.subplot(2, 1, 2)
plt.imshow(convolved_current, interpolation='nearest')
plt.clim(clim)  # Make sure plots are comparable
plt.colorbar()
plt.title('Final, convolved current field (x-component)')
plt.show()

#%%
# Print and plot results, with convolved currents as background
print(o)
o.animation(compare=o2,
            fast=True,
            legend=[
                'Original currents',
                'Current convoled with kernel of size %s' % N
            ],
            background=['x_sea_water_velocity', 'y_sea_water_velocity'])

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

o.plot(fast=True)
Exemplo n.º 12
0
o2 = OceanDrift(loglevel=20)  # Set loglevel to 0 for debug information
o2.add_reader([reader_norkyst, reader_arome])
o2.seed_elements(lon, lat, radius=500, number=2000, time=time)
#o2.set_config('drift:current_uncertainty', .2) # Difference from first run
#o2.set_config('drift:wind_uncertainty', 1)     # Difference from first run
o2.set_config('drift:horizontal_diffusivity', 10)  # Difference from first run
o2.run(duration=timedelta(hours=24))

#%%
# Third run, identical, except for diffusion and shorter timestep
o3 = OceanDrift(loglevel=20)  # Set loglevel to 0 for debug information
o3.add_reader([reader_norkyst, reader_arome])
o3.seed_elements(lon, lat, radius=500, number=2000, time=time)
#o3.set_config('drift:current_uncertainty', .2) # Difference from first run
#o3.set_config('drift:wind_uncertainty', 1)     # Difference from first run
o3.set_config('drift:horizontal_diffusivity', 10)  # Difference from first run
o3.run(duration=timedelta(hours=24), time_step=300, time_step_output=3600)

#%%
# Comparing
o2.animation(compare=[o3, o],
             legend=[
                 'Diffusion, timstep 3600s', 'Diffusion, timestep 300s',
                 'No diffusion'
             ],
             legend_loc='upper center',
             fast=True)

#%%
# .. image:: /gallery/animations/example_horizontal_diffusion_0.gif
Exemplo n.º 13
0
# Norkyst ocean model
reader_norkyst = reader_netCDF_CF_generic.Reader(
    o.test_data_folder() +
    '16Nov2015_NorKyst_z_surface/norkyst800_subset_16Nov2015.nc')
# Uncomment to use live data from thredds
#reader_arome = reader_netCDF_CF_generic.Reader('http://thredds.met.no/thredds/dodsC/meps25files/meps_det_extracted_2_5km_latest.nc')
#reader_norkyst = reader_netCDF_CF_generic.Reader('http://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be')

o.add_reader([reader_norkyst, reader_arome])
time = reader_arome.start_time
o.seed_elements(lon, lat, radius=500, number=2000, time=time)
o.set_config('drift:current_uncertainty', 0)  # 0 is default
o.run(duration=timedelta(hours=24))

# Second run, identical, except for added diffusion

o2 = OceanDrift(loglevel=0)  # Set loglevel to 0 for debug information
o2.add_reader([reader_norkyst, reader_arome])
o2.seed_elements(lon, lat, radius=500, number=2000, time=time)
o2.set_config('drift:current_uncertainty', .2)  # Difference from first run
o2.run(duration=timedelta(hours=24))

# Comparing
o2.animation(filename='diffusion.gif',
             compare=o,
             legend=['0.2 m/s std for current components', 'No diffusion'],
             legend_loc='upper center')

#%%
# .. image:: /gallery/animations/diffusion.gif
o = OceanDrift(loglevel=20)  # 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')
time = reader_norkyst.start_time
reader_norkyst.interpolation = 'linearND'

reader_basemap = reader_basemap_landmask.Reader(
                    llcrnrlon=4, llcrnrlat=59.9,
                    urcrnrlon=5.5, urcrnrlat=61.5, resolution='h')

o.add_reader([reader_norkyst, reader_basemap])
lon = 4.5; lat = 60.0;

# First run, with Euler scheme:
o.set_config('drift:scheme', 'euler')
o.seed_elements(lon, lat, radius=0, number=1, time=time)
o.run(steps=66*2, time_step=1800)

# Second run, with Runge-Kutta scheme:
o2 = OceanDrift(loglevel=20)  # Set loglevel to 0 for debug information
o2.add_reader([reader_norkyst, reader_basemap])
o2.set_config('drift:scheme', 'runge-kutta')
o2.seed_elements(lon, lat, radius=0, number=1, time=time)
o2.run(steps=66*2, time_step=1800)

# Animate and compare the two runs
o.animation(compare=o2, legend=['Euler scheme', 'Runge-Kutta scheme'],
            markersize=10)
Exemplo n.º 15
0
original_current = reader_norkyst.var_block_after["['y_sea_water_velocity', 'x_sea_water_velocity']"].data_dict['x_sea_water_velocity'].copy()

# For the second run, the NorKyst currents are convolved with a kernel,
# effectively lowering the spatial resolution.
# <reader>.convolve may also be given as an array (kernel) directly
N = 10  # Convolusion kernel size
reader_norkyst.convolve = N  # Using convolution kernel for second run
o2 = OceanDrift()  
o2.add_reader([reader_norkyst])
o2.seed_elements(lon, lat, radius=1000, number=1000, time=time)
o2.run(steps=20)
# Store final field of x-component of (convolved) current
convolved_current = reader_norkyst.var_block_after["['y_sea_water_velocity', 'x_sea_water_velocity']"].data_dict['x_sea_water_velocity']

plt.subplot(2,1,1)
plt.imshow(original_current, interpolation='nearest')
plt.title('Original current field (x-component)')
clim = plt.gci().get_clim()
plt.colorbar()
plt.subplot(2,1,2)
plt.imshow(convolved_current, interpolation='nearest')
plt.clim(clim)  # Make sure plots are comparable
plt.colorbar()
plt.title('Final, convolved current field (x-component)')
plt.show()

# Print and plot results
print o
o.animation(compare=o2, legend=[
    'Original currents', 'Current convoled with kernel of size %s' % N])
Exemplo n.º 16
0
# of the elements. Typical empirical values are:
# - 0.035 (3.5 %) for oil and iSphere driftes
# - 0.01  (1 %) for CODE drifters partly submerged ~0.5 m
# As there are large uncertainties, it makes sence to provide a statistical
# distribution of wind_drift_factors

# Using a constant value for all elements:
#wind_drift_factor = 0.03

# Giving each element a unique (random) wind_drift_factor
wind_drift_factor = np.random.uniform(0, 0.06, 2000)

o.seed_elements(4.7, 59.9, radius=3000, number=2000,
                time=reader_current.start_time,
                wind_drift_factor=wind_drift_factor)

#######################
# Running model
#######################
o.run(time_step=timedelta(minutes=15),
      time_step_output=timedelta(minutes=60))

###########################
# Print and plot results
###########################
print o
o.animation()

# Plot trajectories, colored by the wind_drift_factor of each element
o.plot(linecolor='wind_drift_factor')
Exemplo n.º 17
0
# 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
for i in range(num_steps+1):
    o.seed_elements(lons, lats, radius=0, number=100,
                    time=start_time + i*time_step)

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

# Print and plot results
print(o)
o.animation()
Exemplo n.º 18
0
# distribution of wind_drift_factors

# Using a constant value for all elements:
#wind_drift_factor = 0.03

# Giving each element a unique (random) wind_drift_factor
wind_drift_factor = np.random.uniform(0, 0.06, 2000)
o.seed_elements(4.7,
                59.9,
                radius=3000,
                number=2000,
                time=reader_current.start_time,
                wind_drift_factor=wind_drift_factor)

#######################
# Running model
#######################
o.run(time_step=timedelta(minutes=15), time_step_output=timedelta(minutes=60))

###########################
# Print and plot results
###########################
print(o)
o.animation(filename='drifter.gif')

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

# Plot trajectories, colored by the wind_drift_factor of each element
o.plot(linecolor='wind_drift_factor')
Exemplo n.º 19
0
o.add_reader([reader_basemap, reader_norkyst])

# Seeding particles in a checkerboard pattern
di = 5 # Horizontal number of particles per square 
dj = 5 # Vertical number of particles per square
lons = np.linspace(3.5, 5.0, 100)
lats = np.linspace(60, 61, 100)

ii = np.arange(len(lons))//di
jj = np.arange(len(lats))//dj
ii, jj = np.meshgrid(ii, jj)
board = (ii+jj)%2 > 0

lons, lats = np.meshgrid(lons, lats)

lons = lons[board].ravel()
lats = lats[board].ravel()

# Seed oil elements at defined position and time
o.seed_elements(lons, lats, radius=0, number=10000,
                time=reader_norkyst.start_time)

# Running model (until end of driver data)
o.run(steps=66*2, time_step=1800)

# Print and plot results
print o
o.animation(filename="example_checkerboard_anim.gif")
#o.plot()
Exemplo n.º 20
0
"""

from datetime import timedelta
import numpy as np
from opendrift.models.oceandrift import OceanDrift
from opendrift.readers import reader_netCDF_CF_generic

#%%
# Drift simulation using 30 member ensemble wind data
# from MEPS model of MET Norway

o = OceanDrift(loglevel=20)
o.set_config('drift:vertical_mixing', False)
r = reader_netCDF_CF_generic.Reader(
    'https://thredds.met.no/thredds/dodsC/mepslatest/meps_lagged_6_h_latest_2_5km_latest.nc'
)
o.add_reader(r)

o.seed_elements(lat=60, lon=4.8, time=r.start_time, radius=1000, number=10000)

o.run(duration=timedelta(hours=50), time_step=1800, time_step_output=3600)

#%%
# Ensemble members are recycled among the 10000 particles
ensemble_number = np.remainder(o.history['ID'], 30) + 1

o.animation(fast=True, color=ensemble_number, clabel='Ensemble number')

#%%
# .. image:: /gallery/animations/example_ensemble_0.gif
Exemplo n.º 21
0
# will read and process data chuck-by-chunk directly from file using Dask.
# Note that the analysis file will be re-used if existing. Thus this file should be deleted after making any changes to the simulation above.
o = opendrift.open_xarray(outfile, analysis_file='simulation_density.nc')

#%%
# Making two animations, for each of the two seedings / origin_markere.
# The calculated density fields will be stored/cached in the analysis file
# for later re-use, as their calculation may be time consuming
# for huge output files.
# Note that other analysis/plotting methods are not yet adapted
# to datasets opened lazily with open_xarray
for om in [0, 1]:
    o.animation(density=True,
                density_pixelsize_m=500,
                fast=False,
                corners=[4.0, 6, 59.5, 61],
                origin_marker=om,
                show_elements=False,
                vmin=0,
                vmax=200)

#%%
# First seeding

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

#%%
# Second seeding

#%%
# .. image:: /gallery/animations/example_huge_output_1.gif
Exemplo n.º 22
0
lon = 4.5; lat = 60.0; # Outside Bergen

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

# Arome atmospheric model
reader_arome = reader_netCDF_CF_generic.Reader(o.test_data_folder() + '16Nov2015_NorKyst_z_surface/arome_subset_16Nov2015.nc')
# Norkyst ocean model
reader_norkyst = reader_netCDF_CF_generic.Reader(o.test_data_folder() + '16Nov2015_NorKyst_z_surface/norkyst800_subset_16Nov2015.nc')
# Uncomment to use live data from thredds
#reader_arome = reader_netCDF_CF_generic.Reader('http://thredds.met.no/thredds/dodsC/meps25files/meps_det_extracted_2_5km_latest.nc')
#reader_norkyst = reader_netCDF_CF_generic.Reader('http://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be')

o.set_config('general:basemap_resolution', 'i')
o.add_reader([reader_norkyst, reader_arome])
time = reader_arome.start_time
o.seed_elements(lon, lat, radius=500, number=2000, time=time)
o.set_config('drift:current_uncertainty', 0)  # 0 is default
o.run(duration=timedelta(hours=24))

# Second run, identical, except for added diffusion

o2 = OceanDrift(loglevel=0)  # Set loglevel to 0 for debug information
o2.set_config('general:basemap_resolution', 'i')
o2.add_reader([reader_norkyst, reader_arome])
o2.seed_elements(lon, lat, radius=500, number=2000, time=time)
o2.set_config('drift:current_uncertainty', .2) # Difference from first run
o2.run(duration=timedelta(hours=24))

# Comparing
o2.animation(compare=o, legend=['0.2 m/s std for current components', 'No diffusion'], legend_loc='upper center')
Exemplo n.º 23
0
]
drifterlats = drifterlats[::-1]
drifterlons = drifterlons[::-1]
driftertimes = [
    datetime(2015, 6, 10, 5, 50) + timedelta(minutes=10) * i
    for i in range(len(drifterlons))
]

r = reader_current_from_drifter.Reader(lons=drifterlons,
                                       lats=drifterlats,
                                       times=driftertimes)
o.add_reader(r)

#%%
# We seed elements within polygon, as could have been extracted
# from remote sensing imagery
lons = [2.39, 2.391, 2.392, 2.393, 2.394, 2.393, 2.392, 2.391, 2.39]
lats = [60.02, 60.02, 60.019, 60.02, 60.021, 60.022, 60.021, 60.021, 60.02]
o.seed_within_polygon(lons=lons, lats=lats, number=1000, time=r.start_time)

#%%
# Finally running simulation
o.run(end_time=r.end_time, time_step=r.time_step)

o.animation(buffer=.01)

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

o.plot(buffer=.01)
Exemplo n.º 24
0
o.set_config('drift:scheme', 'runge-kutta4')

double_gyre = reader_double_gyre.Reader(epsilon=.25, omega=0.628, A=0.1)
print double_gyre

o.add_reader(double_gyre)

# Calculate Lyapunov exponents
times = [double_gyre.initial_time + n * time_step_output for n in range(steps)]
lcs = o.calculate_ftle(time=times,
                       time_step=time_step,
                       duration=duration,
                       delta=delta,
                       RLCS=False)

# Make run with particles for the same period
o.reset()
x = [.9]
y = [.5]
lon, lat = double_gyre.xy2lonlat(x, y)

o.seed_elements(lon,
                lat,
                radius=.1,
                number=1000,
                time=double_gyre.initial_time)
o.run(duration=duration,
      time_step=time_step,
      time_step_output=time_step_output)
o.animation(buffer=0, lcs=lcs, filename='ALCS_with_particles.mp4')
Exemplo n.º 25
0
from opendrift.readers import reader_ROMS_native
from opendrift.models.oceandrift import OceanDrift

lon = 14.75; lat = 68.1

o = OceanDrift(loglevel=0)

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

# First run, with landmask
o.add_reader([reader_nordic])
time = reader_nordic.start_time
o.seed_elements(lon, lat, radius=3000, number=1000, time=time)
o.set_config('general:use_auto_landmask', True)
o.run(end_time=reader_nordic.end_time, time_step=1800)

# Second run, with landmask from ocean model
o2 = OceanDrift(loglevel=0)
o2.add_reader([reader_nordic])
lon = 14.75; lat = 68.1
o2.seed_elements(lon, lat, radius=3000, number=1000, time=time)
o2.set_config('general:use_auto_landmask', False)
o2.run(end_time=reader_nordic.end_time, time_step=1800)


# Animation illustrating that red particles strand at ocean model land cells, and black particles strand at Basemap land polygons
o.animation(compare=o2, background='land_binary_mask',
            legend=['Landmask', 'Ocean model landmask'])
o.add_reader(double_gyre)

#%%
# Calculate Lyapunov exponents
times = [double_gyre.initial_time + n * time_step_output for n in range(steps)]
lcs = o.calculate_ftle(time=times,
                       time_step=time_step,
                       duration=duration,
                       delta=delta,
                       RLCS=False)
#%%
# Make run with particles for the same period
o.reset()
x = [.9]
y = [.5]
lon, lat = double_gyre.xy2lonlat(x, y)

o.seed_elements(lon,
                lat,
                radius=.1,
                number=1000,
                time=double_gyre.initial_time)
o.run(duration=duration,
      time_step=time_step,
      time_step_output=time_step_output)
o.animation(buffer=0, lcs=lcs)

#%%
# .. image:: /gallery/animations/example_double_gyre_LCS_particles_0.gif
from opendrift.models.oceandrift import OceanDrift

o = OceanDrift(loglevel=20)  # 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')
time = reader_norkyst.start_time
reader_norkyst.interpolation = 'linearND'

reader_basemap = reader_basemap_landmask.Reader(
                    llcrnrlon=4, llcrnrlat=59.9,
                    urcrnrlon=5.5, urcrnrlat=61.5, resolution='h')

o.add_reader([reader_norkyst, reader_basemap])
lon = 4.5; lat = 60.0;

# First run, with Euler scheme:
o.set_config('drift:scheme', 'euler')
o.seed_elements(lon, lat, radius=0, number=1, time=time)
o.run(steps=66*2, time_step=1800)

# Second run, with Runge-Kutta scheme:
o2 = OceanDrift(loglevel=20)  # Set loglevel to 0 for debug information
o2.add_reader([reader_norkyst, reader_basemap])
o2.set_config('drift:scheme', 'runge-kutta')
o2.seed_elements(lon, lat, radius=0, number=1, time=time)
o2.run(steps=66*2, time_step=1800)

# Animate and compare the two runs
o.animation(compare=o2, legend=['Euler scheme', 'Runge-Kutta scheme'])
Exemplo n.º 28
0
reader_basemap = reader_basemap_landmask.Reader(llcrnrlon=-1.5,
                                                llcrnrlat=59,
                                                urcrnrlon=7,
                                                urcrnrlat=64,
                                                resolution='h')

o.add_reader([fake_eddy, reader_basemap])
lon = 2.0
lat = 63.0
# Close to Station M

# First run, with Euler scheme:
o.set_config('drift:scheme', 'euler')
o.seed_elements(lon, lat, radius=0, number=1, time=datetime(2015, 1, 1))
o.run(steps=300, time_step=3600)

# Second run, with Runge-Kutta scheme:
o2 = OceanDrift(loglevel=20)  # Set loglevel to 0 for debug information
o2.add_reader([fake_eddy, reader_basemap])
o2.set_config('drift:scheme', 'runge-kutta')
o2.seed_elements(lon, lat, radius=0, number=1, time=datetime(2015, 1, 1))
o2.run(steps=300, time_step=3600)

o.plot()
o2.plot()
# Animate and compare the two runs
o.animation(compare=o2,
            legend=['Euler scheme', 'Runge-Kutta scheme'],
            markersize=15)
o.set_config('environment:fallback:land_binary_mask', 0)

double_gyre = reader_double_gyre.Reader(epsilon=.25, omega=0.628, A=0.1)
print(double_gyre)
o.add_reader(double_gyre)

#%%
# Calculate Lyapunov exponents
times = [double_gyre.initial_time +
         n*time_step_output for n in range(steps)]
lcs = o.calculate_ftle(time=times, time_step=time_step,
                       duration=duration, delta=delta, RLCS=False)

#%%
# Make run with particles for the same period
o.reset()
x = [.9]
y = [.5]
lon, lat = double_gyre.xy2lonlat(x, y)

o.seed_elements(lon, lat, radius=.15, number=2000,
                time=double_gyre.initial_time)
o.disable_vertical_motion()
o.run(duration=duration, time_step=time_step,
      time_step_output=time_step_output)
o.animation(buffer=0, lcs=lcs, hide_landmask=True)

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

# when necessary coverage (time/space) is known ( <reader>.prepare() )

cmems = reader_cmems.Reader(
    dataset='global-analysis-forecast-phy-001-024-hourly-merged-uv',
    variable_mapping={  # Overriding the mapping in reader_cmems.py
        'utotal': 'x_sea_water_velocity',
        'vtotal': 'y_sea_water_velocity',
        'utide': 'sea_ice_x_velocity',  # Fake mapping, as standard_name
        'vtide': 'sea_ice_y_velocity'
    })  # must be unique for a reader

o = OceanDrift()

o.add_reader(cmems)
# Alternatively, use OPeNDAP directly:
# https://help.marine.copernicus.eu/en/articles/5182598-how-to-consume-the-opendap-api-and-cas-sso-using-python
#o.add_readers_from_list(['https://nrt-dev.cmems-du.eu/thredds/dodsC/global-analysis-forecast-phy-001-024-hourly-merged-uv'])

o.seed_elements(lon=lon, lat=lat, number=5000, radius=1000, time=time)
o.run(duration=duration)

# Although total current (SMOC) has been used as forcing, we plot the tidal current as background field, disguised as ice velocity
o.animation(fast=True,
            clabel='Tidal current [m/s]',
            skip=1,
            scale=20,
            background=['sea_ice_x_velocity', 'sea_ice_y_velocity'])

#%%
# .. image:: /gallery/animations/example_cmems_0.gif
Exemplo n.º 31
0
time = datetime.now()
duration = timedelta(days=3)
bufferlat = duration.total_seconds() / 111000
bufferlon = bufferlat * np.cos(lat * np.pi / 180)

# Fetching current data from CMEMS
cmems_file = 'opendrift_cmems_download.nc'
if os.path.exists(cmems_file):
    # Reuising downloaded file, if existing. Delete it to force update.
    cmems = reader_netCDF_CF_generic.Reader(cmems_file)
else:
    cmems = reader_cmems.Reader(username=username,
                                password=password,
                                lon_min=lon - bufferlon,
                                lon_max=lon + bufferlon,
                                lat_min=lat - bufferlat,
                                lat_max=lat + bufferlat,
                                time_start=time - timedelta(hours=3),
                                time_end=time + duration)

o = OceanDrift()

o.add_reader(cmems)
o.seed_elements(lon=lon, lat=lat, number=5000, radius=1000, time=time)
o.run(duration=duration)
o.animation(fast=True)

#%%
# .. image:: /gallery/animations/example_cmems_0.gif
Exemplo n.º 32
0
o.add_reader(reader_norkyst)
#o.fallback_values['land_binary_mask'] = 0

#%%
# Seeding some particles
lons = np.linspace(3.5, 5.0, 100)
lats = np.linspace(60, 61, 100)
lons, lats = np.meshgrid(lons, lats)
lons = lons.ravel()
lats = lats.ravel()

#%%
# Seed oil elements at defined position and time
o.seed_elements(lons,
                lats,
                radius=0,
                number=10000,
                time=reader_norkyst.start_time)

#%%
# Running model (until end of driver data)
o.run(steps=60 * 2, time_step=1800, time_step_output=1800)

#%%
# Print and plot results
print(o)
o.animation(fast=False, corners=[3.5, 5.5, 59.9, 61.2])

#%%
# .. image:: /gallery/animations/example_grid_0.gif
Exemplo n.º 33
0
# This example works better using hourly input from Thredds than the daily data from test folder
reader_nordic = reader_netCDF_CF_generic.Reader(
    'http://thredds.met.no/thredds/dodsC/sea/nordic4km/zdepths1h/aggregate_be')
#reader_nordic = reader_ROMS_native.Reader(o.test_data_folder() +
#    '2Feb2016_Nordic_sigma_3d/Nordic-4km_SLEVELS_avg_00_subset2Feb2016.nc')

o.add_reader([reader_nordic])
o.set_config('general:coastline_action', 'previous')

# Seeding elements on a grid
lons = np.linspace(12, 14.5, 30)
lats = np.linspace(67.5, 68.5, 30)
lons, lats = np.meshgrid(lons, lats)
lon = lons.ravel()
lat = lats.ravel()

time = reader_nordic.start_time
o.seed_elements(lon, lat, radius=0, number=30 * 30, time=time)

o.run(steps=24 * 2, time_step=3600)

# Print and plot results
print(o)
o.plot()
#o.plot(background=['x_sea_water_velocity', 'y_sea_water_velocity'])
o.animation(filename='coastline.gif')

#%%
# .. image:: /gallery/animations/coastline.gif
Exemplo n.º 34
0
o.set_config('general:coastline_action', 'previous')

shyfem = shyfem.Reader('https://iws.ismar.cnr.it/thredds/dodsC/emerge/shyfem_unstructured_adriatic.nc')
o.add_reader(shyfem)
print(shyfem)

# Seed elements at defined positions, depth and time
N = 1000
z = -15*np.random.uniform(0, 1, N)
o.seed_elements(lon=12.4, lat=45.25, radius=1000, number=N,
                z=z, time=shyfem.start_time)

#%%
# Running model
o.run(time_step=1800, duration=timedelta(hours=12))

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

#%%
# Animations
o.animation(color='z', markersize=5, corners=[12.2, 12.6, 45.1, 45.5])

o.animation_profile(color='z', markersize=5)


#%%
# .. image:: /gallery/animations/example_shyfem_0.gif
o.plot(fast=True, buffer = 1., corners=[12.2, 12.6, 45.1, 45.5])
Exemplo n.º 35
0
#%%
# Seed information
lon = 4.8
lat = 60  # Bergen, Norway
lon = -89
lat = 29.8  # New Orleans
lon = 107
lat = 10  # Ho Chi Minh
lon = 123
lat = -16.3  # Australia

o = OceanDrift()

o.add_readers_from_list([
    'https://nrt.cmems-du.eu/thredds/dodsC/cmems_mod_glo_phy_anfc_merged-uv_PT1H-i'
])

o.seed_elements(lon=lon,
                lat=lat,
                number=5000,
                radius=1000,
                time=datetime.utcnow())
o.run(duration=timedelta(days=3))

o.animation(fast=True,
            clabel='Ocean current [m/s]',
            background=['x_sea_water_velocity', 'y_sea_water_velocity'])

#%%
# .. image:: /gallery/animations/example_cmems_0.gif
Exemplo n.º 36
0
def test_plot(tmpdir):

    anifile = os.path.join(tmpdir, 'anim.mp4')
    plotfile = os.path.join(tmpdir, 'plot.png')
    #anifile = None
    #plotfile = None
    o = OceanDrift(loglevel=30)
    rn = reader_netCDF_CF_generic.Reader(
        o.test_data_folder() +
        '16Nov2015_NorKyst_z_surface/norkyst800_subset_16Nov2015.nc')
    o.add_reader(rn)
    o.seed_elements(lon=4.8,
                    lat=60.0,
                    number=10,
                    radius=1000,
                    time=rn.start_time)
    o.run(steps=5)

    # Making figures/animations
    o.plot(filename=plotfile,
           fast=True,
           background=['x_sea_water_velocity', 'y_sea_water_velocity'])
    o.animation(color='lat',
                filename=anifile,
                show_trajectories=True,
                fast=True)
    o.animation(density=True,
                filename=anifile,
                show_trajectories=True,
                fast=True)
    o.animation(filename=anifile, show_trajectories=True, fast=True)
    o.animation(filename=anifile,
                fast=True,
                background=['x_sea_water_velocity', 'y_sea_water_velocity'])
    o.plot(filename=plotfile, fast=True, linecolor='lat')
    o.plot(filename=plotfile, fast=False)

    # Second run for comparison
    o2 = OceanDrift(loglevel=30)
    o2.add_reader(rn)
    o2.fallback_values['x_wind'] = 15  # Adding wind
    o2.fallback_values['y_wind'] = 0
    o2.seed_elements(lon=4.8,
                     lat=60.0,
                     number=10,
                     radius=1000,
                     time=rn.start_time)
    o2.run(steps=5)

    o.animation(filename=anifile,
                compare=o2,
                fast=True,
                legend=['No wind', '10 m/s wind'])
    o.plot(filename=plotfile,
           compare=o2,
           fast=True,
           legend=['No wind', '10 m/s wind'])

    # Check that files have been written
    assert os.path.exists(anifile)
    assert os.path.exists(plotfile)
Exemplo n.º 37
0
from opendrift.readers import reader_double_gyre
from opendrift.models.oceandrift import OceanDrift

o = OceanDrift(loglevel=20)  # Set loglevel to 0 for debug information
o.fallback_values['land_binary_mask'] = 0
o.set_config('drift:scheme', 'runge-kutta4')

double_gyre = reader_double_gyre.Reader(epsilon=.25, omega=0.628, A=0.1)
print(double_gyre)

o.add_reader(double_gyre)

x = [.9]
y = [.5]
lon, lat = double_gyre.xy2lonlat(x, y)

o.seed_elements(lon,
                lat,
                radius=.1,
                number=1000,
                time=double_gyre.initial_time)

o.run(duration=timedelta(seconds=10), time_step=0.1)
o.animation(buffer=0)

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

o.plot(buffer=0)
Exemplo n.º 38
0
#!/usr/bin/env python

from datetime import timedelta
import numpy as np
from opendrift.models.oceandrift import OceanDrift
from opendrift.readers import reader_netCDF_CF_generic

# Drift simulation using 10 member ensemble wind data
# from MEPS model of MET Norway

o = OceanDrift()
r = reader_netCDF_CF_generic.Reader('http://thredds.met.no/thredds/dodsC/meps25files/meps_allmembers_extracted_2_5km_latest.nc')
o.add_reader(r)

#o.set_config('general:basemap_resolution', 'c')
o.seed_elements(lat=60, lon=4.8, time=r.start_time,
                radius=1000, number=10000)

o.run(duration=timedelta(hours=50), time_step=3600)

# Ensemble members are recycled among the 10000 particles
ensemble_number = np.remainder(o.history['ID'], 10) + 1

o.animation(filename='wind_drift_ensemble.mp4',
            color=ensemble_number, clabel='Ensemble number')