Note
Go to the end to download the full example code.
ROMS native reader
import numpy as np
from opendrift import test_data_folder
from opendrift.readers import reader_ROMS_native
from opendrift.models.oceandrift import OceanDrift
o = OceanDrift(loglevel=20) # Set loglevel to 0 for debug information
16:04:02 INFO opendrift:513: OpenDriftSimulation initialised (version 1.14.2 / v1.14.2-82-g86a40e4)
Creating and adding reader for Nordic 4km current dataset
nordic_native = reader_ROMS_native.Reader(test_data_folder +
'2Feb2016_Nordic_sigma_3d/Nordic-4km_SLEVELS_avg_00_subset2Feb2016.nc')
o.add_reader(nordic_native)
16:04:02 INFO opendrift.readers:61: Opening file with xr.open_dataset
16:04:02 WARNING opendrift.readers.reader_ROMS_native:282: Duplicate variables for latitude, selecting lat_psi, and discarding lat_rho
16:04:02 WARNING opendrift.readers.reader_ROMS_native:282: Duplicate variables for latitude, selecting lat_psi, and discarding lat_u
16:04:02 WARNING opendrift.readers.reader_ROMS_native:282: Duplicate variables for latitude, selecting lat_psi, and discarding lat_v
16:04:02 WARNING opendrift.readers.reader_ROMS_native:282: Duplicate variables for longitude, selecting lon_psi, and discarding lon_rho
16:04:02 WARNING opendrift.readers.reader_ROMS_native:282: Duplicate variables for longitude, selecting lon_psi, and discarding lon_u
16:04:02 WARNING opendrift.readers.reader_ROMS_native:282: Duplicate variables for longitude, selecting lon_psi, and discarding lon_v
16:04:02 WARNING opendrift.readers.reader_ROMS_native:282: Duplicate variables for land_binary_mask, selecting mask_psi, and discarding mask_rho
16:04:02 WARNING opendrift.readers.reader_ROMS_native:282: Duplicate variables for ocean_s_coordinate_g2, selecting s_rho, and discarding s_w
16:04:02 INFO opendrift.readers.reader_ROMS_native:289: The following variables without standard_name are discarded: ['AICEnudass', 'Akk_bak', 'Akp_bak', 'Akt_bak', 'Akv_bak', 'Charnok_alpha', 'CrgBan_cw', 'Cs_r', 'Cs_w', 'FSobc_in', 'FSobc_out', 'Falpha', 'Fbeta', 'Fgamma', 'LtracerSrc', 'M2nudg', 'M2obc_in', 'M2obc_out', 'M3nudg', 'M3obc_in', 'M3obc_out', 'Tcline', 'Tnudg', 'Tobc_in', 'Tobc_out', 'Vstretching', 'Vtransform', 'Znudg', 'Zob', 'Zos', 'Zos_hsig_alpha', 'angle', 'dstart', 'dt', 'dtfast', 'el', 'f', 'gamma2', 'gls_Kmin', 'gls_Pmin', 'gls_c1', 'gls_c2', 'gls_c3m', 'gls_c3p', 'gls_cmu0', 'gls_m', 'gls_n', 'gls_p', 'gls_sigk', 'gls_sigp', 'hc', 'mask_u', 'mask_v', 'nAVG', 'nHIS', 'nRST', 'nSTA', 'ndefAVG', 'ndefHIS', 'ndtfast', 'ntimes', 'ntsAVG', 'ocean_time', 'pm', 'pn', 'rdrg', 'rdrg2', 'rho0', 'spherical', 'swrad', 'sz_alpha', 'theta_b', 'theta_s', 'ubar', 'vbar', 'xl', 'zeta_detided']
16:04:02 WARNING opendrift.readers.basereader.structured:50: No proj string or projection could be derived, using 'fakeproj'. This assumes that the variables are structured and gridded approximately equidistantly on the surface (i.e. in meters). This must be guaranteed by the user. You can get rid of this warning by supplying a valid projection to the reader.
16:04:02 INFO opendrift.readers.basereader.structured:90: Making interpolator for lon,lat to x,y conversion...
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)
16:04:02 INFO opendrift.models.basemodel.environment:206: Adding a global landmask from GSHHG
16:04:07 INFO opendrift.models.basemodel.environment:229: Fallback values will be used for the following variables which have no readers:
16:04:07 INFO opendrift.models.basemodel.environment:232: x_wind: 0.000000
16:04:07 INFO opendrift.models.basemodel.environment:232: y_wind: 0.000000
16:04:07 INFO opendrift.models.basemodel.environment:232: upward_sea_water_velocity: 0.000000
16:04:07 INFO opendrift.models.basemodel.environment:232: ocean_vertical_diffusivity: 0.000000
16:04:07 INFO opendrift.models.basemodel.environment:232: sea_surface_wave_significant_height: 0.000000
16:04:07 INFO opendrift.models.basemodel.environment:232: sea_surface_wave_stokes_drift_x_velocity: 0.000000
16:04:07 INFO opendrift.models.basemodel.environment:232: sea_surface_wave_stokes_drift_y_velocity: 0.000000
16:04:07 INFO opendrift.models.basemodel.environment:232: ocean_mixed_layer_thickness: 50.000000
Running model
o.run(time_step=3600)
16:04:07 INFO opendrift:1722: Skipping environment variable ocean_vertical_diffusivity because of condition ['drift:vertical_mixing', 'is', False]
16:04:07 INFO opendrift:1722: Skipping environment variable ocean_mixed_layer_thickness because of condition ['drift:vertical_mixing', 'is', False]
16:04:07 INFO opendrift:1732: Storing previous values of element property lon because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous']))
16:04:07 INFO opendrift:1732: Storing previous values of element property lat because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous']))
16:04:07 INFO opendrift:1792: Duration, steps or end time not specified, running until end of first reader: 2016-02-04 12:00:00
16:04:07 INFO opendrift:1792: Duration, steps or end time not specified, running until end of first reader: 2016-02-04 12:00:00
16:04:07 INFO opendrift:889: Using existing reader for land_binary_mask
16:04:07 INFO opendrift:918: All points are in ocean
16:04:07 INFO opendrift:2015: 2016-02-02 12:00:00 - step 1 of 48 - 10 active elements (0 deactivated)
16:04:07 INFO opendrift.readers.reader_ROMS_native:339: Using mask_rho for mask_rho
16:04:07 INFO opendrift.readers.reader_ROMS_native:390: Using zeta for sea surface height
16:04:07 INFO opendrift.readers.reader_ROMS_native:360: Using mask_u for mask_u
16:04:07 INFO opendrift.readers.reader_ROMS_native:611: Time: 0:00:00.216937
16:04:07 INFO opendrift.readers.reader_ROMS_native:381: Using mask_v for mask_v
16:04:07 INFO opendrift.readers.reader_ROMS_native:404: Using angle from Dataset.
16:04:07 INFO opendrift:2015: 2016-02-02 13:00:00 - step 2 of 48 - 10 active elements (0 deactivated)
16:04:07 INFO opendrift:2015: 2016-02-02 14:00:00 - step 3 of 48 - 10 active elements (0 deactivated)
16:04:07 INFO opendrift:2015: 2016-02-02 15:00:00 - step 4 of 48 - 10 active elements (0 deactivated)
16:04:07 INFO opendrift:2015: 2016-02-02 16:00:00 - step 5 of 48 - 10 active elements (0 deactivated)
16:04:07 INFO opendrift:2015: 2016-02-02 17:00:00 - step 6 of 48 - 10 active elements (0 deactivated)
16:04:07 INFO opendrift:2015: 2016-02-02 18:00:00 - step 7 of 48 - 10 active elements (0 deactivated)
16:04:07 INFO opendrift:2015: 2016-02-02 19:00:00 - step 8 of 48 - 10 active elements (0 deactivated)
16:04:07 INFO opendrift:2015: 2016-02-02 20:00:00 - step 9 of 48 - 10 active elements (0 deactivated)
16:04:07 INFO opendrift:2015: 2016-02-02 21:00:00 - step 10 of 48 - 10 active elements (0 deactivated)
16:04:07 INFO opendrift:2015: 2016-02-02 22:00:00 - step 11 of 48 - 10 active elements (0 deactivated)
16:04:07 INFO opendrift:2015: 2016-02-02 23:00:00 - step 12 of 48 - 10 active elements (0 deactivated)
16:04:08 INFO opendrift:2015: 2016-02-03 00:00:00 - step 13 of 48 - 10 active elements (0 deactivated)
16:04:08 INFO opendrift:2015: 2016-02-03 01:00:00 - step 14 of 48 - 10 active elements (0 deactivated)
16:04:08 INFO opendrift:2015: 2016-02-03 02:00:00 - step 15 of 48 - 10 active elements (0 deactivated)
16:04:08 INFO opendrift:2015: 2016-02-03 03:00:00 - step 16 of 48 - 10 active elements (0 deactivated)
16:04:08 INFO opendrift:2015: 2016-02-03 04:00:00 - step 17 of 48 - 10 active elements (0 deactivated)
16:04:08 INFO opendrift:2015: 2016-02-03 05:00:00 - step 18 of 48 - 10 active elements (0 deactivated)
16:04:08 INFO opendrift:2015: 2016-02-03 06:00:00 - step 19 of 48 - 10 active elements (0 deactivated)
16:04:08 INFO opendrift:2015: 2016-02-03 07:00:00 - step 20 of 48 - 10 active elements (0 deactivated)
16:04:08 INFO opendrift:2015: 2016-02-03 08:00:00 - step 21 of 48 - 10 active elements (0 deactivated)
16:04:08 INFO opendrift:2015: 2016-02-03 09:00:00 - step 22 of 48 - 10 active elements (0 deactivated)
16:04:08 INFO opendrift:2015: 2016-02-03 10:00:00 - step 23 of 48 - 10 active elements (0 deactivated)
16:04:08 INFO opendrift:2015: 2016-02-03 11:00:00 - step 24 of 48 - 10 active elements (0 deactivated)
16:04:08 INFO opendrift:2015: 2016-02-03 12:00:00 - step 25 of 48 - 10 active elements (0 deactivated)
16:04:08 INFO opendrift:2015: 2016-02-03 13:00:00 - step 26 of 48 - 10 active elements (0 deactivated)
16:04:08 INFO opendrift:2015: 2016-02-03 14:00:00 - step 27 of 48 - 10 active elements (0 deactivated)
16:04:08 INFO opendrift:2015: 2016-02-03 15:00:00 - step 28 of 48 - 10 active elements (0 deactivated)
16:04:08 INFO opendrift:2015: 2016-02-03 16:00:00 - step 29 of 48 - 10 active elements (0 deactivated)
16:04:08 INFO opendrift:2015: 2016-02-03 17:00:00 - step 30 of 48 - 10 active elements (0 deactivated)
16:04:08 INFO opendrift:2015: 2016-02-03 18:00:00 - step 31 of 48 - 10 active elements (0 deactivated)
16:04:08 INFO opendrift:2015: 2016-02-03 19:00:00 - step 32 of 48 - 10 active elements (0 deactivated)
16:04:08 INFO opendrift:2015: 2016-02-03 20:00:00 - step 33 of 48 - 10 active elements (0 deactivated)
16:04:08 INFO opendrift:2015: 2016-02-03 21:00:00 - step 34 of 48 - 10 active elements (0 deactivated)
16:04:08 INFO opendrift:2015: 2016-02-03 22:00:00 - step 35 of 48 - 10 active elements (0 deactivated)
16:04:08 INFO opendrift:2015: 2016-02-03 23:00:00 - step 36 of 48 - 10 active elements (0 deactivated)
16:04:08 INFO opendrift:2015: 2016-02-04 00:00:00 - step 37 of 48 - 10 active elements (0 deactivated)
16:04:08 INFO opendrift:2015: 2016-02-04 01:00:00 - step 38 of 48 - 10 active elements (0 deactivated)
16:04:08 INFO opendrift:2015: 2016-02-04 02:00:00 - step 39 of 48 - 10 active elements (0 deactivated)
16:04:08 INFO opendrift:2015: 2016-02-04 03:00:00 - step 40 of 48 - 10 active elements (0 deactivated)
16:04:08 INFO opendrift:2015: 2016-02-04 04:00:00 - step 41 of 48 - 10 active elements (0 deactivated)
16:04:08 INFO opendrift:2015: 2016-02-04 05:00:00 - step 42 of 48 - 10 active elements (0 deactivated)
16:04:08 INFO opendrift:2015: 2016-02-04 06:00:00 - step 43 of 48 - 10 active elements (0 deactivated)
16:04:08 INFO opendrift:2015: 2016-02-04 07:00:00 - step 44 of 48 - 10 active elements (0 deactivated)
16:04:08 INFO opendrift:2015: 2016-02-04 08:00:00 - step 45 of 48 - 10 active elements (0 deactivated)
16:04:08 INFO opendrift:2015: 2016-02-04 09:00:00 - step 46 of 48 - 10 active elements (0 deactivated)
16:04:08 INFO opendrift:2015: 2016-02-04 10:00:00 - step 47 of 48 - 10 active elements (0 deactivated)
16:04:08 INFO opendrift:2015: 2016-02-04 11:00:00 - step 48 of 48 - 10 active elements (0 deactivated)
Print and plot results, with lines colored by particle depth
print(o)
o.plot(linecolor='z', fast=True)
#o.animation()

===========================
--------------------
Reader performance:
--------------------
roms native
0:00:00.5 total
0:00:00.0 preparing
0:00:00.4 reading
0:00:00.1 interpolation
0:00:00.0 interpolation_time
0:00:00.0 rotating vectors
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:
6.5 total time
5.0 configuration
0.0 preparing main loop
0.0 moving elements to ocean
1.5 main loop
0.0 updating elements
0.0 cleaning up
--------------------
===========================
Model: OceanDrift (OpenDrift version 1.14.2)
10 active Lagrangian3DArray particles (0 deactivated, 0 scheduled)
-------------------
Environment variables:
-----
sea_floor_depth_below_sea_level
sea_surface_height
x_sea_water_velocity
y_sea_water_velocity
1) roms native
-----
land_binary_mask
1) global_landmask
-----
Readers not added for the following variables:
sea_surface_wave_significant_height
sea_surface_wave_stokes_drift_x_velocity
sea_surface_wave_stokes_drift_y_velocity
upward_sea_water_velocity
x_wind
y_wind
Discarded readers:
Time:
Start: 2016-02-02 12:00:00 UTC
Present: 2016-02-04 12:00:00 UTC
Calculation steps: 48 * 1:00:00 - total time: 2 days, 0:00:00
Output steps: 49 * 1:00:00
===========================
16:04:08 WARNING opendrift:2371: Plotting fast. This will make your plots less accurate.
(<GeoAxes: title={'center': 'OpenDrift - OceanDrift\n2016-02-02 12:00 to 2016-02-04 12:00 UTC (49 steps)'}>, <Figure size 1017.13x1100 with 2 Axes>)
Total running time of the script: (0 minutes 14.293 seconds)