def prepare_for_model_step(self, sc, time_step, model_time_datetime): """ Call base class method using super Also updates windage for this timestep :param sc: an instance of gnome.spill_container.SpillContainer class :param time_step: time step in seconds :param model_time_datetime: current time of model as a date time object """ # not sure if we need to redefine this or what we want to do here super(ShipDriftMover, self).prepare_for_model_step(sc, time_step, model_time_datetime) # if no particles released, then no need for windage # TODO: revisit this since sc.num_released shouldn't be None if sc.num_released is None or sc.num_released == 0: return self.grid.prepare_for_model_step(model_time_datetime) # here we might put in drift angle stuff ? if self.active: rand.random_with_persistance(sc['windage_range'][:, 0], sc['windage_range'][:, 1], sc['windages'], sc['windage_persist'], time_step)
def test_exceptions(low, high): """ Test exceptions """ arr = np.zeros((len(low),), dtype=np.float64) with pytest.raises(ValueError): random_with_persistance(low, high, arr)
def prepare_for_model_step(self, sc, time_step, model_time_datetime): """ Call base class method using super Also updates windage for this timestep :param sc: an instance of gnome.spill_container.SpillContainer class :param time_step: time step in seconds :param model_time_datetime: current time of model as a date time object """ # not sure if we need to redefine this or what we want to do here super(ShipDriftMover, self).prepare_for_model_step(sc, time_step, model_time_datetime) # if no particles released, then no need for windage # TODO: revisit this since sc.num_released shouldn't be None if sc.num_released is None or sc.num_released == 0: return self.grid.prepare_for_model_step(model_time_datetime) # here we might put in drift angle stuff ? rand.random_with_persistance(sc['windage_range'][:, 0], sc['windage_range'][:, 1], sc['windages'], sc['windage_persist'], time_step)
def test_random_with_persistance(low, high, array, persist, timestep): """ Since numbers are randomly generated, can only test array length """ if array is None: array = random_with_persistance(low, high, array, persist, time_step=timestep) else: random_with_persistance(low, high, array, persist, time_step=timestep) # persist set to timestep if persist is None: assert np.all(array >= low) and np.all(array <= high) else: # do not update values if persist < 0 low = np.asarray(low) high = np.asarray(high) persist = np.asarray(persist) assert array[persist <= 0] == 0 # for persist == timestep, output is within [low, high] bounds eq_mask = [persist == timestep] if np.any(eq_mask): assert (array[eq_mask] >= low[eq_mask] and array[eq_mask] <= high[eq_mask])
def test_random_with_persistance(low, high, array, persist, timestep): """ Since numbers are randomly generated, can only test array length """ if array is None: array = random_with_persistance(low, high, array, persist, time_step=timestep) else: random_with_persistance(low, high, array, persist, time_step=timestep) # persist set to timestep if persist is None: assert np.all(array >= low) and np.all(array <= high) else: # do not update values if persist < 0 low = np.asarray(low) high = np.asarray(high) persist = np.asarray(persist) assert array[persist <= 0] == 0 # for persist == timestep, output is within [low, high] bounds eq_mask = persist == timestep if np.any(eq_mask): assert (array[eq_mask] >= low[eq_mask] and array[eq_mask] <= high[eq_mask])
def prepare_for_model_step( self, sc, time_step, model_time_datetime, ): """ Call base class method using super Also updates windage for this timestep :param sc: an instance of gnome.spill_container.SpillContainer class :param time_step: time step in seconds :param model_time_datetime: current time of model as a date time object """ super(WindMoversBase, self).prepare_for_model_step(sc, time_step, model_time_datetime) # if no particles released, then no need for windage # todo: revisit this since sc.num_released shouldn't be None if sc.num_released is None or sc.num_released == 0: return for spill in sc.spills: spill_mask = sc.get_spill_mask(spill) if np.any(spill_mask): rand.random_with_persistance( sc['windage_range'][spill_mask, 0], sc['windage_range'][spill_mask, 1], sc['windages'][spill_mask], sc['windage_persist'][spill_mask], time_step)
def initialize(self, num_new_particles, data_arrays, substance): """ Since windages exists in data_arrays, so must windage_range and windage_persist if this initializer is used/called """ if any([k not in data_arrays for k in self.array_types.keys()]): return sl = slice(-num_new_particles, None, 1) data_arrays['windage_range'][sl] = self.windage_range data_arrays['windage_persist'][sl] = self.windage_persist random_with_persistance( data_arrays['windage_range'][-num_new_particles:, 0], data_arrays['windage_range'][-num_new_particles:, 1], data_arrays['windages'][-num_new_particles:] )
def initialize(self, num_new_particles, spill, data_arrays): """ Since windages exists in data_arrays, so must windage_range and windage_persist if this initializer is used/called """ data_arrays['windage_range'][-num_new_particles:, 0] = \ self.windage_range[0] data_arrays['windage_range'][-num_new_particles:, 1] = \ self.windage_range[1] data_arrays['windage_persist'][-num_new_particles:] = \ self.windage_persist # initialize all windages - ignore persistence during initialization # if we have infinite persistence, these values are never updated random_with_persistance( data_arrays['windage_range'][-num_new_particles:][:, 0], data_arrays['windage_range'][-num_new_particles:][:, 1], data_arrays['windages'][-num_new_particles:])
def prepare_for_model_step(self, sc, time_step, model_time_datetime): """ Call base class method using super Also updates windage for this timestep :param sc: an instance of gnome.spill_container.SpillContainer class :param time_step: time step in seconds :param model_time_datetime: current time of model as a date time object """ super(PyWindMover, self).prepare_for_model_step(sc, time_step, model_time_datetime) # if no particles released, then no need for windage # TODO: revisit this since sc.num_released shouldn't be None if sc.num_released is None or sc.num_released == 0: return rand.random_with_persistance( sc["windage_range"][:, 0], sc["windage_range"][:, 1], sc["windages"], sc["windage_persist"], time_step )
def prepare_for_model_step(self, sc, time_step, model_time_datetime): """ Call base class method using super Also updates windage for this timestep :param sc: an instance of gnome.spill_container.SpillContainer class :param time_step: time step in seconds :param model_time_datetime: current time of model as a date time object """ super(WindMoversBase, self).prepare_for_model_step(sc, time_step, model_time_datetime) # if no particles released, then no need for windage # TODO: revisit this since sc.num_released shouldn't be None if sc.num_released is None or sc.num_released == 0: return rand.random_with_persistance(sc['windage_range'][:, 0], sc['windage_range'][:, 1], sc['windages'], sc['windage_persist'], time_step)
def initialize(self, num_new_particles, spill, data_arrays, substance=None): """ Since windages exists in data_arrays, so must windage_range and windage_persist if this initializer is used/called """ (data_arrays['windage_range'][-num_new_particles:, 0], data_arrays['windage_range'][-num_new_particles:, 1], data_arrays['windage_persist'][-num_new_particles:]) = \ (self.windage_range[0], self.windage_range[1], self.windage_persist) # initialize all windages - ignore persistence during initialization # if we have infinite persistence, these values are never updated random_with_persistance( data_arrays['windage_range'][-num_new_particles:][:, 0], data_arrays['windage_range'][-num_new_particles:][:, 1], data_arrays['windages'][-num_new_particles:])
def test_random_with_persistance_low_equals_high(low, high): """ if low==high, then return low - deterministic output """ x = random_with_persistance(low, high) assert np.all(x == low)