Пример #1
0
class LeewayObj(LagrangianArray):
    """Extending LagrangianArray with variables relevant for leeway objects.

    """
    variables = LagrangianArray.add_variables([
        ('objectType', {'dtype': np.int16,
                        'unit': '1',
                        'default': 0}),
        ('orientation', {'dtype': np.int16,
                         'unit': '1',
                         'default': 1}),
        ('jibeProbability', {'dtype': np.float32,
                             'unit': '1/h',
                             'default': 0.04}),
        ('downwindSlope', {'dtype': np.float32,
                           'unit': '%',
                           'default': 1}),
        ('crosswindSlope', {'dtype': np.float32,
                            'unit': '1',
                            'default': 1}),
        ('downwindOffset', {'dtype': np.float32,
                            'unit': 'cm/s',
                            'default': 0}),
        ('crosswindOffset', {'dtype': np.float32,
                             'unit': 'cm/s',
                             'default': 0}),
        ('downwindEps', {'dtype': np.float32,
                         'unit': 'cm/s',
                         'default': 0}),
        ('crosswindEps', {'dtype': np.float32,
                          'unit': 'cm/s',
                          'default': 0})
        ])
Пример #2
0
 def test_move(self):
     A1 = LagrangianArray(lon = [4.1], lat = [60.1])
     A2 = LagrangianArray(lon = [4.0, 4.5], lat = [60.0, 60.5])
     A3 = LagrangianArray(lon = [1.0, 1.5, 1.7], lat = [60.0, 60.5, 61.0])
     # Moving first and third element from A3 to A2
     A3.move_elements(A2, np.array([True, False, True], dtype=bool))
     self.assertEqual(len(A3), 1)
     self.assertEqual(len(A2), 4)
     A2.move_elements(A3, np.array([False, True, False, False], dtype=bool))
     self.assertEqual(len(A2), 3)
     self.assertEqual(len(A1), 1)
     A1.move_elements(A3, np.array([True], dtype=bool))
     self.assertEqual(len(A1), 0)
Пример #3
0
 def test_fromarrays(self):
     """Make LagrangianArray from attribute arrays"""
     lon = [4.0, 4.5, 5.0]
     lat = 60.0
     z = -10
     A = LagrangianArray(lon=lon, lat=lat, z=z)
     self.assertEqual(len(A), 3)
     self.assertEqual(list(A.lon), [4.0, 4.5, 5.0])
Пример #4
0
class Larvae(LagrangianArray):
    """Extending LagrangianArray with variables relevant for (marine) larvae."""

    variables = LagrangianArray.add_variables(
        {'length': {
            'dtype': np.float32,
            'unit': 'mm'
        }})
Пример #5
0
class Lagrangian3DArray(LagrangianArray):
    """Extending LagrangianArray for elements moving in 3 dimensions
    The Particle may be buoyant and/or subject to vertical mixing
    buoyant bahaviour is described by terminal velocity
    """

    variables = LagrangianArray.add_variables([
        ('terminal_velocity', {'dtype': np.float32,
                               'units': 'm/s',
                               'default': 0.})])
Пример #6
0
    def test_extend(self):
        """Test concatenation"""
        e1 = LagrangianArray(lon=2, lat=60, z=[0, 1, 2])
        e2 = LagrangianArray(lon=2, lat=61, z=-1)
        e3 = LagrangianArray(lon=3, lat=61, z=0)

        self.assertTrue(hasattr(e1.z, '__len__'))
        self.assertFalse(hasattr(e2.z, '__len__'))
        # Extend 
        e1.extend(e2)
        e2.extend(e3)
        # Check that identical scalars remain scalars, arrays are concatenated
        self.assertTrue(hasattr(e1.z, '__len__'))
        self.assertTrue(hasattr(e2.z, '__len__'))
        self.assertItemsEqual(e1.z, [0, 1, 2, -1])
        self.assertItemsEqual(e2.lon, [2., 3.])
        self.assertEqual(e2.lat, 61.0)

        self.assertEqual(len(e1), 4)
        self.assertEqual(len(e2), 2)
        self.assertEqual(len(e3), 1)
Пример #7
0
class TemplateElementType(LagrangianArray):
    """Extending LagrangianArray with relevant properties."""
    # Define and name the properties which the elements shall have.
    # These are added to the four core properties (ID, lon, lat, z)
    # inherited from the basic/generic LagrangianArray class.
    # Property names may be freely chosen, but the "update" function (below)
    # will refer to the names in the specifications of the processes.
    variables = LagrangianArray.add_variables([('mass_oil', {
        'dtype': np.float32,
        'unit': 'kg'
    }), ('mass_evaporated', {
        'dtype': np.float32,
        'unit': 'kg',
        'default': 0
    }), ('mass_emulsion', {
        'dtype': np.float32,
        'unit': 'kg',
        'default': 0
    })])
Пример #8
0
class PelagicEgg(Lagrangian3DArray):
    """Extending Lagrangian3DArray with specific properties for pelagic eggs
    """

    variables = LagrangianArray.add_variables([
        ('diameter', {'dtype': np.float32,
                      'units': 'm',
                      'default': 0.0014}),  # for NEA Cod
        ('neutral_buoyancy_salinity', {'dtype': np.float32,
                                       'units': '[]',
                                       'default': 31.25}),  # for NEA Cod
        ('density', {'dtype': np.float32,
                     'units': 'kg/m^3',
                     'default': 1028.}),
        ('age_seconds', {'dtype': np.float32,
                         'units': 's',
                         'default': 0.}),
        ('hatched', {'dtype': np.float32,
                     'units': '',
                     'default': 0.})])
Пример #9
0
class Oil(LagrangianArray):
    """Extending LagrangianArray with variables relevant for oil particles."""

    variables = LagrangianArray.add_variables([
        ('mass_oil', {
            'dtype': np.float32,
            'units': 'kg',
            'default': 1
        }),
        (
            'viscosity',
            {
                'dtype': np.float32,
                #'unit': 'mm2/s (centiStokes)',
                'units': 'N s/m2 (Pa s)',
                'default': 0.5
            }),
        ('density', {
            'dtype': np.float32,
            'units': 'kg/m^3',
            'default': 880
        }),
        ('wind_drift_factor', {
            'dtype': np.float32,
            'units': '%',
            'default': 0.03
        }),
        ('age_seconds', {
            'dtype': np.float32,
            'units': 's',
            'default': 0
        }),
        ('age_exposure_seconds', {
            'dtype': np.float32,
            'units': 's',
            'default': 0
        }),
        ('age_emulsion_seconds', {
            'dtype': np.float32,
            'units': 's',
            'default': 0
        }),
        ('mass_emulsion', {
            'dtype': np.float32,
            'units': 'kg',
            'default': 0
        }),
        ('mass_dispersed', {
            'dtype': np.float32,
            'units': 'kg',
            'default': 0
        }),
        ('mass_evaporated', {
            'dtype': np.float32,
            'units': 'kg',
            'default': 0
        }),
        ('fraction_evaporated', {
            'dtype': np.float32,
            'units': '%',
            'default': 0
        }),
        ('water_content', {
            'dtype': np.float32,
            'units': '%',
            'default': 0
        })
    ])
Пример #10
0
 def test_move(self):
     A1 = LagrangianArray(lon = [4.1], lat = [60.1])
     A2 = LagrangianArray(lon = [4.0, 4.5], lat = [60.0, 60.5])
     A3 = LagrangianArray(lon = [1.0, 1.5, 1.7], lat = [60.0, 60.5, 61.0])
     # Moving first and third element from A3 to A2
     A3.move_elements(A2, np.array([True, False, True], dtype=bool))
     self.assertEqual(len(A3), 1)
     self.assertEqual(len(A2), 4)
     A2.move_elements(A3, np.array([False, True, False, False], dtype=bool))
     self.assertEqual(len(A2), 3)
     self.assertEqual(len(A1), 1)
     A1.move_elements(A3, np.array([True], dtype=bool))
     self.assertEqual(len(A1), 0)
Пример #11
0
 def test_empty(self):
     """Empty LagrangianArray works as expected"""
     A0 = LagrangianArray()
     self.assertEqual(len(A0), 0)
     self.assertFalse(A0)
     self.assertFalse(A0.lon)
Пример #12
0
 def test_init(self):
     """Chcek that init works"""
     A = LagrangianArray(lon=4.0, lat=60.0)
     self.assertEqual(len(A), 1)