Exemplo n.º 1
0
class WindMover(WindMoversBase):
    """
    Python wrapper around the Cython wind_mover module.
    This class inherits from CyMover and contains CyWindMover

    The real work is done by the CyWindMover object.  CyMover
    sets everything up that is common to all movers.
    """
    _schema = WindMoverSchema

    def __init__(self, wind=None, **kwargs):
        """
        Uses super to call CyMover base class __init__

        :param wind: wind object -- provides the wind time series for the mover

        Remaining kwargs are passed onto WindMoversBase __init__ using super.
        See Mover documentation for remaining valid kwargs.

        .. note:: Can be initialized with wind=None; however, wind must be
            set before running. If wind is not None, toggle make_default_refs
            to False since user provided a valid Wind and does not wish to
            use the default from the Model.
        """
        self.mover = CyWindMover()

        self._wind = None
        if wind is not None:
            self.wind = wind
            self.name = wind.name
            kwargs['make_default_refs'] = kwargs.pop('make_default_refs',
                                                     False)
            kwargs['name'] = kwargs.pop('name', wind.name)

        # set optional attributes
        super(WindMover, self).__init__(**kwargs)

    def __repr__(self):
        return (
            '{0.__class__.__module__}.{0.__class__.__name__}(\n{1})'.format(
                self, self._state_as_str()))

    def __str__(self):
        return ('WindMover - current _state. '
                'See "wind" object for wind conditions:\n{0}'.format(
                    self._state_as_str()))

    @property
    def wind(self):
        return self._wind

    @wind.setter
    def wind(self, value):
        if not isinstance(value, Wind):
            raise TypeError('wind must be of type environment.Wind')
        else:
            # update reference to underlying cython object
            self._wind = value
            self.mover.set_ossm(self._wind.ossm)

    @property
    def data_start(self):
        return self.wind.data_start

    @property
    def data_stop(self):
        return self.wind.data_stop

    def prepare_for_model_run(self):
        '''
        if wind attribute is not set, raise ReferencedObjectNotSet excpetion
        '''
        super(WindMover, self).prepare_for_model_run()

        if self.on and self.wind is None:
            msg = "wind object not defined for WindMover"
            raise ReferencedObjectNotSet(msg)
Exemplo n.º 2
0
class WindMover(WindMoversBase, serializable.Serializable):
    """
    Python wrapper around the Cython wind_mover module.
    This class inherits from CyMover and contains CyWindMover

    The real work is done by the CyWindMover object.  CyMover
    sets everything up that is common to all movers.
    """
    _state = copy.deepcopy(WindMoversBase._state)
    _state.add(update=['extrapolate'], save=['extrapolate'])
    _state.add_field(
        serializable.Field('wind', save=True, update=True,
                           save_reference=True))
    _schema = WindMoverSchema

    def __init__(self, wind=None, extrapolate=False, **kwargs):
        #def __init__(self, wind=None, **kwargs):
        """
        Uses super to call CyMover base class __init__

        :param wind: wind object -- provides the wind time series for the mover

        Remaining kwargs are passed onto WindMoversBase __init__ using super.
        See Mover documentation for remaining valid kwargs.

        .. note:: Can be initialized with wind=None; however, wind must be
            set before running. If wind is not None, toggle make_default_refs
            to False since user provided a valid Wind and does not wish to
            use the default from the Model.
        """
        self.mover = CyWindMover()

        self._wind = None
        if wind is not None:
            self.wind = wind
            kwargs['make_default_refs'] = \
                kwargs.pop('make_default_refs', False)
            kwargs['name'] = \
                kwargs.pop('name', wind.name)

        self.extrapolate = extrapolate
        # set optional attributes
        super(WindMover, self).__init__(**kwargs)

        # this will have to be updated when wind is set or changed
        if self.wind is not None:
            self.real_data_start = time_utils.sec_to_datetime(
                self.wind.ossm.get_start_time())
            self.real_data_stop = time_utils.sec_to_datetime(
                self.wind.ossm.get_end_time())

    def __repr__(self):
        """
        .. todo::
            We probably want to include more information.
        """
        return ('{0.__class__.__module__}.{0.__class__.__name__}(\n'
                '{1}'
                ')'.format(self, self._state_as_str()))

    def __str__(self):
        info = ('WindMover - current _state. '
                'See "wind" object for wind conditions:\n'
                '{0}'.format(self._state_as_str()))
        return info

    extrapolate = property(
        lambda self: self.mover.extrapolate,
        lambda self, val: setattr(self.mover, 'extrapolate', val))

    @property
    def wind(self):
        return self._wind

    @wind.setter
    def wind(self, value):
        if not isinstance(value, environment.Wind):
            raise TypeError('wind must be of type environment.Wind')
        else:
            # update reference to underlying cython object
            self._wind = value
            self.mover.set_ossm(self.wind.ossm)

    def prepare_for_model_run(self):
        '''
        if wind attribute is not set, raise ReferencedObjectNotSet excpetion
        '''
        super(WindMover, self).prepare_for_model_run()

        if self.on and self.wind is None:
            msg = "wind object not defined for WindMover"
            raise ReferencedObjectNotSet(msg)

    def serialize(self, json_='webapi'):
        """
        Since 'wind' property is saved as a reference when used in save file
        and 'save' option, need to add appropriate node to WindMover schema
        """
        toserial = self.to_serialize(json_)
        schema = self.__class__._schema()
        if json_ == 'webapi':
            # add wind schema
            schema.add(environment.WindSchema(name='wind'))

        serial = schema.serialize(toserial)

        return serial

    @classmethod
    def deserialize(cls, json_):
        """
        append correct schema for wind object
        """
        schema = cls._schema()
        if 'wind' in json_:
            schema.add(environment.WindSchema())
        _to_dict = schema.deserialize(json_)

        return _to_dict
Exemplo n.º 3
0
class WindMover(WindMoversBase, serializable.Serializable):
    """
    Python wrapper around the Cython wind_mover module.
    This class inherits from CyMover and contains CyWindMover

    The real work is done by the CyWindMover object.  CyMover
    sets everything up that is common to all movers.
    """
    _state = copy.deepcopy(WindMoversBase._state)
    _state.add(update=['extrapolate'],
               save=['extrapolate'])
    _state.add_field(serializable.Field('wind', save=True, update=True,
                                        save_reference=True))
    _schema = WindMoverSchema

    def __init__(self, wind=None, extrapolate=False, **kwargs):
    #def __init__(self, wind=None, **kwargs):
        """
        Uses super to call CyMover base class __init__

        :param wind: wind object -- provides the wind time series for the mover

        Remaining kwargs are passed onto WindMoversBase __init__ using super.
        See Mover documentation for remaining valid kwargs.

        .. note:: Can be initialized with wind=None; however, wind must be
            set before running. If wind is not None, toggle make_default_refs
            to False since user provided a valid Wind and does not wish to
            use the default from the Model.
        """
        self.mover = CyWindMover()

        self._wind = None
        if wind is not None:
            self.wind = wind
            kwargs['make_default_refs'] = \
                kwargs.pop('make_default_refs', False)
            kwargs['name'] = \
                kwargs.pop('name', wind.name)

        self.extrapolate = extrapolate
        # set optional attributes
        super(WindMover, self).__init__(**kwargs)

		# this will have to be updated when wind is set or changed
        if self.wind is not None:
            self.real_data_start = time_utils.sec_to_datetime(self.wind.ossm.get_start_time())
            self.real_data_stop = time_utils.sec_to_datetime(self.wind.ossm.get_end_time())

    def __repr__(self):
        """
        .. todo::
            We probably want to include more information.
        """
        return ('{0.__class__.__module__}.{0.__class__.__name__}(\n'
                '{1}'
                ')'.format(self, self._state_as_str()))

    def __str__(self):
        info = ('WindMover - current _state. '
                'See "wind" object for wind conditions:\n'
                '{0}'.format(self._state_as_str()))
        return info


    extrapolate = property(lambda self: self.mover.extrapolate,
                           lambda self, val: setattr(self.mover,
                                                     'extrapolate',
                                                     val))

    @property
    def wind(self):
        return self._wind

    @wind.setter
    def wind(self, value):
        if not isinstance(value, environment.Wind):
            raise TypeError('wind must be of type environment.Wind')
        else:
            # update reference to underlying cython object
            self._wind = value
            self.mover.set_ossm(self.wind.ossm)

    def prepare_for_model_run(self):
        '''
        if wind attribute is not set, raise ReferencedObjectNotSet excpetion
        '''
        super(WindMover, self).prepare_for_model_run()

        if self.on and self.wind is None:
            msg = "wind object not defined for WindMover"
            raise ReferencedObjectNotSet(msg)

    def serialize(self, json_='webapi'):
        """
        Since 'wind' property is saved as a reference when used in save file
        and 'save' option, need to add appropriate node to WindMover schema
        """
        toserial = self.to_serialize(json_)
        schema = self.__class__._schema()
        if json_ == 'webapi':
            # add wind schema
            schema.add(environment.WindSchema(name='wind'))

        serial = schema.serialize(toserial)

        return serial

    @classmethod
    def deserialize(cls, json_):
        """
        append correct schema for wind object
        """
        schema = cls._schema()
        if 'wind' in json_:
            schema.add(environment.WindSchema())
        _to_dict = schema.deserialize(json_)

        return _to_dict
Exemplo n.º 4
0
class WindMover(WindMoversBase):
    """
    Python wrapper around the Cython wind_mover module.
    This class inherits from CyMover and contains CyWindMover

    The real work is done by the CyWindMover object.  CyMover
    sets everything up that is common to all movers.
    """
    _schema = WindMoverSchema

    def __init__(self, wind=None, **kwargs):
        """
        Uses super to call CyMover base class __init__

        :param wind: wind object -- provides the wind time series for the mover

        Remaining kwargs are passed onto WindMoversBase __init__ using super.
        See Mover documentation for remaining valid kwargs.

        .. note:: Can be initialized with wind=None; however, wind must be
            set before running. If wind is not None, toggle make_default_refs
            to False since user provided a valid Wind and does not wish to
            use the default from the Model.
        """
        self.mover = CyWindMover()

        self._wind = None
        if wind is not None:
            self.wind = wind
            self.name = wind.name
            kwargs['make_default_refs'] = kwargs.pop('make_default_refs',
                                                     False)
            kwargs['name'] = kwargs.pop('name', wind.name)

        # set optional attributes
        super(WindMover, self).__init__(**kwargs)

    def __repr__(self):
        return ('{0.__class__.__module__}.{0.__class__.__name__}(\n{1})'
                .format(self, self._state_as_str()))

    def __str__(self):
        return ('WindMover - current _state. '
                'See "wind" object for wind conditions:\n{0}'
                .format(self._state_as_str()))

    @property
    def wind(self):
        return self._wind

    @wind.setter
    def wind(self, value):
        if not isinstance(value, Wind):
            raise TypeError('wind must be of type environment.Wind')
        else:
            # update reference to underlying cython object
            self._wind = value
            self.mover.set_ossm(self._wind.ossm)

    @property
    def data_start(self):
        return self.wind.data_start

    @property
    def data_stop(self):
        return self.wind.data_stop

    def prepare_for_model_run(self):
        '''
        if wind attribute is not set, raise ReferencedObjectNotSet excpetion
        '''
        super(WindMover, self).prepare_for_model_run()

        if self.on and self.wind is None:
            msg = "wind object not defined for WindMover"
            raise ReferencedObjectNotSet(msg)
Exemplo n.º 5
0
class WindMover(WindMoversBase, serializable.Serializable):
    """
    Python wrapper around the Cython wind_mover module.
    This class inherits from CyMover and contains CyWindMover

    The real work is done by the CyWindMover object.  CyMover
    sets everything up that is common to all movers.

    In addition to base class array_types.basic, also use the
    array_types.windage dict since WindMover requires a windage array
    """
    _state = copy.deepcopy(WindMoversBase._state)
    #_state.add(read=['wind_id'], save=['wind_id'])
    # todo: probably need to make update=True for 'wind' as well
    _state.add_field(serializable.Field('wind', save=True, update=True,
                                         save_reference=True))
    _schema = WindMoverSchema

    def __init__(self, wind, **kwargs):
        """
        Uses super to call CyMover base class __init__

        :param wind: wind object -- provides the wind time series for the mover

        Remaining kwargs are passed onto WindMoversBase __init__ using super.
        See Mover documentation for remaining valid kwargs.
        """
        self.mover = CyWindMover()
        self.wind = wind
        self.name = wind.name

        # set optional attributes
        super(WindMover, self).__init__(**kwargs)

    def __repr__(self):
        """
        .. todo::
            We probably want to include more information.
        """
        return ('{0.__class__.__module__}.{0.__class__.__name__}(\n'
                '{1}'
                ')'.format(self, self._state_as_str()))

    def __str__(self):
        info = ('WindMover - current _state. '
                'See "wind" object for wind conditions:\n'
                '{0}'.format(self._state_as_str()))
        return info

    @property
    def wind(self):
        return self._wind

    @wind.setter
    def wind(self, value):
        if not isinstance(value, environment.Wind):
            raise TypeError('wind must be of type environment.Wind')
        else:
            # update reference to underlying cython object
            self._wind = value
            self.mover.set_ossm(self.wind.ossm)

    def serialize(self, json_='webapi'):
        """
        Since 'wind' property is saved as a reference when used in save file
        and 'save' option, need to add appropriate node to WindMover schema
        """
        toserial = self.to_serialize(json_)
        schema = self.__class__._schema()
        if json_ == 'webapi':
            # add wind schema
            schema.add(environment.WindSchema())

        serial = schema.serialize(toserial)

        return serial

    @classmethod
    def deserialize(cls, json_):
        """
        append correct schema for wind object
        """
        schema = cls._schema()
        if 'wind' in json_:
            schema.add(environment.WindSchema())
        _to_dict = schema.deserialize(json_)

        return _to_dict
Exemplo n.º 6
0
class WindMover(WindMoversBase, serializable.Serializable):

    """
    Python wrapper around the Cython wind_mover module.
    This class inherits from CyMover and contains CyWindMover

    The real work is done by the CyWindMover object.  CyMover
    sets everything up that is common to all movers.

    In addition to base class array_types.basic, also use the
    array_types.windage dict since WindMover requires a windage array
    """
    state = copy.deepcopy(WindMoversBase.state)
    state.add(read=['wind_id'], create=['wind_id'])

    @classmethod
    def new_from_dict(cls, dict_):
        """
        define in WindMover and check wind_id matches wind

        invokes: super(WindMover,cls).new_from_dict(dict\_)
        """

        wind_id = dict_.pop('wind_id')
        if dict_.get('wind').id != wind_id:
            raise ValueError('id of wind object does not match the wind_id'\
                             ' parameter')
        return super(WindMover, cls).new_from_dict(dict_)

    def wind_id_to_dict(self):
        """
        used only for storing state so no wind_id_from_dict is defined. This
        is not a read/write attribute. Only defined for serializable_state
        """

        return self.wind.id

    def from_dict(self, dict_):
        """
        For updating the object from dictionary

        'wind' object is not part of the state since it is not serialized/
        deserialized; however, user can still update the wind attribute with a
        new Wind object. That must be poped out of the dict() here, then call
        super to process the standard dict\_
        """

        self.wind = dict_.pop('wind', self.wind)

        super(WindMover, self).from_dict(dict_)

    def __init__(self, wind, **kwargs):
        """
        Uses super to call CyMover base class __init__

        :param wind: wind object -- provides the wind time series for the mover

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

        self.mover = CyWindMover()
        self.wind = wind

        # set optional attributes
        super(WindMover, self).__init__(**kwargs)

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

        info = 'WindMover(\n{0})'.format(self._state_as_str())
        return info

    def __str__(self):
        info = \
            "WindMover - current state." \
            + " See 'wind' object for wind conditions:\n" \
            + "{0}".format(self._state_as_str())
        return info

    @property
    def wind(self):
        return self._wind

    @wind.setter
    def wind(self, value):
        if not isinstance(value, environment.Wind):
            raise TypeError('wind must be of type environment.Wind')
        else:
            # update reference to underlying cython object
            self._wind = value
            self.mover.set_ossm(self.wind.ossm)