예제 #1
0
    def test_update_coef(self):
        """
        Test that the move is different from original move since
        diffusion coefficient is different
        Use the py.test -s flag to view the difference between the two
        """

        np.set_printoptions(precision=6)
        delta = np.zeros((self.cm.num_le,), dtype=world_point)
        self.move(delta)  # get the move before changing the coefficient

        print
        print "diffusion_coef = {0.diffusion_coef}".format(self.rm),
        print "get_move output:"
        print delta.view(dtype=np.float64).reshape(-1, 3)
        self.rm.diffusion_coef = 10
        assert self.rm.diffusion_coef == 10

        srand(1)
        new_delta = np.zeros((self.cm.num_le,), dtype=world_point)
        self.move(new_delta)  # get the move after changing coefficient
        print
        print "diffusion_coef = {0.diffusion_coef}".format(self.rm),
        print "get_move output:"
        print new_delta.view(dtype=np.float64).reshape(-1, 3)
        print
        print "-- Norm of difference between movement vector --"
        print self._diff(delta, new_delta).reshape(-1, 1)
        assert np.all(delta["lat"] != new_delta["lat"])
        assert np.all(delta["long"] != new_delta["long"])

        self.rm.diffusion_coef = 100000  # reset it
    def test_update_coef(self):
        """
        Test that the move is different from original move since
        vertical diffusion coefficient is different
        Use the py.test -s flag to view the difference between the two
        """

        np.set_printoptions(precision=6)
        delta = np.zeros((self.cm.num_le, ), dtype=world_point)
        self.move(delta)  # get the move before changing the coefficient
        print
        print self.msg.format(self.rm) + ' get_move output:'
        print delta.view(dtype=np.float64).reshape(-1, 3)
        self.rm.vertical_diffusion_coef_above_ml = 10
        assert self.rm.vertical_diffusion_coef_above_ml == 10

        srand(1)
        new_delta = np.zeros((self.cm.num_le, ), dtype=world_point)
        self.move(new_delta)  # get the move after changing coefficient
        print
        print self.msg.format(self.rm) + ' get_move output:'
        print new_delta.view(dtype=np.float64).reshape(-1, 3)
        print
        print '-- Norm of difference between movement vector --'
        print self._diff(delta, new_delta).reshape(-1, 1)

        assert np.all(delta['z'] != new_delta['z'])

        self.rm.vertical_diffusion_coef_above_ml = 5  # reset it
예제 #3
0
    def test_seed(self):
        """
        Since seed is not reset, the move should be repeatable
        """

        delta = np.zeros((self.cm.num_le, ), dtype=world_point)
        self.move(delta)
        srand(1)

        new_delta = np.zeros((self.cm.num_le, ), dtype=world_point)
        self.move(new_delta)

        print
        print '-- Do not reset seed and call get move again',
        print 'to get identical results --'
        print 'get_move results 1st time:'
        print delta.view(dtype=np.float64).reshape(-1, 3)
        print 'get_move results 2nd time - same seed:'
        print new_delta.view(dtype=np.float64).reshape(-1, 3)
        print
        assert np.all(delta['lat'] == new_delta['lat'])
        assert np.all(delta['long'] == new_delta['long'])
        assert np.all(delta['z'] == new_delta['z'])
        print '-- Norm of difference between movement vector --'
        print self._diff(delta, new_delta)
예제 #4
0
    def test_update_horiz_coef(self):
        """
        Test that the move is different from original move since
        horizontal diffusion coefficient is different
        Use the py.test -s flag to view the difference between the two
        """

        np.set_printoptions(precision=6)
        delta = np.zeros((self.cm.num_le, ), dtype=world_point)
        self.move(delta)  # get the move before changing the coefficient
        print
        print self.msg.format(self.rm) + ' get_move output:'
        print delta.view(dtype=np.float64).reshape(-1, 3)
        self.rm.horizontal_diffusion_coef_above_ml = 1000
        assert self.rm.horizontal_diffusion_coef_above_ml == 1000

        srand(1)
        new_delta = np.zeros((self.cm.num_le, ), dtype=world_point)
        self.move(new_delta)  # get the move after changing coefficient
        print
        print self.msg.format(self.rm) + ' get_move output:'
        print new_delta.view(dtype=np.float64).reshape(-1, 3)
        print
        print '-- Norm of difference between movement vector --'
        print self._diff(delta, new_delta).reshape(-1, 1)

        assert np.all(delta['lat'] != new_delta['lat'])
        assert np.all(delta['long'] != new_delta['long'])

        self.rm.horizontal_diffusion_coef_above_ml = 100000  # reset it
    def test_update_coef(self):
        """
        Test that the move is different from original move
        since rise velocity is different
        Use the py.test -s flag to view the difference between the two
        """

        # cy_helpers.srand(1)  # this happens in conftest.py before every test

        np.set_printoptions(precision=6)
        delta = np.zeros((self.cm.num_le, ), dtype=world_point)
        self.move(delta)  # get the move before changing the coefficient

        print
        print 'rise_velocity  = '
        print self.rise_velocity
        print 'get_move output:'
        print delta.view(dtype=np.float64).reshape(-1, 3)
        self.rise_velocity = np.linspace(0.02, 0.05, self.cm.num_le)
        print 'rise_velocity  = '
        print self.rise_velocity

        srand(1)
        new_delta = np.zeros((self.cm.num_le, ), dtype=world_point)
        self.move(new_delta)  # get the move after changing coefficient
        print

        print 'get_move output:'
        print new_delta.view(dtype=np.float64).reshape(-1, 3)
        print
        print '-- Norm of difference between movement vector --'
        print self._diff(delta, new_delta).reshape(-1, 1)
        assert np.all(delta['z'] != new_delta['z'])
    def test_update_coef(self):
        """
        Test that the move is different from original move
        since rise velocity is different
        Use the py.test -s flag to view the difference between the two
        """

        # cy_helpers.srand(1)  # this happens in conftest.py before every test

        np.set_printoptions(precision=6)
        delta = np.zeros((self.cm.num_le, ), dtype=world_point)
        self.move(delta)  # get the move before changing the coefficient

        print
        print 'rise_velocity  = '
        print self.rise_velocity
        print 'get_move output:'
        print delta.view(dtype=np.float64).reshape(-1, 3)
        self.rise_velocity = np.linspace(0.02, 0.05, self.cm.num_le)
        print 'rise_velocity  = '
        print self.rise_velocity

        srand(1)
        new_delta = np.zeros((self.cm.num_le, ), dtype=world_point)
        self.move(new_delta)  # get the move after changing coefficient
        print

        print 'get_move output:'
        print new_delta.view(dtype=np.float64).reshape(-1, 3)
        print
        print '-- Norm of difference between movement vector --'
        print self._diff(delta, new_delta).reshape(-1, 1)
        assert np.all(delta['z'] != new_delta['z'])
예제 #7
0
def seed(seed=1):
    """
    Set the C++, the python and the numpy random seed to desired value

    :param seed: Random number generator should be seeded by this value.
        Default is 1
    """

    cy_helpers.srand(seed)
    random.seed(seed)
    np.random.seed(seed)
예제 #8
0
def seed(seed=1):
    """
    Set the C++, the python and the numpy random seed to desired value

    :param seed: Random number generator should be seeded by this value.
        Default is 1
    """

    cy_helpers.srand(seed)
    random.seed(seed)
    np.random.seed(seed)
    def test_mixed_layer_zero(self):
        """
        Test that the move for z above the mixed layer
        is different from move for z below the mixed layer
        and the same if the mixed layer is zero
        Use the py.test -s flag to view the differences
        """

        srand(1)
        np.set_printoptions(precision=6)
        delta = np.zeros((self.cm.num_le, ), dtype=world_point)
        self.move(delta)  # get the move before changing the coefficient
        print
        print self.msg.format(self.rm) + ' get_move output:'
        print delta.view(dtype=np.float64).reshape(-1, 3)

        srand(1)
        self.cm.ref['z'][:]=20
        new_delta = np.zeros((self.cm.num_le, ), dtype=world_point)
        self.move(new_delta)  # get the move after changing coefficient
        print
        print self.msg.format(self.rm) + ' get_move output:'
        print new_delta.view(dtype=np.float64).reshape(-1, 3)
        print
        assert np.all(delta['z'] != new_delta['z'])

        print '-- Norm of difference between movement vector --'
        print self._diff(delta, new_delta).reshape(-1, 1)

        self.rm.mixed_layer_depth = 0

        srand(1)
    	self.cm.ref['z'][:]=.1
        newer_delta = np.zeros((self.cm.num_le, ), dtype=world_point)
        self.move(newer_delta)  # get the move after changing mld
        print
        print self.msg.format(self.rm) + ' get_move output:'
        print newer_delta.view(dtype=np.float64).reshape(-1, 3)
        print

        msg = r"{0} move is not within a tolerance of {1}"
        tol = 1e-10
        np.testing.assert_allclose(
            new_delta['z'],
            newer_delta['z'],
            tol,
            tol,
            msg.format('random_vertical', tol),
            0,
            )

        print '-- Norm of difference between movement vector --'
        print self._diff(new_delta, newer_delta).reshape(-1, 1)

        self.rm.mixed_layer_depth = 10
예제 #10
0
    def test_mixed_layer_zero(self):
        """
        Test that the move for z above the mixed layer
        is different from move for z below the mixed layer
        and the same if the mixed layer is zero
        Use the py.test -s flag to view the differences
        """

        srand(1)
        np.set_printoptions(precision=6)
        delta = np.zeros((self.cm.num_le, ), dtype=world_point)
        self.move(delta)  # get the move before changing the coefficient
        print
        print self.msg.format(self.rm) + ' get_move output:'
        print delta.view(dtype=np.float64).reshape(-1, 3)

        srand(1)
        self.cm.ref['z'][:]=20
        new_delta = np.zeros((self.cm.num_le, ), dtype=world_point)
        self.move(new_delta)  # get the move after changing coefficient
        print
        print self.msg.format(self.rm) + ' get_move output:'
        print new_delta.view(dtype=np.float64).reshape(-1, 3)
        print
        assert np.all(delta['z'] != new_delta['z'])

        print '-- Norm of difference between movement vector --'
        print self._diff(delta, new_delta).reshape(-1, 1)

        self.rm.mixed_layer_depth = 0

        srand(1)
    	self.cm.ref['z'][:]=.1
        newer_delta = np.zeros((self.cm.num_le, ), dtype=world_point)
        self.move(newer_delta)  # get the move after changing mld
        print
        print self.msg.format(self.rm) + ' get_move output:'
        print newer_delta.view(dtype=np.float64).reshape(-1, 3)
        print

        msg = r"{0} move is not within a tolerance of {1}"
        tol = 1e-10
        np.testing.assert_allclose(
            new_delta['z'],
            newer_delta['z'],
            tol,
            tol,
            msg.format('random_vertical', tol),
            0,
            )

        print '-- Norm of difference between movement vector --'
        print self._diff(new_delta, newer_delta).reshape(-1, 1)

        self.rm.mixed_layer_depth = 10