コード例 #1
0
ファイル: movers.py プロジェクト: satcomlabs/PyGnome
    def __init__(self, **kwargs):  # default min + max values for timespan
        """
        Initialize default Mover/Weatherer parameters

        All parameters are optional (kwargs)

        :param on: boolean as to whether the object is on or not. Default is on
        :param active_start: datetime when the mover should be active
        :param active_stop: datetime after which the mover should be inactive
        """
        self.on = kwargs.pop('on', True)  # turn the mover on / off for the run
        self._active = self.on  # initial value

        active_start = kwargs.pop('active_start',
                                  inf_datetime.InfDateTime('-inf'))
        active_stop = kwargs.pop('active_stop',
                                 inf_datetime.InfDateTime('inf'))

        self._check_active_startstop(active_start, active_stop)

        self.active_start = active_start
        self.active_stop = active_stop

        # empty dict since no array_types required for all movers at present
        self.array_types = set()
        self.name = kwargs.pop('name', self.__class__.__name__)
        self.make_default_refs = kwargs.pop('make_default_refs', True)
コード例 #2
0
ファイル: test_model.py プロジェクト: satcomlabs/PyGnome
def test_callback_add_mover():
    'Test callback after add mover'
    units = 'meter per second'

    model = Model()
    model.start_time = datetime(2012, 1, 1, 0, 0)
    model.duration = timedelta(hours=10)
    model.time_step = timedelta(hours=1)

    # start_loc = (1.0, 2.0, 0.0)  # random non-zero starting points

    # add Movers
    model.movers += SimpleMover(velocity=(1., -1., 0.))
    series = np.array((model.start_time, (10, 45)),
                      dtype=datetime_value_2d).reshape((1, ))
    model.movers += WindMover(Wind(timeseries=series, units=units))

    # this should create a Wind object
    new_wind = Wind(timeseries=series, units=units)
    model.environment += new_wind
    assert new_wind in model.environment
    assert len(model.environment) == 2

    tide_ = Tide(filename=testdata['CatsMover']['tide'])

    d_file = testdata['CatsMover']['curr']
    model.movers += CatsMover(d_file, tide=tide_)

    model.movers += CatsMover(d_file)

    for mover in model.movers:
        assert mover.active_start == inf_datetime.InfDateTime('-inf')
        assert mover.active_stop == inf_datetime.InfDateTime('inf')

        if hasattr(mover, 'wind'):
            assert mover.wind in model.environment

        if hasattr(mover, 'tide'):
            if mover.tide is not None:
                assert mover.tide in model.environment

    # Add a mover with user defined active_start / active_stop values
    # - these should not be updated

    active_on = model.start_time + timedelta(hours=1)
    active_off = model.start_time + timedelta(hours=4)
    custom_mover = SimpleMover(velocity=(1., -1., 0.),
                               active_start=active_on,
                               active_stop=active_off)
    model.movers += custom_mover

    assert model.movers[custom_mover.id].active_start == active_on
    assert model.movers[custom_mover.id].active_stop == active_off
コード例 #3
0
    def deserialize(self, node, cstruct):
        if cstruct in ('inf', '-inf'):
            return inf_datetime.InfDateTime(cstruct)
        else:
            dt = super(LocalDateTime, self).deserialize(node, cstruct)

            return self.strip_timezone(dt)