Ejemplo n.º 1
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 += PyCurrentMover(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
Ejemplo n.º 2
0
def make_model():
    duration_hrs = 48
    time_step = 900
    num_steps = duration_hrs * 3600 / time_step
    mod = Model(start_time=t,
                duration=timedelta(hours=duration_hrs),
                time_step=time_step)

    spill = point_line_release_spill(num_elements=1000,
                                     amount=1600,
                                     units='kg',
                                     start_position=(0.5, 0.5, 0.0),
                                     release_time=t,
                                     end_release_time=t + timedelta(hours=4))
    mod.spills += spill

    method = 'Trapezoid'
    images_dir = method + '-' + str(
        time_step / 60) + 'min-' + str(num_steps) + 'steps'
    renderer = Renderer(output_dir=images_dir, image_size=(800, 800))
    renderer.delay = 5
    renderer.add_grid(g)
    renderer.add_vec_prop(vg)

    renderer.graticule.set_max_lines(max_lines=0)
    mod.outputters += renderer

    mod.movers += PyCurrentMover(current=vg,
                                 default_num_method=method,
                                 extrapolate=True)
    mod.movers += RandomMover(diffusion_coef=10)

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

    return mod
Ejemplo n.º 3
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
Ejemplo n.º 4
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 = 'RK2'

    #     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)
    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
Ejemplo n.º 5
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 = PyCurrentMover(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
Ejemplo n.º 6
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, 1997)'))
    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 = 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
Ejemplo n.º 7
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 = PyCurrentMover(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
Ejemplo n.º 8
0
        model.movers.clear()
        model.weatherers.clear()
        model.environment.clear()

        print 'creating curr MFDataset'
        ds_c = nc4.MFDataset(file_list)

        print 'adding a CurrentMover (Trapeziod/RK4):'
        g_curr = GridCurrent.from_netCDF(
            filename=file_list,
            # dataset=ds_c,
            grid_topology={
                'node_lon': 'lonc',
                'node_lat': 'latc'
            })
        c_mover = PyCurrentMover(current=g_curr, default_num_method='RK4')
        model.movers += c_mover

        print 'creating wind MFDataset'
        ds_w = nc4.MFDataset(file_list_w)

        print 'adding a WindMover (Euler):'
        g_wind = GridWind.from_netCDF(
            filename=file_list_w,
            # dataset=ds_w,
            grid_topology={
                'node_lon': 'lonc',
                'node_lat': 'latc'
            })
        w_mover = PyWindMover(wind=g_wind, default_num_method='Euler')
        model.movers += w_mover