def make_model(images_dir=os.path.join(base_dir, 'images')): print 'initializing the model' start_time = datetime(2006, 3, 31, 20, 0) model = Model(start_time=start_time, duration=timedelta(days=3), time_step=30 * 60, uncertain=True) print 'adding the map' mapfile = get_datafile(os.path.join(base_dir, './coastSF.bna')) model.map = MapFromBNA(mapfile, refloat_halflife=1) # seconds renderer = Renderer(mapfile, images_dir, size=(800, 600), draw_ontop='forecast') renderer.viewport = ((-124.5, 37.), (-120.5, 39)) print 'adding outputters' model.outputters += renderer netcdf_file = os.path.join(base_dir, 'script_sf_bay.nc') scripting.remove_netcdf(netcdf_file) model.outputters += NetCDFOutput(netcdf_file, which_data='all') print 'adding a spill' spill = point_line_release_spill(num_elements=1000, start_position=(-123.57152, 37.369436, 0.0), release_time=start_time, element_type=floating(windage_range=(0.01, 0.04) ) ) model.spills += spill # print 'adding a RandomMover:' # r_mover = gnome.movers.RandomMover(diffusion_coef=50000) # model.movers += r_mover print 'adding a grid wind mover:' wind_file = get_datafile(os.path.join(base_dir, r"./WindSpeedDirSubset.nc") ) topology_file = get_datafile(os.path.join(base_dir, r"./WindSpeedDirSubsetTop.dat")) w_mover = GridWindMover(wind_file, topology_file) #w_mover.uncertain_time_delay = 6 #w_mover.uncertain_duration = 6 w_mover.uncertain_speed_scale = 1 w_mover.set_uncertain_angle(.2, 'rad') # default is .4 w_mover.wind_scale = 2 model.movers += w_mover return model
def test_set_viewport(): """ tests various rendering, re-zooming, etc NOTE: this will only test if the code crashes, you have to look at the rendered images to see if it does the right thing """ input_file = os.path.join(data_dir, 'Star.bna') r = Renderer(input_file, output_dir, image_size=(600, 600), projection_class=GeoProjection) # re-scale: # should show upper right corner r.viewport = ((-73, 40), (-70, 43)) r.draw_background() r.save_background(os.path.join(output_dir, 'star_upper_right.png')) # re-scale: # should show lower right corner r.viewport = ((-73, 37), (-70, 40)) r.draw_background() r.save_background(os.path.join(output_dir, 'star_lower_right.png')) # re-scale: # should show lower left corner r.viewport = ((-76, 37), (-73, 40)) r.draw_background() r.save_background(os.path.join(output_dir, 'star_lower_left.png')) # re-scale: # should show upper left corner r.viewport = ((-76, 40), (-73, 43)) r.draw_background() r.save_background(os.path.join(output_dir, 'star_upper_left.png'))
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(images_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=1000, volume=90, # default volume_units=m^3 start_position=(-76.126872, 37.680952, 1700), release_time=start_time, end_release_time=end_time, element_type=plume(distribution=wd)) model.spills += spill wd = WeibullDistribution(alpha=1.8, lambda_=.00456, max_=.0002) # 200 micron max spill = point_line_release_spill(num_elements=1000, volume=10, start_position=(-76.126872, 37.680952, 1800), release_time=start_time, element_type=plume(distribution=wd)) 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, -.1, 0.0)) model.movers += s_mover 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) # 1 day of data in file # 1/2 hr in seconds model = Model(start_time=start_time, duration=timedelta(days=1), time_step=30 * 60, uncertain=True) mapfile = get_datafile(os.path.join(base_dir, './ChesapeakeBay.bna')) print 'adding the map' model.map = MapFromBNA(mapfile, refloat_halflife=1) # seconds # 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(mapfile, images_dir, size=(800, 600), output_timestep=timedelta(hours=2), 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_chesapeake_bay.nc') scripting.remove_netcdf(netcdf_file) model.outputters += NetCDFOutput(netcdf_file, which_data='all', output_timestep=timedelta(hours=2)) print 'adding a spill' # for now subsurface spill stays on initial layer # - will need diffusion and rise velocity # - wind doesn't act # - start_position = (-76.126872, 37.680952, 5.0), spill = point_line_release_spill(num_elements=1000, start_position=(-76.126872, 37.680952, 0.0), release_time=start_time) model.spills += spill print 'adding a RandomMover:' model.movers += RandomMover(diffusion_coef=50000) print 'adding a wind mover:' series = np.zeros((2, ), dtype=datetime_value_2d) series[0] = (start_time, (30, 0)) series[1] = (start_time + timedelta(hours=23), (30, 0)) wind = Wind(timeseries=series, units='knot') # default is .4 radians w_mover = WindMover(wind, uncertain_angle_scale=0) model.movers += w_mover print 'adding a current mover:' curr_file = get_datafile(os.path.join(base_dir, r"./ChesapeakeBay.nc")) topology_file = get_datafile(os.path.join(base_dir, r"./ChesapeakeBay.dat")) # uncertain_time_delay in hours c_mover = GridCurrentMover(curr_file, topology_file, uncertain_time_delay=3) c_mover.uncertain_along = 0 # default is .5 #c_mover.uncertain_cross = 0 # default is .25 model.movers += c_mover return model
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, 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=1000, 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, r"./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, r"./WACFloodTide.cur")) tide_file = get_datafile(os.path.join(base_dir, r"./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.tide.scale_factor = 1.1864 # will need the fScaleFactor for heights files #c_mover.time_dep.scale_factor = 1.1864 model.movers += c_mover model.environment += c_mover.tide return model