FVCOM: Using model input from unstructured grid

from datetime import timedelta
import urllib.request as urllib_request
import numpy as np
from opendrift.readers import reader_netCDF_CF_unstructured
from opendrift.readers import reader_global_landmask
from opendrift.models.oceandrift import OceanDrift

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

proj = "+proj=utm +zone=33 +north +ellps=WGS84 +datum=WGS84 +units=m +no_defs"
fvcom = reader_netCDF_CF_unstructured.Reader(filename = 'https://thredds.met.no/thredds/dodsC/metusers/knutfd/thredds/netcdf_unstructured_samples/AkvaplanNiva_sample_lonlat_fixed.nc', 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)
20:12:44 INFO    opendrift.models.basemodel:515: OpenDriftSimulation initialised (version 1.12.0 / v1.12.0-26-g390e945)
20:12:44 INFO    opendrift.readers.reader_netCDF_CF_unstructured:98: Opening dataset: https://thredds.met.no/thredds/dodsC/metusers/knutfd/thredds/netcdf_unstructured_samples/AkvaplanNiva_sample_lonlat_fixed.nc
20:12:44 INFO    opendrift.readers.reader_netCDF_CF_unstructured:103: Opening file with Dataset
20:12:45 INFO    opendrift.readers.reader_netCDF_CF_unstructured:107: Using custom projection: +proj=utm +zone=33 +north +ellps=WGS84 +datum=WGS84 +units=m +no_defs..
20:12:45 INFO    opendrift.readers.reader_netCDF_CF_unstructured:117: Reading grid and coordinate variables..
===========================
Reader: https://thredds.met.no/thredds/dodsC/metusers/knutfd/thredds/netcdf_unstructured_samples/AkvaplanNiva_sample_lonlat_fixed.nc
Projection:
  +proj=utm +zone=33 +north +ellps=WGS84 +datum=WGS84 +units=m +no_defs
Coverage: [degrees]
  xmin: 523286.781250   xmax: 724075.187500
  ymin: 7685101.000000   ymax: 7873698.000000
  Corners (lon, lat):
    ( 15.64,  70.97)  ( 21.13,  70.87)
    ( 15.59,  69.27)  ( 20.66,  69.18)
Vertical levels [m]:
  Not specified
Available time range:
  start: 2018-04-30 01:01:52   end: 2018-05-01 00:00:00   step: None
Variables:
  sea_floor_depth_below_geoid
  sea_surface_height_above_geoid
  x_sea_water_velocity
  y_sea_water_velocity
  sea_water_temperature
  sea_water_salinity
  sea_water_speed - derived from ['x_sea_water_velocity', 'y_sea_water_velocity']
===========================
 0:00:02.1  open dataset
 0:00:00.1  build index

20:12:46 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...
20:12:49 INFO    opendrift.models.basemodel.environment:245: Fallback values will be used for the following variables which have no readers:
20:12:49 INFO    opendrift.models.basemodel.environment:248:    sea_surface_height: 0.000000
20:12:49 INFO    opendrift.models.basemodel.environment:248:    x_wind: 0.000000
20:12:49 INFO    opendrift.models.basemodel.environment:248:    y_wind: 0.000000
20:12:49 INFO    opendrift.models.basemodel.environment:248:    upward_sea_water_velocity: 0.000000
20:12:49 INFO    opendrift.models.basemodel.environment:248:    ocean_vertical_diffusivity: 0.000000
20:12:49 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wave_significant_height: 0.000000
20:12:49 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wave_stokes_drift_x_velocity: 0.000000
20:12:49 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wave_stokes_drift_y_velocity: 0.000000
20:12:49 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wave_period_at_variance_spectral_density_maximum: 0.000000
20:12:49 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wave_mean_period_from_variance_spectral_density_second_frequency_moment: 0.000000
20:12:49 INFO    opendrift.models.basemodel.environment:248:    sea_surface_swell_wave_to_direction: 0.000000
20:12:49 INFO    opendrift.models.basemodel.environment:248:    sea_surface_swell_wave_peak_period_from_variance_spectral_density: 0.000000
20:12:49 INFO    opendrift.models.basemodel.environment:248:    sea_surface_swell_wave_significant_height: 0.000000
20:12:49 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wind_wave_to_direction: 0.000000
20:12:49 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wind_wave_mean_period: 0.000000
20:12:49 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wind_wave_significant_height: 0.000000
20:12:49 INFO    opendrift.models.basemodel.environment:248:    surface_downward_x_stress: 0.000000
20:12:49 INFO    opendrift.models.basemodel.environment:248:    surface_downward_y_stress: 0.000000
20:12:49 INFO    opendrift.models.basemodel.environment:248:    turbulent_kinetic_energy: 0.000000
20:12:49 INFO    opendrift.models.basemodel.environment:248:    turbulent_generic_length_scale: 0.000000
20:12:49 INFO    opendrift.models.basemodel.environment:248:    ocean_mixed_layer_thickness: 50.000000
20:12:49 INFO    opendrift.models.basemodel.environment:248:    sea_floor_depth_below_sea_level: 10000.000000

Running model

o.run(time_step=1800, duration=timedelta(hours=12))
20:12:50 INFO    opendrift.models.basemodel:935: Using existing reader for land_binary_mask
20:12:51 INFO    opendrift.models.basemodel:948: Moving 2 out of 1000 points from land to water
20:12:51 INFO    opendrift.models.basemodel:2035: 2018-04-30 01:01:52 - step 1 of 24 - 1000 active elements (0 deactivated)
20:12:51 INFO    opendrift.readers.reader_netCDF_CF_unstructured:388: Reading siglay_centers into memory...
20:12:54 INFO    opendrift.readers.reader_netCDF_CF_unstructured:392: Reading siglev_centers into memory...
20:12:58 INFO    opendrift.readers.reader_netCDF_CF_unstructured:401: Reading ocean depth center into memory...
20:13:01 INFO    opendrift.models.basemodel:2035: 2018-04-30 01:31:52 - step 2 of 24 - 1000 active elements (0 deactivated)
20:13:05 INFO    opendrift.models.basemodel:2035: 2018-04-30 02:01:52 - step 3 of 24 - 998 active elements (2 deactivated)
20:13:07 INFO    opendrift.models.basemodel:2035: 2018-04-30 02:31:52 - step 4 of 24 - 998 active elements (2 deactivated)
20:13:12 INFO    opendrift.models.basemodel:2035: 2018-04-30 03:01:52 - step 5 of 24 - 998 active elements (2 deactivated)
20:13:14 INFO    opendrift.models.basemodel:2035: 2018-04-30 03:31:52 - step 6 of 24 - 998 active elements (2 deactivated)
20:13:17 INFO    opendrift.models.basemodel:2035: 2018-04-30 04:01:52 - step 7 of 24 - 998 active elements (2 deactivated)
20:13:19 INFO    opendrift.models.basemodel:2035: 2018-04-30 04:31:52 - step 8 of 24 - 997 active elements (3 deactivated)
20:13:21 INFO    opendrift.models.basemodel:2035: 2018-04-30 05:01:52 - step 9 of 24 - 997 active elements (3 deactivated)
20:13:22 INFO    opendrift.models.basemodel:2035: 2018-04-30 05:31:52 - step 10 of 24 - 997 active elements (3 deactivated)
20:13:25 INFO    opendrift.models.basemodel:2035: 2018-04-30 06:01:52 - step 11 of 24 - 997 active elements (3 deactivated)
20:13:26 INFO    opendrift.models.basemodel:2035: 2018-04-30 06:31:52 - step 12 of 24 - 997 active elements (3 deactivated)
20:13:29 INFO    opendrift.models.basemodel:2035: 2018-04-30 07:01:52 - step 13 of 24 - 997 active elements (3 deactivated)
20:13:30 INFO    opendrift.models.basemodel:2035: 2018-04-30 07:31:52 - step 14 of 24 - 997 active elements (3 deactivated)
20:13:32 INFO    opendrift.models.basemodel:2035: 2018-04-30 08:01:52 - step 15 of 24 - 997 active elements (3 deactivated)
20:13:34 INFO    opendrift.models.basemodel:2035: 2018-04-30 08:31:52 - step 16 of 24 - 997 active elements (3 deactivated)
20:13:36 INFO    opendrift.models.basemodel:2035: 2018-04-30 09:01:52 - step 17 of 24 - 997 active elements (3 deactivated)
20:13:37 INFO    opendrift.models.basemodel:2035: 2018-04-30 09:31:52 - step 18 of 24 - 993 active elements (7 deactivated)
20:13:40 INFO    opendrift.models.basemodel:2035: 2018-04-30 10:01:52 - step 19 of 24 - 991 active elements (9 deactivated)
20:13:42 INFO    opendrift.models.basemodel:2035: 2018-04-30 10:31:52 - step 20 of 24 - 989 active elements (11 deactivated)
20:13:44 INFO    opendrift.models.basemodel:2035: 2018-04-30 11:01:52 - step 21 of 24 - 989 active elements (11 deactivated)
20:13:46 INFO    opendrift.models.basemodel:2035: 2018-04-30 11:31:52 - step 22 of 24 - 989 active elements (11 deactivated)
20:13:49 INFO    opendrift.models.basemodel:2035: 2018-04-30 12:01:52 - step 23 of 24 - 988 active elements (12 deactivated)
20:13:50 INFO    opendrift.models.basemodel:2035: 2018-04-30 12:31:52 - step 24 of 24 - 988 active elements (12 deactivated)

Print and plot results

print(o)
===========================
--------------------
Reader performance:
--------------------
https://thredds.met.no/thredds/dodsC/metusers/knutfd/thredds/netcdf_unstructured_samples/AkvaplanNiva_sample_lonlat_fixed.nc
 0:00:02.1  open dataset
 0:00:00.1  build index
 0:00:59.5  total
 0:00:00.0  preparing
 0:00:59.4  reading
 0:00:00.0  rotating vectors
 0:00:00.0  masking
--------------------
global_landmask
 0:00:01.4  total
 0:00:00.0  preparing
 0:00:01.4  reading
 0:00:00.0  masking
--------------------
Performance:
 1:08.7 total time
    5.7 configuration
    1.4 preparing main loop
      1.4 moving elements to ocean
 1:01.4 main loop
      0.0 updating elements
    0.0 cleaning up
--------------------
===========================
Model:  OceanDrift     (OpenDrift version 1.12.0)
        983 active Lagrangian3DArray particles  (17 deactivated, 0 scheduled)
-------------------
Environment variables:
  -----
  x_sea_water_velocity
  y_sea_water_velocity
     1) https://thredds.met.no/thredds/dodsC/metusers/knutfd/thredds/netcdf_unstructured_samples/AkvaplanNiva_sample_lonlat_fixed.nc
  -----
  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_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: 2018-04-30 01:01:52 UTC
        Present: 2018-04-30 13:01:52 UTC
        Calculation steps: 24 * 0:30:00 - total time: 12:00:00
        Output steps: 25 * 0:30:00
===========================

Animation (current as background not yet working).

o.animation(color='z')
20:14:08 INFO    opendrift.models.basemodel:4613: Saving animation to /root/project/docs/source/gallery/animations/example_fvcom_0.gif...
20:15:33 INFO    opendrift.models.basemodel:3037: Time to make animation: 0:01:39.802581
../_images/example_fvcom_0.gif
o.plot(fast=True, buffer = 1.)
OpenDrift - OceanDrift 2018-04-30 01:01 to 2018-04-30 13:01 UTC (25 steps)
20:15:33 WARNING opendrift.models.basemodel:2410: Plotting fast. This will make your plots less accurate.

(<GeoAxes: title={'center': 'OpenDrift - OceanDrift\n2018-04-30 01:01 to 2018-04-30 13:01 UTC (25 steps)'}>, <Figure size 768.468x1100 with 1 Axes>)

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

Gallery generated by Sphinx-Gallery