SHYFEM: Using model input from unstructured grid

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

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

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)

Out:

13:43:51 INFO    opendrift.models.basemodel: OpenDriftSimulation initialised (version 1.7.1 / v1.7.1-87-g074c1d2)
13:43:51 INFO    opendrift.readers.unstructured.shyfem: Opening dataset: https://iws.ismar.cnr.it/thredds/dodsC/emerge/shyfem_unstructured_adriatic.nc
13:43:51 INFO    opendrift.readers.unstructured.shyfem: Opening file with Dataset
13:43:51 INFO    opendrift.readers.unstructured.shyfem: Reading grid and coordinate variables..
===========================
Reader: https://iws.ismar.cnr.it/thredds/dodsC/emerge/shyfem_unstructured_adriatic.nc
Projection:
  +proj=lonlat
Coverage: [degrees]
  xmin: 12.240470   xmax: 19.917908
  ymin: 39.957329   ymax: 45.799709
  Corners (lon, lat):
    ( 12.24,  45.80)  ( 19.92,  45.80)
    ( 12.24,  39.96)  ( 19.92,  39.96)
Vertical levels [m]:
  [-0.6000000238418579 -1.600000023841858 -2.5 -3.5 -4.5 -5.5 -7.0 -9.0
 -11.0 -13.0 -16.0 -21.0 -27.0 -34.0 -41.5 -50.0 -60.0 -72.5 -90.0 -110.0
 -135.0 -175.0 -225.0 -275.0 -350.0 -450.0 -550.0 -650.0 -750.0 -850.0
 -950.0 -1050.0 -1155.0]
Available time range:
  start: 2021-04-08 00:00:00   end: 2021-04-08 23:00:00   step: None
Variables:
  depth
  sea_water_salinity
  sea_water_temperature
  sea_floor_depth_below_sea_level
  x_sea_water_velocity
  y_sea_water_velocity
  water_surface_height_above_reference_datum
===========================
 0:00:01.3  open dataset
 0:00:00.0  build index

Running model

o.run(time_step=1800, duration=timedelta(hours=12))

Out:

13:43:52 INFO    opendrift.models.basemodel: Fallback values will be used for the following variables which have no readers:
13:43:52 INFO    opendrift.models.basemodel:    x_wind: 0.000000
13:43:52 INFO    opendrift.models.basemodel:    y_wind: 0.000000
13:43:52 INFO    opendrift.models.basemodel:    upward_sea_water_velocity: 0.000000
13:43:52 INFO    opendrift.models.basemodel:    ocean_vertical_diffusivity: 0.000000
13:43:52 INFO    opendrift.models.basemodel:    sea_surface_wave_significant_height: 0.000000
13:43:52 INFO    opendrift.models.basemodel:    sea_surface_wave_stokes_drift_x_velocity: 0.000000
13:43:52 INFO    opendrift.models.basemodel:    sea_surface_wave_stokes_drift_y_velocity: 0.000000
13:43:52 INFO    opendrift.models.basemodel:    sea_surface_wave_period_at_variance_spectral_density_maximum: 0.000000
13:43:52 INFO    opendrift.models.basemodel:    sea_surface_wave_mean_period_from_variance_spectral_density_second_frequency_moment: 0.000000
13:43:52 INFO    opendrift.models.basemodel:    surface_downward_x_stress: 0.000000
13:43:52 INFO    opendrift.models.basemodel:    surface_downward_y_stress: 0.000000
13:43:52 INFO    opendrift.models.basemodel:    turbulent_kinetic_energy: 0.000000
13:43:52 INFO    opendrift.models.basemodel:    turbulent_generic_length_scale: 0.000000
13:43:52 INFO    opendrift.models.basemodel: Adding a dynamical landmask with max. priority based on assumed maximum speed of 1 m/s. Adding a customised landmask may be faster...
13:43:52 INFO    opendrift_landmask_data.mask: locking landmask for generation..
13:43:52 INFO    opendrift_landmask_data.mask: decompressing memmap landmask to /tmp/landmask/mask.dat..
13:44:05 INFO    opendrift_landmask_data.mask: landmask generated
13:44:11 INFO    opendrift.models.basemodel: Using existing reader for land_binary_mask
13:44:11 INFO    opendrift.models.basemodel: All points are in ocean
13:44:11 INFO    opendrift.models.basemodel: 2021-04-08 00:00:00 - step 1 of 24 - 1000 active elements (0 deactivated)
13:44:12 INFO    opendrift.models.basemodel: 2021-04-08 00:30:00 - step 2 of 24 - 1000 active elements (0 deactivated)
13:44:14 INFO    opendrift.models.basemodel: 2021-04-08 01:00:00 - step 3 of 24 - 1000 active elements (0 deactivated)
13:44:16 INFO    opendrift.models.basemodel: 2021-04-08 01:30:00 - step 4 of 24 - 1000 active elements (0 deactivated)
13:44:18 INFO    opendrift.models.basemodel: 2021-04-08 02:00:00 - step 5 of 24 - 1000 active elements (0 deactivated)
13:44:22 INFO    opendrift.models.basemodel: 2021-04-08 02:30:00 - step 6 of 24 - 1000 active elements (0 deactivated)
13:44:25 INFO    opendrift.models.basemodel: 2021-04-08 03:00:00 - step 7 of 24 - 1000 active elements (0 deactivated)
13:44:27 INFO    opendrift.models.basemodel: 2021-04-08 03:30:00 - step 8 of 24 - 1000 active elements (0 deactivated)
13:44:29 INFO    opendrift.models.basemodel: 2021-04-08 04:00:00 - step 9 of 24 - 1000 active elements (0 deactivated)
13:44:32 INFO    opendrift.models.basemodel: 2021-04-08 04:30:00 - step 10 of 24 - 1000 active elements (0 deactivated)
13:44:34 INFO    opendrift.models.basemodel: 2021-04-08 05:00:00 - step 11 of 24 - 1000 active elements (0 deactivated)
13:44:37 INFO    opendrift.models.basemodel: 2021-04-08 05:30:00 - step 12 of 24 - 1000 active elements (0 deactivated)
13:44:40 INFO    opendrift.models.basemodel: 2021-04-08 06:00:00 - step 13 of 24 - 1000 active elements (0 deactivated)
13:44:42 INFO    opendrift.models.basemodel: 2021-04-08 06:30:00 - step 14 of 24 - 1000 active elements (0 deactivated)
13:44:43 INFO    opendrift.models.basemodel: 2021-04-08 07:00:00 - step 15 of 24 - 1000 active elements (0 deactivated)
13:44:46 INFO    opendrift.models.basemodel: 2021-04-08 07:30:00 - step 16 of 24 - 1000 active elements (0 deactivated)
13:44:50 INFO    opendrift.models.basemodel: 2021-04-08 08:00:00 - step 17 of 24 - 1000 active elements (0 deactivated)
13:44:55 INFO    opendrift.models.basemodel: 2021-04-08 08:30:00 - step 18 of 24 - 1000 active elements (0 deactivated)
13:44:59 INFO    opendrift.models.basemodel: 2021-04-08 09:00:00 - step 19 of 24 - 1000 active elements (0 deactivated)
13:45:04 INFO    opendrift.models.basemodel: 2021-04-08 09:30:00 - step 20 of 24 - 1000 active elements (0 deactivated)
13:45:06 INFO    opendrift.models.basemodel: 2021-04-08 10:00:00 - step 21 of 24 - 1000 active elements (0 deactivated)
13:45:07 INFO    opendrift.models.basemodel: 2021-04-08 10:30:00 - step 22 of 24 - 1000 active elements (0 deactivated)
13:45:10 INFO    opendrift.models.basemodel: 2021-04-08 11:00:00 - step 23 of 24 - 1000 active elements (0 deactivated)
13:45:14 INFO    opendrift.models.basemodel: 2021-04-08 11:30:00 - step 24 of 24 - 1000 active elements (0 deactivated)

Print and plot results

print(o)

Out:

===========================
--------------------
Reader performance:
--------------------
https://iws.ismar.cnr.it/thredds/dodsC/emerge/shyfem_unstructured_adriatic.nc
 0:00:01.3  open dataset
 0:00:00.0  build index
 0:01:06.9  total
 0:00:00.0  preparing
 0:01:06.9  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:
 1:27.9 total time
    1.8 configuration
   18.6 preparing main loop
     18.6 making dynamical landmask
      0.0 moving elements to ocean
   1:07.1 readers
        0.0 global_landmask
        0.0 postprocessing
 1:07.3 main loop
     1:06.9 https://iws.ismar.cnr.it/thredds/dodsC/emerge/shyfem_unstructured_adriatic.nc
      0.0 updating elements
    0.0 cleaning up
--------------------
===========================
Model:  OceanDrift     (OpenDrift version 1.7.1)
        1000 active Lagrangian3DArray particles  (0 deactivated, 0 scheduled)
-------------------
Environment variables:
  -----
  sea_floor_depth_below_sea_level
  x_sea_water_velocity
  y_sea_water_velocity
     1) https://iws.ismar.cnr.it/thredds/dodsC/emerge/shyfem_unstructured_adriatic.nc
  -----
  land_binary_mask
     1) global_landmask
  -----
Readers not added for the following variables:
  ocean_vertical_diffusivity
  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
  surface_downward_x_stress
  surface_downward_y_stress
  turbulent_generic_length_scale
  turbulent_kinetic_energy
  upward_sea_water_velocity
  x_wind
  y_wind

Time:
        Start: 2021-04-08 00:00:00
        Present: 2021-04-08 12:00:00
        Calculation steps: 24 * 0:30:00 - total time: 12:00:00
        Output steps: 25 * 0:30:00
===========================

Animations

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

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

Out:

13:45:36 INFO    opendrift.models.basemodel: Saving animation to /root/project/docs/source/gallery/animations/example_shyfem_0.gif...
13:45:36 INFO    opendrift.models.basemodel: Making animated gif...
MovieWriter imagemagick unavailable; using Pillow instead.
13:45:56 INFO    opendrift.models.basemodel: Saving animation to /root/project/docs/source/gallery/animations/example_shyfem_1.gif...
13:45:56 INFO    opendrift.models.basemodel: Making animated gif...
MovieWriter imagemagick unavailable; using Pillow instead.
../_images/example_shyfem_0.gif
o.plot(fast=True, buffer = 1., corners=[12.2, 12.6, 45.1, 45.5])
OpenDrift - OceanDrift 2021-04-08 00:00 to 2021-04-08 12:00 UTC (25 steps)

Out:

13:45:58 WARNING opendrift.models.basemodel: Plotting fast. This will make your plots less accurate.

(<GeoAxesSubplot:title={'center':'OpenDrift - OceanDrift\n2021-04-08 00:00 to 2021-04-08 12:00 UTC (25 steps)'}>, <module 'matplotlib.pyplot' from '/opt/conda/envs/opendrift/lib/python3.9/site-packages/matplotlib/pyplot.py'>)

Total running time of the script: ( 2 minutes 11.253 seconds)

Gallery generated by Sphinx-Gallery