Note
Go to the end to download the full example code
Coastline interaction
Example to illustrate stranding options using an artificial east-west oscillating current field Knut-Frode Dagestad, Feb 2017
from datetime import datetime
from opendrift.readers import reader_oscillating
from opendrift.models.oceandrift import OceanDrift
o = OceanDrift(loglevel=50) # Set loglevel to 0 for debug information
reader_osc = reader_oscillating.Reader('x_sea_water_velocity', amplitude=1,
zero_time=datetime.utcnow())
o.add_reader([reader_osc]) # Oscillating east-west current component
o.set_config('environment:fallback:y_sea_water_velocity', .2) # Adding northwards drift
Try different options: ‘previous’, ‘stranding’, ‘none’
o.set_config('general:coastline_action', 'previous')
o.seed_elements(lon=12.2, lat=67.7, radius=5000, number=25, time=reader_osc.zero_time)
o.run(steps=36*4, time_step=900, time_step_output=1800)
Print and plot results
print(o)
o.animation()
o.plot()

===========================
--------------------
Reader performance:
--------------------
oscillating_reader
0:00:00.0 total
0:00:00.0 preparing
0:00:00.0 reading
0:00:00.0 masking
--------------------
global_landmask
0:00:00.0 total
0:00:00.0 preparing
0:00:00.0 reading
0:00:00.0 masking
--------------------
Performance:
7.8 total time
0.0 configuration
6.0 preparing main loop
6.0 making dynamical landmask
0.0 moving elements to ocean
1.1 readers
0.0 global_landmask
0.7 postprocessing
1.7 main loop
0.0 oscillating_reader
0.0 updating elements
0.0 cleaning up
--------------------
===========================
Model: OceanDrift (OpenDrift version 1.10.7)
25 active Lagrangian3DArray particles (0 deactivated, 0 scheduled)
-------------------
Environment variables:
-----
x_sea_water_velocity
1) oscillating_reader
-----
land_binary_mask
1) global_landmask
-----
Readers not added for the following variables:
ocean_mixed_layer_thickness
ocean_vertical_diffusivity
sea_floor_depth_below_sea_level
sea_surface_swell_wave_peak_period_from_variance_spectral_density
sea_surface_swell_wave_significant_height
sea_surface_swell_wave_to_direction
sea_surface_wave_mean_period_from_variance_spectral_density_second_frequency_moment
sea_surface_wave_period_at_variance_spectral_density_maximum
sea_surface_wave_significant_height
sea_surface_wave_stokes_drift_x_velocity
sea_surface_wave_stokes_drift_y_velocity
sea_surface_wind_wave_mean_period
sea_surface_wind_wave_significant_height
sea_surface_wind_wave_to_direction
surface_downward_x_stress
surface_downward_y_stress
turbulent_generic_length_scale
turbulent_kinetic_energy
upward_sea_water_velocity
x_wind
y_sea_water_velocity
y_wind
Time:
Start: 2023-09-01 14:04:32.089594 UTC
Present: 2023-09-03 02:04:32.089594 UTC
Calculation steps: 144 * 0:15:00 - total time: 1 day, 12:00:00
Output steps: 73 * 0:30:00
===========================
/opt/conda/envs/opendrift/lib/python3.11/site-packages/cartopy/mpl/geoaxes.py:1696: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
result = super().scatter(*args, **kwargs)
0.9781333791565434 ALPHA
(<GeoAxes: title={'center': 'OpenDrift - OceanDrift\n2023-09-01 14:04 to 2023-09-03 02:04 UTC (73 steps)'}>, <Figure size 1100x861.384 with 1 Axes>)

Total running time of the script: (3 minutes 47.578 seconds)