def test_stranding_3d(self): o = PelagicEggDrift(loglevel=30) 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.fallback_values['y_wind'] = 10 # Some wind for mixing o.seed_elements( lon=14.0, lat=68.15, radius=2000, number=100, time=[reader_nordic.start_time, reader_nordic.end_time], z=0) o.set_config('general:coastline_action', 'stranding') o.set_config('turbulentmixing:timestep', 120) o.max_speed = .1 o.run(end_time=reader_nordic.end_time, time_step=3600 * 6) self.assertEqual(o.status_categories[1], 'stranded') self.assertEqual(o.elements_deactivated.status.min(), 1) self.assertEqual(o.elements_deactivated.status.max(), 1) self.assertEqual(o.num_elements_scheduled(), 0) self.assertEqual(o.num_elements_active(), 79) self.assertEqual(o.num_elements_activated(), 100) self.assertEqual(o.num_elements_deactivated(), 21) self.assertEqual(o.num_elements_total(), 100)
def test_stranding_3d(self): o = PelagicEggDrift(loglevel=30) 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('environment:fallback:y_wind', 10) # Some wind for mixing o.seed_elements( lon=14.0, lat=68.15, radius=2000, number=100, time=[reader_nordic.start_time, reader_nordic.end_time], z=0) o.set_config('general:coastline_action', 'stranding') o.set_config('vertical_mixing:timestep', 120) o.max_speed = .1 o.run(end_time=reader_nordic.end_time, time_step=3600 * 6) self.assertEqual(o.status_categories[1], 'stranded') self.assertEqual(o.elements_deactivated.status.min(), 1) self.assertEqual(o.elements_deactivated.status.max(), 1) self.assertEqual(o.num_elements_scheduled(), 0) self.assertEqual(o.num_elements_active(), 81) self.assertEqual(o.num_elements_activated(), 100) self.assertEqual(o.num_elements_deactivated(), 19) self.assertEqual(o.num_elements_total(), 100) # Check calculated trajectory lengths and speeds total_length, distances, speeds = o.get_trajectory_lengths() self.assertAlmostEqual(total_length.max(), 14978.3, 1) self.assertAlmostEqual(total_length.min(), 1225.2, 1) self.assertAlmostEqual(speeds.max(), 0.127, 1) self.assertAlmostEqual(distances.max(), 2859.0, 1)
def test_reader_boundary(self): o = PelagicEggDrift(loglevel=0) reader_nordic = reader_ROMS_native.Reader( o.test_data_folder() + "2Feb2016_Nordic_sigma_3d/Nordic-4km_SLEVELS_avg_00_subset2Feb2016.nc" ) reader_arctic = reader_netCDF_CF_generic.Reader( o.test_data_folder() + "2Feb2016_Nordic_sigma_3d/Arctic20_1to5Feb_2016.nc" ) ###################################################### # Vertical interpolation is another issue to be fixed: reader_nordic.zlevels = reader_arctic.z ###################################################### o.add_reader([reader_nordic, reader_arctic]) o.fallback_values["land_binary_mask"] = 0 o.fallback_values["x_wind"] = 10 # Some wind for mixing # Seed close to Nordic boundary o.seed_elements(lon=14.9, lat=71.1, radius=2000, number=100, time=reader_nordic.start_time, z=0) o.set_config("turbulentmixing:timestep", 20) o.set_config("turbulentmixing:verticalresolution", 1) o.set_config("drift:scheme", "runge-kutta") o.run(steps=5, time_step=3600, time_step_output=3600) self.assertEqual(o.num_elements_active(), 100) self.assertEqual(o.num_elements_deactivated(), 0) self.assertAlmostEqual(o.elements.lat[0], 71.15, 2) self.assertAlmostEqual(o.elements.z.min(), -35.0, 3) self.assertAlmostEqual(o.elements.z.max(), -0.5, 3) self.assertAlmostEqual(o.elements.lon.max(), 14.87, 2)
def test_reader_boundary(self): o = PelagicEggDrift(loglevel=0) reader_nordic = reader_ROMS_native.Reader( o.test_data_folder() + '2Feb2016_Nordic_sigma_3d/Nordic-4km_SLEVELS_avg_00_subset2Feb2016.nc' ) reader_arctic = reader_netCDF_CF_generic.Reader( o.test_data_folder() + '2Feb2016_Nordic_sigma_3d/Arctic20_1to5Feb_2016.nc') ###################################################### # Vertical interpolation is another issue to be fixed: reader_nordic.zlevels = reader_arctic.z ###################################################### o.add_reader([reader_nordic, reader_arctic]) o.fallback_values['land_binary_mask'] = 0 o.fallback_values['x_wind'] = 10 # Some wind for mixing # Seed close to Nordic boundary o.seed_elements(lon=14.9, lat=71.1, radius=2000, number=100, time=reader_nordic.start_time, z=0) o.set_config('turbulentmixing:timestep', 20) o.set_config('drift:scheme', 'runge-kutta') o.run(steps=5, time_step=3600, time_step_output=3600) self.assertEqual(o.num_elements_active(), 100) self.assertEqual(o.num_elements_deactivated(), 0) self.assertAlmostEqual(o.elements.lat[0], 71.16, 1) #self.assertAlmostEqual(o.elements.z.min(), -41.92, 1) # With past ROMS-masking self.assertAlmostEqual(o.elements.z.min(), -40.1, 1) self.assertAlmostEqual(o.elements.z.max(), -0.01, 1) #self.assertAlmostEqual(o.elements.lon.max(), 14.949, 2) self.assertAlmostEqual(o.elements.lon.max(), 14.87, 2)
def test_stranding_roms(self): o = PelagicEggDrift(loglevel=0) reader_arctic = reader_netCDF_CF_generic.Reader( o.test_data_folder() + '2Feb2016_Nordic_sigma_3d/Arctic20_1to5Feb_2016.nc') 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_arctic) o.add_reader(reader_nordic) o.fallback_values['x_sea_water_velocity'] = 1 o.seed_elements( lon=13.0, lat=68.0, radius=20000, number=100, time=[reader_arctic.start_time, reader_nordic.end_time], z=-30) o.set_config('general:coastline_action', 'previous') o.set_config('processes:turbulentmixing', False) o.max_speed = 1 o.run(end_time=reader_nordic.end_time, time_step=3600 * 36) self.assertEqual(o.num_elements_scheduled(), 0) self.assertEqual(o.num_elements_active(), 100) self.assertEqual(o.num_elements_activated(), 100) self.assertEqual(o.num_elements_deactivated(), 0) self.assertEqual(o.num_elements_total(), 100)
def test_outside_reader_time_coverage(self): o = PelagicEggDrift() reader = reader_netCDF_CF_generic.Reader(o.test_data_folder() + '16Nov2015_NorKyst_z_surface/norkyst800_subset_16Nov2015.nc') o.add_reader(reader) o.fallback_values['x_sea_water_velocity'] = 1 o.fallback_values['land_binary_mask'] = 0 o.set_config('processes:turbulentmixing', False) o.seed_elements(lon=4.8, lat=60, number=1, time=reader.end_time) o.run(steps=2) # Check that fallback value is used when outside time coverage self.assertEqual(o.history['x_sea_water_velocity'][0][-1], 1.0)
def atest_reader_boundary_thredds(self): o = PelagicEggDrift(loglevel=20) reader_norkyst = reader_netCDF_CF_generic.Reader('http://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be') reader_nordic = reader_netCDF_CF_generic.Reader('http://thredds.met.no/thredds/dodsC/fou-hi/nordic4km-1h/Nordic-4km_SURF_1h_avg_00.nc') o.add_reader([reader_norkyst, reader_nordic]) o.fallback_values['land_binary_mask'] = 0 lon = 0.2; lat = 61.0; # Close to NorKyst boundary time = reader_nordic.start_time o.seed_elements(lon, lat, radius=5000, number=100, time=time, z=0) o.set_config('turbulentmixing:timestep', 5) o.run(steps=5, time_step=3600, time_step_output=3600)
def test_stranding_3d(self): o = PelagicEggDrift(loglevel=30) 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.fallback_values['y_wind'] = 10 # Some wind for mixing o.seed_elements(lon=14.0, lat=68.15, radius=2000, number=100, time=[reader_nordic.start_time, reader_nordic.end_time], z=0) o.set_config('general:coastline_action', 'stranding') o.set_config('turbulentmixing:timestep', 60) o.set_config('turbulentmixing:verticalresolution', 10) o.run(end_time=reader_nordic.end_time, time_step=3600*3) self.assertEqual(o.status_categories[1], 'stranded') self.assertEqual(o.elements_deactivated.status.min(), 1) self.assertEqual(o.elements_deactivated.status.max(), 1)
def test_vertical_mixing(self): # Export to file only at end o1 = PelagicEggDrift(loglevel=20) # Profiles and vertical mixing norkyst = reader_netCDF_CF_generic.Reader(o1.test_data_folder() + '14Jan2016_NorKyst_z_3d/NorKyst-800m_ZDEPTHS_his_00_3Dsubset.nc') o1.add_reader([norkyst]) o1.fallback_values['x_wind'] = 8 o1.fallback_values['land_binary_mask'] = 0 o1.seed_elements(4.1, 63.3, radius=1000, number=100, time=norkyst.start_time) o1.set_config('turbulentmixing:timestep', 20.) # seconds o1.set_config('turbulentmixing:verticalresolution', 1.) # m o1.run(steps=20, time_step=300, time_step_output=1800, export_buffer_length=10, outfile='verticalmixing.nc') self.assertAlmostEqual(o1.history['z'].min(), -25.0) self.assertAlmostEqual(o1.history['z'].max(), 0.0) os.remove('verticalmixing.nc')
def test_vertical_mixing(self): # Export to file only at end o1 = PelagicEggDrift(loglevel=20) # Profiles and vertical mixing norkyst = reader_netCDF_CF_generic.Reader(o1.test_data_folder() + '14Jan2016_NorKyst_z_3d/NorKyst-800m_ZDEPTHS_his_00_3Dsubset.nc') o1.add_reader([norkyst]) o1.fallback_values['x_wind'] = 8 o1.fallback_values['land_binary_mask'] = 0 o1.seed_elements(4.1, 63.3, radius=1000, number=100, time=norkyst.start_time) o1.set_config('turbulentmixing:timestep', 20.) # seconds o1.run(steps=20, time_step=300, time_step_output=1800, export_buffer_length=10, outfile='verticalmixing.nc') self.assertAlmostEqual(o1.history['z'].min(), -38.1, 1) self.assertAlmostEqual(o1.history['z'].max(), 0.0, 1) os.remove('verticalmixing.nc')
def test_stranding_roms(self): o = PelagicEggDrift(loglevel=0) reader_arctic = reader_netCDF_CF_generic.Reader(o.test_data_folder() + '2Feb2016_Nordic_sigma_3d/Arctic20_1to5Feb_2016.nc') 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_arctic) o.add_reader(reader_nordic) o.fallback_values['x_sea_water_velocity'] = 1 o.seed_elements(lon=13.0, lat=68.0, radius=20000, number=100, time=[reader_arctic.start_time, reader_nordic.end_time], z=-30) o.set_config('general:basemap_resolution', 'c') o.set_config('general:coastline_action', 'previous') o.set_config('processes:turbulentmixing', False) o.max_speed=1 o.run(end_time=reader_nordic.end_time, time_step=3600*36) self.assertEqual(o.num_elements_scheduled(), 0) self.assertEqual(o.num_elements_active(), 100) self.assertEqual(o.num_elements_activated(), 100) self.assertEqual(o.num_elements_deactivated(), 0) self.assertEqual(o.num_elements_total(), 100)
diameter=0.0014, neutral_buoyancy_salinity=31.25) #%% # Adjusting some configuration o.set_config('drift:vertical_mixing', True) o.set_config( 'vertical_mixing:diffusivitymodel', 'windspeed_Sundby1983') # windspeed parameterization for eddy diffusivity #%% # Vertical mixing requires fast time step o.set_config('vertical_mixing:timestep', 60.) # seconds #%% # Running model o.run(duration=timedelta(hours=48), time_step=3600) #%% # Print and plot results. # At the end the wind vanishes, and eggs come to surface print(o) o.plot(fast=True) o.animation(fast=True, color='z') #%% # .. image:: /gallery/animations/example_codegg_0.gif #%% Vertical distribution of particles o.animate_vertical_distribution()
# spawn NEA cod eggs at defined position and time o.seed_elements(14. , 68.1, z=-40, radius=2000, number=500, time=time, diameter=0.0014, neutral_buoyancy_salinity=31.25) o.seed_elements(12.5, 68.5, z=-40, radius=2000, number=500, time=time, diameter=0.0014, neutral_buoyancy_salinity=31.25) # Adjusting some configuration o.set_config('processes:turbulentmixing', True) o.set_config('turbulentmixing:diffusivitymodel', 'windspeed_Sundby1983') # windspeed parameterization for eddy diffusivity #o.set_config('turbulentmixing:diffusivitymodel', 'environment') # use eddy diffusivity from ocean model # Vertical resolution and time step should be adjusted so to avoid getting # output warnings like 'DEBUG: WARNING! some elements have p+q>1.' o.set_config('turbulentmixing:timestep', 10.) # seconds o.set_config('turbulentmixing:verticalresolution', 2.) # m o.set_config('turbulentmixing:TSprofiles', True) # update T,S frequently in each inner loop for turbulent o.set_config('turbulentmixing:TSprofiles', False) # False is faster # Running model (until end of driver data) o.run(steps=6*2, time_step=1800) # Print and plot results print o o.plot() o.animation() o.plot_vertical_distribution()
o.add_reader([reader_norkyst, reader_arome]) # spawn NEA cod eggs at defined position and time time = reader_arome.start_time o.seed_elements(14. , 68.1, z=-40, radius=2000, number=500, time=time, diameter=0.0014, neutral_buoyancy_salinity=31.25) o.seed_elements(12.5, 68.5, z=-40, radius=2000, number=500, time=time, diameter=0.0014, neutral_buoyancy_salinity=31.25) # Adjusting some configuration o.set_config('processes:turbulentmixing', True) o.set_config('turbulentmixing:diffusivitymodel', 'windspeed_Sundby1983') # windspeed parameterization for eddy diffusivity #o.set_config('turbulentmixing:diffusivitymodel', 'environment') # use eddy diffusivity from ocean model # Vertical resolution and time step should be adjusted so to avoid getting # output warnings like 'DEBUG: WARNING! some elements have p+q>1.' o.set_config('turbulentmixing:timestep', 10.) # seconds o.set_config('turbulentmixing:verticalresolution', 2.) # m # Running model (until end of driver data) o.run(steps=6*2, time_step=1800) # Print and plot results print o o.plot() o.animation() o.plot_vertical_distribution()
number=500, time=time, diameter=0.0014, neutral_buoyancy_salinity=31.25) o.seed_elements(13., 67.8, z=-40, radius=2000, number=500, time=time, diameter=0.0014, neutral_buoyancy_salinity=31.25) # Adjusting some configuration o.set_config('processes:turbulentmixing', True) #o.set_config('turbulentmixing:diffusivitymodel', 'windspeed_Sundby1983') # windspeed parameterization for eddy diffusivity o.set_config('turbulentmixing:diffusivitymodel', 'environment') # use eddy diffusivity from ocean model # Vertical mixing requires fast time step o.set_config('turbulentmixing:timestep', 60.) # seconds # Running model (until end of driver data) o.run(steps=96, time_step=3600) # Print and plot results print(o) o.plot(filename='codegg_forecast.png') o.animation(filename='codegg_forecast.gif') o.plot_vertical_distribution(filename='codegg_vertical.png')