def sample_sc_intrinsic(self, num_elements, rel_time, add_at=None): ''' initialize Sample SC and WeatheringData object objects are constructed and prepare_for_model_run() is invoked on all ''' wd = WeatheringData(Water()) end_time = rel_time + timedelta(hours=1) spills = [ point_line_release_spill(num_elements, (0, 0, 0), rel_time, end_release_time=end_time, amount=100, units='kg', substance=test_oil) ] sc = SpillContainer() sc.spills += spills at = wd.array_types if add_at is not None: at.update(add_at) sc.prepare_for_model_run(at) # test initialization as well wd.prepare_for_model_run(sc) for val in sc.mass_balance.values(): assert val == 0.0 # test initialization as well return (sc, wd)
def sample_sc_intrinsic(self, num_elements, rel_time, add_at=None): ''' initialize Sample SC and WeatheringData object objects are constructed and prepare_for_model_run() is invoked on all ''' wd = WeatheringData(Water()) end_time = rel_time + timedelta(hours=1) spills = [point_line_release_spill(num_elements, (0, 0, 0), rel_time, end_release_time=end_time, amount=100, units='kg', substance=test_oil)] sc = SpillContainer() sc.spills += spills at = wd.array_types if add_at is not None: at.update(add_at) sc.prepare_for_model_run(at) # test initialization as well wd.prepare_for_model_run(sc) for val in sc.mass_balance.values(): assert val == 0.0 # test initialization as well return (sc, wd)
def mk_test_objs(cls, water=None): ''' create SpillContainer and test WeatheringData object test objects so we can run Skimmer, Burn like a model without using a full on Model NOTE: Use this function to define class level objects. Other methods in this class expect sc, and weatherers to be class level objects ''' # spreading does not need to be initialized correctly for these tests, # but since we are mocking the model, let's do it correctly if water is None: water = Water() # keep this order weatherers = [WeatheringData(water), FayGravityViscous(water)] weatherers.sort(key=weatherer_sort) sc = SpillContainer() print "******************" print "Adding a spill to spill container" sc.spills += point_line_release_spill(10, (0, 0, 0), rel_time, substance=test_oil, amount=amount, units='kg', water=water) return (sc, weatherers)
def weathering_data_arrays(n_arrays, water=None, time_step=15.*60, element_type=None, langmuir=False): ''' function to initialize data_arrays set by WeatheringData. Weatherer tests can use this function to release elements and initialize data without defining a model ''' if water is None: water = Water() rqd_weatherers = [WeatheringData(water), FayGravityViscous(water)] arrays = set() arrays.update(n_arrays) for wd in rqd_weatherers: arrays.update(wd.array_types) if element_type is None: element_type = floating(substance=test_oil) sc = sample_sc_release(num_elements=2, element_type=element_type, arr_types=arrays, time_step=time_step) for wd in rqd_weatherers: wd.prepare_for_model_run(sc) wd.initialize_data(sc, sc.num_released) return (sc, time_step, rqd_weatherers)
def test_sort_order(): 'test sort order for Dissolution weatherer' wind = constant_wind(15., 0) waves = Waves(wind, Water()) diss = Dissolution(waves, wind) disp = NaturalDispersion(waves=waves, water=waves.water) weathering_data = WeatheringData(water=waves.water) # dissolution is dependent upon droplet distribution generated by # natural dispersion assert weatherer_sort(disp) < weatherer_sort(diss) # dissolution needs to happen before we treat our weathering data assert weatherer_sort(diss) < weatherer_sort(weathering_data)
def weathering_data_arrays(n_arrays, water=None, time_step=15. * 60, substance=None, langmuir=False, num_elements=2, units='g', amount_per_element=1.0): ''' function to initialize data_arrays set by WeatheringData. Weatherer tests can use this function to release elements and initialize data without defining a model ''' if water is None: water = Water() rqd_weatherers = [WeatheringData(water), FayGravityViscous(water)] arrays = dict() arrays.update(n_arrays) for wd in rqd_weatherers: arrays.update(wd.array_types) if isinstance(substance, six.string_types): substance = GnomeOil(substance) if substance is None: substance = GnomeOil(test_oil) arrays.update(substance.array_types) sc = sample_sc_release(num_elements=num_elements, substance=substance, arr_types=arrays, time_step=time_step, units=units, amount_per_element=amount_per_element) for wd in rqd_weatherers: wd.prepare_for_model_run(sc) wd.initialize_data(sc, sc.num_released) return (sc, time_step, rqd_weatherers)
def test_update_intrinsic_props(self): ''' test multiple spills with same substance ''' weatherers = [WeatheringData(water), FayGravityViscous(water)] rel_time = datetime.now().replace(microsecond=0) end_time = rel_time + timedelta(hours=1) spills = [ point_line_release_spill(100, (0, 0, 0), rel_time, end_release_time=end_time, amount=100, units='kg', substance=test_oil), point_line_release_spill(50, (0, 0, 0), rel_time + timedelta(hours=.25), substance=test_oil, amount=100, units='kg') ] sc = SpillContainer() sc.spills += spills at = dict() for w in weatherers: at.update(w.array_types) sc.prepare_for_model_run(at) # test initialization as well for w in weatherers: w.prepare_for_model_run(sc) for val in sc.mass_balance.values(): assert val == 0.0 # test initialization as well ts = 900 for i in range(-1, 5): curr_time = rel_time + timedelta(seconds=i * ts) num_released = sc.release_elements(ts, curr_time) if num_released > 0: for w in weatherers: w.initialize_data(sc, num_released) for w in weatherers: self.step(w, sc, curr_time) for key, val in sc.mass_balance.iteritems(): if len(sc) > 0 and key not in ('beached', 'non_weathering', 'off_maps'): assert val > 0 else: # everything, including avg_density is 0 if nothing is # released assert val == 0.0 if len(sc) > 0: # area arrays initialized correctly mask = sc['age'] == 0 if np.any(~mask): # sc['fay_area'][mask] is initial area of blob # sc['fay_area'][~mask] is area of aged blob assert (sc['fay_area'][mask].sum() != sc['fay_area'][~mask].sum()) assert all(sc['fay_area'] > 0) assert all(sc['init_mass'] > 0) # wd props arrays initialized correctly assert all(sc['density'] > 0) assert all(sc['viscosity'] > 0) sc['age'] += ts # model would do this operation print 'Completed step: ', i
def test_init(self): WeatheringData(water)