def make_model(images_dir=os.path.join(base_dir, 'images')): # create the maps: print 'creating the maps' mapfile = gs.get_datafile(os.path.join(base_dir, './MassBayMap.bna')) gnome_map = gs.MapFromBNA( mapfile, refloat_halflife=1, # hours raster_size=2048 * 2048 # about 4 MB ) renderer = gs.Renderer(mapfile, images_dir, image_size=(800, 800), projection_class=GeoProjection) print 'initializing the model' # start_time = datetime(2013, 3, 12, 10, 0) start_time = "2013-03-12T10:00" # 15 minutes in seconds # Default to now, rounded to the nearest hour model = gs.Model(time_step=gs.minutes(15), start_time=start_time, duration=gs.days(1), map=gnome_map, uncertain=True) print 'adding outputters' model.outputters += renderer netcdf_file = os.path.join(base_dir, 'script_boston.nc') gs.remove_netcdf(netcdf_file) model.outputters += gs.NetCDFOutput(netcdf_file, which_data='all') model.outputters += gs.KMZOutput( os.path.join(base_dir, 'script_boston.kmz')) print 'adding a RandomMover:' model.movers += gs.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=25), (5, 180)) # w_mover = WindMover(Wind(timeseries=series, units='m/s')) # model.movers += w_mover # model.environment += w_mover.wind w_mover = gs.constant_wind_mover(5, 180, units='m/s') model.movers += w_mover print 'adding a cats shio mover:' curr_file = gs.get_datafile(os.path.join(base_dir, r"./EbbTides.cur")) tide_file = gs.get_datafile(os.path.join(base_dir, r"./EbbTidesShio.txt")) c_mover = gs.CatsMover(curr_file, tide=gs.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 = gs.get_datafile( os.path.join(base_dir, "MerrimackMassCoast.cur")) tide_file = gs.get_datafile( os.path.join(base_dir, "MerrimackMassCoastOSSM.txt")) c_mover = gs.CatsMover(curr_file, tide=gs.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 = gs.get_datafile(os.path.join(base_dir, "MassBaySewage.cur")) c_mover = gs.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 = gs.get_datafile(os.path.join(base_dir, "WAC10msNW.cur")) component_file2 = gs.get_datafile(os.path.join(base_dir, "WAC10msSW.cur")) comp_mover = gs.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 = gs.asdatetime(start_time) + gs.hours(12) spill = gs.point_line_release_spill(num_elements=100, start_position=(-70.911432, 42.369142, 0.0), release_time=start_time, end_release_time=end_time) model.spills += spill return model
WINDAGE = 0.03 print "running with windage:", WINDAGE # gs.set_verbose('info') # pf = gs.PrintFinder() rel_time = "2019-04-18T21:00:00" model = gs.Model( name='Whale Drift', time_step=3600, start_time=rel_time, duration=gs.days(3), ) mapfile = gs.get_datafile(os.path.join(base_dir, 'coast.bna')) model.map = gs.MapFromBNA(mapfile, refloat_halflife=float("inf")) # nam = gs.PyWindMover("NAM_5K.nc") # nam.active_range = (gs.MinusInfTime(), # gs.asdatetime("2019-04-19T22:00")) # model.movers += nam # gfs = gs.PyWindMover("GFS_Global_0p5deg-4-18.nc") # model.movers += gfs windfile = gs.get_datafile( os.path.join(base_dir, '28NM SSW San Francisco CA-4-18.nws')) forecast = gs.wind_mover_from_file(windfile)
def make_model(images_dir=os.path.join(base_dir, 'images')): print 'initializing the model' start_time = "1985-01-01T13:31" model = gs.Model(start_time=start_time, duration=gs.days(2), time_step=gs.hours(1)) mapfile = gs.get_datafile(os.path.join(base_dir, 'ak_arctic.bna')) print 'adding the map' model.map = gs.MapFromBNA(mapfile, refloat_halflife=0.0) # seconds print 'adding outputters' renderer = gs.Renderer(mapfile, images_dir, image_size=(1024, 768)) renderer.set_viewport(((-165, 69), (-161.5, 70))) # model.outputters += renderer netcdf_file = os.path.join(base_dir, 'script_ice.nc') gs.remove_netcdf(netcdf_file) model.outputters += gs.NetCDFOutput(netcdf_file, which_data='all') print 'adding a spill' # For a subsurfce spill, you would need to add vertical movers: # - gs.RiseVelocityMover # - gs.RandomVerticalMover spill1 = gs.point_line_release_spill(num_elements=1000, start_position=(-163.75, 69.75, 0.0), release_time=start_time) model.spills += spill1 print 'adding the ice movers' fn = [gs.get_datafile('arctic_avg2_0001_gnome.nc'), gs.get_datafile('arctic_avg2_0002_gnome.nc'), ] gt = {'node_lon': 'lon', 'node_lat': 'lat'} ice_aware_curr = gs.IceAwareCurrent.from_netCDF(filename=fn, grid_topology=gt) ice_aware_wind = gs.IceAwareWind.from_netCDF(filename=fn, grid=ice_aware_curr.grid,) method = 'RK2' i_c_mover = gs.PyCurrentMover(current=ice_aware_curr, default_num_method=method) i_w_mover = gs.PyWindMover(wind=ice_aware_wind, default_num_method=method) # shifting to -360 to 0 longitude ice_aware_curr.grid.node_lon = ice_aware_curr.grid.node_lon[:] - 360 model.movers += i_c_mover model.movers += i_w_mover print 'adding an Ice RandomMover:' model.movers += IceAwareRandomMover(ice_concentration=ice_aware_curr.ice_concentration, diffusion_coef=50000) # to visualize the grid and currents # renderer.add_grid(ice_aware_curr.grid) # renderer.add_vec_prop(ice_aware_curr) return model
def make_model(images_dir=os.path.join(base_dir, 'images')): print 'initializing the model' start_time = "1985-01-01T13:31" model = gs.Model(start_time=start_time, duration=gs.days(2), time_step=gs.hours(1)) mapfile = gs.get_datafile(os.path.join(base_dir, 'ak_arctic.bna')) print 'adding the map' model.map = gs.MapFromBNA(mapfile, refloat_halflife=0.0) # seconds print 'adding outputters' renderer = gs.Renderer(mapfile, images_dir, image_size=(1024, 768)) renderer.set_viewport(((-165, 69), (-161.5, 70))) # model.outputters += renderer netcdf_file = os.path.join(base_dir, 'script_ice.nc') gs.remove_netcdf(netcdf_file) model.outputters += gs.NetCDFOutput(netcdf_file, which_data='all') print 'adding a spill' # For a subsurfce spill, you would need to add vertical movers: # - gs.RiseVelocityMover # - gs.RandomVerticalMover spill1 = gs.point_line_release_spill(num_elements=1000, start_position=(-163.75, 69.75, 0.0), release_time=start_time) model.spills += spill1 print 'adding the ice movers' fn = [ gs.get_datafile('arctic_avg2_0001_gnome.nc'), gs.get_datafile('arctic_avg2_0002_gnome.nc'), ] gt = {'node_lon': 'lon', 'node_lat': 'lat'} ice_aware_curr = gs.IceAwareCurrent.from_netCDF(filename=fn, grid_topology=gt) ice_aware_wind = gs.IceAwareWind.from_netCDF( filename=fn, grid=ice_aware_curr.grid, ) method = 'RK2' i_c_mover = gs.PyCurrentMover(current=ice_aware_curr, default_num_method=method) i_w_mover = gs.PyWindMover(wind=ice_aware_wind, default_num_method=method) # shifting to -360 to 0 longitude ice_aware_curr.grid.node_lon = ice_aware_curr.grid.node_lon[:] - 360 model.movers += i_c_mover model.movers += i_w_mover print 'adding an Ice RandomMover:' model.movers += IceAwareRandomMover( ice_concentration=ice_aware_curr.ice_concentration, diffusion_coef=50000) # to visualize the grid and currents # renderer.add_grid(ice_aware_curr.grid) # renderer.add_vec_prop(ice_aware_curr) return model
def make_model(images_dir=os.path.join(base_dir, 'images')): # create the maps: print 'creating the maps' mapfile = gs.get_datafile(os.path.join(base_dir, './MassBayMap.bna')) gnome_map = gs.MapFromBNA(mapfile, refloat_halflife=1, # hours raster_size=2048 * 2048 # about 4 MB ) renderer = gs.Renderer(mapfile, images_dir, image_size=(800, 800), projection_class=GeoProjection) print 'initializing the model' # start_time = datetime(2013, 3, 12, 10, 0) start_time = "2013-03-12T10:00" # 15 minutes in seconds # Default to now, rounded to the nearest hour model = gs.Model(time_step=gs.minute(15), start_time=start_time, duration=gs.days(1), map=gnome_map, uncertain=True) print 'adding outputters' model.outputters += renderer netcdf_file = os.path.join(base_dir, 'script_boston.nc') gs.remove_netcdf(netcdf_file) model.outputters += gs.NetCDFOutput(netcdf_file, which_data='all') model.outputters += gs.KMZOutput(os.path.join(base_dir, 'script_boston.kmz')) print 'adding a RandomMover:' model.movers += gs.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=25), (5, 180)) # w_mover = WindMover(Wind(timeseries=series, units='m/s')) # model.movers += w_mover # model.environment += w_mover.wind w_mover = gs.constant_wind_mover(5, 180, units='m/s') model.movers += w_mover print 'adding a cats shio mover:' curr_file = gs.get_datafile(os.path.join(base_dir, r"./EbbTides.cur")) tide_file = gs.get_datafile(os.path.join(base_dir, r"./EbbTidesShio.txt")) c_mover = gs.CatsMover(curr_file, tide=gs.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 = gs.get_datafile(os.path.join(base_dir, "MerrimackMassCoast.cur")) tide_file = gs.get_datafile(os.path.join(base_dir, "MerrimackMassCoastOSSM.txt")) c_mover = gs.CatsMover(curr_file, tide=gs.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 = gs.get_datafile(os.path.join(base_dir, "MassBaySewage.cur")) c_mover = gs.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 = gs.get_datafile(os.path.join(base_dir, "WAC10msNW.cur")) component_file2 = gs.get_datafile(os.path.join(base_dir, "WAC10msSW.cur")) comp_mover = gs.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 = gs.asdatetime(start_time) + hours(12) spill = point_line_release_spill(num_elements=100, start_position=(-70.911432, 42.369142, 0.0), release_time=start_time, end_release_time=end_time) model.spills += spill return model