def test_serialize_deserialize(tide, json_): """ test serialize/deserialize/update_from_dict doesn't raise errors """ c_cats = CatsMover(curr_file, tide=tide) toserial = c_cats.serialize(json_) dict_ = c_cats.deserialize(toserial) # check our CatsMover attributes if json_ == 'webapi': assert toserial['filename'] == basename(toserial['filename']) else: # in save context, we expect a full path to file assert toserial['filename'] != basename(toserial['filename']) if tide: assert 'tide' in toserial dict_['tide'] = tide # no longer updating properties of nested objects assert c_cats.tide is tide if json_ == 'webapi': assert (toserial['tide']['filename'] == basename(toserial['tide']['filename'])) else: assert (toserial['tide']['filename'] != basename(toserial['tide']['filename'])) c_cats.update_from_dict(dict_)
def make_model(images_dir=os.path.join(base_dir, 'images')): print 'creating the maps' mapfile = get_datafile(os.path.join(base_dir, 'LowerMississippiMap.bna')) gnome_map = MapFromBNA(mapfile, refloat_halflife=6) # hours print 'initializing the model' start_time = datetime(2012, 9, 15, 12, 0) # default to now, rounded to the nearest hour model = Model(time_step=600, start_time=start_time, duration=timedelta(days=1), map=gnome_map, uncertain=True) print 'adding outputters' model.outputters += Renderer(mapfile, images_dir, size=(800, 600)) netcdf_file = os.path.join(base_dir, 'script_lower_mississippi.nc') scripting.remove_netcdf(netcdf_file) model.outputters += NetCDFOutput(netcdf_file, which_data='all') print 'adding a RandomMover:' model.movers += RandomMover(diffusion_coef=10000) print 'adding a wind mover:' series = np.zeros((5, ), dtype=datetime_value_2d) series[0] = (start_time, (2, 45)) series[1] = (start_time + timedelta(hours=18), (2, 90)) series[2] = (start_time + timedelta(hours=30), (2, 135)) series[3] = (start_time + timedelta(hours=42), (2, 180)) series[4] = (start_time + timedelta(hours=54), (2, 225)) w_mover = WindMover(Wind(timeseries=series, units='m/s')) model.movers += w_mover print 'adding a cats mover:' curr_file = get_datafile(os.path.join(base_dir, 'LMiss.CUR')) c_mover = CatsMover(curr_file) # but do need to scale (based on river stage) c_mover.scale = True c_mover.scale_refpoint = (-89.699944, 29.494558) # based on stage height 10ft (range is 0-18) c_mover.scale_value = 1.027154 model.movers += c_mover print 'adding a spill' spill = point_line_release_spill(num_elements=1000, start_position=(-89.699944, 29.494558, 0.0), release_time=start_time) model.spills += spill return model
def test_new_from_dict_curronly(): """ test to_dict function for Wind object create a new wind object and make sure it has same properties """ c_cats = CatsMover(curr_file) dict_ = c_cats.to_dict('create') c2 = CatsMover.new_from_dict(dict_) assert c_cats == c2
def test_exception_new_from_dict(): """ test exceptions raised for new_from_dict """ c_cats = CatsMover(curr_file) dict_ = c_cats.to_dict('create') dict_.update({'tide': td}) with pytest.raises(KeyError): CatsMover.new_from_dict(dict_)
def test_new_from_dict_tide(): """ test to_dict function for Wind object create a new wind object and make sure it has same properties """ c_cats = CatsMover(curr_file, tide=td) dict_ = c_cats.to_dict('create') dict_.update({'tide': td}) c2 = CatsMover.new_from_dict(dict_) assert c_cats == c2
def test_serialize_deserialize(tide): """ test serialize/deserialize/update_from_dict doesn't raise errors """ c_cats = CatsMover(curr_file, tide=tide) toserial = c_cats.serialize('webapi') dict_ = c_cats.deserialize(toserial) if tide: assert 'tide' in toserial dict_['tide'] = tide # no longer updating properties of nested objects assert c_cats.tide is tide c_cats.update_from_dict(dict_)
def test_save_load(tide): """ test save/loading with and without tide """ saveloc = tempfile.mkdtemp() c_cats = CatsMover(curr_file, tide=tide) save_json, zipfile_, _refs = c_cats.save(saveloc) assert validate_save_json(save_json, zipfile.ZipFile(zipfile_), c_cats) loaded = CatsMover.load(zipfile_) assert loaded == c_cats
def test_serialize_deserialize(tide): """ test serialize/deserialize/update_from_dict doesn't raise errors """ c_cats = CatsMover(curr_file, tide=tide) serial = c_cats.serialize() assert validate_serialize_json(serial, c_cats) # check our CatsMover attributes deser = CatsMover.deserialize(serial) assert deser == c_cats
def make_model(images_dir=os.path.join(base_dir, 'images')): print 'initializing the model' start_time = datetime(2012, 9, 15, 12, 0) mapfile = get_datafile(os.path.join(base_dir, './LongIslandSoundMap.BNA')) gnome_map = MapFromBNA(mapfile, refloat_halflife=6) # hours # # the image output renderer # global renderer # one hour timestep model = Model(start_time=start_time, duration=timedelta(hours=48), time_step=3600, map=gnome_map, uncertain=True, cache_enabled=True) netcdf_file = os.path.join(base_dir, 'script_long_island.nc') scripting.remove_netcdf(netcdf_file) print 'adding outputters' model.outputters += Renderer(mapfile, images_dir, size=(800, 600)) model.outputters += NetCDFOutput(netcdf_file, which_data='all') print 'adding a spill' spill = point_line_release_spill(num_elements=1000, start_position=(-72.419992, 41.202120, 0.0), release_time=start_time) model.spills += spill print 'adding a RandomMover:' model.movers += RandomMover(diffusion_coef=500000, uncertain_factor=2) print 'adding a wind mover:' series = np.zeros((5, ), dtype=datetime_value_2d) series[0] = (start_time, (10, 45)) series[1] = (start_time + timedelta(hours=18), (10, 90)) series[2] = (start_time + timedelta(hours=30), (10, 135)) series[3] = (start_time + timedelta(hours=42), (10, 180)) series[4] = (start_time + timedelta(hours=54), (10, 225)) wind = Wind(timeseries=series, units='m/s') model.movers += WindMover(wind) print 'adding a cats mover:' curr_file = get_datafile(os.path.join(base_dir, r"./LI_tidesWAC.CUR")) tide_file = get_datafile(os.path.join(base_dir, r"./CLISShio.txt")) c_mover = CatsMover(curr_file, tide=Tide(tide_file)) model.movers += c_mover model.environment += c_mover.tide print 'viewport is:', [ o.viewport for o in model.outputters if isinstance(o, Renderer) ] return model
def setup_model(): print 'initializing the model' # start with default time,duration...this will be changed when model is run model = Model( ) #change to use all defaults and set time_step also in Setup_TAP!! mapfile = os.path.join(setup.MapFileDir, setup.MapFileName) print 'adding the map: ', mapfile model.map = MapFromBNA(mapfile, refloat_halflife=0.0) # seconds print 'adding a GridCurrentMover:' if setup.curr_fn.endswith('.nc'): c_mover = GridCurrentMover(filename=setup.curr_fn, extrapolate=True) elif setup.curr_fn.endswith('.cur'): tide = Tide(setup.tide_fn) c_mover = CatsMover(filename=setup.curr_fn, tide=tide) model.movers += c_mover print 'adding a WindMover:' if setup.wind_fn is not None: w = Wind(filename=setup.wind_fn) w_mover = WindMover(w) elif setup.wind_data is not None: w_mover = constant_wind_mover(setup.wind_data[0], setup.wind_data[1], units='knots') # w_mover = GridWindMover(wind_file=setup.w_filelist) model.movers += w_mover if setup.diff_coef is not None: print 'adding a RandomMover:' random_mover = RandomMover(diffusion_coef=setup.diff_coef) #in cm/s model.movers += random_mover return model
def test_serialize_deserialize(tide, json_): """ test serialize/deserialize/update_from_dict doesn't raise errors """ c_cats = CatsMover(curr_file, tide=tide) toserial = c_cats.serialize(json_) dict_ = c_cats.deserialize(toserial) # check our CatsMover attributes if json_ == 'webapi': assert toserial['filename'] == basename(toserial['filename']) else: # in save context, we expect a full path to file assert toserial['filename'] != basename(toserial['filename']) if tide: assert 'tide' in toserial dict_['tide'] = tide # no longer updating properties of nested objects assert c_cats.tide is tide if json_ == 'webapi': assert (toserial['tide']['filename'] == basename( toserial['tide']['filename'])) else: assert (toserial['tide']['filename'] != basename( toserial['tide']['filename'])) c_cats.update_from_dict(dict_)
def test_uncertain_loop(): """ test one time step with uncertainty on the spill checks there is non-zero motion. """ pSpill = sample_sc_release(num_le, start_pos, rel_time, uncertain=True) cats = CatsMover(curr_file, tide=td) u_delta = _uncertain_loop(pSpill, cats) _assert_move(u_delta) return u_delta
def test_loop(): """ test one time step with no uncertainty on the spill checks there is non-zero motion. also checks the motion is same for all LEs """ pSpill = sample_sc_release(num_le, start_pos, rel_time) cats = CatsMover(curr_file, tide=td) delta = _certain_loop(pSpill, cats) _assert_move(delta) assert np.all(delta[:, 0] == delta[0, 0]) # lat move matches for all LEs assert np.all(delta[:, 1] == delta[0, 1]) # long move matches for all LEs assert np.all(delta[:, 2] == 0) # 'z' is zeros return delta
def test_serialize_deserialize_curronly(do): """ test to_dict function for Wind object create a new wind object and make sure it has same properties """ c_cats = CatsMover(curr_file) json_ = c_cats.serialize(do) dict_ = c_cats.deserialize(json_) if do == 'create': c2 = CatsMover.new_from_dict(dict_) assert c_cats == c2 else: c_cats.from_dict(dict_)
def test_serialize_deserialize_tide(do): """ test to_dict function for Wind object create a new wind object and make sure it has same properties """ c_cats = CatsMover(curr_file, tide=td) json_ = c_cats.serialize(do) dict_ = c_cats.deserialize(json_) if do == 'create': dict_.update({'tide': td}) c2 = CatsMover.new_from_dict(dict_) assert c_cats == c2 else: assert json_['tide'] == td.serialize(do) c_cats.from_dict(dict_) assert c_cats.tide is td
def make_model(images_dir=os.path.join(base_dir, 'images')): # create the maps: print 'creating the maps' mapfile = get_datafile(os.path.join(base_dir, 'DelawareRiverMap.bna')) gnome_map = MapFromBNA(mapfile, refloat_halflife=1) # hours renderer = Renderer(mapfile, images_dir, image_size=(800, 800), projection_class=GeoProjection) print 'initializing the model' start_time = datetime(2012, 8, 20, 13, 0) # 15 minutes in seconds # Default to now, rounded to the nearest hour model = Model(time_step=900, start_time=start_time, duration=timedelta(days=1), map=gnome_map, uncertain=False) print 'adding outputters' model.outputters += renderer netcdf_file = os.path.join(base_dir, 'script_delaware_bay.nc') scripting.remove_netcdf(netcdf_file) model.outputters += NetCDFOutput(netcdf_file, which_data='all') print 'adding a RandomMover:' model.movers += RandomMover(diffusion_coef=100000) print 'adding a wind mover:' # wind_file = get_datafile(os.path.join(base_dir, 'ConstantWind.WND')) # wind = Wind(filename=wind_file) series = np.zeros((2, ), dtype=datetime_value_2d) series[0] = (start_time, (5, 270)) series[1] = (start_time + timedelta(hours=25), (5, 270)) wind = Wind(timeseries=series, units='m/s') # w_mover = WindMover(Wind(timeseries=series, units='knots')) w_mover = WindMover(wind) model.movers += w_mover print 'adding a cats shio mover:' curr_file = get_datafile(os.path.join(base_dir, 'FloodTides.cur')) tide_file = get_datafile(os.path.join(base_dir, 'FloodTidesShio.txt')) c_mover = CatsMover(curr_file, tide=Tide(tide_file)) # this is the value in the file (default) c_mover.scale_refpoint = (-75.081667, 38.7995) c_mover.scale = True c_mover.scale_value = 1 model.movers += c_mover # TODO: cannot add this till environment base class is created model.environment += c_mover.tide print 'adding a cats mover:' curr_file = get_datafile(os.path.join(base_dir, 'Offshore.cur')) c_mover = CatsMover(curr_file) # but do need to scale (based on river stage) c_mover.scale = True c_mover.scale_refpoint = (-74.7483333, 38.898333) c_mover.scale_value = .03 model.movers += c_mover # # these are from windows they don't match Mac values... # pat1Angle 315; # pat1Speed 30; pat1SpeedUnits knots; # pat1ScaleToValue 0.314426 # # pat2Angle 225; # pat2Speed 30; pat2SpeedUnits knots; # pat2ScaleToValue 0.032882 # scaleBy WindStress print 'adding a component mover:' # if only using one current pattern # comp_mover = ComponentMover(curr_file1, None, wind) # # todo: following is not working when model is saved out - fix # comp_mover = ComponentMover(curr_file1, curr_file2, # Wind(timeseries=series, units='m/s')) # comp_mover = ComponentMover(curr_file1, curr_file2, # wind=Wind(filename=wind_file)) curr_file1 = get_datafile(os.path.join(base_dir, 'NW30ktwinds.cur')) curr_file2 = get_datafile(os.path.join(base_dir, 'SW30ktwinds.cur')) comp_mover = ComponentMover(curr_file1, curr_file2, wind) comp_mover.scale_refpoint = (-75.263166, 39.1428333) comp_mover.pat1_angle = 315 comp_mover.pat1_speed = 30 comp_mover.pat1_speed_units = 1 # comp_mover.pat1ScaleToValue = .314426 comp_mover.pat1_scale_to_value = .502035 comp_mover.pat2_angle = 225 comp_mover.pat2_speed = 30 comp_mover.pat2_speed_units = 1 # comp_mover.pat2ScaleToValue = .032882 comp_mover.pat2_scale_to_value = .021869 model.movers += comp_mover print 'adding a spill' end_time = start_time + timedelta(hours=12) spill = point_line_release_spill(num_elements=1000, release_time=start_time, # end_release_time=end_time, start_position=(-75.262319, 39.142987, 0.0), ) model.spills += spill return model
def make_model(images_dir=os.path.join(base_dir, 'images')): print 'initializing the model' start_time = datetime(2012, 9, 15, 12, 0) mapfile = get_datafile(os.path.join(base_dir, './LongIslandSoundMap.BNA')) gnome_map = MapFromBNA(mapfile, refloat_halflife=6) # hours # # the image output renderer # global renderer # one hour timestep model = Model(start_time=start_time, duration=timedelta(hours=48), time_step=3600, map=gnome_map, uncertain=False, cache_enabled=False) print 'adding a spill' et = floating_weathering(substance='FUEL OIL NO.6') spill = point_line_release_spill(num_elements=1000, start_position=(-72.419992, 41.202120, 0.0), release_time=start_time, amount=1000, units='kg', element_type=et) spill.amount_uncertainty_scale = 1.0 model.spills += spill print 'adding a RandomMover:' model.movers += RandomMover(diffusion_coef=500000, uncertain_factor=2) print 'adding a wind mover:' series = np.zeros((5, ), dtype=datetime_value_2d) series[0] = (start_time, (10, 45)) series[1] = (start_time + timedelta(hours=18), (10, 90)) series[2] = (start_time + timedelta(hours=30), (10, 135)) series[3] = (start_time + timedelta(hours=42), (10, 180)) series[4] = (start_time + timedelta(hours=54), (10, 225)) wind = Wind(timeseries=series, units='m/s', speed_uncertainty_scale=0.5) model.movers += WindMover(wind) print 'adding a cats mover:' curr_file = get_datafile(os.path.join(base_dir, r"./LI_tidesWAC.CUR")) tide_file = get_datafile(os.path.join(base_dir, r"./CLISShio.txt")) c_mover = CatsMover(curr_file, tide=Tide(tide_file)) model.movers += c_mover model.environment += c_mover.tide print 'adding Weatherers' water_env = Water(311.15) model.environment += water_env model.weatherers += [Evaporation(water_env, wind), Dispersion(), Burn(), Skimmer()] print 'adding outputters' model.outputters += WeatheringOutput() return model
import numpy as np import pytest # from gnome.basic_types import oil_status from gnome.utilities import time_utils from gnome.environment import Tide from gnome.spill import SpatialRelease, Spill, point_line_release_spill from gnome.movers import CatsMover from gnome.outputters import CurrentJsonOutput from ..conftest import testdata td = Tide(filename=testdata['CatsMover']['tide']) c_cats = CatsMover(testdata['CatsMover']['curr'], tide=td) rel_time = datetime(2012, 9, 15, 12) time_step = 15 * 60 # seconds model_time = time_utils.sec_to_date(time_utils.date_to_sec(rel_time)) @pytest.fixture(scope='function') def model(sample_model, output_dir): model = sample_model['model'] rel_start_pos = sample_model['release_start_pos'] rel_end_pos = sample_model['release_end_pos'] model.cache_enabled = True model.uncertain = True
def make_model(images_dir=os.path.join(base_dir, 'images')): print 'initializing the model' start_time = datetime(2013, 2, 13, 9, 0) # 1/2 hr in seconds model = Model(start_time=start_time, duration=timedelta(days=2), time_step=30 * 60, uncertain=False) print 'adding the map' mapfile = get_datafile(os.path.join(base_dir, 'GuamMap.bna')) model.map = MapFromBNA(mapfile, refloat_halflife=6) # hours print 'adding outputters' renderer = Renderer(mapfile, images_dir, image_size=(800, 600)) renderer.viewport = ((144.6, 13.4), (144.7, 13.5)) model.outputters += renderer netcdf_file = os.path.join(base_dir, 'script_guam.nc') scripting.remove_netcdf(netcdf_file) model.outputters += NetCDFOutput(netcdf_file, which_data='all') print 'adding a spill' end_time = start_time + timedelta(hours=6) spill = point_line_release_spill(num_elements=10, start_position=(144.664166, 13.441944, 0.0), release_time=start_time, end_release_time=end_time) model.spills += spill print 'adding a RandomMover:' model.movers += RandomMover(diffusion_coef=50000) print 'adding a wind mover:' series = np.zeros((4, ), dtype=datetime_value_2d) series[0] = (start_time, (5, 135)) series[1] = (start_time + timedelta(hours=23), (5, 135)) series[2] = (start_time + timedelta(hours=25), (5, 0)) series[3] = (start_time + timedelta(hours=48), (5, 0)) wind = Wind(timeseries=series, units='knot') w_mover = WindMover(wind) model.movers += w_mover model.environment += w_mover.wind print 'adding a cats mover:' curr_file = get_datafile(os.path.join(base_dir, 'OutsideWAC.cur')) c_mover = CatsMover(curr_file) c_mover.scale = True c_mover.scale_refpoint = (144.601, 13.42) c_mover.scale_value = .15 model.movers += c_mover print 'adding a cats shio mover:' curr_file = get_datafile(os.path.join(base_dir, 'WACFloodTide.cur')) tide_file = get_datafile(os.path.join(base_dir, 'WACFTideShioHts.txt')) c_mover = CatsMover(curr_file, tide=Tide(tide_file)) # this is different from the value in the file! c_mover.scale_refpoint = (144.621667, 13.45) c_mover.scale = True c_mover.scale_value = 1 # will need the fScaleFactor for heights files # c_mover.time_dep.scale_factor = 1.1864 c_mover.tide.scale_factor = 1.1864 model.movers += c_mover model.environment += c_mover.tide return model
def make_model(images_dir=os.path.join(base_dir, 'images')): # create the maps: print 'creating the maps' mapfile = get_datafile(os.path.join(base_dir, './MassBayMap.bna')) gnome_map = MapFromBNA(mapfile, refloat_halflife=1) # hours renderer = Renderer(mapfile, images_dir, size=(800, 800), projection_class=GeoProjection) print 'initializing the model' start_time = datetime(2013, 3, 12, 10, 0) # 15 minutes in seconds # Default to now, rounded to the nearest hour model = Model(time_step=900, start_time=start_time, duration=timedelta(days=1), map=gnome_map, uncertain=False) print 'adding outputters' model.outputters += renderer netcdf_file = os.path.join(base_dir, 'script_boston.nc') scripting.remove_netcdf(netcdf_file) model.outputters += NetCDFOutput(netcdf_file, which_data='all') print 'adding a RandomMover:' model.movers += RandomMover(diffusion_coef=100000) print 'adding a wind mover:' series = np.zeros((2, ), dtype=datetime_value_2d) series[0] = (start_time, (5, 180)) series[1] = (start_time + timedelta(hours=18), (5, 180)) w_mover = WindMover(Wind(timeseries=series, units='m/s')) model.movers += w_mover model.environment += w_mover.wind print 'adding a cats shio mover:' curr_file = get_datafile(os.path.join(base_dir, r"./EbbTides.cur")) tide_file = get_datafile(os.path.join(base_dir, r"./EbbTidesShio.txt")) c_mover = CatsMover(curr_file, tide=Tide(tide_file)) # this is the value in the file (default) c_mover.scale_refpoint = (-70.8875, 42.321333) c_mover.scale = True c_mover.scale_value = -1 model.movers += c_mover # TODO: cannot add this till environment base class is created model.environment += c_mover.tide print 'adding a cats ossm mover:' # ossm_file = get_datafile(os.path.join(base_dir, # r"./MerrimackMassCoastOSSM.txt")) curr_file = get_datafile( os.path.join(base_dir, r"./MerrimackMassCoast.cur")) tide_file = get_datafile( os.path.join(base_dir, r"./MerrimackMassCoastOSSM.txt")) c_mover = CatsMover(curr_file, tide=Tide(tide_file)) # but do need to scale (based on river stage) c_mover.scale = True c_mover.scale_refpoint = (-70.65, 42.58333) c_mover.scale_value = 1. model.movers += c_mover model.environment += c_mover.tide print 'adding a cats mover:' curr_file = get_datafile(os.path.join(base_dir, r"MassBaySewage.cur")) c_mover = CatsMover(curr_file) # but do need to scale (based on river stage) c_mover.scale = True c_mover.scale_refpoint = (-70.78333, 42.39333) # the scale factor is 0 if user inputs no sewage outfall effects c_mover.scale_value = .04 model.movers += c_mover # pat1Angle 315; # pat1Speed 19.44; pat1SpeedUnits knots; # pat1ScaleToValue 0.138855 # # pat2Angle 225; # pat2Speed 19.44; pat2SpeedUnits knots; # pat2ScaleToValue 0.05121 # # scaleBy WindStress print "adding a component mover:" component_file1 = get_datafile(os.path.join(base_dir, r"./WAC10msNW.cur")) component_file2 = get_datafile(os.path.join(base_dir, r"./WAC10msSW.cur")) comp_mover = ComponentMover(component_file1, component_file2, w_mover.wind) # todo: callback did not work correctly below - fix! # comp_mover = ComponentMover(component_file1, # component_file2, # Wind(timeseries=series, units='m/s')) comp_mover.scale_refpoint = (-70.855, 42.275) comp_mover.pat1_angle = 315 comp_mover.pat1_speed = 19.44 comp_mover.pat1_speed_units = 1 comp_mover.pat1ScaleToValue = .138855 comp_mover.pat2_angle = 225 comp_mover.pat2_speed = 19.44 comp_mover.pat2_speed_units = 1 comp_mover.pat2ScaleToValue = .05121 model.movers += comp_mover print 'adding a spill' end_time = start_time + timedelta(hours=12) spill = point_line_release_spill(num_elements=1000, start_position=(-70.911432, 42.369142, 0.0), release_time=start_time, end_release_time=end_time) model.spills += spill return model
def test_certain_uncertain(): """ make sure certain and uncertain loop results in different deltas """ delta = test_loop() u_delta = test_uncertain_loop() print print delta print u_delta assert np.all(delta[:, :2] != u_delta[:, :2]) assert np.all(delta[:, 2] == u_delta[:, 2]) c_cats = CatsMover(curr_file) 0 def test_default_props(): """ test default properties """ assert c_cats.uncertain_duration == 48.0 assert c_cats.uncertain_time_delay == 0 assert c_cats.up_cur_uncertain == 0.3 assert c_cats.down_cur_uncertain == -0.3 assert c_cats.right_cur_uncertain == 0.1 assert c_cats.left_cur_uncertain == -0.1 assert c_cats.scale is False
def make_model(uncertain=False, geojson_output=False): print 'initializing the model' start_time = datetime(2012, 9, 15, 12, 0) mapfile = testdata["lis"]["map"] gnome_map = MapFromBNA(mapfile, refloat_halflife=6) # hours # # the image output renderer # global renderer # one hour timestep model = Model(start_time=start_time, duration=timedelta(hours=48), time_step=3600, map=gnome_map, uncertain=uncertain, cache_enabled=False) print 'adding a spill' spill = point_line_release_spill(num_elements=1000, start_position=(-72.419992, 41.202120, 0.0), release_time=start_time, amount=1000, substance=test_oil, units='kg') spill.amount_uncertainty_scale = 1.0 model.spills += spill print 'adding a RandomMover:' model.movers += RandomMover(diffusion_coef=500000, uncertain_factor=2) print 'adding a wind mover:' series = np.zeros((5, ), dtype=datetime_value_2d) series[0] = (start_time, (20, 45)) series[1] = (start_time + timedelta(hours=18), (20, 90)) series[2] = (start_time + timedelta(hours=30), (20, 135)) series[3] = (start_time + timedelta(hours=42), (20, 180)) series[4] = (start_time + timedelta(hours=54), (20, 225)) wind = Wind(timeseries=series, units='m/s', speed_uncertainty_scale=0.05) model.movers += WindMover(wind) print 'adding a cats mover:' c_mover = CatsMover(testdata["lis"]["cats_curr"], tide=Tide(testdata["lis"]["cats_tide"])) model.movers += c_mover model.environment += c_mover.tide print 'adding Weatherers' rel_time = model.spills[0].get('release_time') skim_start = rel_time + timedelta(hours=4) amount = spill.amount units = spill.units # define skimmer/burn cleanup options skimmer = Skimmer(0.3 * amount, units=units, efficiency=0.3, active_start=skim_start, active_stop=skim_start + timedelta(hours=4)) # thickness = 1m so area is just 20% of volume volume = spill.get_mass() / spill.get('substance').get_density() burn = Burn(0.2 * volume, 1.0, active_start=skim_start, efficiency=.9) c_disp = ChemicalDispersion(0.1, efficiency=0.5, active_start=skim_start, active_stop=skim_start + timedelta(hours=1)) water_env = Water(311.15) model.environment += water_env model.weatherers += [Evaporation(water_env, wind), c_disp, burn, skimmer] print 'adding outputters' model.outputters += WeatheringOutput() if geojson_output: model.outputters += TrajectoryGeoJsonOutput() return model
def make_model(images_dir=os.path.join(base_dir, 'images')): # create the maps: print 'creating the maps' mapfile = get_datafile(os.path.join(base_dir, 'SanJuanMap.bna')) gnome_map = MapFromBNA(mapfile, refloat_halflife=1, raster_size=1024 * 1024) renderer = Renderer(mapfile, images_dir, size=(800, 800), projection_class=GeoProjection) renderer.viewport = ((-66.24, 18.39), (-66.1, 18.55)) print 'initializing the model' start_time = datetime(2014, 9, 3, 13, 0) # 15 minutes in seconds # Default to now, rounded to the nearest hour model = Model(time_step=900, start_time=start_time, duration=timedelta(days=1), map=gnome_map, uncertain=False) print 'adding outputters' model.outputters += renderer netcdf_file = os.path.join(base_dir, 'script_san_juan.nc') scripting.remove_netcdf(netcdf_file) model.outputters += NetCDFOutput(netcdf_file, which_data='all') print 'adding a RandomMover:' model.movers += RandomMover(diffusion_coef=100000) print 'adding a wind mover:' series = np.zeros((2, ), dtype=datetime_value_2d) series[0] = (start_time, (0, 270)) series[1] = (start_time + timedelta(hours=18), (0, 270)) wind = Wind(timeseries=series, units='m/s') w_mover = WindMover(wind) model.movers += w_mover print 'adding a cats shio mover:' # need to add the scale_factor for the tide heights file curr_file = get_datafile(os.path.join(base_dir, 'EbbTides.cur')) tide_file = get_datafile(os.path.join(base_dir, 'EbbTidesShioHt.txt')) c_mover = CatsMover(curr_file, tide=Tide(tide_file, scale_factor=.15)) # this is the value in the file (default) c_mover.scale_refpoint = (-66.116667, 18.458333) c_mover.scale = True c_mover.scale_value = 1.0 # c_mover.tide.scale_factor = 0.15 model.movers += c_mover print 'adding a cats mover:' curr_file = get_datafile(os.path.join(base_dir, 'Offshore.cur')) c_mover = CatsMover(curr_file) # this is the value in the file (default) # c_mover.scale_refpoint = (-66.082836, 18.469334) c_mover.scale_refpoint = (-66.084333333, 18.46966667) c_mover.scale = True c_mover.scale_value = 0.1 model.movers += c_mover print 'adding a spill' end_time = start_time + timedelta(hours=12) spill = point_line_release_spill(num_elements=1000, release_time=start_time, start_position=(-66.16374, 18.468054, 0.0), # start_position=(-66.129099, # 18.465332, 0.0), # end_release_time=end_time, ) model.spills += spill return model
def make_model(images_dir=os.path.join(base_dir, 'images')): # create the maps: print 'creating the maps' mapfile = get_datafile(os.path.join(base_dir, './MassBayMap.bna')) gnome_map = MapFromBNA(mapfile, refloat_halflife=1) # hours renderer = Renderer(mapfile, images_dir, size=(800, 800), projection_class=GeoProjection) print 'initializing the model' start_time = datetime(2013, 3, 12, 10, 0) # 15 minutes in seconds # Default to now, rounded to the nearest hour model = Model(time_step=900, start_time=start_time, duration=timedelta(days=1), map=gnome_map, uncertain=False) print 'adding outputters' model.outputters += renderer netcdf_file = os.path.join(base_dir, 'script_boston.nc') scripting.remove_netcdf(netcdf_file) model.outputters += NetCDFOutput(netcdf_file, which_data='all') print 'adding a RandomMover:' model.movers += RandomMover(diffusion_coef=100000) print 'adding a wind mover:' series = np.zeros((2, ), dtype=datetime_value_2d) series[0] = (start_time, (5, 180)) series[1] = (start_time + timedelta(hours=18), (5, 180)) w_mover = WindMover(Wind(timeseries=series, units='m/s')) model.movers += w_mover model.environment += w_mover.wind print 'adding a cats shio mover:' curr_file = get_datafile(os.path.join(base_dir, r"./EbbTides.cur")) tide_file = get_datafile(os.path.join(base_dir, r"./EbbTidesShio.txt")) c_mover = CatsMover(curr_file, tide=Tide(tide_file)) # this is the value in the file (default) c_mover.scale_refpoint = (-70.8875, 42.321333) c_mover.scale = True c_mover.scale_value = -1 model.movers += c_mover # TODO: cannot add this till environment base class is created model.environment += c_mover.tide print 'adding a cats ossm mover:' #ossm_file = get_datafile(os.path.join(base_dir, # r"./MerrimackMassCoastOSSM.txt")) curr_file = get_datafile(os.path.join(base_dir, r"./MerrimackMassCoast.cur")) tide_file = get_datafile(os.path.join(base_dir, r"./MerrimackMassCoastOSSM.txt")) c_mover = CatsMover(curr_file, tide=Tide(tide_file)) # but do need to scale (based on river stage) c_mover.scale = True c_mover.scale_refpoint = (-70.65, 42.58333) c_mover.scale_value = 1. model.movers += c_mover model.environment += c_mover.tide print 'adding a cats mover:' curr_file = get_datafile(os.path.join(base_dir, r"MassBaySewage.cur")) c_mover = CatsMover(curr_file) # but do need to scale (based on river stage) c_mover.scale = True c_mover.scale_refpoint = (-70.78333, 42.39333) # the scale factor is 0 if user inputs no sewage outfall effects c_mover.scale_value = .04 model.movers += c_mover # print "adding a component mover:" # component_file1 = os.path.join( base_dir, r"./WAC10msNW.cur") # component_file2 = os.path.join( base_dir, r"./WAC10msSW.cur") print 'adding a spill' end_time = start_time + timedelta(hours=12) spill = point_line_release_spill(num_elements=1000, start_position=(-70.911432, 42.369142, 0.0), release_time=start_time, end_release_time=end_time) model.spills += spill return model
def make_model(images_dir, uncertain=False): ''' Create a model from the data in sample_data/boston_data It contains: - the GeoProjection - wind mover - random mover - cats shio mover - cats ossm mover - plain cats mover ''' mapfile = get_datafile(os.path.join(datafiles, './MassBayMap.bna')) start_time = datetime(2013, 2, 13, 9, 0) model = Model(start_time=start_time, duration=timedelta(days=2), time_step=timedelta(minutes=30).total_seconds(), uncertain=uncertain, map=MapFromBNA(mapfile, refloat_halflife=1)) print 'adding a renderer' model.outputters += Renderer(mapfile, images_dir, size=(800, 600)) print 'adding a spill' start_position = (144.664166, 13.441944, 0.0) end_release_time = start_time + timedelta(hours=6) model.spills += point_line_release_spill(num_elements=1000, start_position=start_position, release_time=start_time, end_release_time=end_release_time) # need a scenario for SimpleMover # model.movers += SimpleMover(velocity=(1.0, -1.0, 0.0)) print 'adding a RandomMover:' model.movers += RandomMover(diffusion_coef=100000) print 'adding a wind mover:' series = np.zeros((2, ), dtype=datetime_value_2d) series[0] = (start_time, (5, 180)) series[1] = (start_time + timedelta(hours=18), (5, 180)) w_mover = WindMover(Wind(timeseries=series, units='m/s')) model.movers += w_mover model.environment += w_mover.wind print 'adding a cats shio mover:' d_file1 = get_datafile(os.path.join(datafiles, './EbbTides.cur')) d_file2 = get_datafile(os.path.join(datafiles, './EbbTidesShio.txt')) c_mover = CatsMover(d_file1, tide=Tide(d_file2)) # c_mover.scale_refpoint should automatically get set from tide object c_mover.scale = True # default value c_mover.scale_value = -1 # tide object automatically gets added by model model.movers += c_mover print 'adding a cats ossm mover:' d_file1 = get_datafile(os.path.join(datafiles, './MerrimackMassCoast.cur')) d_file2 = get_datafile(os.path.join(datafiles, './MerrimackMassCoastOSSM.txt')) c_mover = CatsMover(d_file1, tide=Tide(d_file2)) c_mover.scale = True # but do need to scale (based on river stage) c_mover.scale_refpoint = (-70.65, 42.58333) c_mover.scale_value = 1. #model.movers += c_mover #model.environment += c_mover.tide print 'adding a cats mover:' d_file1 = get_datafile(os.path.join(datafiles, 'MassBaySewage.cur')) c_mover = CatsMover(d_file1) c_mover.scale = True # but do need to scale (based on river stage) c_mover.scale_refpoint = (-70.78333, 42.39333) # the scale factor is 0 if user inputs no sewage outfall effects c_mover.scale_value = .04 model.movers += c_mover print 'adding a Weatherer' weatherer = Weatherer() model.weatherers += weatherer return model
''' Run the following save/load test on multiple pygnome objects so collect tests here and parametrize it by the objects ''' base_dir = os.path.dirname(__file__) # For WindMover test_save_load in test_wind_mover g_objects = ( GridCurrent.from_netCDF(testdata['GridCurrentMover']['curr_tri']), Tide(testdata['CatsMover']['tide']), Wind(filename=testdata['ComponentMover']['wind']), Wind(timeseries=(sec_to_date(24 * 60 * 60), (0, 0)), units='mps'), Water(temperature=273), RandomMover(), CatsMover(testdata['CatsMover']['curr']), CatsMover(testdata['CatsMover']['curr'], tide=Tide(testdata['CatsMover']['tide'])), ComponentMover(testdata['ComponentMover']['curr']), ComponentMover(testdata['ComponentMover']['curr'], wind=Wind(filename=testdata['ComponentMover']['wind'])), RandomMover3D(), SimpleMover(velocity=(10.0, 10.0, 0.0)), map.MapFromBNA(testdata['MapFromBNA']['testmap'], 6), NetCDFOutput(os.path.join(base_dir, u'xtemp.nc')), Renderer(testdata['Renderer']['bna_sample'], os.path.join(base_dir, 'output_dir')), WeatheringOutput(), spill.PointLineRelease(release_time=datetime.now(), num_elements=10, start_position=(0, 0, 0)),
def make_model(images_dir=os.path.join(base_dir, 'images')): # create the maps: print 'creating the maps' mapfile = get_datafile(os.path.join(base_dir, 'SanJuanMap.bna')) gnome_map = MapFromBNA(mapfile, refloat_halflife=1, raster_size=1024 * 1024) renderer = Renderer(mapfile, images_dir, image_size=(800, 800), projection_class=GeoProjection) renderer.viewport = ((-66.24, 18.39), (-66.1, 18.55)) print 'initializing the model' start_time = datetime(2014, 9, 3, 13, 0) # 15 minutes in seconds # Default to now, rounded to the nearest hour model = Model(time_step=900, start_time=start_time, duration=timedelta(days=1), map=gnome_map, uncertain=False) print 'adding outputters' model.outputters += renderer netcdf_file = os.path.join(base_dir, 'script_san_juan.nc') scripting.remove_netcdf(netcdf_file) model.outputters += NetCDFOutput(netcdf_file, which_data='all') print 'adding a RandomMover:' model.movers += RandomMover(diffusion_coef=100000) print 'adding a wind mover:' series = np.zeros((2, ), dtype=datetime_value_2d) series[0] = (start_time, (0, 270)) series[1] = (start_time + timedelta(hours=18), (0, 270)) wind = Wind(timeseries=series, units='m/s') w_mover = WindMover(wind) wind.extrapolation_is_allowed = True model.movers += w_mover print 'adding a cats shio mover:' # need to add the scale_factor for the tide heights file curr_file = get_datafile(os.path.join(base_dir, 'EbbTides.cur')) tide_file = get_datafile(os.path.join(base_dir, 'EbbTidesShioHt.txt')) c_mover = CatsMover(curr_file, tide=Tide(tide_file, scale_factor=.15)) # this is the value in the file (default) c_mover.scale_refpoint = (-66.116667, 18.458333) c_mover.scale = True c_mover.scale_value = 1.0 # c_mover.tide.scale_factor = 0.15 model.movers += c_mover print 'adding a cats mover:' curr_file = get_datafile(os.path.join(base_dir, 'Offshore.cur')) c_mover = CatsMover(curr_file) # this is the value in the file (default) # c_mover.scale_refpoint = (-66.082836, 18.469334) c_mover.scale_refpoint = (-66.084333333, 18.46966667) c_mover.scale = True c_mover.scale_value = 0.1 model.movers += c_mover print 'adding a spill' end_time = start_time + timedelta(hours=12) spill = point_line_release_spill( num_elements=1000, release_time=start_time, start_position=(-66.16374, 18.468054, 0.0), # start_position=(-66.129099, # 18.465332, 0.0), # end_release_time=end_time, ) model.spills += spill return model
def make_model(uncertain=False, mode='gnome'): ''' Create a model from the data in sample_data/boston_data It contains: - the GeoProjection - wind mover - random mover - cats shio mover - cats ossm mover - plain cats mover ''' start_time = datetime(2013, 2, 13, 9, 0) model = Model(start_time=start_time, duration=timedelta(days=2), time_step=timedelta(minutes=30).total_seconds(), uncertain=uncertain, map=MapFromBNA(testdata['boston_data']['map'], refloat_halflife=1), mode=mode) print 'adding a spill' start_position = (144.664166, 13.441944, 0.0) end_release_time = start_time + timedelta(hours=6) spill_amount = 1000.0 spill_units = 'kg' model.spills += point_line_release_spill(num_elements=1000, start_position=start_position, release_time=start_time, end_release_time=end_release_time, amount=spill_amount, units=spill_units, substance=test_oil) spill = model.spills[-1] spill_volume = spill.get_mass() / spill.substance.density_at_temp() # need a scenario for SimpleMover # model.movers += SimpleMover(velocity=(1.0, -1.0, 0.0)) print 'adding a RandomMover:' model.movers += RandomMover(diffusion_coef=100000) print 'adding a wind mover:' series = np.zeros((2, ), dtype=datetime_value_2d) series[0] = (start_time, (5, 180)) series[1] = (start_time + timedelta(hours=18), (5, 180)) w_mover = WindMover(Wind(timeseries=series, units='m/s')) model.movers += w_mover model.environment += w_mover.wind print 'adding a cats shio mover:' c_mover = CatsMover(testdata['boston_data']['cats_curr2'], tide=Tide(testdata['boston_data']['cats_shio'])) # c_mover.scale_refpoint should automatically get set from tide object c_mover.scale = True # default value c_mover.scale_value = -1 # tide object automatically gets added by model model.movers += c_mover print 'adding a cats ossm mover:' c_mover = CatsMover(testdata['boston_data']['cats_curr2'], tide=Tide(testdata['boston_data']['cats_ossm'])) c_mover.scale = True # but do need to scale (based on river stage) c_mover.scale_refpoint = (-70.65, 42.58333, 0.0) c_mover.scale_value = 1. print 'adding a cats mover:' c_mover = CatsMover(testdata['boston_data']['cats_curr3']) c_mover.scale = True # but do need to scale (based on river stage) c_mover.scale_refpoint = (-70.78333, 42.39333, 0.0) # the scale factor is 0 if user inputs no sewage outfall effects c_mover.scale_value = .04 model.movers += c_mover # TODO: seg faulting for component mover - comment test for now # print "adding a component mover:" # comp_mover = ComponentMover(testdata['boston_data']['component_curr1'], # testdata['boston_data']['component_curr2'], # w_mover.wind) # TODO: callback did not work correctly below - fix! # comp_mover = ComponentMover(component_file1, # component_file2, # Wind(timeseries=series, units='m/s')) # comp_mover.ref_point = (-70.855, 42.275) # comp_mover.pat1_angle = 315 # comp_mover.pat1_speed = 19.44 # comp_mover.pat1_speed_units = 1 # comp_mover.pat1ScaleToValue = .138855 # comp_mover.pat2_angle = 225 # comp_mover.pat2_speed = 19.44 # comp_mover.pat2_speed_units = 1 # comp_mover.pat2ScaleToValue = .05121 # model.movers += comp_mover print 'adding a Weatherer' model.environment += Water(311.15) skim_start = start_time + timedelta(hours=3) model.weatherers += [Evaporation(), Skimmer(spill_amount * .5, spill_units, efficiency=.3, active_start=skim_start, active_stop=skim_start + timedelta(hours=2)), Burn(0.2 * spill_volume, 1.0, skim_start, efficiency=0.9)] model.outputters += \ CurrentJsonOutput(model.find_by_attr('_ref_as', 'current_movers', model.movers, allitems=True)) return model
def make_model(images_dir=os.path.join(base_dir, 'images')): # create the maps: print 'creating the maps' mapfile = get_datafile(os.path.join(base_dir, './DelawareRiverMap.bna')) gnome_map = MapFromBNA(mapfile, refloat_halflife=1) # hours renderer = Renderer(mapfile, images_dir, size=(800, 800), projection_class=GeoProjection) print 'initializing the model' start_time = datetime(2012, 8, 20, 13, 0) # 15 minutes in seconds # Default to now, rounded to the nearest hour model = Model(time_step=900, start_time=start_time, duration=timedelta(days=1), map=gnome_map, uncertain=False) print 'adding outputters' model.outputters += renderer netcdf_file = os.path.join(base_dir, 'script_delaware_bay.nc') scripting.remove_netcdf(netcdf_file) model.outputters += NetCDFOutput(netcdf_file, which_data='all') print 'adding a RandomMover:' model.movers += RandomMover(diffusion_coef=100000) print 'adding a wind mover:' series = np.zeros((2, ), dtype=datetime_value_2d) series[0] = (start_time, (5, 270)) series[1] = (start_time + timedelta(hours=18), (5, 270)) wind_file = get_datafile(os.path.join(base_dir, r"ConstantWind.WND")) # wind = Wind(filename=wind_file) wind = Wind(timeseries=series, units='m/s') w_mover = WindMover(wind) #w_mover = WindMover(Wind(timeseries=series, units='knots')) model.movers += w_mover print 'adding a cats shio mover:' curr_file = get_datafile(os.path.join(base_dir, r"./FloodTides.cur")) tide_file = get_datafile(os.path.join(base_dir, r"./FloodTidesShio.txt")) c_mover = CatsMover(curr_file, tide=Tide(tide_file)) # this is the value in the file (default) c_mover.scale_refpoint = (-75.081667,38.7995) c_mover.scale = True c_mover.scale_value = 1 model.movers += c_mover # TODO: cannot add this till environment base class is created model.environment += c_mover.tide print 'adding a cats mover:' curr_file = get_datafile(os.path.join(base_dir, r"./Offshore.cur")) c_mover = CatsMover(curr_file) # but do need to scale (based on river stage) c_mover.scale = True c_mover.scale_refpoint = (-74.7483333,38.898333) c_mover.scale_value = .03 model.movers += c_mover # # pat1Angle 315; pat1Speed 30; pat1SpeedUnits knots; pat1ScaleToValue 0.314426 # these are from windows they don't match Mac values... # pat2Angle 225; pat2Speed 30; pat2SpeedUnits knots; pat2ScaleToValue 0.032882 # scaleBy WindStress print 'adding a component mover:' curr_file1 = get_datafile(os.path.join(base_dir, r"NW30ktwinds.cur")) curr_file2 = get_datafile(os.path.join(base_dir, r"SW30ktwinds.cur")) comp_mover = ComponentMover(curr_file1, curr_file2, wind) #todo: following is not working when model is saved out - fix #comp_mover = ComponentMover(curr_file1, curr_file2, Wind(timeseries=series, units='m/s')) #comp_mover = ComponentMover(curr_file1, curr_file2, wind=Wind(filename=wind_file)) comp_mover.ref_point = (-75.263166,39.1428333) comp_mover.pat1_angle = 315 comp_mover.pat1_speed = 30 comp_mover.pat1_speed_units = 1 #comp_mover.pat1ScaleToValue = .314426 comp_mover.pat1_scale_to_value = .502035 comp_mover.pat2_angle = 225 comp_mover.pat2_speed = 30 comp_mover.pat2_speed_units = 1 #comp_mover.pat2ScaleToValue = .032882 comp_mover.pat2_scale_to_value = .021869 model.movers += comp_mover print 'adding a spill' end_time = start_time + timedelta(hours=12) spill = point_line_release_spill(num_elements=1000, start_position=(-75.262319, 39.142987, 0.0), release_time=start_time) #end_release_time=end_time) model.spills += spill return model
def make_model(uncertain=False, mode='gnome'): ''' Create a model from the data in sample_data/boston_data It contains: - the GeoProjection - wind mover - random mover - cats shio mover - cats ossm mover - plain cats mover ''' start_time = datetime(2013, 2, 13, 9, 0) model = Model(start_time=start_time, duration=timedelta(days=2), time_step=timedelta(minutes=30).total_seconds(), uncertain=uncertain, map=MapFromBNA(testdata['boston_data']['map'], refloat_halflife=1), mode=mode) print 'adding a spill' start_position = (144.664166, 13.441944, 0.0) end_release_time = start_time + timedelta(hours=6) spill_amount = 1000.0 spill_units = 'kg' model.spills += point_line_release_spill(num_elements=1000, start_position=start_position, release_time=start_time, end_release_time=end_release_time, amount=spill_amount, units=spill_units, substance=test_oil) spill = model.spills[-1] spill_volume = spill.get_mass() / spill.substance.density_at_temp() # need a scenario for SimpleMover # model.movers += SimpleMover(velocity=(1.0, -1.0, 0.0)) print 'adding a RandomMover:' model.movers += RandomMover(diffusion_coef=100000) print 'adding a wind mover:' series = np.zeros((2, ), dtype=datetime_value_2d) series[0] = (start_time, (5, 180)) series[1] = (start_time + timedelta(hours=18), (5, 180)) w_mover = WindMover(Wind(timeseries=series, units='m/s')) model.movers += w_mover model.environment += w_mover.wind print 'adding a cats shio mover:' c_mover = CatsMover(testdata['boston_data']['cats_curr2'], tide=Tide(testdata['boston_data']['cats_shio'])) # c_mover.scale_refpoint should automatically get set from tide object c_mover.scale = True # default value c_mover.scale_value = -1 # tide object automatically gets added by model model.movers += c_mover print 'adding a cats ossm mover:' c_mover = CatsMover(testdata['boston_data']['cats_curr2'], tide=Tide(testdata['boston_data']['cats_ossm'])) c_mover.scale = True # but do need to scale (based on river stage) c_mover.scale_refpoint = (-70.65, 42.58333, 0.0) c_mover.scale_value = 1. print 'adding a cats mover:' c_mover = CatsMover(testdata['boston_data']['cats_curr3']) c_mover.scale = True # but do need to scale (based on river stage) c_mover.scale_refpoint = (-70.78333, 42.39333, 0.0) # the scale factor is 0 if user inputs no sewage outfall effects c_mover.scale_value = .04 model.movers += c_mover # TODO: seg faulting for component mover - comment test for now # print "adding a component mover:" # comp_mover = ComponentMover(testdata['boston_data']['component_curr1'], # testdata['boston_data']['component_curr2'], # w_mover.wind) # TODO: callback did not work correctly below - fix! # comp_mover = ComponentMover(component_file1, # component_file2, # Wind(timeseries=series, units='m/s')) # comp_mover.ref_point = (-70.855, 42.275) # comp_mover.pat1_angle = 315 # comp_mover.pat1_speed = 19.44 # comp_mover.pat1_speed_units = 1 # comp_mover.pat1ScaleToValue = .138855 # comp_mover.pat2_angle = 225 # comp_mover.pat2_speed = 19.44 # comp_mover.pat2_speed_units = 1 # comp_mover.pat2ScaleToValue = .05121 # model.movers += comp_mover print 'adding a Weatherer' model.environment += Water(311.15) skim_start = start_time + timedelta(hours=3) model.weatherers += [ Evaporation(), Skimmer(spill_amount * .5, spill_units, efficiency=.3, active_range=(skim_start, skim_start + timedelta(hours=2))), Burn(0.2 * spill_volume, 1.0, (skim_start, InfDateTime('inf')), efficiency=0.9) ] model.outputters += \ CurrentJsonOutput(model.find_by_attr('_ref_as', 'current_movers', model.movers, allitems=True)) return model
def test_all_movers(start_time, release_delay, duration): ''' Tests that all the movers at least can be run Add new ones as they come along! ''' model = Model() model.time_step = timedelta(hours=1) model.duration = timedelta(seconds=model.time_step * duration) model.start_time = start_time start_loc = (1., 2., 0.) # random non-zero starting points # a spill - release after 5 timesteps release_time = (start_time + timedelta(seconds=model.time_step * release_delay)) model.spills += point_line_release_spill(num_elements=10, start_position=start_loc, release_time=release_time) # the land-water map model.map = gnome.map.GnomeMap() # the simplest of maps # simple mover model.movers += SimpleMover(velocity=(1., -1., 0.)) assert len(model.movers) == 1 # random mover model.movers += RandomMover(diffusion_coef=100000) assert len(model.movers) == 2 # wind mover series = np.array((start_time, (10, 45)), dtype=datetime_value_2d).reshape( (1, )) model.movers += WindMover(Wind(timeseries=series, units='meter per second')) assert len(model.movers) == 3 # CATS mover model.movers += CatsMover(testdata['CatsMover']['curr']) assert len(model.movers) == 4 # run the model all the way... num_steps_output = 0 for step in model: num_steps_output += 1 print 'running step:', step # test release happens correctly for all cases if release_delay < duration: # at least one get_move has been called after release assert np.all(model.spills.LE('positions')[:, :2] != start_loc[:2]) elif release_delay == duration: # particles are released after last step so no motion, # only initial _state assert np.all(model.spills.LE('positions') == start_loc) else: # release_delay > duration so nothing released though model ran assert len(model.spills.LE('positions')) == 0 # there is the zeroth step, too. calculated_steps = (model.duration.total_seconds() / model.time_step) + 1 assert num_steps_output == calculated_steps