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, 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' import pysgrid import netCDF4 as nc df = nc.Dataset(fn) lon = df['lon'][:] lat = df['lat'][:] grd = pysgrid.SGrid(node_lon=np.repeat(lon.reshape(1, -1), len(lat), axis=0), node_lat=np.repeat(lat.reshape(-1, 1), len(lon), axis=1)) print(grd.node_lon.shape) print(grd.node_lat.shape) gc = GridCurrent.from_netCDF(fn, units='m/s', grid=grd) model.movers += IceMover(fn_ice) model.movers += GridCurrentMover(fn) 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'] = gc 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
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
# 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'])), RandomVerticalMover(), 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)), spill.point_line_release_spill(10, (0, 0, 0), datetime.now()), spill.elements.ElementType(substance=test_oil), Skimmer(100, 'kg', 0.3, (datetime(2014, 1, 1, 0, 0), datetime(2014, 1, 1, 4, 0))), Burn(100, 1, (datetime(2014, 1, 1, 0, 0), InfDateTime('inf')),
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