def test_update_from_dict(self): gmap = GnomeMap() json_ = {'map_bounds': [(-10, 10), (10, 10), (10, -10), (-10, -10)]} assert np.all(gmap.map_bounds != json_['map_bounds']) gmap.update_from_dict(json_) assert np.all(gmap.map_bounds == json_['map_bounds'])
def test_new_from_dict(self, json_): context = json_['json_'] dict_ = GnomeMap.deserialize(json_) gmap = GnomeMap.new_from_dict(dict_) u_json_ = gmap.serialize(context) for key in json_: assert u_json_[key] == json_[key]
def test_update_from_dict(self): gmap = GnomeMap() json_ = gmap.serialize('save') json_['map_bounds'] = [(-10, 10), (10, 10), (10, -10), (-10, -10)] dict_ = gnome.map.GnomeMap.deserialize(json_) gmap.update_from_dict(dict_) u_json_ = gmap.serialize('save') for key in json_: assert u_json_[key] == json_[key]
def test_on_map_array(self): """ a little bit more complex tests and test of arrays of points """ # a concave map boundary map_bounds = ((-40.0, 50.0), (-40.0, 58.0), (-30.0, 58.0), (-35.0, 53.0), (-30.0, 50.0)) gmap = GnomeMap(map_bounds=map_bounds) points = ((-35, 55, 0.), (-45, 55, 0.)) result = gmap.on_map(points) # some points on the map: assert np.array_equal(result, (True, False))
def test_on_map(self): gmap = GnomeMap() assert gmap.on_map((0., 0., 0.)) is True # too big latitude print gmap.on_map((0., 91.0, 0.)) assert gmap.on_map((0., 91.0, 0.)) is False # too small latitude assert gmap.on_map((0., -91.0, 0.)) is False # too big langitude assert gmap.on_map((0., 361.0, 0.)) is False # too small langitude assert gmap.on_map((0., -361.0, 0.)) is False
def make_model(images_dir=os.path.join(base_dir, 'images')): print 'initializing the model' # set up the modeling environment start_time = datetime(2016, 9, 18, 1, 0) model = Model(start_time=start_time, duration=timedelta(days=3), time_step=30 * 60, uncertain=False) print 'adding the map' model.map = GnomeMap() # this is a "water world -- no land anywhere" # renderere is only top-down view on 2d -- but it's something renderer = Renderer( output_dir=images_dir, size=(1024, 768), output_timestep=timedelta(hours=1), ) renderer.viewport = ((-87.095, 27.595), (-87.905, 28.405)) print 'adding outputters' model.outputters += renderer # Also going to write the results out to a netcdf file netcdf_file = os.path.join(base_dir, 'gulf_tamoc.nc') scripting.remove_netcdf(netcdf_file) model.outputters += NetCDFOutput( netcdf_file, which_data='most', # output most of the data associated with the elements output_timestep=timedelta(hours=2)) print "adding Horizontal and Vertical diffusion" # Horizontal Diffusion model.movers += RandomMover(diffusion_coef=100000) # vertical diffusion (different above and below the mixed layer) model.movers += RandomVerticalMover( vertical_diffusion_coef_above_ml=50, vertical_diffusion_coef_below_ml=10, horizontal_diffusion_coef_above_ml=100000, horizontal_diffusion_coef_below_ml=100, mixed_layer_depth=10) print 'adding Rise Velocity' # droplets rise as a function of their density and radius model.movers += TamocRiseVelocityMover() print 'adding the 3D current mover' gc = GridCurrent.from_netCDF('HYCOM_3d.nc') model.movers += GridCurrentMover('HYCOM_3d.nc') # model.movers += SimpleMover(velocity=(0., 0, 0.)) # model.movers += constant_wind_mover(5, 315, units='knots') # Wind from a buoy w = Wind(filename='KIKT.osm') model.movers += WindMover(w) # Now to add in the TAMOC "spill" print "Adding TAMOC spill" model.spills += tamoc_spill.TamocSpill( release_time=start_time, start_position=(-87.5, 28.0, 2000), num_elements=30000, end_release_time=start_time + timedelta(days=2), name='TAMOC plume', TAMOC_interval=None, # how often to re-run TAMOC ) model.spills[0].data_sources['currents'] = gc return model
def get_gnomemap(): return GnomeMap(map_bounds=((10, 10), (15, 10), (15, 15), (10, 15)), spillable_area=((11, 11), (14, 11), (14, 14), (11, 14)), land_polys=None, name="Test Map for TideflatMap")
def test_allowable_spill_position(self): gmap = GnomeMap() assert gmap.allowable_spill_position((18.0, -87.0, 0.)) is True assert gmap.allowable_spill_position((370.0, -87.0, 0.)) is False
def make_model(images_dir=os.path.join(base_dir, 'images')): print 'initializing the model' # set up the modeling environment start_time = datetime(2004, 12, 31, 13, 0) model = Model(start_time=start_time, duration=timedelta(days=3), time_step=30 * 60, uncertain=False) print 'adding the map' model.map = GnomeMap() # this is a "water world -- no land anywhere" # renderere is only top-down view on 2d -- but it's something renderer = Renderer( output_dir=images_dir, size=(1024, 768), output_timestep=timedelta(hours=1), ) renderer.viewport = ((-.15, -.35), (.15, .35)) print 'adding outputters' model.outputters += renderer # Also going to write the results out to a netcdf file netcdf_file = os.path.join(base_dir, 'script_plume.nc') scripting.remove_netcdf(netcdf_file) model.outputters += NetCDFOutput( netcdf_file, which_data='most', # output most of the data associated with the elements output_timestep=timedelta(hours=2)) print "adding Horizontal and Vertical diffusion" # Horizontal Diffusion # model.movers += RandomMover(diffusion_coef=5) # vertical diffusion (different above and below the mixed layer) model.movers += RandomVerticalMover(vertical_diffusion_coef_above_ml=5, vertical_diffusion_coef_below_ml=.11, mixed_layer_depth=10) print 'adding Rise Velocity' # droplets rise as a function of their density and radius model.movers += RiseVelocityMover() print 'adding a circular current and eastward current' # This is .3 m/s south model.movers += PyCurrentMover(current=vg, default_num_method='Trapezoid', extrapolate=True) model.movers += SimpleMover(velocity=(0., -0.1, 0.)) # Now to add in the TAMOC "spill" print "Adding TAMOC spill" model.spills += tamoc_spill.TamocSpill( release_time=start_time, start_position=(0, 0, 1000), num_elements=1000, end_release_time=start_time + timedelta(days=1), name='TAMOC plume', TAMOC_interval=None, # how often to re-run TAMOC ) return model
def test_in_water(self): gmap = GnomeMap() assert gmap.in_water((18.0, -87.0, 0.)) assert gmap.in_water((370.0, -87.0, 0.)) is False
def test_on_land(self): gmap = GnomeMap() assert gmap.on_land((18.0, -87.0, 0.)) is False
def make_model(images_dir=os.path.join(base_dir, 'images')): print 'initializing the model' # set up the modeling environment start_time = datetime(2016, 9, 23, 0, 0) model = Model(start_time=start_time, duration=timedelta(days=2), time_step=30 * 60, uncertain=False) print 'adding the map' model.map = GnomeMap() # this is a "water world -- no land anywhere" # renderere is only top-down view on 2d -- but it's something renderer = Renderer(output_dir=images_dir, image_size=(1024, 768), output_timestep=timedelta(hours=1), ) renderer.viewport = ((196.14, 71.89), (196.18, 71.93)) print 'adding outputters' model.outputters += renderer # Also going to write the results out to a netcdf file netcdf_file = os.path.join(base_dir, 'script_arctic_plume.nc') scripting.remove_netcdf(netcdf_file) model.outputters += NetCDFOutput(netcdf_file, which_data='most', # output most of the data associated with the elements output_timestep=timedelta(hours=2)) print "adding Horizontal and Vertical diffusion" # Horizontal Diffusion model.movers += RandomMover(diffusion_coef=500) # vertical diffusion (different above and below the mixed layer) model.movers += RandomMover3D(vertical_diffusion_coef_above_ml=5, vertical_diffusion_coef_below_ml=.11, mixed_layer_depth=10) print 'adding Rise Velocity' # droplets rise as a function of their density and radius model.movers += TamocRiseVelocityMover() print 'adding a circular current and eastward current' fn = 'hycom_glb_regp17_2016092300_subset.nc' fn_ice = 'hycom-cice_ARCu0.08_046_2016092300_subset.nc' iconc = IceConcentration.from_netCDF(filename=fn_ice) ivel = IceVelocity.from_netCDF(filename=fn_ice, grid = iconc.grid) ic = IceAwareCurrent.from_netCDF(ice_concentration = iconc, ice_velocity= ivel, filename=fn) model.movers += PyCurrentMover(current = ic) model.movers += SimpleMover(velocity=(0., 0., 0.)) model.movers += constant_wind_mover(20, 315, units='knots') # Now to add in the TAMOC "spill" print "Adding TAMOC spill" model.spills += tamoc_spill.TamocSpill(release_time=start_time, start_position=(196.16, 71.91, 40.0), num_elements=1000, end_release_time=start_time + timedelta(days=1), name='TAMOC plume', TAMOC_interval=None, # how often to re-run TAMOC ) model.spills[0].data_sources['currents'] = ic return model
def make_model(images_dir=os.path.join(base_dir, 'images')): print 'initializing the model' start_time = datetime(2004, 12, 31, 13, 0) model = Model(start_time=start_time, duration=timedelta(days=3), time_step=30 * 60, uncertain=False) print 'adding the map' model.map = GnomeMap() # draw_ontop can be 'uncertain' or 'forecast' # 'forecast' LEs are in black, and 'uncertain' are in red # default is 'forecast' LEs draw on top renderer = Renderer( output_dir=images_dir, # size=(800, 600), output_timestep=timedelta(hours=1), draw_ontop='uncertain') renderer.viewport = ((-76.5, 37.), (-75.8, 38.)) print 'adding outputters' model.outputters += renderer netcdf_file = os.path.join(base_dir, 'script_plume.nc') scripting.remove_netcdf(netcdf_file) model.outputters += NetCDFOutput(netcdf_file, which_data='most', output_timestep=timedelta(hours=2)) print 'adding two spills' # Break the spill into two spills, first with the larger droplets # and second with the smaller droplets. # Split the total spill volume (100 m^3) to have most # in the larger droplet spill. # Smaller droplets start at a lower depth than larger wd = WeibullDistribution(alpha=1.8, lambda_=.00456, min_=.0002) # 200 micron min end_time = start_time + timedelta(hours=24) # spill = point_line_release_spill(num_elements=10, # amount=90, # default volume_units=m^3 # units='m^3', # start_position=(-76.126872, 37.680952, # 1700), # release_time=start_time, # end_release_time=end_time, # element_type=plume(distribution=wd, # density=600) # ) spill = subsurface_plume_spill( num_elements=10, start_position=(-76.126872, 37.680952, 1700), release_time=start_time, distribution=wd, amount=90, # default volume_units=m^3 units='m^3', end_release_time=end_time, density=600) model.spills += spill wd = WeibullDistribution(alpha=1.8, lambda_=.00456, max_=.0002) # 200 micron max spill = point_line_release_spill( num_elements=10, amount=90, units='m^3', start_position=(-76.126872, 37.680952, 1800), release_time=start_time, element_type=plume(distribution=wd, substance_name='oil_crude')) model.spills += spill print 'adding a RandomMover:' model.movers += RandomMover(diffusion_coef=50000) print 'adding a RiseVelocityMover:' model.movers += RiseVelocityMover() print 'adding a RandomVerticalMover:' model.movers += RandomVerticalMover(vertical_diffusion_coef_above_ml=5, vertical_diffusion_coef_below_ml=.11, mixed_layer_depth=10) # print 'adding a wind mover:' # series = np.zeros((2, ), dtype=gnome.basic_types.datetime_value_2d) # series[0] = (start_time, (30, 90)) # series[1] = (start_time + timedelta(hours=23), (30, 90)) # wind = Wind(timeseries=series, units='knot') # # default is .4 radians # w_mover = gnome.movers.WindMover(wind, uncertain_angle_scale=0) # # model.movers += w_mover print 'adding a simple mover:' s_mover = SimpleMover(velocity=(0.0, -.3, 0.0)) model.movers += s_mover return model