Esempio n. 1
0
    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)
Esempio n. 2
0
 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)
Esempio n. 3
0
 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)
Esempio n. 4
0
    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)
Esempio n. 5
0
    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)
Esempio n. 6
0
 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)
Esempio n. 7
0
 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)
Esempio n. 8
0
 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)
Esempio n. 9
0
 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)
Esempio n. 10
0
 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')
Esempio n. 11
0
    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')
Esempio n. 12
0
    def test_get_environment(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', name='Nordic')
        reader_arctic = reader_netCDF_CF_generic.Reader(o.test_data_folder() + '2Feb2016_Nordic_sigma_3d/Arctic20_1to5Feb_2016.nc', name='Arctic')
        ######################################################
        # Vertical interpolation is another issue to be fixed:
        reader_nordic.zlevels = reader_arctic.z
        ######################################################
        o.add_reader([reader_nordic, reader_arctic])
        # One point covered only by Nordic, two points coverd
        # by both readers, and two points covered by none of the readers
        testlon = np.array((14.0, 20.0, 20.1, 4, 5))
        testlat = np.array((70.1, 76.0, 76.1, 60, 60))
        testz = np.random.uniform(0, 0, len(testlon))
        self.assertItemsEqual([0], reader_nordic.covers_positions(
                                    testlon, testlat, testz))
        self.assertItemsEqual([0, 1, 2], reader_arctic.covers_positions(
                                    testlon, testlat, testz))
        o.seed_elements(testlon, testlat, testz, time=reader_nordic.start_time)
        o.fallback_values['land_binary_mask'] = 0
        env, env_profiles, missing = \
            o.get_environment(o.required_variables,
                              reader_nordic.start_time,
                              testlon, testlat, testz,
                              o.required_profiles)
        self.assertAlmostEqual(env['sea_water_temperature'][0], 4.338, 2)
        self.assertAlmostEqual(env['sea_water_temperature'][1], 0.6282, 3)
        self.assertAlmostEqual(env['sea_water_temperature'][4], 10.0)
        self.assertItemsEqual(missing, [False,False,False,False,False])
        self.assertAlmostEqual(env_profiles['sea_water_temperature'][0,0],
                               4.338, 2)
        self.assertAlmostEqual(env_profiles['sea_water_temperature'][0,4], 10)
        self.assertAlmostEqual(env_profiles['sea_water_temperature'][8,2], 10)
        self.assertAlmostEqual(env_profiles['sea_water_temperature'][7,2],
                               2.252265, 3)
        # Get separate data
        env2, env_profiles2, missing2 = \
            o.get_environment(['x_sea_water_velocity', 'y_sea_water_velocity',
                               'sea_water_temperature'],
                              reader_nordic.start_time,
                              testlon, testlat, testz,
                              ['sea_water_temperature'])
        self.assertTrue(env_profiles2 is not None)
        self.assertEqual(env_profiles2.keys(), ['z', 'sea_water_temperature'])
        # Get separate data, without profile
        env3, env_profiles3, missing3 = \
            o.get_environment(['x_sea_water_velocity', 'y_sea_water_velocity',
                               'sea_water_temperature'],
                              reader_nordic.start_time,
                              testlon, testlat, testz,
                              profiles=None)
        self.assertTrue(env_profiles3 is None)
        # Get separate data
        env4, env_profiles4, missing4 = \
            o.get_environment(['x_sea_water_velocity', 'y_sea_water_velocity',
                               'sea_water_temperature'],
                              reader_nordic.start_time,
                              testlon, testlat, testz,
                              ['sea_water_temperature'])

        self.assertItemsEqual(env['x_sea_water_velocity'],
                              env2['x_sea_water_velocity'])
        #print env_profiles['sea_water_temperature'], '1'*50
        #print env_profiles2['sea_water_temperature'], '2'*50
        #print env_profiles4['sea_water_temperature'], '4'*50
        # Test below should also pass, To be fixed
        #self.assertItemsEqual(env_profiles['sea_water_temperature'].ravel(),
        #                      env_profiles2['sea_water_temperature'].ravel())
        self.assertItemsEqual(env_profiles2['sea_water_temperature'].ravel(),
                              env_profiles4['sea_water_temperature'].ravel())
Esempio n. 13
0
    def test_get_environment(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', name='Nordic')
        reader_arctic = reader_netCDF_CF_generic.Reader(o.test_data_folder() + '2Feb2016_Nordic_sigma_3d/Arctic20_1to5Feb_2016.nc', name='Arctic')
        ######################################################
        # Vertical interpolation is another issue to be fixed:
        reader_nordic.zlevels = reader_arctic.z
        ######################################################
        o.add_reader([reader_nordic, reader_arctic])
        # One point covered only by Nordic, two points coverd
        # by both readers, and two points covered by none of the readers
        testlon = np.array((14.0, 20.0, 20.1, 4, 5))
        testlat = np.array((70.1, 76.0, 76.1, 60, 60))
        testz = np.random.uniform(0, 0, len(testlon))
        self.assertItemsEqual([0], reader_nordic.covers_positions(
                                    testlon, testlat, testz))
        self.assertItemsEqual([0, 1, 2], reader_arctic.covers_positions(
                                    testlon, testlat, testz))
        o.seed_elements(testlon, testlat, testz, time=reader_nordic.start_time)
        o.fallback_values['land_binary_mask'] = 0
        env, env_profiles, missing = \
            o.get_environment(o.required_variables,
                              reader_nordic.start_time,
                              testlon, testlat, testz,
                              o.required_profiles)
        self.assertAlmostEqual(env['sea_water_temperature'][0], 4.2849, 3)
        self.assertAlmostEqual(env['sea_water_temperature'][1], 0.6282, 3)
        self.assertAlmostEqual(env['sea_water_temperature'][4], 10.0)
        self.assertItemsEqual(missing, [False,False,False,False,False])
        self.assertAlmostEqual(env_profiles['sea_water_temperature'][0,0],
                               4.284938, 3)
        self.assertAlmostEqual(env_profiles['sea_water_temperature'][0,4], 10)
        self.assertAlmostEqual(env_profiles['sea_water_temperature'][8,2], 10)
        self.assertAlmostEqual(env_profiles['sea_water_temperature'][7,2],
                               2.252265, 3)
        # Get separate data
        env2, env_profiles2, missing2 = \
            o.get_environment(['x_sea_water_velocity', 'y_sea_water_velocity',
                               'sea_water_temperature'],
                              reader_nordic.start_time,
                              testlon, testlat, testz,
                              ['sea_water_temperature'])
        self.assertTrue(env_profiles2 is not None)
        self.assertEqual(env_profiles2.keys(), ['z', 'sea_water_temperature'])
        # Get separate data, without profile
        env3, env_profiles3, missing3 = \
            o.get_environment(['x_sea_water_velocity', 'y_sea_water_velocity',
                               'sea_water_temperature'],
                              reader_nordic.start_time,
                              testlon, testlat, testz,
                              profiles=None)
        self.assertTrue(env_profiles3 is None)
        # Get separate data
        env4, env_profiles4, missing4 = \
            o.get_environment(['x_sea_water_velocity', 'y_sea_water_velocity',
                               'sea_water_temperature'],
                              reader_nordic.start_time,
                              testlon, testlat, testz,
                              ['sea_water_temperature'])

        self.assertItemsEqual(env['x_sea_water_velocity'],
                              env2['x_sea_water_velocity'])
        #print env_profiles['sea_water_temperature'], '1'*50
        #print env_profiles2['sea_water_temperature'], '2'*50
        #print env_profiles4['sea_water_temperature'], '4'*50
        # Test below should also pass, To be fixed
        #self.assertItemsEqual(env_profiles['sea_water_temperature'].ravel(),
        #                      env_profiles2['sea_water_temperature'].ravel())
        self.assertItemsEqual(env_profiles2['sea_water_temperature'].ravel(),
                              env_profiles4['sea_water_temperature'].ravel())