コード例 #1
0
class RiseVelocityMover(CyMover):
    """
    This mover class inherits from CyMover and contains CyRiseVelocityMover

    The real work is done by CyRiseVelocityMover.
    CyMover sets everything up that is common to all movers.
    """
    _schema = RiseVelocityMoverSchema

    def __init__(self, **kwargs):
        """
        Uses super to invoke base class __init__ method.

        Optional parameters (kwargs) used to initialize CyRiseVelocityMover

        :param water_density: Default is 1020 kg/m3
        :param water_viscosity: Default is 1.e-6

        Remaining kwargs are passed onto Mover's __init__ using super.
        See Mover documentation for remaining valid kwargs.
        """
        self.mover = CyRiseVelocityMover()

        super(RiseVelocityMover, self).__init__(**kwargs)

        self.array_types['rise_vel'] = gat('rise_vel')

    def __repr__(self):
        """
        .. todo::
            We probably want to include more information.
        """
        return ('RiseVelocityMover(active_range={0}, on={1})'
                .format(self.active_range, self.on))

    def get_move(self, sc, time_step, model_time_datetime):
        """
        Override base class functionality because mover has a different
        get_move signature

        :param sc: an instance of the gnome.SpillContainer class
        :param time_step: time step in seconds
        :param model_time_datetime: current time of the model as a date time
            object
        """
        self.prepare_data_for_get_move(sc, model_time_datetime)

        if self.active and len(self.positions) > 0:
            self.mover.get_move(self.model_time,
                                time_step,
                                self.positions,
                                self.delta,
                                sc['rise_vel'],
                                self.status_codes,
                                self.spill_type)

        return (self.delta.view(dtype=world_point_type)
                .reshape((-1, len(world_point))))
コード例 #2
0
class RiseVelocityMover(CyMover):
    """
    This mover class inherits from CyMover and contains CyRiseVelocityMover

    The real work is done by CyRiseVelocityMover.
    CyMover sets everything up that is common to all movers.
    """
    _schema = RiseVelocityMoverSchema

    def __init__(self, **kwargs):
        """
        Uses super to invoke base class __init__ method.

        Optional parameters (kwargs) used to initialize CyRiseVelocityMover

        :param water_density: Default is 1020 kg/m3
        :param water_viscosity: Default is 1.e-6

        Remaining kwargs are passed onto Mover's __init__ using super.
        See Mover documentation for remaining valid kwargs.
        """
        self.mover = CyRiseVelocityMover()

        super(RiseVelocityMover, self).__init__(**kwargs)

        self.array_types.add('rise_vel')

    def __repr__(self):
        """
        .. todo::
            We probably want to include more information.
        """
        return ('RiseVelocityMover(active_range={0}, on={1})'
                .format(self.active_range, self.on))

    def get_move(self, sc, time_step, model_time_datetime):
        """
        Override base class functionality because mover has a different
        get_move signature

        :param sc: an instance of the gnome.SpillContainer class
        :param time_step: time step in seconds
        :param model_time_datetime: current time of the model as a date time
            object
        """
        self.prepare_data_for_get_move(sc, model_time_datetime)

        if self.active and len(self.positions) > 0:
            self.mover.get_move(self.model_time,
                                time_step,
                                self.positions,
                                self.delta,
                                sc['rise_vel'],
                                self.status_codes,
                                self.spill_type)

        return (self.delta.view(dtype=world_point_type)
                .reshape((-1, len(world_point))))
コード例 #3
0
    def __init__(self, **kwargs):
        """
        Uses super to invoke base class __init__ method.

        Optional parameters (kwargs) used to initialize CyRiseVelocityMover

        :param water_density: Default is 1020 kg/m3
        :param water_viscosity: Default is 1.e-6

        Remaining kwargs are passed onto Mover's __init__ using super.
        See Mover documentation for remaining valid kwargs.
        """
        self.mover = CyRiseVelocityMover()

        super(RiseVelocityMover, self).__init__(**kwargs)

        self.array_types['rise_vel'] = gat('rise_vel')
コード例 #4
0
    def __init__(self, **kwargs):
        """
        Uses super to invoke base class __init__ method.

        Optional parameters (kwargs) used to initialize CyRiseVelocityMover

        :param water_density: Default is 1020 kg/m3
        :param water_viscosity: Default is 1.e-6

        Remaining kwargs are passed onto Mover's __init__ using super.
        See Mover documentation for remaining valid kwargs.
        """
        self.mover = CyRiseVelocityMover()

        super(RiseVelocityMover, self).__init__(**kwargs)

        self.array_types.add('rise_vel')
コード例 #5
0
class RiseVelocityMover(CyMover, serializable.Serializable):

    """
    This mover class inherits from CyMover and contains CyRiseVelocityMover

    The real work is done by CyRiseVelocityMover.
    CyMover sets everything up that is common to all movers.
    """

    _state = copy.deepcopy(CyMover._state)
    # _state.add(update=['water_density'], save=['water_density'])
    # _state.add(update=['water_viscosity'], save=['water_viscosity'])
    _schema = RiseVelocityMoverSchema

    def __init__(
        self,
        # water_density=1020,
        # water_viscosity=1.e-6,
        **kwargs
    ):
        """
        Uses super to invoke base class __init__ method.

        Optional parameters (kwargs) used to initialize CyRiseVelocityMover

        :param water_density: Default is 1020 kg/m3
        :param water_viscosity: Default is 1.e-6

        Remaining kwargs are passed onto Mover's __init__ using super.
        See Mover documentation for remaining valid kwargs.
        """

        # self.mover = CyRiseVelocityMover(water_density, water_viscosity)
        self.mover = CyRiseVelocityMover()
        super(RiseVelocityMover, self).__init__(**kwargs)
        self.array_types.add("rise_vel")

    #     @property
    #     def water_density(self):
    #         return self.mover.water_density
    #
    #     @property
    #     def water_viscosity(self):
    #         return self.mover.water_viscosity
    #
    #     @water_density.setter
    #     def water_density(self, value):
    #         self.mover.water_density = value
    #
    #     @water_viscosity.setter
    #     def water_viscosity(self, value):
    #         self.mover.water_viscosity = value

    def __repr__(self):
        """
        .. todo::
            We probably want to include more information.
        """

        return ("RiseVelocityMover(active_start={0}, active_stop={1}," " on={2})").format(
            self.active_start, self.active_stop, self.on
        )

    def get_move(self, sc, time_step, model_time_datetime):
        """
        Override base class functionality because mover has a different
        get_move signature

        :param sc: an instance of the gnome.SpillContainer class
        :param time_step: time step in seconds
        :param model_time_datetime: current time of the model as a date time
            object
        """

        self.prepare_data_for_get_move(sc, model_time_datetime)

        if self.active and len(self.positions) > 0:
            self.mover.get_move(
                self.model_time,
                time_step,
                self.positions,
                self.delta,
                sc["rise_vel"],
                self.status_codes,
                self.spill_type,
            )

        return self.delta.view(dtype=world_point_type).reshape((-1, len(world_point)))
コード例 #6
0
class TestRiseVelocity:

    cm = CyTestMove()
    #rv = CyRiseVelocityMover(water_density=1020,
    #                        water_viscosity=.000001)
    rv = CyRiseVelocityMover()

    # set these values and try with NaNs
    # rise_velocity = np.zeros((cm.num_le,), dtype=np.double)

    rise_velocity = np.linspace(0.01, 0.04, cm.num_le)

    def move(self, delta):
        self.rv.prepare_for_model_run()

        self.rv.prepare_for_model_step(self.cm.model_time, self.cm.time_step)
        self.rv.get_move(
            self.cm.model_time,
            self.cm.time_step,
            self.cm.ref,
            delta,
            self.rise_velocity,
            self.cm.status,
            spill_type.forecast,
        )

    def test_move(self):
        """
        test that it moved
        """

        self.move(self.cm.delta)
        np.set_printoptions(precision=4)
        print

        # print '''rise_velocity  = {0:0.1f} get_move output:
        #      '''.format(self.rise_velocity)

        print 'rise_velocity  = '
        print self.rise_velocity
        print 'get_move output:'
        print self.cm.delta.view(dtype=np.float64).reshape(-1, 3)
        assert np.all(self.cm.delta['z'] != 0)

    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_zero_rise_velocity(self):
        """
        ensure no move for 0 rise velocity
        """

        self.rise_velocity = np.zeros((self.cm.num_le, ), dtype=np.double)
        print 'rise_velocity  = '
        print self.rise_velocity
        new_delta = np.zeros((self.cm.num_le, ), dtype=world_point)
        self.move(new_delta)
        print new_delta.view(dtype=np.float64).reshape(-1, 3)
        assert np.all(new_delta.view(dtype=np.double).reshape(1, -1) == 0)

    def _diff(self, delta, new_delta):
        """
        gives the norm of the (delta-new_delta)
        """

        diff = delta.view(dtype=world_point_type).reshape(-1, 3)
        diff -= new_delta.view(dtype=world_point_type).reshape(-1, 3)
        return np.sum(diff**2, axis=1)**.5