示例#1
0
def setup_model():
    print 'initializing the model'
    # start with default time,duration...this will be changed when model is run
    model = Model(
    )  #change to use all defaults and set time_step also in Setup_TAP!!
    mapfile = os.path.join(setup.MapFileDir, setup.MapFileName)
    print 'adding the map: ', mapfile
    model.map = MapFromBNA(mapfile, refloat_halflife=0.0)  # seconds

    print 'adding a GridCurrentMover:'
    c_mover = GridCurrentMover(filename=setup.curr_fn, extrapolate=True)
    model.movers += c_mover

    print 'adding a WindMover:'
    w = Wind(filename=setup.wind_fn)
    w_mover = WindMover(w)
    # w_mover = GridWindMover(wind_file=setup.w_filelist)
    model.movers += w_mover

    if setup.diff_coef is not None:
        print 'adding a RandomMover:'
        random_mover = RandomMover(diffusion_coef=setup.diff_coef)  #in cm/s
        model.movers += random_mover

    return model
示例#2
0
def CurrentsAndWinds(timeStep, start_time, duration, weatheringSteps, mapfile, uncertain, data_path, curr_path, wind_path, map_path, reFloatHalfLife, windFile, currFile, tidalFile, num_elements, depths, lat, lon, output_path, wind_scale, save_nc, timestep_outputs, weatherers, td):
    print 'initializing the model:'
    model = Model(time_step=timeStep, start_time=start_time, duration=duration)
    print 'adding the map:'
    print (data_path, map_path, mapfile)
    mapfile = get_datafile(os.path.join(data_path, map_path, mapfile))
    model.map = MapFromBNA(mapfile, refloat_halflife=reFloatHalfLife)
    print 'adding a renderer'
    model.outputters += Renderer(mapfile, output_path, size=(800, 600), output_timestep=timedelta(hours=timestep_outputs))
    if save_nc:
        nc_outputter = NetCDFOutput('currentsAndWinds_example.nc', which_data='standard', output_timestep=timedelta(hours=timestep_outputs))
        model.outputters += nc_outputter
    print 'adding a wind mover:'
    wind_file = get_datafile(os.path.join(data_path, wind_path, windFile))
    wind = GridWindMover(wind_file)
    wind.wind_scale = wind_scale
    model.movers += wind
    print 'adding a current mover: '
    curr_file = get_datafile(os.path.join(data_path, curr_path, currFile))
    model.movers += GridCurrentMover(curr_file, num_method='RK4')
    if td:
        random_mover = RandomMover(diffusion_coef=10000)
        model.movers += random_mover
    print 'adding spill'
    model.spills += point_line_release_spill(num_elements=num_elements, start_position=(lon, lat, 0), release_time=start_time, end_release_time=start_time + duration)
    return model
示例#3
0
def allWeatherers(timeStep, start_time, duration, weatheringSteps, map, uncertain, data_path, curr_path, wind_path, map_path, reFloatHalfLife, windFile, currFile, tidalFile, num_elements, depths, lat, lon, output_path, wind_scale, save_nc, timestep_outputs, weatherers, td):
    print 'initializing the model:'
    model = Model(time_step=timeStep, start_time=start_time, duration=duration)
    print 'adding the map:'
    map_folder = os.path.join(data_path, map_path)
    if not(os.path.exists(map_folder)):
        print('The map folder is incorrectly set:', map_folder)
    mapfile = get_datafile( os.path.join(map_folder,map) )
    model.map = MapFromBNA(mapfile, refloat_halflife=reFloatHalfLife)
    print 'adding a renderer'
    model.outputters += Renderer(mapfile, output_path, size=(800, 600), output_timestep=timedelta(hours=1))
    if save_nc:
        nc_outputter = NetCDFOutput(netcdf_file, which_data='most', output_timestep=timedelta(hours=1))
        model.outputters += nc_outputter
    print 'adding a wind mover:'
    wind_file = get_datafile(os.path.join(data_path, wind_path, windFile))
    wind = GridWindMover(wind_file)
    wind.wind_scale = wind_scale
    model.movers += wind
    print 'adding a current mover: '
    curr_file = get_datafile(os.path.join(data_path, curr_path, currFile))
    model.movers += GridCurrentMover(curr_file, num_method='RK4')
    if td:
        random_mover = RandomMover(diffusion_coef=10000)
        model.movers += random_mover
    print 'adding spill'
    model.spills += point_line_release_spill(num_elements=num_elements, start_position=(lon, lat, 0), release_time=start_time, end_release_time=start_time + duration)
    print 'adding weatherers'
    water = Water(280.92)
    wind = constant_wind(20.0, 117, 'knots')
    waves = Waves(wind, water)
    model.weatherers += Evaporation(water, wind)
    model.weatherers += Emulsification(waves)
    model.weatherers += NaturalDispersion(waves, water)
    return model
示例#4
0
def test_simple_run_with_map():
    '''
    pretty much all this tests is that the model will run
    '''

    start_time = datetime(2012, 9, 15, 12, 0)

    model = Model()

    model.map = gnome.map.MapFromBNA(testmap, refloat_halflife=6)  # hours
    a_mover = SimpleMover(velocity=(1., 2., 0.))

    model.movers += a_mover
    assert len(model.movers) == 1

    spill = point_line_release_spill(num_elements=10,
                                     start_position=(0., 0., 0.),
                                     release_time=start_time)

    model.spills += spill
    assert len(model.spills) == 1
    model.start_time = spill.release.release_time

    # test iterator
    for step in model:
        print 'just ran time step: %s' % step
        assert step['step_num'] == model.current_time_step

    # reset and run again
    model.reset()

    # test iterator is repeatable
    for step in model:
        print 'just ran time step: %s' % step
        assert step['step_num'] == model.current_time_step
示例#5
0
def make_model(images_dir=os.path.join(base_dir, 'images')):
    print 'initializing the model'

    start_time = datetime(2012, 10, 25, 0, 1)
    # start_time = datetime(2015, 12, 18, 06, 01)

    # 1 day of data in file
    # 1/2 hr in seconds
    model = Model(start_time=start_time,
                  duration=timedelta(hours=6),
                  time_step=900)

    mapfile = get_datafile(os.path.join(base_dir, 'nyharbor.bna'))

    print 'adding the map'
    '''TODO: sort out MapFromBna's map_bounds parameter...
    it does nothing right now, and the spill is out of bounds'''
    model.map = MapFromBNA(mapfile, refloat_halflife=0.0)  # 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=(1024, 768))
    #     renderer.viewport = ((-73.5, 40.5), (-73.1, 40.75))
    #     renderer.viewport = ((-122.9, 45.6), (-122.6, 46.0))

    print 'adding outputters'
    model.outputters += renderer

    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),
    spill1 = point_line_release_spill(num_elements=1000,
                                      start_position=(-74.15, 40.5, 0.0),
                                      release_time=start_time)

    model.spills += spill1

    print 'adding a RandomMover:'
    model.movers += RandomMover(diffusion_coef=50000)

    print 'adding a wind mover:'

    model.movers += constant_wind_mover(4, 270, units='m/s')

    print 'adding a current mover:'

    # url is broken, fix and include the following section
    #     url = ('http://geoport.whoi.edu/thredds/dodsC/clay/usgs/users/jcwarner/Projects/Sandy/triple_nest/00_dir_NYB05.ncml')
    # #     cf = roms_field('nos.tbofs.fields.n000.20160406.t00z_sgrid.nc')
    #     cf = GridCurrent.from_netCDF(url)
    #     renderer.add_grid(cf.grid)
    #     renderer.delay = 25
    #     u_mover = PyCurrentMover(cf, default_num_method='Euler')
    #     model.movers += u_mover
    #

    return model
def make_model(images_dir=os.path.join(base_dir, 'images')):
    print 'initializing the model'

    start_time = datetime(2015, 9, 24, 3, 0)

    # 1 day of data in file
    # 1/2 hr in seconds
    model = Model(start_time=start_time,
                  duration=timedelta(hours = 48),
                  time_step=3600)

    mapfile = get_datafile(os.path.join(base_dir, 'Perfland.bna'))

    print 'adding the map'
    model.map = MapFromBNA(mapfile, refloat_halflife=1, raster_size=1024*1024)  # 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=1),
                        timestamp_attrib={'size': 'medium', 'color':'uncert_LE'})
    renderer.set_timestamp_attrib(format='%a %c')
    renderer.graticule.set_DMS(True)
#     renderer.viewport = ((-124.25, 47.5), (-122.0, 48.70))


    print 'adding outputters'
    model.outputters += renderer

    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),
    spill1 = point_line_release_spill(num_elements=5000,
                                     start_position=(0.0,
                                                     0.0,
                                                     0.0),
                                     release_time=start_time)

    model.spills += spill1

    print 'adding a RandomMover:'
    model.movers += RandomMover(diffusion_coef=50000)

    print 'adding a wind mover:'

    model.movers += constant_wind_mover(13, 270, units='m/s')

    print 'adding a current mover:'
#     curr_file = get_datafile(os.path.join(base_dir, 'COOPSu_CREOFS24.nc'))
#
#     # uncertain_time_delay in hours
#     c_mover = GridCurrentMover(curr_file)
#     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(2015, 9, 24, 3, 0)

    # 1 day of data in file
    # 1/2 hr in seconds
    model = Model(start_time=start_time,
                  duration=timedelta(hours = 48),
                  time_step=3600)

    mapfile = get_datafile(os.path.join(base_dir, 'Perfland.bna'))

    print 'adding the map'
    model.map = MapFromBNA(mapfile, refloat_halflife=1, raster_size=1024*1024)  # 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=1),
                        timestamp_attrib={'size': 'medium', 'color':'uncert_LE'})
    renderer.set_timestamp_attrib(format='%a %c')
    renderer.graticule.set_DMS(True)
#     renderer.viewport = ((-124.25, 47.5), (-122.0, 48.70))


    print 'adding outputters'
    model.outputters += renderer

    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),
    spill1 = point_line_release_spill(num_elements=5000,
                                     start_position=(0.0,
                                                     0.0,
                                                     0.0),
                                     release_time=start_time)

    model.spills += spill1

    print 'adding a RandomMover:'
    model.movers += RandomMover(diffusion_coef=50000)

    print 'adding a wind mover:'

    model.movers += constant_wind_mover(13, 270, units='m/s')

    print 'adding a current mover:'
#     curr_file = get_datafile(os.path.join(base_dir, 'COOPSu_CREOFS24.nc'))
#
#     # uncertain_time_delay in hours
#     c_mover = GridCurrentMover(curr_file)
#     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, 1, 1, 1)  # data starts at 1:00 instead of 0:00
    model = Model(start_time=start_time, duration=timedelta(days=1),
                  time_step=900, uncertain=False)

    try:
        mapfile = get_datafile(os.path.join(base_dir, './pearl_harbor.bna'))
    except HTTPError:
        print ('Could not download Pearl Harbor data from server - '
               'returning empty model')
        return model

    print 'adding the map'
    model.map = MapFromBNA(mapfile, refloat_halflife=1)  # hours

    #
    # Add the outputters -- render to images, and save out as netCDF
    #

    print 'adding renderer and netcdf output'
    model.outputters += Renderer(mapfile, images_dir, size=(800, 600))

    netcdf_output_file = os.path.join(base_dir, 'pearl_harbor_output.nc')
    scripting.remove_netcdf(netcdf_output_file)
    model.outputters += NetCDFOutput(netcdf_output_file, which_data='all')

    # #
    # # Set up the movers:
    # #
    print 'adding a random mover:'
    model.movers += RandomMover(diffusion_coef=10000)

    print 'adding a wind mover:'
    series = np.zeros((3, ), dtype=datetime_value_2d)
    series[0] = (start_time, (4, 180))
    series[1] = (start_time + timedelta(hours=12), (2, 270))
    series[2] = (start_time + timedelta(hours=24), (4, 180))

    w_mover = WindMover(Wind(timeseries=series, units='knots'))
    model.movers += w_mover
    model.environment += w_mover.wind

    print 'adding a current mover:'
    # this is CH3D currents
    curr_file = os.path.join(base_dir, r"./ch3d2013.nc")
    topology_file = os.path.join(base_dir, r"./PearlHarborTop.dat")
    model.movers += GridCurrentMover(curr_file, topology_file)

    # #
    # # Add a spill (sources of elements)
    # #
    print 'adding spill'
    model.spills += point_line_release_spill(num_elements=1000,
                                             start_position=(-157.97064,
                                                             21.331524, 0.0),
                                             release_time=start_time)
    return model
示例#9
0
def make_model(images_dir=os.path.join(base_dir, 'images')):
    print 'initializing the model'

    start_time = datetime(2015, 9, 24, 1, 1)

    # 1 day of data in file
    # 1/2 hr in seconds
    model = Model(start_time=start_time,
                  duration=timedelta(hours=48),
                  time_step=900)

    mapfile = get_datafile(os.path.join(base_dir, 'columbia_river.bna'))

    print 'adding the map'
    model.map = MapFromBNA(mapfile, refloat_halflife=0.0)  # 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=(600, 1200))
    renderer.graticule.set_DMS(True)
    #     renderer.viewport = ((-123.35, 45.6), (-122.68, 46.13))
    #     renderer.viewport = ((-122.9, 45.6), (-122.6, 46.0))

    print 'adding outputters'
    model.outputters += renderer

    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),
    spill1 = point_line_release_spill(num_elements=1000,
                                      start_position=(-122.625, 45.609, 0.0),
                                      release_time=start_time)

    model.spills += spill1

    print 'adding a RandomMover:'
    # model.movers += RandomMover(diffusion_coef=50000)

    print 'adding a wind mover:'

    model.movers += constant_wind_mover(0.5, 0, units='m/s')

    print 'adding a current mover:'
    curr_file = get_datafile(os.path.join(base_dir, 'COOPSu_CREOFS24.nc'))

    # uncertain_time_delay in hours
    # vec_field = TriVectorField('COOPSu_CREOFS24.nc')
    # u_mover = UGridCurrentMover(vec_field)
    c_mover = GridCurrentMover(curr_file)
    # c_mover.uncertain_cross = 0  # default is .25

    # model.movers += u_mover
    model.movers += c_mover
    model.save

    return model
示例#10
0
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
示例#11
0
def make_model(images_dir=os.path.join(base_dir, 'images')):
    print 'initializing the model'

    start_time = datetime(2015, 9, 24, 1, 1)

    # 1 day of data in file
    # 1/2 hr in seconds
    model = Model(start_time=start_time,
                  duration=timedelta(hours = 48),
                  time_step=900)

    mapfile = get_datafile(os.path.join(base_dir, 'columbia_river.bna'))

    print 'adding the map'
    model.map = MapFromBNA(mapfile, refloat_halflife=0.0)  # 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=(600, 1200))
    renderer.graticule.set_DMS(True)
#     renderer.viewport = ((-123.35, 45.6), (-122.68, 46.13))
#     renderer.viewport = ((-122.9, 45.6), (-122.6, 46.0))
    

    print 'adding outputters'
    model.outputters += renderer

    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),
    spill1 = point_line_release_spill(num_elements=5000,
                                     start_position=(-122.625,
                                                     45.609,
                                                     0.0),
                                     release_time=start_time)

    model.spills += spill1

    print 'adding a RandomMover:'
    model.movers += RandomMover(diffusion_coef=5000)

    print 'adding a wind mover:'
   
#     model.movers += constant_wind_mover(8, 90, units='m/s')

    print 'adding a current mover:'
    curr_file = get_datafile(os.path.join(base_dir, 'COOPSu_CREOFS24.nc'))
   
    # uncertain_time_delay in hours
    c_mover = GridCurrentMover(curr_file)
    c_mover.uncertain_cross = 0  # default is .25
   
    model.movers += c_mover

    return model
示例#12
0
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
示例#14
0
def make_models():
    print 'initializing the model'

    # start_time = datetime(2015, 12, 18, 06, 01)

    # 1 day of data in file
    # 1/2 hr in seconds
    models = []
    start_time = datetime(2012, 10, 27, 0, 30)
    duration_hrs=23
    time_step=450
    num_steps = duration_hrs * 3600 / time_step
    names = [
             'Euler',
             'Trapezoid',
             'RK4',
             ]

    mapfile = get_datafile(os.path.join(base_dir, 'long_beach.bna'))
    print 'gen map'
    map = MapFromBNA(mapfile, refloat_halflife=0.0)  # seconds
    fn = ('00_dir_roms_display.ncml.nc4')
    curr = GridCurrent.from_netCDF(filename=fn)
    models = []
    for method in names:

        mod = Model(start_time=start_time,
                    duration=timedelta(hours=duration_hrs),
                    time_step=time_step)

        mod.map = map
        spill = point_line_release_spill(num_elements=1000,
                                         start_position=(-74.1,
                                                      39.7525,
                                                      0.0),
                                         release_time=start_time)
        mod.spills += spill
        mod.movers += RandomMover(diffusion_coef=100)
        mod.movers += PyGridCurrentMover(current=curr, default_num_method=method)

        images_dir = method + '-' + str(time_step / 60) + 'min-' + str(num_steps) + 'steps'
        renderer = Renderer(mapfile, images_dir, image_size=(1024, 768))
        renderer.delay = 25
#         renderer.add_grid(curr.grid)
        mod.outputters += renderer


        netCDF_fn = os.path.join(base_dir, images_dir + '.nc')
        mod.outputters += NetCDFOutput(netCDF_fn, which_data='all')
        models.append(mod)

    print 'returning models'
    return models
示例#15
0
def make_model(timeStep,start_time, duration, weatheringSteps, map, uncertain, data_path, reFloatHalfLife, windFile, currFile, tidalFile,
               num_elements, depths, lat, lon, output_path, evaporation):
    #initalizing the model
    print 'initializing the model:'
    # model = Model(time_step = timeStep, start_time= start_time, duration=duration, uncertain = uncertain)
    model = Model(time_step = timeStep, start_time= start_time, duration=duration)

    #adding the map
    print 'adding the map:'
    print 'pinche path', data_path
    mapfile = get_datafile(os.path.join(data_path, map))
    model.map = MapFromBNA(mapfile, refloat_halflife = reFloatHalfLife)
    #model.map = GnomeMap()


    print 'adding a renderer'
    # renderer is a class that writes map images for GNOME results
    model.outputters += Renderer(mapfile, output_path, size=(800, 600), output_timestep=timedelta(hours=1))
    ##scripting.remove_netcdf(netcdf_file)
    #nc_outputter = NetCDFOutput(netcdf_file, which_data='most', output_timestep=timedelta(hours=1))
    #model.outputters += nc_outputter
    #adding the movers

    print 'adding a wind mover:'
    wind_file = get_datafile(os.path.join(data_path, windFile))
    wind = GridWindMover(wind_file)
    wind.wind_scale = 2
    model.movers += wind

    print 'adding a current mover: '
    curr_file = get_datafile(os.path.join(data_path,currFile))
    model.movers+= GridCurrentMover(curr_file, num_method='RK4')
    #random_mover = RandomMover(diffusion_coef=10000) #in cm/sdfd
    #model.movers += random_mover

    if evaporation:
    
     #wind for evaporation
	print'adding evaporation'
    	wind = constant_wind(1, 0, 'knots')
    	water = Water(temperature=300.0, salinity=35.0)
    	model.weatherers += Evaporation(wind=wind, water=water)
    #

    print 'adding a spill'
    # for i in depths:
    #     model.spills+= point_line_release_spill(num_elements=num_elements, start_position=(lon,lat,i), release_time=start_time)
    model.spills+= point_line_release_spill(num_elements=num_elements, start_position=(lon,lat,0), release_time=start_time,
                                            end_release_time=start_time+timedelta(days=93))

    return model
示例#16
0
def make_model(base_dir='.'):
    #,images_dir=os.path.join(base_dir, 'images',gdat_dir='/data/dylan/ArcticTAP/data_gnome/ROMS_h2ouv/')):
    print 'initializing the model'
    print base_dir
    start_time = datetime(1985, 1, 1, 13, 31)
    # start with generic times...this will be changed when model is run
    model = Model(start_time=start_time, time_step=setup.time_step)

    mapfile = get_datafile(os.path.join(base_dir, setup.MapFileName))
    print mapfile
    print 'adding the map'
    model.map = MapFromBNA(mapfile, refloat_halflife=0.0)  # seconds

    return model
示例#17
0
def make_model(base_dir='.'):
    #,images_dir=os.path.join(base_dir, 'images',gdat_dir='/data/dylan/ArcticTAP/data_gnome/ROMS_h2ouv/')):
    print 'initializing the model'
    print base_dir
    start_time = datetime(1985, 1, 1, 13, 31)
    # start with generic times...this will be changed when model is run
    model = Model(start_time=start_time,
                  duration=timedelta(hours=96),
                  time_step=120*60)
    mapfile = get_datafile(os.path.join(base_dir, 'arctic_coast3.bna'))
    print mapfile
    print 'adding the map'
    model.map = MapFromBNA(mapfile, refloat_halflife=0.0)  # seconds

    return model
示例#18
0
def test_simple_run_rewind():
    '''
    Pretty much all this tests is that the model will run
    and the seed is set during first run, then set correctly
    after it is rewound and run again
    '''

    start_time = datetime(2012, 9, 15, 12, 0)

    model = Model()

    model.map = gnome.map.GnomeMap()
    a_mover = SimpleMover(velocity=(1., 2., 0.))

    model.movers += a_mover
    assert len(model.movers) == 1

    spill = point_line_release_spill(num_elements=10,
                                     start_position=(0., 0., 0.),
                                     release_time=start_time)

    model.spills += spill
    assert len(model.spills) == 1

    # model.add_spill(spill)

    model.start_time = spill.release.release_time

    # test iterator
    for step in model:
        print 'just ran time step: %s' % model.current_time_step
        assert step['step_num'] == model.current_time_step

    pos = np.copy(model.spills.LE('positions'))

    # rewind and run again:
    print 'rewinding'
    model.rewind()

    # test iterator is repeatable
    for step in model:
        print 'just ran time step: %s' % model.current_time_step
        assert step['step_num'] == model.current_time_step

    assert np.all(model.spills.LE('positions') == pos)
示例#19
0
def test_simple_run_rewind():
    '''
    Pretty much all this tests is that the model will run
    and the seed is set during first run, then set correctly
    after it is rewound and run again
    '''

    start_time = datetime(2012, 9, 15, 12, 0)

    model = Model()

    model.map = gnome.map.GnomeMap()
    a_mover = SimpleMover(velocity=(1., 2., 0.))

    model.movers += a_mover
    assert len(model.movers) == 1

    spill = point_line_release_spill(num_elements=10,
                                     start_position=(0., 0., 0.),
                                     release_time=start_time)

    model.spills += spill
    assert len(model.spills) == 1

    # model.add_spill(spill)

    model.start_time = spill.release.release_time

    # test iterator
    for step in model:
        print 'just ran time step: %s' % model.current_time_step
        assert step['step_num'] == model.current_time_step

    pos = np.copy(model.spills.LE('positions'))

    # rewind and run again:
    print 'rewinding'
    model.rewind()

    # test iterator is repeatable
    for step in model:
        print 'just ran time step: %s' % model.current_time_step
        assert step['step_num'] == model.current_time_step

    assert np.all(model.spills.LE('positions') == pos)
示例#20
0
def only_Winds(timeStep, start_time, duration, weatheringSteps, map, uncertain, data_path, curr_path, wind_path, map_path, reFloatHalfLife, windFile, currFile, tidalFile, num_elements, depths, lat, lon, output_path, wind_scale, save_nc, timestep_outputs, weatherers, td):
    print 'initializing the model:'
    model = Model(time_step=timeStep, start_time=start_time, duration=duration)
    print 'adding the map:'
    mapfile = get_datafile(os.path.join(data_path, map_path, map))
    model.map = MapFromBNA(mapfile, refloat_halflife=reFloatHalfLife)
    print 'adding a renderer'
    model.outputters += Renderer(mapfile, output_path, size=(800, 600), output_timestep=timedelta(hours=timestep_outputs))
    if save_nc:
        nc_outputter = NetCDFOutput(netcdf_file, which_data='most', output_timestep=timedelta(hours=timestep_outputs))
        model.outputters += nc_outputter
    print 'adding a wind mover:'
    wind_file = get_datafile(os.path.join(data_path, wind_path, windFile))
    wind = GridWindMover(wind_file)
    wind.wind_scale = wind_scale
    model.movers += wind
    print 'adding a spill'
    model.spills += point_line_release_spill(num_elements=num_elements, start_position=(lon, lat, 0), release_time=start_time, end_release_time=start_time + duration)
    return model
示例#21
0
def test_simple_run_with_map():
    """
    pretty much all this tests is that the model will run
    """

    start_time = datetime(2012, 9, 15, 12, 0)

    model = Model()

    model.map = gnome.map.MapFromBNA(testmap, refloat_halflife=6)  # hours
    a_mover = SimpleMover(velocity=(1., 2., 0.))

    model.movers += a_mover
    assert len(model.movers) == 1

    spill = PointLineSource(num_elements=10,
            start_position=(0., 0., 0.), release_time=start_time)

    model.spills += spill

    # model.add_spill(spill)

    assert len(model.spills) == 1
    model.start_time = spill.release_time

    # test iterator:

    for step in model:
        print 'just ran time step: %s' % step

    # reset and run again:

    model.reset()

    # test iterator:

    for step in model:
        print 'just ran time step: %s' % step

    assert True
示例#22
0
def setup_model():
    print 'initializing the model'
    # start with default time,duration...this will be changed when model is run
    model = Model() #change to use all defaults and set time_step also in Setup_TAP!!
    mapfile = os.path.join(setup.MapFileDir, setup.MapFileName)
    print 'adding the map: ', mapfile
    model.map = MapFromBNA(mapfile, refloat_halflife=0.0)  # seconds
    
    print 'adding a GridCurrentMover:'
    c_mover = GridCurrentMover(filename=setup.curr_fn,topology_file=setup.curr_topo)
    model.movers += c_mover

    # print 'adding a GridWindMover:'
    # w_mover = GridWindMover(wind_file=setup.w_filelist,topology_file=setup.w_Topology)
    # w_mover = GridWindMover(wind_file=setup.w_filelist)
    # model.movers += w_mover

    if setup.diff_coef is not None:
        print 'adding a RandomMover:'
        random_mover = RandomMover(diffusion_coef=setup.diff_coef) #in cm/s 
        model.movers += random_mover

    return model
示例#23
0
def test_simple_run_with_map():
    '''
    pretty much all this tests is that the model will run
    '''

    start_time = datetime(2012, 9, 15, 12, 0)

    model = Model()

    model.map = gnome.map.MapFromBNA(testdata['MapFromBNA']['testmap'],
                                     refloat_halflife=6)  # hours
    a_mover = SimpleMover(velocity=(1., 2., 0.))

    model.movers += a_mover
    assert len(model.movers) == 1

    spill = point_line_release_spill(num_elements=10,
                                     start_position=(0., 0., 0.),
                                     release_time=start_time)

    model.spills += spill
    assert len(model.spills) == 1
    model.start_time = spill.release.release_time

    # test iterator
    for step in model:
        print 'just ran time step: %s' % step
        assert step['step_num'] == model.current_time_step

    # reset and run again
    model.reset()

    # test iterator is repeatable
    for step in model:
        print 'just ran time step: %s' % step
        assert step['step_num'] == model.current_time_step
示例#24
0
def make_modelF(timeStep, start_time, duration, weatheringSteps, map, uncertain, data_path, curr_path, wind_path, map_path, reFloatHalfLife, windFile, currFile, num_elements, depths, lat, lon, output_path, wind_scale, save_nc, timestep_outputs, weatherers, td, dif_coef,temp_water):
    print 'initializing the model:'
    model = Model(time_step=timeStep, start_time=start_time, duration=duration, uncertain=uncertain)
    print 'adding the map:'
    mapfile = get_datafile(os.path.join(data_path, map_path, map))
    model.map = MapFromBNA(mapfile, refloat_halflife=reFloatHalfLife)
    print 'adding a renderer'

    if save_nc:
        scripting.remove_netcdf(output_path+'/'+'output.nc')
        nc_outputter = NetCDFOutput(output_path+'/'+'output.nc', which_data='standard', output_timestep=timedelta(hours=timestep_outputs))
        model.outputters += nc_outputter

    print 'adding a wind mover:'
    wind_file = get_datafile(os.path.join(data_path, wind_path, windFile))
    wind = GridWindMover(wind_file)
    # wind.wind_scale = wind_scale
    model.movers += wind
    print 'adding a current mover:'
    curr_file = get_datafile(os.path.join(data_path, curr_path, currFile))
    model.movers += GridCurrentMover(curr_file, num_method='RK4')
    if td:
        random_mover = RandomMover(diffusion_coef=dif_coef)
        model.movers += random_mover
    print 'adding spill'
    model.spills += point_line_release_spill(num_elements=num_elements, start_position=(lon, lat, 0), release_time=start_time, end_release_time=start_time + duration)#, substance='AD04001', amount=9600000, units='kg')

    if weatherers:
        print 'adding weatherers'
        water = Water(temp_water)
        wind = constant_wind(0.0001, 0, 'knots')
        waves = Waves(wind, water)
        model.weatherers += Evaporation(water, wind)
    # model.weatherers += Emulsification(waves)
        model.weatherers += NaturalDispersion(waves, water)
    return model
示例#25
0
def make_model(images_dir=os.path.join(base_dir, 'images')):
    print 'initializing the model'

    start_time = datetime(2016, 4, 5, 18, 0)

    model = Model(start_time=start_time,
                  duration=timedelta(hours=12),
                  time_step=.25 * 3600)

    mapfile = (os.path.join(base_dir, 'coast.bna'))

    print 'adding the map'
    '''TODO: sort out MapFromBna's map_bounds parameter...
    it does nothing right now, and the spill is out of bounds'''
    model.map = MapFromBNA(mapfile, refloat_halflife=0.0)  # 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=(1024, 768))
    #     renderer.viewport = ((-73.5, 40.5), (-73.1, 40.75))
    #     renderer.viewport = ((-122.9, 45.6), (-122.6, 46.0))

    print 'adding outputters'
    model.outputters += renderer

    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),
    spill1 = point_line_release_spill(num_elements=500,
                                      start_position=(-82.73888, 27.5475, 0.0),
                                      release_time=start_time,
                                      end_release_time=start_time +
                                      timedelta(hours=24))
    spill2 = point_line_release_spill(num_elements=500,
                                      start_position=(-82.73888, 27.545, 0.0),
                                      release_time=start_time,
                                      end_release_time=start_time +
                                      timedelta(hours=24))
    spill3 = point_line_release_spill(num_elements=500,
                                      start_position=(-82.73888, 27.5425, 0.0),
                                      release_time=start_time,
                                      end_release_time=start_time +
                                      timedelta(hours=24))
    spill4 = point_line_release_spill(num_elements=500,
                                      start_position=(-82.73988, 27.5475, 0.0),
                                      release_time=start_time,
                                      end_release_time=start_time +
                                      timedelta(hours=24))

    spill5 = point_line_release_spill(num_elements=500,
                                      start_position=(-82.73988, 27.5450, 0.0),
                                      release_time=start_time,
                                      end_release_time=start_time +
                                      timedelta(hours=24))

    spill6 = point_line_release_spill(num_elements=500,
                                      start_position=(-82.73988, 27.5425, 0.0),
                                      release_time=start_time,
                                      end_release_time=start_time +
                                      timedelta(hours=24))

    model.spills += spill1
    model.spills += spill2
    model.spills += spill3
    model.spills += spill4
    model.spills += spill5
    model.spills += spill6
    model.spills._spill_container.spills.remove(0)

    print 'adding a current mover:'

    fn = 'nos.tbofs.fields.n000.20160406.t00z_sgrid.nc'
    #fn = 'dbofs_newFormat.nc'

    cf = GridCurrent.from_netCDF(filename=fn)
    u_mover = PyGridCurrentMover(cf, extrapolate=True)
    #u_mover = GridCurrentMover(fn)
    renderer.add_grid(cf.grid)
    #     renderer.add_vec_prop(cf)
    model.movers += u_mover

    # curr_file = get_datafile(os.path.join(base_dir, 'COOPSu_CREOFS24.nc'))
    # c_mover = GridCurrentMover(curr_file)
    # model.movers += c_mover

    return model
示例#26
0
def make_model(images_dir=os.path.join(base_dir, 'images')):
    print 'initializing the model'

    start_time = datetime(2012, 10, 25, 0, 1)
    # start_time = datetime(2015, 12, 18, 06, 01)

    # 1 day of data in file
    # 1/2 hr in seconds
    model = Model(start_time=start_time,
                  duration=timedelta(hours=6),
                  time_step=900)

    mapfile = get_datafile(os.path.join(base_dir, 'nyharbor.bna'))

    print 'adding the map'
    '''TODO: sort out MapFromBna's map_bounds parameter...
    it does nothing right now, and the spill is out of bounds'''
    model.map = MapFromBNA(mapfile, refloat_halflife=0.0)  # 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=(1024, 768))
#     renderer.viewport = ((-73.5, 40.5), (-73.1, 40.75))
#     renderer.viewport = ((-122.9, 45.6), (-122.6, 46.0))

    print 'adding outputters'
    model.outputters += renderer

    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),
    spill1 = point_line_release_spill(num_elements=1000,
                                      start_position=(-74.15,
                                                      40.5,
                                                      0.0),
                                      release_time=start_time)

    model.spills += spill1

    print 'adding a RandomMover:'
    model.movers += RandomMover(diffusion_coef=50000)

    print 'adding a wind mover:'

    model.movers += constant_wind_mover(4, 270, units='m/s')

    print 'adding a current mover:'

    url = ('http://geoport.whoi.edu/thredds/dodsC/clay/usgs/users/jcwarner/Projects/Sandy/triple_nest/00_dir_NYB05.ncml')
#     cf = roms_field('nos.tbofs.fields.n000.20160406.t00z_sgrid.nc')
    cf = GridCurrent.from_netCDF(url)
    renderer.add_grid(cf.grid)
    renderer.delay = 25
    u_mover = PyGridCurrentMover(cf, default_num_method='Euler')
    model.movers += u_mover

    # curr_file = get_datafile(os.path.join(base_dir, 'COOPSu_CREOFS24.nc'))
    # c_mover = GridCurrentMover(curr_file)
    # model.movers += c_mover

    return model
示例#27
0
def make_model(images_dir=os.path.join(base_dir, 'images')):
    print 'initializing the model'

    start_time = datetime(1985, 1, 1, 13, 31)

    # 1 day of data in file
    # 1/2 hr in seconds
    model = Model(start_time=start_time,
                  duration=timedelta(days=4),
                  time_step=7200)

#     mapfile = get_datafile(os.path.join(base_dir, 'ak_arctic.bna'))
    mapfile = get_datafile('arctic_coast3.bna')

    print 'adding the map'
    model.map = MapFromBNA(mapfile, refloat_halflife=0.0)  # seconds

    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),
#     spill1 = point_line_release_spill(num_elements=10000,
#                                       start_position=(-163.75,
#                                                       69.75,
#                                                       0.0),
#                                       release_time=start_time)
#
    spill1 = point_line_release_spill(num_elements=50000,
                                      start_position=(196.25,
                                                      69.75,
                                                      0.0),
                                      release_time=start_time)

    model.spills += spill1
#     model.spills += spill2

    print 'adding a wind mover:'

#     model.movers += constant_wind_mover(0.5, 0, units='m/s')

    print 'adding a current mover:'

    fn = ['arctic_avg2_0001_gnome.nc',
          'arctic_avg2_0002_gnome.nc']

#     fn = ['C:\\Users\\jay.hennen\\Documents\\Code\\pygnome\\py_gnome\\scripts\\script_TAP\\arctic_avg2_0001_gnome.nc',
#           'C:\\Users\\jay.hennen\\Documents\\Code\\pygnome\\py_gnome\\scripts\\script_TAP\\arctic_avg2_0002_gnome.nc']

    gt = {'node_lon': 'lon',
          'node_lat': 'lat'}
#     fn='arctic_avg2_0001_gnome.nc'

    wind_method = 'Euler'
    method = 'RK2'
    print 'adding outputters'

    # 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=(1024, 768))
    model.outputters += renderer
    netcdf_file = os.path.join(base_dir, str(model.time_step / 60) + method + '.nc')
    scripting.remove_netcdf(netcdf_file)

    print 'adding movers'
    model.outputters += NetCDFOutput(netcdf_file, which_data='all')


    print 'loading entire current data'
    ice_aware_curr = IceAwareCurrent.from_netCDF(filename=fn,
                                                 grid_topology=gt)

#     env1 = get_env_from_netCDF(filename)
#     mov = PyCurrentMover.from_netCDF(filename)

    ice_aware_curr.ice_velocity.variables[0].dimension_ordering = ['time', 'x', 'y']
    ice_aware_wind = IceAwareWind.from_netCDF(filename=fn,
                                              ice_velocity=ice_aware_curr.ice_velocity,
                                              ice_concentration=ice_aware_curr.ice_concentration,
                                              grid=ice_aware_curr.grid)

    curr = GridCurrent.from_netCDF(filename=fn)
#     GridCurrent.is_gridded()

#     import pprint as pp
#     from gnome.utilities.orderedcollection import OrderedCollection
#     model.environment = OrderedCollection(dtype=Environment)
#     model.environment.add(ice_aware_curr)
#     from gnome.environment import WindTS

    print 'loading entire wind data'

#     i_c_mover = PyCurrentMover(current=ice_aware_curr)
#     i_c_mover = PyCurrentMover(current=ice_aware_curr, default_num_method='Euler')
    i_c_mover = PyCurrentMover(current=ice_aware_curr, default_num_method=method, extrapolate=True)
    i_w_mover = PyWindMover(wind=ice_aware_wind, default_num_method=wind_method)

#     ice_aware_curr.grid.node_lon = ice_aware_curr.grid.node_lon[:]-360
#     ice_aware_curr.grid.build_celltree()
    model.movers += i_c_mover
    model.movers += i_w_mover

    print 'adding an IceAwareRandomMover:'
    model.movers += IceAwareRandomMover(ice_concentration=ice_aware_curr.ice_concentration,
                                        diffusion_coef=1000)
#     renderer.add_grid(ice_aware_curr.grid)
#     renderer.add_vec_prop(ice_aware_curr)


    # curr_file = get_datafile(os.path.join(base_dir, 'COOPSu_CREOFS24.nc'))
    # c_mover = GridCurrentMover(curr_file)
    # model.movers += c_mover
#     model.environment.add(WindTS.constant(10, 300))
#     print('Saving')
#     model.environment[0].ice_velocity.variables[0].serialize()
#     IceVelocity.deserialize(model.environment[0].ice_velocity.serialize())
#     model.save('.')
#     from gnome.persist.save_load import load
#     print('Loading')
#     model2 = load('./Model.zip')

    return model
示例#28
0
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
示例#30
0
def make_model(images_dir=os.path.join(base_dir, 'images')):
    print 'initializing the model'

    start_time = datetime(2012, 10, 25, 0, 1)
    # start_time = datetime(2015, 12, 18, 06, 01)

    # 1 day of data in file
    # 1/2 hr in seconds
    model = Model(start_time=start_time,
                  duration=timedelta(hours=24),
                  time_step=900)

    mapfile = get_datafile(os.path.join(base_dir, 'nyharbor.bna'))

    print 'adding the map'
    '''TODO: sort out MapFromBna's map_bounds parameter...
    it does nothing right now, and the spill is out of bounds'''
    model.map = MapFromBNA(mapfile, refloat_halflife=0.0)  # 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=(1024, 768))
#     renderer.viewport = ((-73.5, 40.5), (-73.1, 40.75))
#     renderer.viewport = ((-122.9, 45.6), (-122.6, 46.0))

    print 'adding outputters'
    model.outputters += renderer

    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),
    spill1 = point_line_release_spill(num_elements=1000,
                                      start_position=(-74.15,
                                                      40.5,
                                                      0.0),
                                      release_time=start_time)

    model.spills += spill1

    print 'adding a RandomMover:'
#     model.movers += RandomMover(diffusion_coef=50000)

    print 'adding a wind mover:'

    series = []
    for i in [(1, (5, 90)), (7, (5, 180)), (13, (5, 270)), (19, (5, 0)), (25, (5, 90))]:
        series.append((start_time + timedelta(hours=i[0]), i[1]))

    wind1 = WindTS.constant_wind('wind1', 5, 270, 'knots')
    wind2 = WindTS(timeseries = series, units='knots', extrapolate=True)

    wind = Wind(timeseries=series, units='knots')

    model.movers += PyWindMover(wind=wind2)
#     model.movers += WindMover(wind)

#     print 'adding a current mover:'
#
#     url = ('http://geoport.whoi.edu/thredds/dodsC/clay/usgs/users/jcwarner/Projects/Sandy/triple_nest/00_dir_NYB05.ncml')
# #     cf = roms_field('nos.tbofs.fields.n000.20160406.t00z_sgrid.nc')
#     cf = roms_field(url)
#     cf.set_appearance(on=True)
#     renderer.grids += [cf]
#     renderer.delay = 25
#     u_mover = UGridCurrentMover(cf)
#     model.movers += u_mover

    # curr_file = get_datafile(os.path.join(base_dir, 'COOPSu_CREOFS24.nc'))
    # c_mover = GridCurrentMover(curr_file)
    # model.movers += c_mover

    return model
示例#31
0
def make_model(images_dir=os.path.join(base_dir, 'images')):
    print 'initializing the model'

    start_time = datetime(2012, 10, 25, 0, 1)
    # start_time = datetime(2015, 12, 18, 06, 01)

    # 1 day of data in file
    # 1/2 hr in seconds
    model = Model(start_time=start_time,
                  duration=timedelta(hours=2),
                  time_step=900)

    mapfile = get_datafile(os.path.join(base_dir, 'nyharbor.bna'))

    print 'adding the map'
    '''TODO: sort out MapFromBna's map_bounds parameter...
    it does nothing right now, and the spill is out of bounds'''
    model.map = MapFromBNA(mapfile, refloat_halflife=0.0)  # 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=(1024, 768))
#     renderer.viewport = ((-73.5, 40.5), (-73.1, 40.75))
#     renderer.viewport = ((-122.9, 45.6), (-122.6, 46.0))

    print 'adding outputters'
    model.outputters += renderer

    netcdf_file = os.path.join(base_dir, 'script_ny_plume.nc')
    scripting.remove_netcdf(netcdf_file)

    model.outputters += NetCDFOutput(netcdf_file, which_data='all')

    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

    end_time = start_time + model.duration
#     wd = WeibullDistribution(alpha=1.8,
#                              lambda_=.00456,
#                              min_=.0002)  # 200 micron min
# 
#     spill = subsurface_plume_spill(num_elements=10,
#                                    start_position=(-74.15,
#                                                    40.5,
#                                                    7.2),
#                                    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

    wd = UniformDistribution(low=.0002,
                             high=.0002)

    spill = point_line_release_spill(num_elements=10, amount=90,
                                     units='m^3',
                                     start_position=(-74.15,
                                                     40.5,
                                                     7.2),
                                     release_time=start_time,
                                     element_type=plume(distribution=wd,
                                                        substance_name='ALASKA NORTH SLOPE (MIDDLE PIPELINE)')
                                     )
    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)

    url = ('http://geoport.whoi.edu/thredds/dodsC/clay/usgs/users/jcwarner/Projects/Sandy/triple_nest/00_dir_NYB05.ncml')
    gc = GridCurrent.from_netCDF(url)
    u_mover = PyGridCurrentMover(gc, default_num_method='Trapezoid')
    model.movers += u_mover
    # 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
示例#32
0
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
示例#33
0
def make_model(images_dir=os.path.join(base_dir, 'images')):
    print 'initializing the model'

    start_time = datetime(2015, 9, 24, 1, 1)
    # start_time = datetime(2015, 12, 18, 06, 01)

    # 1 day of data in file
    # 1/2 hr in seconds
    model = Model(start_time=start_time,
                  duration=timedelta(hours=47),
                  time_step=300)

    mapfile = get_datafile(os.path.join(base_dir, 'columbia_river.bna'))

    print 'adding the map'
    model.map = MapFromBNA(mapfile, refloat_halflife=0.0)  # 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=(600, 1200))
    renderer.delay=15
#     renderer.viewport = ((-123.35, 45.6), (-122.68, 46.13))
#     renderer.viewport = ((-122.9, 45.6), (-122.6, 46.0))

    print 'adding outputters'
    model.outputters += renderer

    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),
    spill1 = continuous_release_spill(initial_elements=10000,
                                      num_elements=400,
                                      start_position=(-122.625,
                                                      45.609,
                                                      0.0),
                                      release_time=start_time,
                                      end_position=(-122.6, 45.605, 0.0),
                                      end_release_time=start_time + timedelta(seconds=36000))

    model.spills += spill1

    print 'adding a RandomMover:'
#     model.movers += RandomMover(diffusion_coef=10000)

    print 'adding a wind mover:'
    series = []
    for i in [(1, (5, 90)), (7, (5, 180)), (13, (5, 270)), (19, (5, 0)), (25, (5, 90))]:
        series.append((start_time + timedelta(hours=i[0]), i[1]))

    wind1 = WindTS.constant_wind('wind1', 0.5, 0, 'm/s')
    wind2 = WindTS(timeseries = series, units='knots', extrapolate=True)

#     wind = Wind(timeseries=series, units='knots')

    model.movers += PyWindMover(wind=wind1)

    print 'adding a current mover:'

#     url = ('http://geoport.whoi.edu/thredds/dodsC/clay/usgs/users/jcwarner/Projects/Sandy/triple_nest/00_dir_NYB05.ncml')
#     test = GridCurrent.from_netCDF(name='gc1', filename=url)

    curr_file = get_datafile('COOPSu_CREOFS24.nc')
    curr = GridCurrent.from_netCDF(name='gc2', filename=curr_file,)

    c_mover = PyGridCurrentMover(curr, extrapolate = True, default_num_method='Trapezoid')

#     renderer.add_grid(curr.grid)
#     renderer.add_vec_prop(curr)
    model.movers += c_mover

    print 'adding a random mover'
    model.movers += RandomMover(diffusion_coef=1000)


    # curr_file = get_datafile(os.path.join(base_dir, 'COOPSu_CREOFS24.nc'))
    # c_mover = GridCurrentMover(curr_file)
    # model.movers += c_mover

    return model
示例#34
0
def main(RootDir, Data_Dir, StartSite, RunSite, NumStarts, RunStarts,
         ReleaseLength, TrajectoryRunLength, StartTimeFiles, TrajectoriesPath,
         NumLEs, MapFileName, refloat, current_files, wind_files,
         diffusion_coef, model_timestep, windage_range, windage_persist,
         OutputTimestep):

    timingRecord = open(os.path.join(RootDir, "timing.txt"), "w")
    count = len(StartTimeFiles) * len(RunStarts)
    timingRecord.write("This file tracks the time to process " + str(count) +
                       " gnome runs")

    # model timing
    release_duration = timedelta(hours=ReleaseLength)
    run_time = timedelta(hours=TrajectoryRunLength)

    # initiate model
    model = Model(duration=run_time, time_step=model_timestep, uncertain=False)

    # determine boundary for model
    print "Adding the map:", MapFileName
    mapfile = get_datafile(os.path.join(Data_Dir, MapFileName))
    # model.map = MapFromBNA(mapfile, refloat_halflife=refloat) no, model map needs to inclde mudflats. later

    # loop through seasons
    for Season in StartTimeFiles:
        timer1 = datetime.now()

        SeasonName = Season[1]
        start_times = open(Season[0], 'r').readlines()[:NumStarts]
        SeasonTrajDir = os.path.join(RootDir, TrajectoriesPath, SeasonName)
        if not os.path.isdir(SeasonTrajDir):
            print "Creating directory: ", SeasonTrajDir
            make_dir(SeasonTrajDir)
        print "  Season:", SeasonName

        # get and parse start times in this season
        start_dt = []
        for start_time in start_times:
            start_time = [int(i) for i in start_time.split(',')]
            start_time = datetime(start_time[0], start_time[1], start_time[2],
                                  start_time[3], start_time[4])
            start_dt.append(start_time)

        ## loop through start times
        for time_idx in RunStarts:
            timer2 = datetime.now()

            gc.collect()
            model.movers.clear()

            ## set the start location
            start_time = start_dt[time_idx]
            end_time = start_time + run_time
            model.start_time = start_time
            print "  ", start_time, "to", end_time

            ## get a list of the only data files needed for the start time (less data used)
            ## note: requires data files in year increments
            #Todo: needs fixing before real run
            years = range(start_time.year, end_time.year + 1)
            years = [str(i) for i in years]
            wind = [s for s in wind_files if any(xs in s for xs in years)]
            current = [
                s for s in current_files if any(xs in s for xs in years)
            ]

            #Todo: add mudflats. Does it work like this?
            topology = {'node_lon': 'x', 'node_lat': 'y'}

            ## add wind movers
            w_mover = PyWindMover(filename=wind)
            model.movers += w_mover

            ## add current movers
            current_mover = gs.GridCurrent.from_netCDF(current,
                                                       grid_topology=topology)
            c_mover = PyCurrentMover(current=current_mover)
            model.movers += c_mover

            tideflat = Matroos_Mudflats(current, grid_topology=topology)
            land_map = gs.MapFromBNA(mapfile)
            model.map = TideflatMap(land_map, tideflat)

            ## add diffusion
            model.movers += RandomMover(diffusion_coef=diffusion_coef)

            ## loop through start locations
            timer3 = datetime.now()

            #Todo: can it deal with the test.location.txt file??
            start_position = [float(i) for i in StartSite.split(',')]

            OutDir = os.path.join(RootDir, TrajectoriesPath, SeasonName,
                                  'pos_%03i' % (RunSite + 1))
            make_dir(OutDir)

            print "    ", RunSite, time_idx
            print "    Running: start time:", start_time,
            print "at start location:", start_position

            ## set the spill to the location
            spill = surface_point_line_spill(
                num_elements=NumLEs,
                start_position=(start_position[0], start_position[1], 0.0),
                release_time=start_time,
                end_release_time=start_time + release_duration,
                windage_range=windage_range,
                windage_persist=windage_persist)

            # print "adding netcdf output"
            netcdf_output_file = os.path.join(
                OutDir,
                'pos_%03i-t%03i_%08i.nc' %
                (RunSite + 1, time_idx, int(start_time.strftime('%y%m%d%H'))),
            )
            model.outputters.clear()
            model.outputters += NetCDFOutput(
                netcdf_output_file,
                output_timestep=timedelta(hours=OutputTimestep))

            model.spills.clear()
            model.spills += spill

            model.full_run(rewind=True)

            timer4 = datetime.now()
            diff = round((timer4 - timer3).total_seconds() / 60, 2)
            timingRecord.write("\t\t" + str(RunSite) + " took " + str(diff) +
                               " minutes to complete")
        diff = round((timer4 - timer1).total_seconds() / 3600, 2)
        count = len(RunStarts)
        timingRecord.write("\t" + str(SeasonName) + " took " + str(diff) +
                           " hours to finish " + str(count) + " Gnome runs")
    #OutDir.close
    timingRecord.close
示例#35
0
def make_model(images_dir=os.path.join(base_dir, 'images')):
    print 'initializing the model'

    start_time = datetime(2012, 10, 25, 0, 1)
    # start_time = datetime(2015, 12, 18, 06, 01)

    # 1 day of data in file
    # 1/2 hr in seconds
    model = Model(start_time=start_time,
                  duration=timedelta(hours=24),
                  time_step=900)

    mapfile = get_datafile(os.path.join(base_dir, 'nyharbor.bna'))

    print 'adding the map'
    '''TODO: sort out MapFromBna's map_bounds parameter...
    it does nothing right now, and the spill is out of bounds'''
    model.map = MapFromBNA(mapfile, refloat_halflife=0.0)  # 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=(1024, 768))
    #     renderer.viewport = ((-73.5, 40.5), (-73.1, 40.75))
    #     renderer.viewport = ((-122.9, 45.6), (-122.6, 46.0))

    print 'adding outputters'
    model.outputters += renderer

    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),
    spill1 = point_line_release_spill(num_elements=1000,
                                      start_position=(-74.15, 40.5, 0.0),
                                      release_time=start_time)

    model.spills += spill1

    print 'adding a RandomMover:'
    #     model.movers += RandomMover(diffusion_coef=50000)

    print 'adding a wind mover:'

    series = []
    for i in [(1, (5, 90)), (7, (5, 180)), (13, (5, 270)), (19, (5, 0)),
              (25, (5, 90))]:
        series.append((start_time + timedelta(hours=i[0]), i[1]))

    wind1 = WindTS.constant_wind('wind1', 5, 270, 'knots')
    wind2 = WindTS(timeseries=series, units='knots', extrapolate=True)

    wind = Wind(timeseries=series, units='knots')

    model.movers += PyWindMover(wind=wind2)
    #     model.movers += WindMover(wind)

    #     print 'adding a current mover:'
    #
    #     url = ('http://geoport.whoi.edu/thredds/dodsC/clay/usgs/users/jcwarner/Projects/Sandy/triple_nest/00_dir_NYB05.ncml')
    # #     cf = roms_field('nos.tbofs.fields.n000.20160406.t00z_sgrid.nc')
    #     cf = roms_field(url)
    #     cf.set_appearance(on=True)
    #     renderer.grids += [cf]
    #     renderer.delay = 25
    #     u_mover = UGridCurrentMover(cf)
    #     model.movers += u_mover

    # curr_file = get_datafile(os.path.join(base_dir, 'COOPSu_CREOFS24.nc'))
    # c_mover = GridCurrentMover(curr_file)
    # model.movers += c_mover

    return model
示例#36
0
def make_model(images_dir=os.path.join(base_dir, 'images')):
    print 'initializing the model'

    start_time = datetime(2012, 10, 25, 0, 1)
    # start_time = datetime(2015, 12, 18, 06, 01)

    # 1 day of data in file
    # 1/2 hr in seconds
    model = Model(start_time=start_time,
                  duration=timedelta(hours=2),
                  time_step=900)

    mapfile = get_datafile(os.path.join(base_dir, 'nyharbor.bna'))

    print 'adding the map'
    '''TODO: sort out MapFromBna's map_bounds parameter...
    it does nothing right now, and the spill is out of bounds'''
    model.map = MapFromBNA(mapfile, refloat_halflife=0.0)  # 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=(1024, 768))
#     renderer.viewport = ((-73.5, 40.5), (-73.1, 40.75))
#     renderer.viewport = ((-122.9, 45.6), (-122.6, 46.0))

    print 'adding outputters'
    model.outputters += renderer

    netcdf_file = os.path.join(base_dir, 'script_ny_plume.nc')
    scripting.remove_netcdf(netcdf_file)

    model.outputters += NetCDFOutput(netcdf_file, which_data='all')

    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

    end_time = start_time + model.duration
#     wd = WeibullDistribution(alpha=1.8,
#                              lambda_=.00456,
#                              min_=.0002)  # 200 micron min
# 
#     spill = subsurface_plume_spill(num_elements=10,
#                                    start_position=(-74.15,
#                                                    40.5,
#                                                    7.2),
#                                    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

    oil_name = 'ALASKA NORTH SLOPE (MIDDLE PIPELINE, 1997)'
    
    wd = UniformDistribution(low=.0002,
                             high=.0002)

    spill = point_line_release_spill(num_elements=10, amount=90,
                                     units='m^3',
                                     start_position=(-74.15,
                                                     40.5,
                                                     7.2),
                                     release_time=start_time,
                                     substance = GnomeOil(oil_name,initializers=plume_initializers(distribution=wd))
                                     #element_type=plume(distribution=wd,
                                                        #substance_name='ALASKA NORTH SLOPE (MIDDLE PIPELINE, 1997)')
                                     )
    model.spills += spill

    print 'adding a RandomMover:'
    model.movers += RandomMover(diffusion_coef=50000)

    print 'adding a RiseVelocityMover:'
    model.movers += RiseVelocityMover()

    print 'adding a RandomMover3D:'
#     model.movers += RandomMover3D(vertical_diffusion_coef_above_ml=5,
#                                         vertical_diffusion_coef_below_ml=.11,
#                                         mixed_layer_depth=10)

    # the url is broken, update and include the following four lines
#     url = ('http://geoport.whoi.edu/thredds/dodsC/clay/usgs/users/jcwarner/Projects/Sandy/triple_nest/00_dir_NYB05.ncml')
#     gc = GridCurrent.from_netCDF(url)
#     u_mover = PyCurrentMover(gc, default_num_method='RK2')
#     model.movers += u_mover

    # 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
示例#37
0
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
示例#38
0
def test_all_movers(start_time, release_delay, duration):
    '''
    Tests that all the movers at least can be run

    Add new ones as they come along!
    '''

    model = Model()
    model.time_step = timedelta(hours=1)
    model.duration = timedelta(seconds=model.time_step * duration)
    model.start_time = start_time
    start_loc = (1., 2., 0.)  # random non-zero starting points

    # a spill - release after 5 timesteps

    release_time = (start_time +
                    timedelta(seconds=model.time_step * release_delay))
    model.spills += point_line_release_spill(num_elements=10,
                                             start_position=start_loc,
                                             release_time=release_time)

    # the land-water map
    model.map = gnome.map.GnomeMap()  # the simplest of maps

    # simple mover
    model.movers += SimpleMover(velocity=(1., -1., 0.))
    assert len(model.movers) == 1

    # random mover
    model.movers += RandomMover(diffusion_coef=100000)
    assert len(model.movers) == 2

    # wind mover
    series = np.array((start_time, (10, 45)), dtype=datetime_value_2d).reshape(
        (1, ))
    model.movers += WindMover(Wind(timeseries=series,
                                   units='meter per second'))
    assert len(model.movers) == 3

    # CATS mover
    model.movers += CatsMover(testdata['CatsMover']['curr'])
    assert len(model.movers) == 4

    # run the model all the way...
    num_steps_output = 0
    for step in model:
        num_steps_output += 1
        print 'running step:', step

    # test release happens correctly for all cases
    if release_delay < duration:
        # at least one get_move has been called after release
        assert np.all(model.spills.LE('positions')[:, :2] != start_loc[:2])
    elif release_delay == duration:
        # particles are released after last step so no motion,
        # only initial _state
        assert np.all(model.spills.LE('positions') == start_loc)
    else:
        # release_delay > duration so nothing released though model ran
        assert len(model.spills.LE('positions')) == 0

    # there is the zeroth step, too.
    calculated_steps = (model.duration.total_seconds() / model.time_step) + 1
    assert num_steps_output == calculated_steps
示例#39
0
def make_model(images_dir=os.path.join(base_dir, 'images')):
    print 'initializing the model'

    start_time = datetime(2013, 5, 18, 0)

    model = Model(start_time=start_time, duration=timedelta(days=8),
                  time_step=1 * 3600, uncertain=False)

    mapfile = get_datafile(os.path.join(base_dir, './mariana_island.bna'))

    print 'adding the map'
    model.map = MapFromBNA(mapfile, refloat_halflife=6)  # hours

    #
    # Add the outputters -- render to images, and save out as netCDF
    #

    print 'adding renderer'
    model.outputters += Renderer(mapfile, images_dir, size=(800, 600))

    # print "adding netcdf output"
    # netcdf_output_file = os.path.join(base_dir,'mariana_output.nc')
    # scripting.remove_netcdf(netcdf_output_file)
    # model.outputters += gnome.netcdf_outputter.NetCDFOutput(netcdf_output_file,
    #                                                         which_data='all')

    # #
    # # Set up the movers:
    # #

    print 'adding a RandomMover:'
    model.movers += RandomMover(diffusion_coef=10000)

    print 'adding a simple wind mover:'
    model.movers += constant_wind_mover(5, 315, units='m/s')

    print 'adding a current mover:'

    # # this is HYCOM currents
    curr_file = get_datafile(os.path.join(base_dir, r"./HYCOM.nc"))
    model.movers += GridCurrentMover(curr_file)

    # #
    # # Add some spills (sources of elements)
    # #

    print 'adding four spill'
    model.spills += point_line_release_spill(num_elements=NUM_ELEMENTS // 4,
                                             start_position=(145.25, 15.0,
                                                             0.0),
                                             release_time=start_time)
    model.spills += point_line_release_spill(num_elements=NUM_ELEMENTS // 4,
                                             start_position=(146.25, 15.0,
                                                             0.0),
                                             release_time=start_time)
    model.spills += point_line_release_spill(num_elements=NUM_ELEMENTS // 4,
                                             start_position=(145.75, 15.25,
                                                             0.0),
                                             release_time=start_time)
    model.spills += point_line_release_spill(num_elements=NUM_ELEMENTS // 4,
                                             start_position=(145.75, 14.75,
                                                             0.0),
                                             release_time=start_time)

    return model
示例#40
0
def make_model(images_dir=os.path.join(base_dir, 'images')):
    print 'initializing the model'

    start_time = datetime(1985, 1, 1, 13, 31)

    # 1 day of data in file
    # 1/2 hr in seconds
    model = Model(start_time=start_time,
                  duration=timedelta(days=4),
                  time_step=7200)

    #     mapfile = get_datafile(os.path.join(base_dir, 'ak_arctic.bna'))
    mapfile = get_datafile('arctic_coast3.bna')

    print 'adding the map'
    model.map = MapFromBNA(mapfile, refloat_halflife=0.0)  # seconds

    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),
    #     spill1 = point_line_release_spill(num_elements=10000,
    #                                       start_position=(-163.75,
    #                                                       69.75,
    #                                                       0.0),
    #                                       release_time=start_time)
    #
    spill1 = point_line_release_spill(num_elements=50000,
                                      start_position=(196.25, 69.75, 0.0),
                                      release_time=start_time)

    model.spills += spill1
    #     model.spills += spill2

    print 'adding a wind mover:'

    #     model.movers += constant_wind_mover(0.5, 0, units='m/s')

    print 'adding a current mover:'

    fn = ['arctic_avg2_0001_gnome.nc', 'arctic_avg2_0002_gnome.nc']

    #     fn = ['C:\\Users\\jay.hennen\\Documents\\Code\\pygnome\\py_gnome\\scripts\\script_TAP\\arctic_avg2_0001_gnome.nc',
    #           'C:\\Users\\jay.hennen\\Documents\\Code\\pygnome\\py_gnome\\scripts\\script_TAP\\arctic_avg2_0002_gnome.nc']

    gt = {'node_lon': 'lon', 'node_lat': 'lat'}
    #     fn='arctic_avg2_0001_gnome.nc'

    wind_method = 'Euler'
    method = 'RK2'
    print 'adding outputters'

    # 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=(1024, 768))
    model.outputters += renderer
    netcdf_file = os.path.join(base_dir,
                               str(model.time_step / 60) + method + '.nc')
    scripting.remove_netcdf(netcdf_file)

    print 'adding movers'
    model.outputters += NetCDFOutput(netcdf_file, which_data='all')

    print 'loading entire current data'
    ice_aware_curr = IceAwareCurrent.from_netCDF(filename=fn, grid_topology=gt)

    #     env1 = get_env_from_netCDF(filename)
    #     mov = PyCurrentMover.from_netCDF(filename)

    ice_aware_curr.ice_velocity.variables[0].dimension_ordering = [
        'time', 'x', 'y'
    ]
    ice_aware_wind = IceAwareWind.from_netCDF(
        filename=fn,
        ice_velocity=ice_aware_curr.ice_velocity,
        ice_concentration=ice_aware_curr.ice_concentration,
        grid=ice_aware_curr.grid)

    curr = GridCurrent.from_netCDF(filename=fn)
    #     GridCurrent.is_gridded()

    #     import pprint as pp
    #     from gnome.utilities.orderedcollection import OrderedCollection
    #     model.environment = OrderedCollection(dtype=Environment)
    #     model.environment.add(ice_aware_curr)
    #     from gnome.environment import WindTS

    print 'loading entire wind data'

    #     i_c_mover = PyCurrentMover(current=ice_aware_curr)
    #     i_c_mover = PyCurrentMover(current=ice_aware_curr, default_num_method='Euler')
    i_c_mover = PyCurrentMover(current=ice_aware_curr,
                               default_num_method=method,
                               extrapolate=True)
    i_w_mover = PyWindMover(wind=ice_aware_wind,
                            default_num_method=wind_method)

    #     ice_aware_curr.grid.node_lon = ice_aware_curr.grid.node_lon[:]-360
    #     ice_aware_curr.grid.build_celltree()
    model.movers += i_c_mover
    model.movers += i_w_mover

    print 'adding an IceAwareRandomMover:'
    model.movers += IceAwareRandomMover(
        ice_concentration=ice_aware_curr.ice_concentration,
        diffusion_coef=1000)
    #     renderer.add_grid(ice_aware_curr.grid)
    #     renderer.add_vec_prop(ice_aware_curr)

    # curr_file = get_datafile(os.path.join(base_dir, 'COOPSu_CREOFS24.nc'))
    # c_mover = GridCurrentMover(curr_file)
    # model.movers += c_mover
    #     model.environment.add(WindTS.constant(10, 300))
    #     print('Saving')
    #     model.environment[0].ice_velocity.variables[0].serialize()
    #     IceVelocity.deserialize(model.environment[0].ice_velocity.serialize())
    #     model.save('.')
    #     from gnome.persist.save_load import load
    #     print('Loading')
    #     model2 = load('./Model.zip')

    return model
示例#41
0
def make_model(images_dir=os.path.join(base_dir, 'images')):
    print 'initializing the model'

    start_time = datetime(1985, 1, 1, 13, 31)

    # 1 day of data in file
    # 1/2 hr in seconds
    model = Model(start_time=start_time,
                  duration=timedelta(days=4),
                  time_step=3600*2)

    mapfile = get_datafile(os.path.join(base_dir, 'arctic_coast3.bna'))

    print 'adding the map'
    model.map = MapFromBNA(mapfile, refloat_halflife=0.0)  # seconds
#     model.map = GnomeMap()

    print 'adding outputters'

    # 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=(1024, 768))
#     model.outputters += renderer
    netcdf_file = os.path.join(base_dir, 'script_old_TAPa.nc')
    scripting.remove_netcdf(netcdf_file)

    model.outputters += NetCDFOutput(netcdf_file, which_data='all')

    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),
    spill1 = point_line_release_spill(num_elements=10000,
                                      start_position=(196.25,
                                                      69.75,
                                                      0.0),
                                      release_time=start_time)
#
#     spill2 = point_line_release_spill(num_elements=5000,
#                                       start_position=(-163.75,
#                                                       69.5,
#                                                       0.0),
#                                       release_time=start_time)

    model.spills += spill1
#     model.spills += spill2

    print 'adding a RandomMover:'
    model.movers += RandomMover(diffusion_coef=1000)

    print 'adding a wind mover:'
     # winds from the ROMS Arctic run, provided by Walter Johnson
    wind_file = os.path.join(base_dir, 'arctic_filelist.txt')
    print wind_file
    topology_file = os.path.join(base_dir, 'arctic_subset_newtopo2.DAT')
    model.movers += IceWindMover(wind_file, topology_file)
    # 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, 'arctic_filelist.txt')
    topology_file = os.path.join(base_dir, 'arctic_subset_newtopo2.DAT')
    model.movers += IceMover(ice_file, topology_file)
    # model.movers += IceMover(ice_file)
    print ice_file

    print 'adding a current mover:'
#
#     fn = ['N:\\Users\\Dylan.Righi\\OutBox\\ArcticROMS\\arctic_avg2_0001_gnome.nc',
#                  'N:\\Users\\Dylan.Righi\\OutBox\\ArcticROMS\\arctic_avg2_0002_gnome.nc']
#
#     gt = {'node_lon':'lon',
#           'node_lat':'lat'}
# #     fn='arctic_avg2_0001_gnome.nc'
#
#     ice_aware_curr = IceAwareCurrent.from_netCDF(filename=fn,
#                                                  grid_topology=gt)
#     ice_aware_wind = IceAwareWind.from_netCDF(filename=fn,
#                                               grid = ice_aware_curr.grid,)
#     method = 'Trapezoid'
#
# #     i_c_mover = PyGridCurrentMover(current=ice_aware_curr)
# #     i_c_mover = PyGridCurrentMover(current=ice_aware_curr, default_num_method='Euler')
#     i_c_mover = PyGridCurrentMover(current=ice_aware_curr, default_num_method=method)
#     i_w_mover = PyWindMover(wind = ice_aware_wind, default_num_method=method)
#
#     ice_aware_curr.grid.node_lon = ice_aware_curr.grid.node_lon[:]-360
# #     ice_aware_curr.grid.build_celltree()
#     model.movers += i_c_mover
#     model.movers += i_w_mover
#     renderer.add_grid(ice_aware_curr.grid)
#     renderer.add_vec_prop(ice_aware_curr)


#     renderer.set_viewport(((-190.9, 60), (-72, 89)))
    # curr_file = get_datafile(os.path.join(base_dir, 'COOPSu_CREOFS24.nc'))
    # c_mover = GridCurrentMover(curr_file)
    # model.movers += c_mover
    model.save('.')
    return model
示例#42
0
    def make_model():
        print ('initializing the model')

        #print (start_date)

        start_time = startday

        model = Model(start_time=start_time, duration=timedelta(days=30), 
                      #weathering_substeps = 6,
                      time_step=24 * 3600,
                      uncertain=False)

        mapfile = get_datafile(os.path.join(base_dir,'gulf.bna'))

        #mapfile='gulf.bna'

        print ('adding the map')
        model.map = MapFromBNA(mapfile, refloat_halflife=6)  # hours

        #
        # Add the outputters -- render to images, and save out as netCDF
        #

        

        

        print ("adding shapefile output")

         # with open("Result {}".format(spill_num), "w") as fp:
         # fp.write("text")
        
        dir_name = os.path.join (base_dir, season, str(position), "Spillnum {}".format(spill_num))
        
        if not os.path.exists(dir_name):
            os.makedirs(dir_name)
        
        #os.makedirs(dir_name, exist_ok =True)

        for i in range(1, 31, 1):
            model.outputters += ShapeOutput(os.path.join(dir_name, 'gnome_result {id}'.format(id=i)),
                                        zip_output=False,
                                        output_timestep=timedelta(days=i)) 
        images_dir = os.path.join(dir_name, 'image')
        # print 'adding renderer'
        # model.outputters += Renderer(mapfile,
        #                         images_dir,
        #                         image_size=(800, 600))
                                 
        # print ('adding renderer')
        # dir_image = os.path.join(dir_name)
        # model.outputters += Renderer(mapfile,
        #                            dir_image,
        #                             size=(800, 600))
                              

        #
        # Set up the movers:
        #

        print ('adding a RandomMover:')
        model.movers += RandomMover(diffusion_coef=10000)

        print ('adding a simple wind mover:')
    

        
        wind_file = get_datafile(os.path.join(base_dir, 'ECMWF.nc'))
        model.movers += GridWindMover(wind_file)

                                                  

        print ('adding a current mover:')

        # # this is NEMO currents

        curr_file = get_datafile(os.path.join(base_dir, Currents))
        model.movers += GridCurrentMover(curr_file,
                                         num_method='Euler');


        
        # # Add some spills (sources of elements)
        

        print ('adding one spill')

        
       
        spill = point_line_release_spill(num_elements=1000,
                                                 amount=  3200000000 * spilldur , units='grams',
                                                 start_position = position,
                                                 release_time = start_time,
                                                 substance = (sub))
        model.spills += spill

        ####### open excel file 
        print ('adding Excel file')
      
        workbook = xlsxwriter.Workbook(os.path.join(dir_name, 'Result {}_{}.xlsx'.format(spill_num, position)))
        worksheet = workbook.add_worksheet () 
        a = ((spilldur*3200)**(-0.3))*0.000069
        worksheet.write ('A1', a)
        workbook.close()

        
        print ('adding weatherers and cleanup options:')

        model.environment += [water,wind,waves]
        model.weatherers += Evaporation()
        model.weatherers += Emulsification()
        model.weatherers += NaturalDispersion()
        print ('model full run:')
        model.full_run()
        return model
示例#43
0
def make_model(images_dir=os.path.join(base_dir, "images")):
    print "initializing the model"

    start_time = datetime(1985, 1, 1, 13, 31)

    # 1 day of data in file
    # 1/2 hr in seconds
    model = Model(start_time=start_time, duration=timedelta(days=4), time_step=3600)

    mapfile = get_datafile(os.path.join(base_dir, "ak_arctic.bna"))

    print "adding the map"
    model.map = MapFromBNA(mapfile, refloat_halflife=0.0)  # seconds

    print "adding outputters"

    # 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=(1024, 768))
    #     model.outputters += renderer
    netcdf_file = os.path.join(base_dir, "script_ice.nc")
    scripting.remove_netcdf(netcdf_file)

    model.outputters += NetCDFOutput(netcdf_file, which_data="all")

    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),
    spill1 = point_line_release_spill(num_elements=10000, start_position=(-163.75, 69.75, 0.0), release_time=start_time)
    #
    #     spill2 = point_line_release_spill(num_elements=5000,
    #                                       start_position=(-163.75,
    #                                                       69.5,
    #                                                       0.0),
    #                                       release_time=start_time)

    model.spills += spill1
    #     model.spills += spill2

    print "adding a RandomMover:"
    model.movers += RandomMover(diffusion_coef=1000)

    print "adding a wind mover:"

    #     model.movers += constant_wind_mover(0.5, 0, units='m/s')

    print "adding a current mover:"

    fn = [get_datafile("arctic_avg2_0001_gnome.nc"), get_datafile("arctic_avg2_0002_gnome.nc")]

    gt = {"node_lon": "lon", "node_lat": "lat"}

    ice_aware_curr = IceAwareCurrent.from_netCDF(filename=fn, grid_topology=gt)
    ice_aware_wind = IceAwareWind.from_netCDF(filename=fn, grid=ice_aware_curr.grid)
    method = "Trapezoid"

    #     i_c_mover = PyGridCurrentMover(current=ice_aware_curr)
    #     i_c_mover = PyGridCurrentMover(current=ice_aware_curr, default_num_method='Euler')
    i_c_mover = PyGridCurrentMover(current=ice_aware_curr, default_num_method=method)
    i_w_mover = PyWindMover(wind=ice_aware_wind, default_num_method=method)

    ice_aware_curr.grid.node_lon = ice_aware_curr.grid.node_lon[:] - 360
    #     ice_aware_curr.grid.build_celltree()
    model.movers += i_c_mover
    model.movers += i_w_mover
    #     renderer.add_grid(ice_aware_curr.grid)
    #     renderer.add_vec_prop(ice_aware_curr)

    #     renderer.set_viewport(((-190.9, 60), (-72, 89)))
    # curr_file = get_datafile(os.path.join(base_dir, 'COOPSu_CREOFS24.nc'))
    # c_mover = GridCurrentMover(curr_file)
    # 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, 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
示例#45
0
def make_model(images_dir=os.path.join(base_dir, 'images')):
    print 'initializing the model'

    start_time = datetime(1985, 1, 1, 13, 31)

    # 1 day of data in file
    # 1/2 hr in seconds
    model = Model(start_time=start_time,
                  duration=timedelta(days=4),
                  time_step=3600)

#     mapfile = get_datafile(os.path.join(base_dir, 'ak_arctic.bna'))
    mapfile = get_datafile('arctic_coast3.bna')

    print 'adding the map'
    model.map = MapFromBNA(mapfile, refloat_halflife=0.0)  # seconds

    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),
#     spill1 = point_line_release_spill(num_elements=10000,
#                                       start_position=(-163.75,
#                                                       69.75,
#                                                       0.0),
#                                       release_time=start_time)
#
    spill1 = point_line_release_spill(num_elements=50000,
                                      start_position=(196.25,
                                                      69.75,
                                                      0.0),
                                      release_time=start_time)

    model.spills += spill1
#     model.spills += spill2

    print 'adding a wind mover:'

#     model.movers += constant_wind_mover(0.5, 0, units='m/s')

    print 'adding a current mover:'

    fn = ['arctic_avg2_0001_gnome.nc',
          'arctic_avg2_0002_gnome.nc']

    gt = {'node_lon': 'lon',
          'node_lat': 'lat'}
#     fn='arctic_avg2_0001_gnome.nc'

    wind_method = 'Euler'
    method = 'Trapezoid'
    print 'adding outputters'

    # 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=(1024, 768))
#     model.outputters += renderer
    netcdf_file = os.path.join(base_dir, str(model.time_step / 60) + method + '.nc')
    scripting.remove_netcdf(netcdf_file)

    print 'adding movers'
    model.outputters += NetCDFOutput(netcdf_file, which_data='all')

    load = False

    print 'loading entire current data'
    ice_aware_curr = IceAwareCurrent.from_netCDF(filename=fn,
                                                 grid_topology=gt,
                                                 load_all=load)
    print 'loading entire wind data'
    ice_aware_wind = IceAwareWind.from_netCDF(filename=fn,
                                              ice_var=ice_aware_curr.ice_var,
                                              ice_conc_var=ice_aware_curr.ice_conc_var,
                                              grid=ice_aware_curr.grid,
                                              load_all=load)

#     i_c_mover = PyGridCurrentMover(current=ice_aware_curr)
#     i_c_mover = PyGridCurrentMover(current=ice_aware_curr, default_num_method='Euler')
    i_c_mover = PyGridCurrentMover(current=ice_aware_curr, default_num_method=method, extrapolate=True)
    i_w_mover = PyWindMover(wind=ice_aware_wind, default_num_method=wind_method)

#     ice_aware_curr.grid.node_lon = ice_aware_curr.grid.node_lon[:]-360
#     ice_aware_curr.grid.build_celltree()
    model.movers += i_c_mover
    model.movers += i_w_mover

    print 'adding an IceAwareRandomMover:'
    model.movers += IceAwareRandomMover(ice_conc_var=ice_aware_curr.ice_conc_var,
                                        diffusion_coef=1000)
#     renderer.add_grid(ice_aware_curr.grid)
#     renderer.add_vec_prop(ice_aware_curr)


#     renderer.set_viewport(((-190.9, 60), (-72, 89)))
    # curr_file = get_datafile(os.path.join(base_dir, 'COOPSu_CREOFS24.nc'))
    # c_mover = GridCurrentMover(curr_file)
    # model.movers += c_mover

    return model
示例#46
0
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
def make_model(images_dir=os.path.join(base_dir, 'images')):
    print 'initializing the model'

    start_time = datetime(2015, 9, 24, 1, 1)
    # start_time = datetime(2015, 12, 18, 06, 01)

    # 1 day of data in file
    # 1/2 hr in seconds
    model = Model(start_time=start_time,
                  duration=timedelta(hours=47),
                  time_step=300)

    mapfile = get_datafile(os.path.join(base_dir, 'columbia_river.bna'))

    print 'adding the map'
    model.map = MapFromBNA(mapfile, refloat_halflife=0.0)  # 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=(600, 1200))
    renderer.delay = 15
    #     renderer.viewport = ((-123.35, 45.6), (-122.68, 46.13))
    #     renderer.viewport = ((-122.9, 45.6), (-122.6, 46.0))

    print 'adding outputters'
    model.outputters += renderer

    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),
    spill1 = continuous_release_spill(initial_elements=10000,
                                      num_elements=400,
                                      start_position=(-122.625, 45.609, 0.0),
                                      release_time=start_time,
                                      end_position=(-122.6, 45.605, 0.0),
                                      end_release_time=start_time +
                                      timedelta(seconds=36000))

    model.spills += spill1

    print 'adding a RandomMover:'
    #     model.movers += RandomMover(diffusion_coef=10000)

    print 'adding a wind mover:'
    series = []
    for i in [(1, (5, 90)), (7, (5, 180)), (13, (5, 270)), (19, (5, 0)),
              (25, (5, 90))]:
        series.append((start_time + timedelta(hours=i[0]), i[1]))

    wind1 = WindTS.constant_wind('wind1', 0.5, 0, 'm/s')
    wind2 = WindTS(timeseries=series, units='knots', extrapolate=True)

    #     wind = Wind(timeseries=series, units='knots')

    model.movers += PyWindMover(wind=wind1)

    print 'adding a current mover:'

    #     url = ('http://geoport.whoi.edu/thredds/dodsC/clay/usgs/users/jcwarner/Projects/Sandy/triple_nest/00_dir_NYB05.ncml')
    #     test = GridCurrent.from_netCDF(name='gc1', filename=url)

    curr_file = get_datafile('COOPSu_CREOFS24.nc')
    curr = GridCurrent.from_netCDF(
        name='gc2',
        filename=curr_file,
    )

    c_mover = PyGridCurrentMover(curr,
                                 extrapolate=True,
                                 default_num_method='Trapezoid')

    #     renderer.add_grid(curr.grid)
    #     renderer.add_vec_prop(curr)
    model.movers += c_mover

    print 'adding a random mover'
    model.movers += RandomMover(diffusion_coef=1000)

    # curr_file = get_datafile(os.path.join(base_dir, 'COOPSu_CREOFS24.nc'))
    # c_mover = GridCurrentMover(curr_file)
    # model.movers += c_mover

    return model
示例#48
0
def make_model(images_dir=os.path.join(base_dir, 'images')):
    print 'initializing the model'

    start_time = datetime(1985, 1, 1, 13, 31)

    # 1 day of data in file
    # 1/2 hr in seconds
    model = Model(start_time=start_time,
                  duration=timedelta(days=4),
                  time_step=3600 * 2)

    #     mapfile = get_datafile(os.path.join(base_dir, 'ak_arctic.bna'))
    mapfile = get_datafile('arctic_coast3.bna')

    print 'adding the map'
    model.map = MapFromBNA(mapfile, refloat_halflife=0.0)  # seconds

    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),
    #     spill1 = point_line_release_spill(num_elements=10000,
    #                                       start_position=(-163.75,
    #                                                       69.75,
    #                                                       0.0),
    #                                       release_time=start_time)
    #
    spill1 = point_line_release_spill(num_elements=100,
                                      start_position=(196.25, 69.75, 0.0),
                                      release_time=start_time)

    model.spills += spill1
    #     model.spills += spill2

    print 'adding a wind mover:'

    #     model.movers += constant_wind_mover(0.5, 0, units='m/s')

    print 'adding a current mover:'

    fn = ['arctic_avg2_0001_gnome.nc', 'arctic_avg2_0002_gnome.nc']

    gt = {'node_lon': 'lon', 'node_lat': 'lat'}
    #     fn='arctic_avg2_0001_gnome.nc'

    wind_method = 'Euler'
    method = 'Trapezoid'
    print 'adding outputters'

    # 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=(1024, 768))
    #     model.outputters += renderer
    netcdf_file = os.path.join(base_dir,
                               str(model.time_step / 60) + method + '.nc')
    scripting.remove_netcdf(netcdf_file)

    print 'adding movers'
    model.outputters += NetCDFOutput(netcdf_file, which_data='all')

    ice_aware_curr = IceAwareCurrent.from_netCDF(filename=fn, grid_topology=gt)
    ice_aware_wind = IceAwareWind.from_netCDF(
        filename=fn,
        ice_var=ice_aware_curr.ice_var,
        ice_conc_var=ice_aware_curr.ice_conc_var,
        grid=ice_aware_curr.grid,
    )

    #     i_c_mover = PyGridCurrentMover(current=ice_aware_curr)
    #     i_c_mover = PyGridCurrentMover(current=ice_aware_curr, default_num_method='Euler')
    i_c_mover = PyGridCurrentMover(current=ice_aware_curr,
                                   default_num_method=method)
    i_w_mover = PyWindMover(wind=ice_aware_wind,
                            default_num_method=wind_method)

    #     ice_aware_curr.grid.node_lon = ice_aware_curr.grid.node_lon[:]-360
    #     ice_aware_curr.grid.build_celltree()
    model.movers += i_c_mover
    model.movers += i_w_mover

    print 'adding an IceAwareRandomMover:'
    model.movers += IceAwareRandomMover(
        ice_conc_var=ice_aware_curr.ice_conc_var, diffusion_coef=1000)
    #     renderer.add_grid(ice_aware_curr.grid)
    #     renderer.add_vec_prop(ice_aware_curr)

    #     renderer.set_viewport(((-190.9, 60), (-72, 89)))
    # curr_file = get_datafile(os.path.join(base_dir, 'COOPSu_CREOFS24.nc'))
    # c_mover = GridCurrentMover(curr_file)
    # model.movers += c_mover

    return model
示例#49
0
def test_all_movers(start_time, release_delay, duration):
    '''
    Tests that all the movers at least can be run

    Add new ones as they come along!
    '''

    model = Model()
    model.time_step = timedelta(hours=1)
    model.duration = timedelta(seconds=model.time_step * duration)
    model.start_time = start_time
    start_loc = (1., 2., 0.)  # random non-zero starting points

    # a spill - release after 5 timesteps

    release_time = (start_time +
                    timedelta(seconds=model.time_step * release_delay))
    model.spills += point_line_release_spill(num_elements=10,
                                             start_position=start_loc,
                                             release_time=release_time)

    # the land-water map
    model.map = gnome.map.GnomeMap()  # the simplest of maps

    # simple mover
    model.movers += SimpleMover(velocity=(1., -1., 0.))
    assert len(model.movers) == 1

    # random mover
    model.movers += RandomMover(diffusion_coef=100000)
    assert len(model.movers) == 2

    # wind mover
    series = np.array((start_time, (10, 45)),
                      dtype=datetime_value_2d).reshape((1, ))
    model.movers += WindMover(Wind(timeseries=series,
                              units='meter per second'))
    assert len(model.movers) == 3

    # CATS mover
    model.movers += CatsMover(testdata['CatsMover']['curr'])
    assert len(model.movers) == 4

    # run the model all the way...
    num_steps_output = 0
    for step in model:
        num_steps_output += 1
        print 'running step:', step

    # test release happens correctly for all cases
    if release_delay < duration:
        # at least one get_move has been called after release
        assert np.all(model.spills.LE('positions')[:, :2] != start_loc[:2])
    elif release_delay == duration:
        # particles are released after last step so no motion,
        # only initial _state
        assert np.all(model.spills.LE('positions') == start_loc)
    else:
        # release_delay > duration so nothing released though model ran
        assert len(model.spills.LE('positions')) == 0

    # there is the zeroth step, too.
    calculated_steps = (model.duration.total_seconds() / model.time_step) + 1
    assert num_steps_output == calculated_steps
示例#50
0
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
示例#51
0
def make_model(images_dir=os.path.join(base_dir, 'images')):
    print 'initializing the model'

    start_time = datetime(2013, 5, 18, 0)

    model = Model(start_time=start_time, duration=timedelta(days=8),
                  time_step=4 * 3600, uncertain=False)

    mapfile = get_datafile(os.path.join(base_dir, 'mariana_island.bna'))

    print 'adding the map'
    model.map = MapFromBNA(mapfile, refloat_halflife=6)  # hours

    #
    # Add the outputters -- render to images, and save out as netCDF
    #

    print 'adding renderer'
    rend =  Renderer(mapfile,
                                 images_dir,
                                 size=(800, 600),
                                 draw_map_bounds=True
                                 )
    rend.draw_raster_map()
    model.outputters += rend
#                                 draw_back_to_fore=True)

    # print "adding netcdf output"
    # netcdf_output_file = os.path.join(base_dir,'mariana_output.nc')
    # scripting.remove_netcdf(netcdf_output_file)
    # model.outputters += NetCDFOutput(netcdf_output_file, which_data='all')

    #
    # Set up the movers:
    #
    rend.zoom(0.5)
    rend.zoom(2)

    print 'adding a RandomMover:'
    model.movers += RandomMover(diffusion_coef=10000)

    print 'adding a simple wind mover:'
    model.movers += constant_wind_mover(7, 90, units='m/s')

    print 'adding a current mover:'

#     # # this is HYCOM currents
#     curr_file = get_datafile(os.path.join(base_dir, 'HYCOM.nc'))
#     model.movers += GridCurrentMover(curr_file,
#                                      num_method=numerical_methods.euler);

    # #
    # # Add some spills (sources of elements)
    # #

    print 'adding four spill'
    model.spills += point_line_release_spill(num_elements=NUM_ELEMENTS // 4,
                                             start_position=(146, 15.25,
                                                             0.0),
                                             release_time=start_time)
    model.spills += point_line_release_spill(num_elements=NUM_ELEMENTS // 4,
                                             start_position=(146, 15.125,
                                                             0.0),
                                             release_time=start_time)
    model.spills += point_line_release_spill(num_elements=NUM_ELEMENTS // 4,
                                             start_position=(146, 15.0,
                                                             0.0),
                                             release_time=start_time)
    model.spills += point_line_release_spill(num_elements=NUM_ELEMENTS // 4,
                                             start_position=(146, 14.875,
                                                             0.0),
                                             release_time=start_time)

    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
示例#53
0
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
示例#54
0
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
示例#55
0
def make_model(images_dir=os.path.join(base_dir, 'images')):
    print 'initializing the model'

    start_time = datetime(2013, 5, 18, 0)

    model = Model(start_time=start_time,
                  duration=timedelta(days=8),
                  time_step=4 * 3600,
                  uncertain=False)

    mapfile = get_datafile(os.path.join(base_dir, 'mariana_island.bna'))

    print 'adding the map'
    model.map = MapFromBNA(mapfile, refloat_halflife=6)  # hours

    #
    # Add the outputters -- render to images, and save out as netCDF
    #

    print 'adding renderer'
    model.outputters += Renderer(
        mapfile,
        images_dir,
        size=(800, 600),
    )
    #                                 draw_back_to_fore=True)

    # print "adding netcdf output"
    # netcdf_output_file = os.path.join(base_dir,'mariana_output.nc')
    # scripting.remove_netcdf(netcdf_output_file)
    # model.outputters += NetCDFOutput(netcdf_output_file, which_data='all')

    #
    # Set up the movers:
    #

    print 'adding a RandomMover:'
    model.movers += RandomMover(diffusion_coef=10000)

    print 'adding a simple wind mover:'
    model.movers += constant_wind_mover(5, 315, units='m/s')

    print 'adding a current mover:'

    # # this is HYCOM currents
    curr_file = get_datafile(os.path.join(base_dir, 'HYCOM.nc'))
    model.movers += GridCurrentMover(curr_file,
                                     num_method=numerical_methods.euler)

    # #
    # # Add some spills (sources of elements)
    # #

    print 'adding four spill'
    model.spills += point_line_release_spill(num_elements=NUM_ELEMENTS // 4,
                                             start_position=(145.25, 15.0,
                                                             0.0),
                                             release_time=start_time)
    model.spills += point_line_release_spill(num_elements=NUM_ELEMENTS // 4,
                                             start_position=(146.25, 15.0,
                                                             0.0),
                                             release_time=start_time)
    model.spills += point_line_release_spill(num_elements=NUM_ELEMENTS // 4,
                                             start_position=(145.75, 15.25,
                                                             0.0),
                                             release_time=start_time)
    model.spills += point_line_release_spill(num_elements=NUM_ELEMENTS // 4,
                                             start_position=(145.75, 14.75,
                                                             0.0),
                                             release_time=start_time)

    return model
示例#56
0
def make_model(images_dir=os.path.join(base_dir, 'images')):
    print 'initializing the model'

    start_time = datetime(2016, 4, 5, 18, 0)


    model = Model(start_time=start_time,
                  duration=timedelta(hours=12),
                  time_step=.25*3600)

    mapfile = (os.path.join(base_dir, 'coast.bna'))

    print 'adding the map'
    '''TODO: sort out MapFromBna's map_bounds parameter...
    it does nothing right now, and the spill is out of bounds'''
    model.map = MapFromBNA(mapfile, refloat_halflife=0.0)  # 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=(1024, 768))
#     renderer.viewport = ((-73.5, 40.5), (-73.1, 40.75))
#     renderer.viewport = ((-122.9, 45.6), (-122.6, 46.0))

    print 'adding outputters'
    model.outputters += renderer

    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),
    spill1 = point_line_release_spill(num_elements=500,
                                      start_position=(-82.73888,
                                                      27.5475,
                                                      0.0),
                                      release_time=start_time,
                                      end_release_time=start_time+timedelta(hours=24))
    spill2 = point_line_release_spill(num_elements=500,
                                      start_position=(-82.73888,
                                                      27.545,
                                                      0.0),
                                      release_time=start_time,
                                      end_release_time=start_time+timedelta(hours=24))
    spill3 = point_line_release_spill(num_elements=500,
                                      start_position=(-82.73888,
                                                      27.5425,
                                                      0.0),
                                      release_time=start_time,
                                      end_release_time=start_time+timedelta(hours=24))
    spill4 = point_line_release_spill(num_elements=500,
                                      start_position=(-82.73988,
                                                      27.5475,
                                                      0.0),
                                      release_time=start_time,
                                      end_release_time=start_time+timedelta(hours=24))

    spill5 = point_line_release_spill(num_elements=500,
                                      start_position=(-82.73988,
                                                      27.5450,
                                                      0.0),
                                      release_time=start_time,
                                      end_release_time=start_time+timedelta(hours=24))

    spill6 = point_line_release_spill(num_elements=500,
                                      start_position=(-82.73988,
                                                      27.5425,
                                                      0.0),
                                      release_time=start_time,
                                      end_release_time=start_time+timedelta(hours=24))


    model.spills += spill1
    model.spills += spill2
    model.spills += spill3
    model.spills += spill4
    model.spills += spill5
    model.spills += spill6
    model.spills._spill_container.spills.remove(0)


    print 'adding a current mover:'

    fn = 'nos.tbofs.fields.n000.20160406.t00z_sgrid.nc'
    #fn = 'dbofs_newFormat.nc'

    cf = GridCurrent.from_netCDF(filename=fn)
    u_mover = PyGridCurrentMover(cf, extrapolate=True)
    #u_mover = GridCurrentMover(fn)
    renderer.add_grid(cf.grid)
#     renderer.add_vec_prop(cf)
    model.movers += u_mover

    # curr_file = get_datafile(os.path.join(base_dir, 'COOPSu_CREOFS24.nc'))
    # c_mover = GridCurrentMover(curr_file)
    # model.movers += c_mover

    return model