o = OceanDrift(loglevel=0) # Set loglevel to 0 for debug information # Adding nordic reader for coastline reader_nordic = reader_ROMS_native.Reader(o.test_data_folder() + '2Feb2016_Nordic_sigma_3d/Nordic-4km_SLEVELS_avg_00_subset2Feb2016.nc') reader_nordic.variables = ['land_binary_mask'] reader_osc = reader_oscillating.Reader('x_sea_water_velocity', amplitude=1, zero_time=reader_nordic.start_time) o.add_reader([reader_osc]) # Oscillating east-west current component o.fallback_values['y_sea_water_velocity'] = .2 # Adding northwards drift o.set_config('general:basemap_resolution', 'i') ########################################################## # Try different options: 'previous', 'stranding', 'none' o.set_config('general:coastline_action', 'previous') ########################################################## time = reader_osc.zero_time lon = 12.2; lat = 67.7 o.seed_elements(lon, lat, radius=5000, number=15, time=time) o.run(steps=36*4, time_step=900) # Print and plot results print o o.plot() #o.plot(background=['x_sea_water_velocity', 'y_sea_water_velocity']) o.animation()
#%% # Seeding some particles lons = np.linspace(10.2, 12.2, 50) lats = np.linspace(69.8, 70.8, 50) lons, lats = np.meshgrid(lons, lats) #%% # Seed oil elements at defined position and time o.seed_elements(lons, lats, radius=0, number=2500, time=reader_norkyst.start_time) o.set_config('drift:vertical_mixing', False) #%% # Running model o.run(steps=16 * 4, time_step=900, time_step_output=1800) #%% # Print and plot results print(o) o.animation(fast=True) #%% # .. image:: /gallery/animations/example_reader_boundary_0.gif o.plot(fast=True)
from opendrift.readers import reader_netCDF_CF_generic from opendrift.models.oceandrift import OceanDrift o = OceanDrift(loglevel=20) # Set loglevel to 0 for debug information # Norkyst ocean model reader_norkyst = reader_netCDF_CF_generic.Reader(o.test_data_folder() + '16Nov2015_NorKyst_z_surface/norkyst800_subset_16Nov2015.nc') #o.add_reader([reader_norkyst, reader_arome]) o.add_reader([reader_norkyst]) #%% # Calculating attracting/backwards FTLE/LCS at 20 hours lcs = o.calculate_ftle( time=reader_norkyst.start_time + timedelta(hours=20), time_step=timedelta(minutes=30), duration=timedelta(hours=5), delta=1000, RLCS=False) #%% # Simulation from beginning and up to 30 hours (time of LCS) o.reset() o.seed_elements(lon=4.4, lat=60.2, number=1000, radius=1000, time=reader_norkyst.start_time) o.run(end_time=reader_norkyst.start_time+timedelta(hours=20), time_step=timedelta(minutes=30)) o.plot(lcs=lcs, vmin=1e-7, vmax=1e-4, colorbar=True, show_elements=True)
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)
'https://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() #%% # .. image:: /gallery/animations/example_coastline_0.gif
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.set_config('environment:fallback:land_binary_mask', 0) o.set_config('drift:advection_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=5000, time=double_gyre.initial_time) o.run(duration=timedelta(seconds=10), time_step=0.1) o.animation(buffer=0, hide_landmask=True) #%% # .. image:: /gallery/animations/example_double_gyre_0.gif o.plot(buffer=0, hide_landmask=True)
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)
from datetime import datetime, timedelta from opendrift.readers import reader_netCDF_CF_generic from opendrift.models.oceandrift import OceanDrift o = OceanDrift(loglevel=20) # Set loglevel to 0 for debug information # Norkyst ocean model reader_norkyst = reader_netCDF_CF_generic.Reader(o.test_data_folder() + '16Nov2015_NorKyst_z_surface/norkyst800_subset_16Nov2015.nc') #o.add_reader([reader_norkyst, reader_arome]) o.add_reader([reader_norkyst]) # Calculating attracting/backwards FTLE/LCS at 20 hours lcs = o.calculate_ftle( time=reader_norkyst.start_time + timedelta(hours=20), time_step=timedelta(minutes=30), duration=timedelta(hours=5), delta=1000, RLCS=False) # Simulation from beginning and up to 30 hours (time of LCS) o.reset() o.seed_elements(lon=4.4, lat=60.2, number=1000, radius=1000, time=reader_norkyst.start_time) o.run(end_time=reader_norkyst.start_time+timedelta(hours=20), time_step=timedelta(minutes=30)) o.plot(lcs=lcs, vmin=1e-7, vmax=1e-4, colorbar=True, show_particles=True)
['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_elements=False, fast=False) o.animation(color='z', buffer=.1, fast=True) #%% # .. image:: /gallery/animations/example_depth_0.gif
lats=drifter_lats, times=drifter_times) wind_drift_factor, azimuth = wind_drift_factor_from_trajectory(t) o.seed_elements(lon=4, lat=60, number=1, time=ot.readers[list(ot.readers)[0]].start_time, wind_drift_factor=0.033) #%% # New simulation, this time without diffusivity/noise o.run(duration=timedelta(hours=12), time_step=600) o.plot(fast=True, legend=True, trajectory_dict=trajectory_dict) #%% # The mean retrieved wind_drift_factor is 0.036, slichtly higher than the value 0.033 used for the simulation. # The difference is due to the "noise" added by horizontal diffusion. # Note that the retieved wind_drift_factor is linked to the wind and current used for the retrieval, # other forcing datasets will yeld different value of the wind_drift_factor. print(wind_drift_factor.mean()) plt.hist(wind_drift_factor, label='Retrieved wind_drift_factor') plt.axvline(x=0.033, label='Actual wind_drift_factor of 0.033', color='k') plt.axvline(x=wind_drift_factor.mean(), label='Mean retieved wind_drift_factor of %.3f' % wind_drift_factor.mean(), color='r')
o2.run(end_time=reader_nordic.end_time, time_step=1800, time_step_output=3 * 3600) #%% Prepare cusom colormap/colors for land and ocean from matplotlib.colors import ListedColormap import cartopy.feature as cfeature #cmap = ListedColormap(('blue', 'red')) cmap = ListedColormap((cfeature.COLORS['water'], cfeature.COLORS['land'])) #%% # .. _model_landmask_only_model: # # To only show the landmask from the model, hide the coastline landmask by doing: o2.plot(background='land_binary_mask', hide_landmask=True, cmap=cmap) #%% # Animation illustrating that red particles strand at ocean model land cells, and black particles strand at GSHHG land polygons o.animation(compare=o2, background='land_binary_mask', cmap=cmap, legend=['Default GSHHG landmask', 'Ocean model landmask']) #%% # .. image:: /gallery/animations/example_model_landmask_0.gif o.plot(compare=o2, background='land_binary_mask', cmap=cmap, legend=['Default GSHHG landmask', 'Ocean model landmask'])
ax.margins(x=0) ax.legend() ax.set_xticks([]) ax.set_xlabel(None) ax4.set_title('Density of water at Station') ax4.xaxis.set_major_formatter(DateFormatter("%d %b %H")) plt.show() #%% # Finally, plot the spatial distribution of mean age of water num = o.get_histogram(pixelsize_m=1500, weights=None, density=False) num.name = 'number' num.to_netcdf(histogram_file) mas = o.get_histogram(pixelsize_m=1500, weights=o.ds['age_seconds'], density=False) mas = mas / 3600 # in hours mas = mas / num # per area mas.name = 'mean_age' mas.to_netcdf(histogram_file, 'a') mas = mas.mean(dim='time').sum(dim='origin_marker') # Mean time of both rivers #mas = mas.mean(dim='time').isel(origin_marker=1) # Mean age of a single river mas.name = 'Mean age of water [hours]' o.plot(background=mas.where(mas > 0), fast=True, show_elements=False) # Cleaning up os.remove(outfile) os.remove(histogram_file)
# 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) # Prevent mixing elements downwards o.set_config('drift:vertical_mixing', False) #%% # 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)
#%% # 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=48 * 2, time_step=3600) #%% # Print and plot results print(o) ax, _ = o.plot(hide_landmask=True, show=False) #%% # Show shapes ax.add_geometries(reader_natural.polys, ccrs.PlateCarree(), facecolor=cfeature.COLORS['land'], edgecolor='black') plt.show() o.animation() #%% # .. image:: /gallery/animations/example_shape_landmask_0.gif
rname = "./results_depth/onebyone_Ancud_site_{0}_z{1}.nc".format(j, depths) if j < 100: rname = "./results_depth/onebyone_Ancud_site_0{0}_z{1}.nc".format( j, depths) if j < 10: rname = "./results_depth/onebyone_Ancud_site_00{0}_z{1}.nc".format( j, depths) # # Simulacion # # 4320 = 30*24*6 o.run(steps=4320, time_step=timedelta(minutes=10), time_step_output=timedelta(hours=1), outfile=rname) fname = "./Figures/onebyone_Ancud_site_{0}_z{1}.png".format(j, depths) if j < 100: fname = "./Figures/onebyone_Ancud_site_0{0}_z{1}.png".format(j, depths) if j < 10: fname = "./Figures/onebyone_Ancud_site_00{0}_z{1}.png".format(j, depths) print(fname) time.sleep(2) o.plot(filename=fname) #o.animation (filename ='./Animations/many_v3.mp4') o.reset() cmd = "rm " + rname os.system(cmd)
from opendrift.models.oceandrift import OceanDrift o = OceanDrift(loglevel=20) # Set loglevel to 0 for debug information # Seed oil particles within contours from shapefile o.seed_from_shapefile(o.test_data_folder() + 'shapefile_spawning_areas/Torsk.shp', number=2000, layername=None, featurenum=[2, 4], time=datetime.now()) o.fallback_values['x_wind'] = -4 # Constant wind drift o.fallback_values['y_wind'] = 8 o.set_config('drift:wind_uncertainty', 4) # Adding some diffusion # Running model o.run(steps=50, time_step=3600) # Print and plot results print(o) o.plot(fast=True) if len(argv) > 1: o.animation(filename=argv[1]) if len(argv) > 2: try: o.plot(filename=argv[2]) except: pass
['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, outfile='openoil.nc') #%% # 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
# This is actual data of SLDMB/Code drifter as used in this study: # Jones, C.E., Dagestad, K.-F., Breivik, O., Holt, B., Rohrs, J., Christensen, K.H., Espeseth, M.M., Brekke, C., Skrunes, S. (2016): Measurement and modeling of oil slick transport. Journal of Geophysical Research - Oceans, Volume 121, Issue 10, October 2016, Pages 7759-7775. DOI: 10.1002/2016JC012113. drifterlons = [2.407376, 2.405140, 2.403248, 2.401872, 2.400152, 2.398518, 2.397056, 2.395766, 2.394476, 2.393358, 2.392584, 2.391810, 2.390606, 2.389316, 2.388628, 2.388370, 2.387940, 2.387510, 2.387338, 2.387166, 2.387252, 2.387338, 2.387682, 2.387854, 2.388284, 2.388628, 2.389230, 2.390004, 2.390434, 2.390692, 2.391380, 2.391896, 2.392068, 2.392154, 2.392068, 2.391896, 2.391896, 2.391896, 2.391638, 2.391380, 2.391208, 2.391036, 2.390692, 2.390090, 2.389660, 2.389058, 2.388628] drifterlats = [60.034740, 60.033880, 60.033106, 60.032246, 60.031300, 60.030182, 60.028892, 60.027602, 60.026656, 60.025538, 60.024420, 60.023388, 60.022442, 60.021496, 60.020378, 60.019346, 60.018572, 60.017626, 60.016852, 60.016164, 60.015734, 60.015304, 60.014616, 60.014100, 60.013670, 60.013412, 60.013240, 60.013068, 60.013154, 60.013412, 60.013584, 60.013842, 60.014186, 60.014616, 60.015218, 60.015820, 60.016594, 60.017454, 60.018400, 60.019346, 60.020464, 60.021410, 60.022442, 60.023474, 60.024678, 60.025882, 60.026914] 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, filename='current_from_drifter.gif') #%% # .. image:: /gallery/animations/current_from_drifter.gif o.plot(buffer=.01)
from opendrift.readers import reader_ROMS_native from opendrift.models.oceandrift import OceanDrift o = OceanDrift(loglevel=20) # Set loglevel to 0 for debug information #%% # Creating and adding reader for Nordic 4km current dataset nordic_native = reader_ROMS_native.Reader( o.test_data_folder() + '2Feb2016_Nordic_sigma_3d/Nordic-4km_SLEVELS_avg_00_subset2Feb2016.nc') o.add_reader(nordic_native) #%% # Seed elements at defined positions, depth and time o.seed_elements(lon=12.0, lat=68.3, radius=0, number=10, z=np.linspace(0, -150, 10), time=nordic_native.start_time) #%% # Running model o.run(time_step=3600) #%% # Print and plot results, with lines colored by particle depth print(o) o.plot(linecolor='z', fast=True) #o.animation()
============= """ from datetime import datetime, timedelta from opendrift.models.oceandrift import OceanDrift o = OceanDrift(loglevel=20) # Set loglevel to 0 for debug information #%% # Adding no input models, but instead constant northwards current of 1 m/s o.fallback_values['x_sea_water_velocity'] = 0 o.fallback_values['y_sea_water_velocity'] = 1 o.fallback_values['land_binary_mask'] = 0 #%% # Seed elements at defined position and time o.seed_elements(lon=4.0, lat=60.0, radius=5000, number=100, time=datetime(2015, 9, 22, 6, 0, 0)) #%% # Running model for 50 hours o.run(duration=timedelta(hours=50)) #%% # Print and plot results print(o) o.plot(fast=True, buffer=1)
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-' })
o = OceanDrift(loglevel=0) # Set loglevel to 0 for debug information # Nordic 4km nordic_native = reader_ROMS_native.Reader(o.test_data_folder() + '2Feb2016_Nordic_sigma_3d/Nordic-4km_SLEVELS_avg_00_subset2Feb2016.nc') # Landmask (Basemap) reader_basemap = reader_basemap_landmask.Reader( llcrnrlon=11.0, llcrnrlat=67.5, urcrnrlon=16.0, urcrnrlat=69.0, resolution='h', projection='merc') o.add_reader([reader_basemap, nordic_native]) # Seeding some particles time = nordic_native.start_time lon = 12.0; lat = 68.3; # Seed oil elements at defined position and time o.seed_elements(lon, lat, radius=0, number=10, z=np.linspace(0, -150, 10), time=time) print o # Running model o.run(time_step=3600) # Print and plot results print o o.plot(linecolor='z') #o.animation()
# - 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')
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)
from opendrift.readers import reader_ArtificialOceanEddy from opendrift.models.oceandrift import OceanDrift o = OceanDrift(loglevel=0) # Set loglevel to 0 for debug information fake_eddy = reader_ArtificialOceanEddy.Reader(2, 62) 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(compare=o2, legend=['Euler scheme', 'Runge-Kutta scheme']) #o2.plot() # Animate and compare the two runs o.animation(compare=o2, legend=['Euler scheme', 'Runge-Kutta scheme'])
o.set_config('environment:fallback:x_sea_water_velocity', 0) o.set_config('environment:fallback:y_sea_water_velocity', 0) o.set_config('drift:wind_uncertainty', 0) o.set_config('drift:current_uncertainty', 0) time = datetime(2016, 1, 20, 12, 30, 0) #%% # Seeding a single element at a point print('\n' + '=' * 70) print('Seeding a single element at a point:') print('o.seed_elements(lon=4, lat=60, time=time)') print('=' * 70) o.seed_elements(lon=4, lat=60, time=time) #o.run(steps=1) o.plot(buffer=.7, fast=True) #%% # Seeding 100 elements within a radius of 1000 m print('\n' + '=' * 70) print('Seeding 100 elements within a radius of 1000 m:') print('o.seed_elements(lon=4, lat=60, number=100, radius=1000, time=time)') print('=' * 70) o.seed_elements(lon=4, lat=60, number=100, radius=1000, time=time) #o.run(steps=1) o.plot(buffer=.7, fast=True) #%% # Seeding 100 elements within a radius of 1000 m and specifying a property (here z/depth) as an array print('\n' + '=' * 70) print(
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])
#%% # 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.disable_vertical_motion() o.run(steps=50 * 4, time_step=900, time_step_output=3600, outfile=ncfile) #%% # Print and plot results print(o) o.plot(buffer=.2, fast=True) ##%% # Backward run: # Import forward run, and seed elements at final positions and time o = opendrift.open(ncfile) elements_final = o.elements time_final = o.time del o o = OceanDrift(loglevel=20) # Set loglevel to 0 for debug information o.fallback_values['land_binary_mask'] = 0 o.add_reader(reader_norkyst) o.schedule_elements(elements_final, time_final) o.disable_vertical_motion() #%%
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) # Print and plot results print(o) o.plot(buffer=.2, filename='forward.png') ################# ## Backward run ################# o = OceanDrift(loglevel=0) # Set loglevel to 0 for debug information #o.add_reader([reader_norkyst, reader_basemap]) # Import forward run, and seed elements at final positions and time o.io_import_file(ncfile) elements_final = o.elements time_final = o.time del o o = OceanDrift(loglevel=0) # Set loglevel to 0 for debug information o.add_reader([reader_norkyst, reader_basemap]) o.schedule_elements(elements_final, time_final)
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)
# 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')
from opendrift.models.oceandrift import OceanDrift o = OceanDrift(loglevel=0) # Set loglevel to 0 for debug information fake_eddy = reader_ArtificialOceanEddy.Reader(2, 62) 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)