def test_lift_above_seafloor(self): # See an element at some depth, and progapate towards coast # (shallower water) and check that it is not penetrating seafloor o = OceanDrift(loglevel=50) o.max_speed = 100 reader_norkyst = reader_netCDF_CF_generic.Reader( o.test_data_folder() + '14Jan2016_NorKyst_z_3d/NorKyst-800m_ZDEPTHS_his_00_3Dsubset.nc') reader_norkyst.buffer = 200 o.add_reader([reader_norkyst], variables='sea_floor_depth_below_sea_level') o.set_config('environment:fallback:x_sea_water_velocity', 10) # Pure eastward motion o.set_config('environment:fallback:y_sea_water_velocity', 0) o.set_config('environment:fallback:land_binary_mask', 0) o.seed_elements(3.9, 62.0, z=-200, time=reader_norkyst.start_time) o.set_config('drift:vertical_mixing', False) o.run(steps=12, time_step=300) seafloor_depth, status = o.get_property( 'sea_floor_depth_below_sea_level') z, status = o.get_property('z') # Uncomment to plot #import matplotlib.pyplot as plt #plt.plot(-seafloor_depth, label='Seafloor depth') #plt.plot(z, label='Element depth') #plt.legend(loc='best') #plt.show() # Check that element has not penetrated seafloor self.assertFalse( o.elements.z < -o.environment.sea_floor_depth_below_sea_level) self.assertIsNone( np.testing.assert_array_almost_equal(o.elements.z, -134.5, 1))
""" Use a shapefile as landmask =========================== """ import numpy as np import matplotlib.pyplot as plt import cartopy.crs as ccrs import cartopy.feature as cfeature from opendrift.readers import reader_netCDF_CF_generic from opendrift.readers import reader_ROMS_native from opendrift.readers import reader_shape from opendrift.models.oceandrift import OceanDrift o = OceanDrift(loglevel=20) # Set loglevel to 0 for debug information o.max_speed = 3 # This example works better using hourly input from Thredds than the daily data from test folder reader_nordic = reader_netCDF_CF_generic.Reader( 'https://thredds.met.no/thredds/dodsC/sea/nordic4km/zdepths1h/aggregate_be' ) #%% # Use shapes from Cartopy for tests. These shapefiles are less acurate than those # provided by the GSHHS dataset (available though the reader_global_landmask reader). import cartopy.io.shapereader as shpreader shpfilename = shpreader.natural_earth(resolution='110m', category='cultural', name='admin_0_countries') reader_natural = reader_shape.Reader.from_shpfiles(shpfilename) #reader_nordic = reader_ROMS_native.Reader(o.test_data_folder() +
import numpy as np from datetime import datetime, timedelta from opendrift.readers import reader_global_landmask from opendrift.readers import reader_ROMS_native_MOANA from opendrift.models.oceandrift import OceanDrift #from opendrift.models.pelagicplankton_moana import PelagicPlanktonDrift #from opendrift.models.sedimentdrift import SedimentDrift ############################### # MODEL SELECTION ############################### o = OceanDrift(loglevel=100) #o = SedimentDrift(loglevel=100) # 0 for debug output #o = PelagicPlanktonDrift(loglevel=50) # Set loglevel to 0 for debug information o.max_speed = 3.0 # ############################### # READERS ############################### thredds_path_1 = 'http://thredds.moanaproject.org:8080/thredds/dodsC/moana/ocean/NZB/v1.9/raw_3D/nz5km_his_201709.nc?ntimes,dt,hc,grid,s_rho[5:1:12],Cs_r[5:1:12],h[0:1:466][0:1:396],lon_rho[0:1:466][0:1:396],lat_rho[0:1:466][0:1:396],lon_u[0:1:466][0:1:395],lat_u[0:1:466][0:1:395],lon_v[0:1:465][0:1:396],lat_v[0:1:465][0:1:396],lon_psi[0:1:465][0:1:395],angle[0:1:466][0:1:396],mask_rho[0:1:466][0:1:396],mask_u[0:1:466][0:1:395],mask_v[0:1:465][0:1:396],ocean_time[0:1:240],z_rho[0:1:240][5:1:12][0:1:466][0:1:396],u_eastward[0:1:240][5:1:12][0:1:466][0:1:396],v_northward[0:1:240][5:1:12][0:1:466][0:1:396]' # Limit to selected depths (raw data: [0:1:39])#'http://thredds.moanaproject.org:8080/thredds/dodsC/moana/ocean/NZB/v1.9/raw_3D/nz5km_his_201710.nc' reader_moana_v19_1 = reader_ROMS_native_MOANA.Reader( [thredds_path_1]) #load data for that year reader_moana_v19_1.multiprocessing_fail = True # bypass the use of multi core for coordinates conversion and seems to make the model run much faster. thredds_path_2 = 'http://thredds.moanaproject.org:8080/thredds/dodsC/moana/ocean/NZB/v1.9/raw_3D/nz5km_his_201708.nc?ntimes,dt,hc,grid,s_rho[5:1:12],Cs_r[5:1:12],h[0:1:466][0:1:396],lon_rho[0:1:466][0:1:396],lat_rho[0:1:466][0:1:396],lon_u[0:1:466][0:1:395],lat_u[0:1:466][0:1:395],lon_v[0:1:465][0:1:396],lat_v[0:1:465][0:1:396],lon_psi[0:1:465][0:1:395],angle[0:1:466][0:1:396],mask_rho[0:1:466][0:1:396],mask_u[0:1:466][0:1:395],mask_v[0:1:465][0:1:396],ocean_time[0:1:248],z_rho[0:1:248][5:1:12][0:1:466][0:1:396],u_eastward[0:1:248][5:1:12][0:1:466][0:1:396],v_northward[0:1:248][5:1:12][0:1:466][0:1:396]' # to finish the run in the previous month reader_moana_v19_2 = reader_ROMS_native_MOANA.Reader([thredds_path_2]) # reader_moana_v19_2.multiprocessing_fail = True thredds_path_3 = 'http://thredds.moanaproject.org:8080/thredds/dodsC/moana/ocean/NZB/v1.9/raw_3D/nz5km_his_201707.nc?ntimes,dt,hc,grid,s_rho[5:1:12],Cs_r[5:1:12],h[0:1:466][0:1:396],lon_rho[0:1:466][0:1:396],lat_rho[0:1:466][0:1:396],lon_u[0:1:466][0:1:395],lat_u[0:1:466][0:1:395],lon_v[0:1:465][0:1:396],lat_v[0:1:465][0:1:396],lon_psi[0:1:465][0:1:395],angle[0:1:466][0:1:396],mask_rho[0:1:466][0:1:396],mask_u[0:1:466][0:1:395],mask_v[0:1:465][0:1:396],ocean_time[0:1:248],z_rho[0:1:248][5:1:12][0:1:466][0:1:396],u_eastward[0:1:248][5:1:12][0:1:466][0:1:396],v_northward[0:1:248][5:1:12][0:1:466][0:1:396]' # to finish the run in the previous month
#!/usr/bin/env python import numpy as np from opendrift.readers import reader_netCDF_CF_generic from opendrift.readers import reader_ROMS_native from opendrift.models.oceandrift import OceanDrift o = OceanDrift(loglevel=0) # Set loglevel to 0 for debug information o.max_speed = 3 # This example works better using hourly input from Thredds than the daily data from test folder reader_nordic = reader_netCDF_CF_generic.Reader('http://thredds.met.no/thredds/dodsC/sea/nordic4km/zdepths1h/aggregate_be') #reader_nordic = reader_ROMS_native.Reader(o.test_data_folder() + # '2Feb2016_Nordic_sigma_3d/Nordic-4km_SLEVELS_avg_00_subset2Feb2016.nc') o.add_reader([reader_nordic]) o.set_config('general:basemap_resolution', 'h') o.set_config('general:coastline_action', 'previous') # Seeding elements on a grid lons = np.linspace(12, 14.5, 30) lats = np.linspace(67.5, 68.5, 30) lons, lats = np.meshgrid(lons, lats) lon = lons.ravel() lat = lats.ravel() time = reader_nordic.start_time o.seed_elements(lon, lat, radius=0, number=30*30, time=time)
from opendrift.models.oceandrift import OceanDrift from opendrift.readers import reader_oscillating # readers o = OceanDrift(loglevel=50) reader_norkyst = reader_netCDF_CF_generic.Reader(o.test_data_folder() + '14Jan2016_NorKyst_z_3d/NorKyst-800m_ZDEPTHS_his_00_3Dsubset.nc') reader_osc = reader_oscillating.Reader('x_sea_water_velocity', amplitude=10, period_seconds=3600) runs = [] seafloor_actions = ['previous', 'deactivate', 'lift_to_seafloor'] for seafloor_action in seafloor_actions: o = OceanDrift(loglevel=50) # Set loglevel to 0 for debug information o.max_speed = 10 o.add_reader([reader_osc, reader_norkyst]) o.set_config('drift:horizontal_diffusivity', 0) o.set_config('environment:constant:y_sea_water_velocity', 0) o.set_config('environment:constant:land_binary_mask', 0) o.set_config('general:use_auto_landmask', False) o.set_config('general:seafloor_action', seafloor_action) # Seeding some particles 50m above seafloor o.seed_elements(lon=4.2, lat=62.0, z='seafloor+50', radius=7000, number=200, time=reader_norkyst.start_time) o.run(duration=timedelta(hours=2), time_step=120) runs.append(o)