def test_rewind(): """ Test rewinding spill containter rewinds the spills. - SpillContainer should reset its the data_arrays to empty and num_released to 0 - it should reset num_released = 0 for all spills and reset start_time_invalid flag to True. Basically all spills are rewound """ num_elements = 100 release_time = datetime(2012, 1, 1, 12) release_time2 = release_time + timedelta(hours=24) start_position = (23.0, -78.5, 0.0) sc = SpillContainer() spills = [ point_line_release_spill(num_elements, start_position, release_time), point_line_release_spill(num_elements, start_position, release_time2) ] sc.spills.add(spills) sc.prepare_for_model_run(windage_at) for time in [release_time, release_time2]: sc.release_elements(3600, time) assert sc.num_released == num_elements * len(spills) for spill in spills: assert spill.get('num_released') == spill.release.num_elements sc.rewind() assert sc.num_released == 0 assert_dataarray_shape_size(sc) for spill in spills: assert spill.get('num_released') == 0 assert spill.release.start_time_invalid is None
def test_rewind(): """ Test rewinding spill containter rewinds the spills. - SpillContainer should reset its the data_arrays to empty and num_released to 0 - it should reset num_released = 0 for all spills and reset start_time_invalid flag to True. Basically all spills are rewound """ num_elements = 100 release_time = datetime(2012, 1, 1, 12) release_time2 = release_time + timedelta(hours=24) start_position = (23.0, -78.5, 0.0) sc = SpillContainer() spills = [point_line_release_spill(num_elements, start_position, release_time), point_line_release_spill(num_elements, start_position, release_time2)] sc.spills.add(spills) sc.prepare_for_model_run(windage_at) for time in [release_time, release_time2]: sc.release_elements(3600, time) assert sc.num_released == num_elements * len(spills) for spill in spills: assert spill.num_released == spill.release.num_elements sc.rewind() assert sc.num_released == 0 assert_dataarray_shape_size(sc) for spill in spills: assert spill.num_released == 0 assert spill.release.start_time_invalid is None
def test_SpillContainer_add_array_types(): ''' Test an array_type is dynamically added/subtracted from SpillContainer if it is contained in Initailizer's array_types property. For example: Add 'rise_vel' initializer, InitRiseVelFromDropletSizeFromDist()) is added to Spill's element_type object. Now, the array_types for this initailizer are 'rise_vel' and 'droplet_diameter'. Only if a RiseVelocityMover is added to the model in which case the Model provides 'rise_vel' as an array_type to the SpillContainer to append it to its own list, then the SpillContainer will also add the 'droplet_diameter' array_type that is additionally set by the Initializer but is not explicitly required by the Mover. ''' sc = SpillContainer() s = Spill(Release(datetime(2014, 1, 1, 12, 0), 0)) s.set_initializer( InitRiseVelFromDropletSizeFromDist(distribution=UniformDistribution())) sc.spills += s assert 'rise_vel' not in sc.array_types assert 'droplet_diameter' not in sc.array_types # Now say you added RiseVelocityMover and the Model collects ArrayTypes # from all movers and passes it into SpillContainer's prepare_for_model_run # sc.prepare_for_model_run(array_types={'rise_vel'}) assert 'rise_vel' in sc.array_types assert 'droplet_diameter' in sc.array_types # calling prepare_for_model_run without different array_types keeps the # previously added 'rise_vel' array_types - always rewind if you want to # clear out the state and reset array_types to original data sc.prepare_for_model_run() assert 'rise_vel' in sc.array_types assert 'droplet_diameter' in sc.array_types # Now let's rewind array_types and these extra properties should disappear # they are only added after the prepare_for_model_run step sc.rewind() sc.prepare_for_model_run() assert 'rise_vel' not in sc.array_types assert 'droplet_diameter' not in sc.array_types
def test_SpillContainer_add_array_types(): ''' Test an array_type is dynamically added/subtracted from SpillContainer if it is contained in Initailizer's array_types property. For example: Add 'rise_vel' initializer, InitRiseVelFromDropletSizeFromDist()) is added to Spill's element_type object. Now, the array_types for this initailizer are 'rise_vel' and 'droplet_diameter'. Only if a RiseVelocityMover is added to the model in which case the Model provides 'rise_vel' as an array_type to the SpillContainer to append it to its own list, then the SpillContainer will also add the 'droplet_diameter' array_type that is additionally set by the Initializer but is not explicitly required by the Mover. ''' sc = SpillContainer() s = Spill(Release(datetime(2014, 1, 1, 12, 0), 0)) s.set_initializer(InitRiseVelFromDropletSizeFromDist(distribution = UniformDistribution())) sc.spills += s assert 'rise_vel' not in sc.array_types assert 'droplet_diameter' not in sc.array_types # Now say you added RiseVelocityMover and the Model collects ArrayTypes # from all movers and passes it into SpillContainer's prepare_for_model_run # sc.prepare_for_model_run(array_types={'rise_vel'}) assert 'rise_vel' in sc.array_types assert 'droplet_diameter' in sc.array_types # calling prepare_for_model_run without different array_types keeps the # previously added 'rise_vel' array_types - always rewind if you want to # clear out the state and reset array_types to original data sc.prepare_for_model_run() assert 'rise_vel' in sc.array_types assert 'droplet_diameter' in sc.array_types # Now let's rewind array_types and these extra properties should disappear # they are only added after the prepare_for_model_run step sc.rewind() sc.prepare_for_model_run() assert 'rise_vel' not in sc.array_types assert 'droplet_diameter' not in sc.array_types
def test_array_types_reset(): """ check the array_types are reset on rewind() only """ sc = SpillContainer() sc.prepare_for_model_run(array_types=windage_at) assert 'windages' in sc.array_types sc.rewind() assert 'windages' not in sc.array_types assert sc.array_types == sc_default_array_types sc.prepare_for_model_run(array_types=windage_at) assert 'windages' in sc.array_types # now if we invoke prepare_for_model_run without giving it any array_types # it should not reset the dict to default sc.prepare_for_model_run() # set to any datetime assert 'windages' in sc.array_types
def test_array_types_reset(): """ check the array_types are reset on rewind() only """ sc = SpillContainer() sc.prepare_for_model_run(array_types=windage_at) assert 'windages' in sc.array_types sc.rewind() assert 'windages' not in sc.array_types assert sc.array_types == sc_default_array_types sc.prepare_for_model_run(array_types=windage_at) assert 'windages' in sc.array_types # now if we invoke prepare_for_model_run without giving it any array_types # it should not reset the dict to default sc.prepare_for_model_run() # set to any datetime assert 'windages' in sc.array_types