def test_active_start_after_one_timestep(self): start_time = self.model_time + timedelta(seconds=self.time_step) mv = Mover(active_range=(start_time, InfDateTime('inf'))) mv.prepare_for_model_step(self.sc, self.time_step, self.model_time) assert mv.active is False
def test_active_start_after_one_timestep(self): start_time = self.model_time + timedelta(seconds=self.time_step) mv = Mover(active_start=start_time) mv.prepare_for_model_step(self.sc, self.time_step, self.model_time) assert mv.active is False # model_time + time_step = active_start
def test_get_move(): ''' assert base class get_move returns an array of nan[s] ''' time_step = 15 * 60 # seconds model_time = datetime(2012, 8, 20, 13) sc = sample_sc_release(10, (0, 0, 0)) # no used for anything mv = Mover() delta = mv.get_move(sc, time_step, model_time) assert np.all(np.isnan(delta))
def test_default_properties(): mover = Mover() assert mover.on is True assert mover.active_range == (InfDateTime('-inf'), InfDateTime('inf')) assert mover.make_default_refs is True
def __init__(self, wind_file=None, topology_file=None, grid_type=1, drift_angle=0, extrapolation_is_allowed=False, time_offset=0, **kwargs): """ :param wind_file: file containing wind data on a grid :param topology_file: Default is None. When exporting topology, it is stored in this file :param wind_scale: Value to scale wind data :param extrapolate: Allow current data to be extrapolated before and after file data :param time_offset: Time zone shift if data is in GMT Pass optional arguments to base class uses super: super(ShipDriftMover,self).__init__(\*\*kwargs) """ if not os.path.exists(wind_file): raise ValueError( 'Path for wind file does not exist: {0}'.format(wind_file)) if topology_file is not None: if not os.path.exists(topology_file): raise ValueError( 'Path for Topology file does not exist: {0}'.format( topology_file)) # is wind_file and topology_file is stored with cy_gridwind_mover? self.wind_file = wind_file self.topology_file = topology_file self.name = os.path.split(wind_file)[1] self.drift_angle = drift_angle self._wind_scale = kwargs.pop('wind_scale', 1) self.grid_type = grid_type self.grid = Grid(wind_file, topology_file, grid_type) self.mover = Mover() super(ShipDriftMover, self).__init__(**kwargs) # have to override any uncertainty # self.grid.load_data(wind_file, topology_file) self.model_time = 0 self.positions = np.zeros((0, 3), dtype=world_point_type) self.delta = np.zeros((0, 3), dtype=world_point_type) self.status_codes = np.zeros((0, 1), dtype=status_code_type) self.array_types.update( {'windages', 'windage_range', 'windage_persist'})
def test_default_properties(): mover = Mover() assert mover.name == 'Mover' assert mover.on is True assert mover.active_range == (InfDateTime('-inf'), InfDateTime('inf')) assert mover.array_types == set() assert mover.make_default_refs is True
def test_active_start_modeltime(self): mv = Mover(active_range=(self.model_time, InfDateTime('inf'))) mv.prepare_for_model_step(self.sc, self.time_step, self.model_time) assert mv.active is True
def test_active_default(self): mv = Mover() # active_range defaults to (-Inf, Inf) mv.prepare_for_model_step(self.sc, self.time_step, self.model_time) assert mv.active is True
class TestActive: time_step = 15 * 60 # seconds model_time = datetime(2012, 8, 20, 13) sc = sample_sc_release(1, (0, 0, 0)) # no used for anything mv = Mover() def test_active_default(self): mv = Mover() # active_range defaults to (-Inf, Inf) mv.prepare_for_model_step(self.sc, self.time_step, self.model_time) assert mv.active is True def test_active_start_modeltime(self): mv = Mover(active_range=(self.model_time, InfDateTime('inf'))) mv.prepare_for_model_step(self.sc, self.time_step, self.model_time) assert mv.active is True def test_active_start_after_one_timestep(self): start_time = self.model_time + timedelta(seconds=self.time_step) mv = Mover(active_range=(start_time, InfDateTime('inf'))) mv.prepare_for_model_step(self.sc, self.time_step, self.model_time) assert mv.active is False def test_active_start_after_half_timestep(self): self.mv.active_range = ((self.model_time + timedelta(seconds=self.time_step / 2)), InfDateTime('inf')) self.mv.prepare_for_model_step(self.sc, self.time_step, self.model_time) assert self.mv.active is True # Next test just some more borderline cases that active is set correctly def test_active_stop_greater_than_timestep(self): self.mv.active_range = (self.model_time, (self.model_time + timedelta(seconds=1.5 * self.time_step))) self.mv.prepare_for_model_step(self.sc, self.time_step, self.model_time) assert self.mv.active is True def test_active_stop_after_half_timestep(self): self.mv.active_range = (self.model_time, (self.model_time + timedelta(seconds=0.5 * self.time_step))) self.mv.prepare_for_model_step(self.sc, self.time_step, self.model_time) assert self.mv.active is True def test_active_stop_less_than_half_timestep(self): self.mv.active_range = (self.model_time, (self.model_time + timedelta(seconds=0.25 * self.time_step))) self.mv.prepare_for_model_step(self.sc, self.time_step, self.model_time) assert self.mv.active is False
def test_exceptions(): with raises(ValueError): now = datetime.now() _mover = Mover(active_range=(now, now))
def test_active_start_modeltime(self): mv = Mover(active_start=self.model_time) mv.prepare_for_model_step(self.sc, self.time_step, self.model_time) assert mv.active is True # model_time = active_start
class TestActive: time_step = 15 * 60 # seconds model_time = datetime(2012, 8, 20, 13) sc = sample_sc_release(1, (0, 0, 0)) # no used for anything mv = Mover() def test_active_default(self): mv = Mover() mv.prepare_for_model_step(self.sc, self.time_step, self.model_time) assert mv.active is True # model_time = active_start def test_active_start_modeltime(self): mv = Mover(active_start=self.model_time) mv.prepare_for_model_step(self.sc, self.time_step, self.model_time) assert mv.active is True # model_time = active_start def test_active_start_after_one_timestep(self): start_time = self.model_time + timedelta(seconds=self.time_step) mv = Mover(active_start=start_time) mv.prepare_for_model_step(self.sc, self.time_step, self.model_time) assert mv.active is False # model_time + time_step = active_start def test_active_start_after_half_timestep(self): self.mv.active_start = \ self.model_time + timedelta(seconds=self.time_step / 2) self.mv.prepare_for_model_step(self.sc, self.time_step, self.model_time) # model_time + time_step / 2 = active_start assert self.mv.active is True # Next test just some more borderline cases that active is set correctly def test_active_stop_greater_than_timestep(self): self.mv.active_start = self.model_time self.mv.active_stop = (self.model_time + timedelta(seconds=1.5 * self.time_step)) self.mv.prepare_for_model_step(self.sc, self.time_step, self.model_time) # model_time + 1.5 * time_step = active_stop assert self.mv.active is True def test_active_stop_after_half_timestep(self): self.mv.active_start = self.model_time self.mv.active_stop = (self.model_time + timedelta(seconds=0.5 * self.time_step)) self.mv.prepare_for_model_step(self.sc, self.time_step, self.model_time) # model_time + 1.5 * time_step = active_stop assert self.mv.active is True def test_active_stop_less_than_half_timestep(self): self.mv.active_start = self.model_time self.mv.active_stop = (self.model_time + timedelta(seconds=0.25 * self.time_step)) self.mv.prepare_for_model_step(self.sc, self.time_step, self.model_time) # current_model_time = active_stop assert self.mv.active is False
def test_exceptions(): with raises(ValueError): now = datetime.now() _mover = Mover(active_start=now, active_stop=now)