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 = ((-0.15, -0.35), (0.15, 0.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=0.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 += PyGridCurrentMover(current=vg, default_num_method="Trapezoid", extrapolate=True) model.movers += SimpleMover(velocity=(0.0, -0.1, 0.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 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, image_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, substance=NonWeatheringSubstance(windage_range=(0.01, .04)) #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, 'WindSpeedDirSubset.nc')) topology_file = get_datafile( os.path.join(base_dir, '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.uncertain_angle_scale = 0.2 # default is .4 w_mover.wind_scale = 2 model.movers += w_mover return model
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.uncertain_angle_scale = 0.2 # 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 test_set_viewport(output_dir): """ 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 """ r = Renderer(bna_star, 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( 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
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 += 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 += 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(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')): print 'initializing the model' start_time = datetime(2014, 6, 9, 0, 0) mapfile = get_datafile(os.path.join(base_dir, 'PassamaquoddyMap.bna')) gnome_map = MapFromBNA(mapfile, refloat_halflife=1) # hours # # the image output renderer # global renderer # one hour timestep model = Model(start_time=start_time, duration=timedelta(hours=24), time_step=360, map=gnome_map, uncertain=False, cache_enabled=True) print 'adding outputters' renderer = Renderer(mapfile, images_dir, size=(800, 600), # output_timestep=timedelta(hours=1), draw_ontop='uncertain') renderer.viewport = ((-67.15, 45.), (-66.9, 45.2)) model.outputters += renderer netcdf_file = os.path.join(base_dir, 'script_passamaquoddy.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=(-66.991344, 45.059316, 0.0), release_time=start_time) model.spills += spill print 'adding a RandomMover:' model.movers += RandomMover(diffusion_coef=30000, uncertain_factor=2) print 'adding a wind mover:' series = np.zeros((5, ), dtype=datetime_value_2d) series[0] = (start_time, (5, 90)) series[1] = (start_time + timedelta(hours=18), (5, 180)) series[2] = (start_time + timedelta(hours=30), (5, 135)) series[3] = (start_time + timedelta(hours=42), (5, 180)) series[4] = (start_time + timedelta(hours=54), (5, 225)) wind = Wind(timeseries=series, units='m/s') model.movers += WindMover(wind) print 'adding a current mover:' curr_file = get_datafile(os.path.join(base_dir, 'PQBayCur.nc4')) topology_file = get_datafile(os.path.join(base_dir, 'PassamaquoddyTOP.dat') ) tide_file = get_datafile(os.path.join(base_dir, 'EstesHead.txt')) cc_mover = CurrentCycleMover(curr_file, topology_file, tide=Tide(tide_file)) model.movers += cc_mover model.environment += cc_mover.tide print 'viewport is:', [o.viewport for o in model.outputters if isinstance(o, Renderer)] return model
def make_model(images_dir=os.path.join(base_dir, 'images')): print('get contiguous') kml_file = os.path.join(base_dir, 'contigua.kml') with open(kml_file) as f: contiguous = parser.parse(f).getroot().Document coordinates = contiguous.Placemark.LineString.coordinates.text.split(' ') cont_coord = [] for x in coordinates: x = x.split(',') if len(x) > 1 and float(x[1]) > -12 and float(x[1]) < -3: cont_coord.append([float(x[0]), float(x[1])]) print('initializing the model') start_time = datetime(2022, 1, 22, 12, 0) mapfile = get_datafile(os.path.join(base_dir, './brazil-coast.BNA')) gnome_map = MapFromBNA(mapfile, refloat_halflife=6) # hours duration = timedelta(days=1) timestep = timedelta(minutes=5) end_time = start_time + duration steps = duration.total_seconds() / timestep.total_seconds() print("Total step: %.4i " % (steps)) # one hour timestep model = Model(start_time=start_time, duration=duration, time_step=timestep, map=gnome_map, uncertain=False, cache_enabled=False) oil_name = 'GENERIC MEDIUM CRUDE' wd = UniformDistribution(low=.0002, high=.0002) subs = GnomeOil(oil_name, initializers=plume_initializers(distribution=wd)) #model.spills += point_line_release_spill(release_time=start_time, start_position=(-35.153, -8.999, 0.0), num_elements=1000, end_release_time=end_time, substance= subs, units='kg') #model.spills += point_line_release_spill(release_time=start_time, start_position=(-35.176, -9.135, 0.0), num_elements=1000, end_release_time=end_time, substance= subs, units='kg') #model.spills += point_line_release_spill(release_time=start_time, start_position=(-35.062, -9.112, 0.0), num_elements=1000, end_release_time=end_time, substance= subs, units='kg') #model.spills += point_line_release_spill(release_time=start_time, start_position=(-34.994, -9.248, 0.0), num_elements=1000, end_release_time=end_time, substance= subs, units='kg') for idx in range(0, len(cont_coord)): model.spills += point_line_release_spill( num_elements=500, start_position=(cont_coord[idx][0], cont_coord[idx][1], 0.0), release_time=start_time, end_release_time=start_time + timedelta(days=1), amount=500, substance=subs, units='kg') #shp_file = os.path.join(base_dir, 'surface_concentration') #scripting.remove_netcdf(shp_file + ".zip") #model.outputters += ShapeOutput(shp_file, # zip_output=False, # surface_conc="kde", # ) print('adding movers:') print('adding a RandomMover:') model.movers += RandomMover(diffusion_coef=10000) print('adding a current mover:') # # this is HYCOM currents curr_file = get_datafile(os.path.join(base_dir, 'currents.nc')) model.movers += GridCurrentMover(curr_file, num_method='Euler') print('adding a grid wind mover:') wind_file = get_datafile(os.path.join(base_dir, 'wind.nc')) #topology_file = get_datafile(os.path.join(base_dir, 'WindSpeedDirSubsetTop.dat')) #w_mover = GridWindMover(wind_file, topology_file) w_mover = GridWindMover(wind_file) w_mover.uncertain_speed_scale = 1 w_mover.uncertain_angle_scale = 0.2 # default is .4 w_mover.wind_scale = 2 model.movers += w_mover print('adding outputters') renderer = Renderer(mapfile, images_dir, image_size=(900, 600), output_timestep=timestep, draw_ontop='forecast') #set the viewport to zoom in on the map: #renderer.viewport = ((-37, -11), (-34, -8)) #alagoas renderer.viewport = ((-36, -10), (-30, 5)) model.outputters += renderer netcdf_file = os.path.join(base_dir, 'contigua.nc') scripting.remove_netcdf(netcdf_file) model.outputters += NetCDFOutput(netcdf_file, which_data='standard', surface_conc='kde') return model
def make_model(images_dir=os.path.join(base_dir, 'images')): # create the maps: start_time = datetime(2013, 3, 12, 10, 0) # 15 minutes in seconds # Default to now, rounded to the nearest hour model = Model(time_step=60 * 60, start_time=start_time, duration=timedelta(days=1), uncertain=False) print 'adding outputters' renderer = Renderer(output_dir=images_dir, image_size=(800, 800), # viewport=((-70.25, 41.75), # FIXME -- why doesn't this work? # (-69.75, 42.25)), projection_class=GeoProjection) renderer.viewport = ((-70.25, 41.75), (-69.75, 42.25)) model.outputters += renderer netcdf_file = os.path.join(base_dir, 'surface_concentration.nc') scripting.remove_netcdf(netcdf_file) model.outputters += NetCDFOutput(netcdf_file, surface_conc='kde') shape_file = os.path.join(base_dir, 'surface_concentration') model.outputters += ShapeOutput(shape_file, surface_conc='kde') shp_file = os.path.join(base_dir, 'surface_concentration') scripting.remove_netcdf(shp_file + ".zip") model.outputters += ShapeOutput(shp_file, zip_output=False, surface_conc="kde", ) 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=25), (5, 270)) w_mover = WindMover(Wind(timeseries=series, units='m/s')) model.movers += w_mover model.environment += w_mover.wind print 'adding a spill' end_time = start_time + timedelta(hours=12) spill = point_line_release_spill(num_elements=100, amount=10000, units='gal', start_position=(-70.0, 42, 0.0), release_time=start_time, end_release_time=end_time, ) model.spills += spill return model
def make_model(images_dir=os.path.join(base_dir, 'images2')): print('initializing the model') start_time = datetime(int(sys.argv[1]), int(sys.argv[2]), int(sys.argv[3]), int(sys.argv[4]), int(sys.argv[5])) mapfile = get_datafile(os.path.join(base_dir, './brazil-coast.bna')) gnome_map = MapFromBNA(mapfile, refloat_halflife=6) # hours # # the image output renderer # global renderer #duration = timedelta(minutes=5) #timestep = timedelta(minutes=5) duration = timedelta(minutes=5) timestep = timedelta(minutes=5) endtime = start_time + duration steps = duration.total_seconds() / timestep.total_seconds() print("Total step: %.4i " % (steps)) model = Model(start_time=start_time, duration=duration, time_step=timestep, map=gnome_map, uncertain=False, cache_enabled=False) oil_name = 'GENERIC MEDIUM CRUDE' wd = UniformDistribution(low=.0002, high=.0002) subs = GnomeOil(oil_name, initializers=plume_initializers(distribution=wd)) #print 'adding a spill' #spill = point_line_release_spill(num_elements=122, # start_position=(-35.14, # -9.40, 0.0), # release_time=start_time) #model.spills += spill #spill2 = spatial_release_spill(-35.14,-9.40, 0.0, start_time) #model.spills += spill2 #print 'load nc' #netcdf_file = os.path.join(base_dir, 'maceio.nc') #relnc = InitElemsFromFile(netcdf_file,release_time=start_time) #relnc = InitElemsFromFile(netcdf_file,index=5) #spillnc = Spill(release=relnc) #print spillnc.release.num_elements #print spillnc.release.name #print spillnc.substance #print relnc._init_data['age'] #print relnc.release_time #model.spills += spillnc #model._load_spill_data() #for sc in model.spills.items(): # sc.prepare_for_model_run() #print(relnc.num_elements) #print(relnc.num_released) # add particles - it works print('adding particles') # Persistent oil spill in contiguous zone border if int(sys.argv[6]) == 1: release = release_from_splot_data(start_time, 'contiguous.txt') print("Adding new particles") model.spills += Spill(release=release, substance=subs) # Particles from previows simulation step try: f = open('step.txt') f.close() release2 = release_from_splot_data(start_time, 'step.txt') model.spills += Spill(release=release2, substance=subs) except IOError: print('No previous step, using only contiguous.txt') #assert rel.num_elements == exp_num_elems #assert len(rel.start_position) == exp_num_elems #cumsum = np.cumsum(exp) #for ix in xrange(len(cumsum) - 1): # assert np.all(rel.start_position[cumsum[ix]] == # rel.start_position[cumsum[ix]:cumsum[ix + 1]]) #assert np.all(rel.start_position[0] == rel.start_position[:cumsum[0]]) #spnc = Spill(release=None) #spnc.release = relnc print('adding a RandomMover:') #model.movers += RandomMover(diffusion_coef=10000, uncertain_factor=2) model.movers += RandomMover(diffusion_coef=10000) print('adding a current mover:') # # this is HYCOM currents curr_file = get_datafile(os.path.join(base_dir, 'corrente15a28de09.nc')) model.movers += GridCurrentMover(curr_file, num_method='Euler') print('adding a grid wind mover:') wind_file = get_datafile(os.path.join(base_dir, 'vento15a28de09.nc')) #topology_file = get_datafile(os.path.join(base_dir, 'WindSpeedDirSubsetTop.dat')) #w_mover = GridWindMover(wind_file, topology_file) w_mover = GridWindMover(wind_file) w_mover.uncertain_speed_scale = 1 w_mover.uncertain_angle_scale = 0.2 # default is .4 w_mover.wind_scale = 2 model.movers += w_mover print('adding outputters') renderer = Renderer(mapfile, images_dir, image_size=(900, 600), output_timestep=timestep, draw_ontop='forecast') #set the viewport to zoom in on the map: #renderer.viewport = ((-37, -11), (-34, -8)) #alagoas renderer.viewport = ((-55, -34), (-30, 5)) #1/4 N alagoas model.outputters += renderer netcdf_file = os.path.join(base_dir, 'step.nc') scripting.remove_netcdf(netcdf_file) model.outputters += NetCDFOutput(netcdf_file, which_data='standard', surface_conc='kde') return model
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 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(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, 'ChesapeakeBay.nc')) topology_file = get_datafile(os.path.join(base_dir, '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(1985, 7, 1, 13, 30) start_time = datetime(1985, 1, 2, 0, 0) # model time-step in seconds model = Model(start_time=start_time, duration=timedelta(hours=3 * 24 + 23), time_step=15 * 60, uncertain=False) print 'adding the map' mapfile = get_datafile(os.path.join(base_dir, 'coast_SBbig.bna')) model.map = MapFromBNA(mapfile, refloat_halflife=6) # hours print 'adding outputters' renderer = Renderer(mapfile, images_dir, size=(800, 600)) renderer.viewport = ((-122, 33), (-117, 35)) model.outputters += renderer netcdf_file = os.path.join(base_dir, 'script_SB') scripting.remove_netcdf(netcdf_file) model.outputters += NetCDFOutput(netcdf_file, which_data='all') print 'adding a spill' end_time = start_time + timedelta(hours=24) spill = point_line_release_spill(num_elements=1000, start_position=(202.294666, 71.922333, 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 current mover:' # currents from ROMS Santa Barbara run, provided by UCLA curr_file = os.path.join(base_dir, 'BOEM', 'Currentfilelist.txt') print curr_file topology_file = os.path.join(base_dir, 'TopologyCurrent.DAT') model.movers += GridCurrentMover(curr_file, topology_file) # model.movers += GridCurrentMover(curr_file) print 'adding a wind mover:' # winds from the ROMS Arctic run, provided by Walter Johnson wind_file = os.path.join(base_dir, 'BOEM', 'Windfilelist.txt') print wind_file topology_file = os.path.join(base_dir, 'TopologyCurrent.DAT') model.movers += GridWindMover(wind_file, topology_file) # model.movers += GridWindMover(wind_file, topology_file) # print 'adding an ice mover:' # ice from the ROMS Arctic run, provided by Walter Johnson # ice_file = os.path.join(base_dir, 'data_gnome', 'ROMS_h2ouv', 'arctic_filelist.txt') # topology_file = os.path.join(base_dir, 'data_gnome', 'arctic_subset_newtopo2.DAT') # model.movers += IceMover(ice_file, topology_file) # model.movers += IceMover(ice_file) # print ice_file return model
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 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' # 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 make_model(images_dir=os.path.join(base_dir, 'images')): # create the maps: start_time = datetime(2013, 3, 12, 10, 0) # 15 minutes in seconds # Default to now, rounded to the nearest hour model = Model(time_step=60 * 60, start_time=start_time, duration=timedelta(days=1), uncertain=False) print 'adding outputters' renderer = Renderer( output_dir=images_dir, image_size=(800, 800), # viewport=((-70.25, 41.75), # FIXME -- why doesn't this work? # (-69.75, 42.25)), projection_class=GeoProjection) renderer.viewport = ((-70.25, 41.75), (-69.75, 42.25)) model.outputters += renderer netcdf_file = os.path.join(base_dir, 'surface_concentration.nc') scripting.remove_netcdf(netcdf_file) model.outputters += NetCDFOutput(netcdf_file, surface_conc='kde') shape_file = os.path.join(base_dir, 'surface_concentration') model.outputters += ShapeOutput(shape_file, surface_conc='kde') shp_file = os.path.join(base_dir, 'surface_concentration') scripting.remove_netcdf(shp_file + ".zip") model.outputters += ShapeOutput( shp_file, zip_output=False, surface_conc="kde", ) 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=25), (5, 270)) w_mover = WindMover(Wind(timeseries=series, units='m/s')) model.movers += w_mover model.environment += w_mover.wind print 'adding a spill' end_time = start_time + timedelta(hours=12) spill = point_line_release_spill( num_elements=100, amount=10000, units='gal', start_position=(-70.0, 42, 0.0), release_time=start_time, 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, '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')): 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, image_size=(800, 600), output_timestep=timedelta(hours=2), draw_ontop='forecast') # set the viewport to zoom in on the map: renderer.viewport = ((-76.5, 37.), (-75.8, 38.)) # add the raster map, so we can see it... # note: this is really slow, so only use for diagnostics # renderer.raster_map = model.map 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) wind.extrapolation_is_allowed = True model.movers += w_mover print 'adding a current mover:' curr_file = get_datafile(os.path.join(base_dir, 'ChesapeakeBay.nc')) topology_file = get_datafile(os.path.join(base_dir, '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