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)
08:40:17 INFO    opendrift.models.basemodel:533: OpenDriftSimulation initialised (version 1.11.2 / v1.11.2-45-g6369924)
08:40:17 INFO    opendrift.readers.unstructured.shyfem:67: Opening dataset: https://iws.ismar.cnr.it/thredds/dodsC/emerge/shyfem_unstructured_adriatic.nc
08:40:17 INFO    opendrift.readers.unstructured.shyfem:72: Opening file with Dataset
08:40:18 INFO    opendrift.readers.unstructured.shyfem:77: 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
  sea_water_speed - derived from ['x_sea_water_velocity', 'y_sea_water_velocity']
===========================
 0:00:01.3  open dataset
 0:00:00.0  build index

08:40:19 INFO    opendrift.models.basemodel.environment:218: Adding a dynamical landmask with max. priority based on assumed maximum speed of 2.0 m/s. Adding a customised landmask may be faster...
08:40:24 INFO    opendrift.models.basemodel.environment:245: Fallback values will be used for the following variables which have no readers:
08:40:24 INFO    opendrift.models.basemodel.environment:248:    sea_surface_height: 0.000000
08:40:24 INFO    opendrift.models.basemodel.environment:248:    x_wind: 0.000000
08:40:24 INFO    opendrift.models.basemodel.environment:248:    y_wind: 0.000000
08:40:24 INFO    opendrift.models.basemodel.environment:248:    upward_sea_water_velocity: 0.000000
08:40:24 INFO    opendrift.models.basemodel.environment:248:    ocean_vertical_diffusivity: 0.000000
08:40:24 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wave_significant_height: 0.000000
08:40:24 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wave_stokes_drift_x_velocity: 0.000000
08:40:24 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wave_stokes_drift_y_velocity: 0.000000
08:40:24 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wave_period_at_variance_spectral_density_maximum: 0.000000
08:40:24 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wave_mean_period_from_variance_spectral_density_second_frequency_moment: 0.000000
08:40:24 INFO    opendrift.models.basemodel.environment:248:    sea_surface_swell_wave_to_direction: 0.000000
08:40:24 INFO    opendrift.models.basemodel.environment:248:    sea_surface_swell_wave_peak_period_from_variance_spectral_density: 0.000000
08:40:24 INFO    opendrift.models.basemodel.environment:248:    sea_surface_swell_wave_significant_height: 0.000000
08:40:24 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wind_wave_to_direction: 0.000000
08:40:24 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wind_wave_mean_period: 0.000000
08:40:24 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wind_wave_significant_height: 0.000000
08:40:24 INFO    opendrift.models.basemodel.environment:248:    surface_downward_x_stress: 0.000000
08:40:24 INFO    opendrift.models.basemodel.environment:248:    surface_downward_y_stress: 0.000000
08:40:24 INFO    opendrift.models.basemodel.environment:248:    turbulent_kinetic_energy: 0.000000
08:40:24 INFO    opendrift.models.basemodel.environment:248:    turbulent_generic_length_scale: 0.000000
08:40:24 INFO    opendrift.models.basemodel.environment:248:    ocean_mixed_layer_thickness: 50.000000

Running model

o.run(time_step=1800, duration=timedelta(hours=12))
08:40:24 INFO    opendrift.models.basemodel:911: Using existing reader for land_binary_mask
08:40:24 INFO    opendrift.models.basemodel:922: All points are in ocean
08:40:24 WARNING opendrift.models.basemodel:705: Seafloor check not being run because environment is missing. This will happen the first time the function is run but if it happens subsequently there is probably a problem.
08:40:24 INFO    opendrift.models.basemodel:2011: 2021-04-08 00:00:00 - step 1 of 24 - 1000 active elements (0 deactivated)
08:40:25 INFO    opendrift.models.basemodel:2011: 2021-04-08 00:30:00 - step 2 of 24 - 1000 active elements (0 deactivated)
08:40:25 INFO    opendrift.models.basemodel:2011: 2021-04-08 01:00:00 - step 3 of 24 - 1000 active elements (0 deactivated)
08:40:25 INFO    opendrift.models.basemodel:2011: 2021-04-08 01:30:00 - step 4 of 24 - 1000 active elements (0 deactivated)
08:40:26 INFO    opendrift.models.basemodel:2011: 2021-04-08 02:00:00 - step 5 of 24 - 1000 active elements (0 deactivated)
08:40:26 INFO    opendrift.models.basemodel:2011: 2021-04-08 02:30:00 - step 6 of 24 - 1000 active elements (0 deactivated)
08:40:26 INFO    opendrift.models.basemodel:2011: 2021-04-08 03:00:00 - step 7 of 24 - 1000 active elements (0 deactivated)
08:40:27 INFO    opendrift.models.basemodel:2011: 2021-04-08 03:30:00 - step 8 of 24 - 1000 active elements (0 deactivated)
08:40:27 INFO    opendrift.models.basemodel:2011: 2021-04-08 04:00:00 - step 9 of 24 - 1000 active elements (0 deactivated)
08:40:27 INFO    opendrift.models.basemodel:2011: 2021-04-08 04:30:00 - step 10 of 24 - 1000 active elements (0 deactivated)
08:40:28 INFO    opendrift.models.basemodel:2011: 2021-04-08 05:00:00 - step 11 of 24 - 1000 active elements (0 deactivated)
08:40:28 INFO    opendrift.models.basemodel:2011: 2021-04-08 05:30:00 - step 12 of 24 - 1000 active elements (0 deactivated)
08:40:29 INFO    opendrift.models.basemodel:2011: 2021-04-08 06:00:00 - step 13 of 24 - 1000 active elements (0 deactivated)
08:40:29 INFO    opendrift.models.basemodel:2011: 2021-04-08 06:30:00 - step 14 of 24 - 1000 active elements (0 deactivated)
08:40:29 INFO    opendrift.models.basemodel:2011: 2021-04-08 07:00:00 - step 15 of 24 - 1000 active elements (0 deactivated)
08:40:30 INFO    opendrift.models.basemodel:2011: 2021-04-08 07:30:00 - step 16 of 24 - 1000 active elements (0 deactivated)
08:40:30 INFO    opendrift.models.basemodel:2011: 2021-04-08 08:00:00 - step 17 of 24 - 1000 active elements (0 deactivated)
08:40:30 INFO    opendrift.models.basemodel:2011: 2021-04-08 08:30:00 - step 18 of 24 - 1000 active elements (0 deactivated)
08:40:31 INFO    opendrift.models.basemodel:2011: 2021-04-08 09:00:00 - step 19 of 24 - 1000 active elements (0 deactivated)
08:40:31 INFO    opendrift.models.basemodel:2011: 2021-04-08 09:30:00 - step 20 of 24 - 1000 active elements (0 deactivated)
08:40:32 INFO    opendrift.models.basemodel:2011: 2021-04-08 10:00:00 - step 21 of 24 - 1000 active elements (0 deactivated)
08:40:32 INFO    opendrift.models.basemodel:2011: 2021-04-08 10:30:00 - step 22 of 24 - 1000 active elements (0 deactivated)
08:40:32 INFO    opendrift.models.basemodel:2011: 2021-04-08 11:00:00 - step 23 of 24 - 1000 active elements (0 deactivated)
08:40:33 INFO    opendrift.models.basemodel:2011: 2021-04-08 11:30:00 - step 24 of 24 - 1000 active elements (0 deactivated)

Print and plot results

print(o)
===========================
--------------------
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:00:08.7  total
 0:00:00.0  preparing
 0:00:08.7  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:
   15.8 total time
    6.7 configuration
    0.0 preparing main loop
      0.0 moving elements to ocean
    9.1 main loop
      0.0 updating elements
    0.0 cleaning up
--------------------
===========================
Model:  OceanDrift     (OpenDrift version 1.11.2)
        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_mixed_layer_thickness
  ocean_vertical_diffusivity
  sea_surface_height
  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_wind

Discarded readers:

Time:
        Start: 2021-04-08 00:00:00 UTC
        Present: 2021-04-08 12:00:00 UTC
        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)
08:41:57 INFO    opendrift.models.basemodel:4570: Saving animation to /root/project/docs/source/gallery/animations/example_shyfem_0.gif...
08:43:26 INFO    opendrift.models.basemodel:3003: Time to make animation: 0:02:53.421580
08:43:27 INFO    opendrift.models.basemodel:4570: Saving animation to /root/project/docs/source/gallery/animations/example_shyfem_1.gif...
08:43:29 INFO    opendrift.models.basemodel:3217: Time to make animation: 0:00:02.561216
../_images/example_shyfem_0.gif ../_images/example_shyfem_1.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)
08:43:29 WARNING opendrift.models.basemodel:2379: Plotting fast. This will make your plots less accurate.

(<GeoAxes: title={'center': 'OpenDrift - OceanDrift\n2021-04-08 00:00 to 2021-04-08 12:00 UTC (25 steps)'}>, <Figure size 773.734x1100 with 1 Axes>)

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

Gallery generated by Sphinx-Gallery