def test_get_variables(benchmark): r = reader_netCDF_CF_unstructured.Reader(akvaplan, proj4=proj) x = np.array([5.6e5, 5.6e5]) y = np.array([7.76e6, 7.76e6]) z = np.array([0, 30]) u = benchmark(r.get_variables, ['x_sea_water_velocity'], r.start_time, x, y, z)['x_sea_water_velocity'] print(u) print(u.shape) assert u.shape == (len(x),) assert len(u) == len(x) # test get_variables against manually retrieved value tidx = [3,4] idx = [150, 170, 171, 2000] zidx = [0, 3, 4, 7] times = r.times[tidx] xc = r.xc[idx] yc = r.yc[idx] z = (r.dataset['siglay_center'][zidx, idx] * r.dataset['h_center'][idx]).diagonal() assert z.shape == xc.shape # u is a face / siglay variable uu = r.dataset['u'][tidx[0], zidx, idx].diagonal() u = r.get_variables(['x_sea_water_velocity'], times[0], xc, yc, z)['x_sea_water_velocity'] np.testing.assert_array_equal(uu, u) uu = r.dataset['u'][tidx[1], zidx, idx].diagonal() u = r.get_variables(['x_sea_water_velocity'], times[1], xc, yc, z)['x_sea_water_velocity'] np.testing.assert_array_equal(uu, u)
def test_get_variables_many(benchmark): r = reader_netCDF_CF_unstructured.Reader(akvaplan, proj4=proj) x = np.linspace(5.6e5, 6.0e5, 1000) y = np.linspace(7.76e6, 7.8e6, 1000) z = np.array([0, 30]).repeat(500) u = benchmark(r.get_variables, ['x_sea_water_velocity'], r.start_time, x, y, z)['x_sea_water_velocity'] assert len(u) == len(x)
def test_nearest_node(benchmark): r = reader_netCDF_CF_unstructured.Reader(akvaplan, proj4=proj) x = np.linspace(5.6e5, 6.0e5, 100) y = np.linspace(7.4e6, 7.6e6, 100) x, y = np.meshgrid(x, y) x = x.ravel() y = y.ravel() print("getting nearest for %d points" % len(x)) benchmark(r._nearest_node_, x, y)
def tets_not_contains(benchmark): r = reader_netCDF_CF_unstructured.Reader(akvaplan, proj4=proj) x = np.linspace(5.6e5, 6.0e5, 100) y = np.linspace(7.4e6, 7.6e6, 100) x, y = np.meshgrid(x, y) x = x.ravel() y = y.ravel() # r.plot_mesh() # plt.scatter(x, y, marker = 'x', color = 'b') # plt.show() covers = benchmark(r.covers_positions, x, y) assert not np.all(covers)
def test_profile(): o = OceanDrift() r = reader_netCDF_CF_unstructured.Reader(akvaplan, proj4=proj) o.add_reader(r) o.seed_elements(lon=17, lat=70, z=np.atleast_1d([0, -10, -50]), number=3, time=r.start_time) print(o) o.run(steps=3) #o.plot(linecolor='z') # Elements at 0 and 10m depth should not have same trajectory # This is ok assert o.elements.lon[0] != o.elements.lon[1] # Elements at 10 and 50m depth should not have same trajectory # This is presently failing assert o.elements.lon[1] != o.elements.lon[2]
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=33W, +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) #%%
def test_open(): r = reader_netCDF_CF_unstructured.Reader(akvaplan, proj4=proj) print(r)