当前位置: 首页>>代码示例>>Python>>正文


Python outputters.Renderer类代码示例

本文整理汇总了Python中gnome.outputters.Renderer的典型用法代码示例。如果您正苦于以下问题:Python Renderer类的具体用法?Python Renderer怎么用?Python Renderer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Renderer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_rewind

def test_rewind(output_dir):
    'test rewind calls base function and clear_output_dir'
    r = Renderer(bna_sample, output_dir)
    bg_name = r.background_map_name
    fg_format = r.foreground_filename_format

    # dump some files into output dir:

    open(os.path.join(output_dir, bg_name), 'w').write('some junk')

    for i in range(5):
        open(os.path.join(output_dir, fg_format.format(i)), 'w'
             ).write('some junk')

    now = datetime.now()
    r.prepare_for_model_run(model_start_time=now)

    assert r._model_start_time == now

    r.rewind()
    assert r._model_start_time is None  # check super is called correctly
    # there should only be a background image now.

    files = os.listdir(output_dir)
    assert files == []
开发者ID:axiom-data-science,项目名称:PyGnome,代码行数:25,代码来源:test_renderer.py

示例2: test_rewind

def test_rewind(output_dir):
    'test rewind calls base function and clear_output_dir'
    r = Renderer(bna_sample, output_dir)
    bg_name = r.background_map_name
    fg_format = r.foreground_filename_format

    # dump some files into output dir:

    open(os.path.join(output_dir, bg_name), 'w').write('some junk')

    for i in range(5):
        open(os.path.join(output_dir, fg_format.format(i)), 'w'
             ).write('some junk')

    now = datetime.now()
    r.prepare_for_model_run(model_start_time=now)

    assert r._model_start_time == now

    r.rewind()
    # check super is called correctly
    assert r._model_start_time is None
    assert r._dt_since_lastoutput is None
    assert r._write_step is True

    # changed renderer and netcdf ouputter to delete old files in
    # prepare_for_model_run() rather than rewind()
    # -- rewind() was getting called a lot
    # -- before there was time to change the ouput file names, etc.
    # So for this unit test, there should only be a background image now.
    files = os.listdir(output_dir)
    assert files == ['background_map.png']
开发者ID:sandhujasmine,项目名称:PyGnome,代码行数:32,代码来源:test_renderer.py

示例3: test_exception

def test_exception():
    with pytest.raises(ValueError):
        Renderer(bna_sample, output_dir, draw_ontop='forecasting')

    r = Renderer(bna_sample, output_dir)
    with pytest.raises(ValueError):
        r.draw_ontop = 'forecasting'
开发者ID:JamesMakela-NOAA,项目名称:PyGnome,代码行数:7,代码来源:test_renderer.py

示例4: make_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
开发者ID:NOAA-ORR-ERD,项目名称:PyGnome,代码行数:60,代码来源:script_animation_demo.py

示例5: make_model

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

    # set up the modeling environment
    start_time = datetime(2004, 12, 31, 13, 0)
    model = Model(start_time=start_time, duration=timedelta(days=3), time_step=30 * 60, uncertain=False)

    print "adding the map"
    model.map = GnomeMap()  # this is a "water world -- no land anywhere"

    # renderere is only top-down view on 2d -- but it's something
    renderer = Renderer(output_dir=images_dir, size=(1024, 768), output_timestep=timedelta(hours=1))
    renderer.viewport = ((-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
开发者ID:NOAA-ORR-ERD,项目名称:PyGnome,代码行数:59,代码来源:script_tamoc.py

示例6: test_show_hide_map_bounds

def test_show_hide_map_bounds(output_dir):
    r = Renderer(bna_star, output_dir, image_size=(600, 600))

    r.draw_background()
    r.save_background(os.path.join(output_dir, 'star_background.png'))

    # try again without the map bounds:

    r.draw_map_bounds = False
    r.draw_background()
    r.save_background(os.path.join(output_dir,
                      'star_background_no_bound.png'))
开发者ID:axiom-data-science,项目名称:PyGnome,代码行数:12,代码来源:test_renderer.py

示例7: make_models

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
开发者ID:,项目名称:,代码行数:53,代码来源:

示例8: make_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
开发者ID:axiom-data-science,项目名称:PyGnome,代码行数:53,代码来源:script_sf_wind.py

示例9: test_show_hide_map_bounds

def test_show_hide_map_bounds():
    input_file = os.path.join(data_dir, 'Star.bna')
    r = Renderer(input_file, output_dir, image_size=(600, 600))

    r.draw_background()
    r.save_background(os.path.join(output_dir, 'star_background.png'))

    # try again without the map bounds:

    r.draw_map_bounds = False
    r.draw_background()
    r.save_background(os.path.join(output_dir,
                      'star_background_no_bound.png'))
开发者ID:JamesMakela-NOAA,项目名称:PyGnome,代码行数:13,代码来源:test_renderer.py

示例10: test_render_beached_elements

def test_render_beached_elements():
    """
    Should this test be in map_canvas?
    """

    input_file = os.path.join(data_dir,
                              r"MapBounds_2Spillable2Islands2Lakes.bna")
    r = Renderer(input_file, output_dir, image_size=(800, 600))

    BB = r.map_BB
    (min_lon, min_lat) = BB[0]
    (max_lon, max_lat) = BB[1]

    N = 100

    # create some random particle positions:

    lon = random.uniform(min_lon, max_lon, (N, ))
    lat = random.uniform(min_lat, max_lat, (N, ))

    # create a sc

    sc = sample_sc_release(num_elements=N)
    sc['positions'][:, 0] = lon
    sc['positions'][:, 1] = lat

    # make half of them on land

    sc['status_codes'][::2] = oil_status.on_land

    r.create_foreground_image()
    r.draw_elements(sc)

    # create an uncertainty sc

    lon = random.uniform(min_lon, max_lon, (N, ))
    lat = random.uniform(min_lat, max_lat, (N, ))

    sc = sample_sc_release(num_elements=N, uncertain=True)
    sc['positions'][:, 0] = lon
    sc['positions'][:, 1] = lat

    # make half of them on land

    sc['status_codes'][::2] = oil_status.on_land

    r.draw_elements(sc)

    # save the image

    r.save_foreground(os.path.join(output_dir, 'foreground2.png'))
    assert True
开发者ID:JamesMakela-NOAA,项目名称:PyGnome,代码行数:52,代码来源:test_renderer.py

示例11: test_file_delete

def test_file_delete(output_dir):
    r = Renderer(bna_sample, output_dir)
    bg_name = r.background_map_name
    fg_format = r.foreground_filename_format

    # dump some files into output dir:

    open(os.path.join(output_dir, bg_name), 'w').write('some junk')

    for i in range(5):
        open(os.path.join(output_dir, fg_format.format(i)), 'w'
             ).write('some junk')

    r.prepare_for_model_run(model_start_time=datetime.now())

    # there should only be a background image now.

    files = os.listdir(output_dir)
    assert files == [r.background_map_name]
开发者ID:axiom-data-science,项目名称:PyGnome,代码行数:19,代码来源:test_renderer.py

示例12: test_render_elements

def test_render_elements(output_dir):
    """
    Should this test be in map_canvas?
    """

#   put in current dir for now:
    output_dir = './'
    r = Renderer(bna_sample, output_dir, image_size=(800, 600))

    BB = r.map_BB
    (min_lon, min_lat) = BB[0]
    (max_lon, max_lat) = BB[1]

    N = 1000

    # create some random particle positions:

    lon = random.uniform(min_lon, max_lon, (N, ))
    lat = random.uniform(min_lat, max_lat, (N, ))

    # create a sc

    sc = sample_sc_release(num_elements=N)
    sc['positions'][:, 0] = lon
    sc['positions'][:, 1] = lat

    r.create_foreground_image()
    r.draw_elements(sc)

    # create an uncertainty sc

    lon = random.uniform(min_lon, max_lon, (N, ))
    lat = random.uniform(min_lat, max_lat, (N, ))

    sc = sample_sc_release(num_elements=N, uncertain=True)
    sc['positions'][:, 0] = lon
    sc['positions'][:, 1] = lat

    r.draw_elements(sc)

    # save the image

    r.save_foreground(os.path.join(output_dir, 'foreground1.png'))
    assert True
开发者ID:axiom-data-science,项目名称:PyGnome,代码行数:44,代码来源:test_renderer.py

示例13: make_model

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 += PyGridCurrentMover(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
开发者ID:,项目名称:,代码行数:36,代码来源:

示例14: make_model

def make_model(images_dir=os.path.join(base_dir, 'images')):

    # create the maps:

    print 'creating the maps'
    mapfile = get_datafile(os.path.join(base_dir, 'SanJuanMap.bna'))
    gnome_map = MapFromBNA(mapfile, refloat_halflife=1,
                           raster_size=1024 * 1024)

    renderer = Renderer(mapfile,
                        images_dir,
                        size=(800, 800),
                        projection_class=GeoProjection)

    renderer.viewport = ((-66.24, 18.39), (-66.1, 18.55))

    print 'initializing the model'
    start_time = datetime(2014, 9, 3, 13, 0)

    # 15 minutes in seconds
    # Default to now, rounded to the nearest hour
    model = Model(time_step=900, start_time=start_time,
                  duration=timedelta(days=1),
                  map=gnome_map, uncertain=False)

    print 'adding outputters'
    model.outputters += renderer

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

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

    print 'adding a wind mover:'

    series = np.zeros((2, ), dtype=datetime_value_2d)
    series[0] = (start_time, (0, 270))
    series[1] = (start_time + timedelta(hours=18), (0, 270))

    wind = Wind(timeseries=series, units='m/s')
    w_mover = WindMover(wind)
    model.movers += w_mover

    print 'adding a cats shio mover:'

    # need to add the scale_factor for the tide heights file
    curr_file = get_datafile(os.path.join(base_dir, 'EbbTides.cur'))
    tide_file = get_datafile(os.path.join(base_dir, 'EbbTidesShioHt.txt'))

    c_mover = CatsMover(curr_file, tide=Tide(tide_file, scale_factor=.15))

    # this is the value in the file (default)
    c_mover.scale_refpoint = (-66.116667, 18.458333)
    c_mover.scale = True
    c_mover.scale_value = 1.0
    # c_mover.tide.scale_factor = 0.15

    model.movers += c_mover

    print 'adding a cats mover:'

    curr_file = get_datafile(os.path.join(base_dir, 'Offshore.cur'))

    c_mover = CatsMover(curr_file)

    # this is the value in the file (default)
    # c_mover.scale_refpoint = (-66.082836, 18.469334)
    c_mover.scale_refpoint = (-66.084333333, 18.46966667)
    c_mover.scale = True
    c_mover.scale_value = 0.1

    model.movers += c_mover

    print 'adding a spill'

    end_time = start_time + timedelta(hours=12)
    spill = point_line_release_spill(num_elements=1000,
                                     release_time=start_time,
                                     start_position=(-66.16374,
                                                     18.468054, 0.0),
                                     # start_position=(-66.129099,
                                     #                 18.465332, 0.0),
                                     # end_release_time=end_time,
                                     )

    model.spills += spill

    return model
开发者ID:liuy0813,项目名称:PyGnome,代码行数:90,代码来源:script_san_juan.py

示例15: make_model

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

    start_time = datetime(2004, 12, 31, 13, 0)
    model = Model(start_time=start_time, duration=timedelta(days=3),
                  time_step=30 * 60, uncertain=False)

    print 'adding the map'
    model.map = GnomeMap()

    # draw_ontop can be 'uncertain' or 'forecast'
    # 'forecast' LEs are in black, and 'uncertain' are in red
    # default is 'forecast' LEs draw on top
    renderer = Renderer(images_dir=images_dir,
                        #size=(800, 600),
                        output_timestep=timedelta(hours=1),
                        draw_ontop='uncertain')
    renderer.viewport = ((-76.5, 37.), (-75.8, 38.))

    print 'adding outputters'
    model.outputters += renderer

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

    model.outputters += NetCDFOutput(netcdf_file, which_data='most',
                                     output_timestep=timedelta(hours=2))

    print 'adding two spills'
    # Break the spill into two spills, first with the larger droplets
    # and second with the smaller droplets.
    # Split the total spill volume (100 m^3) to have most
    # in the larger droplet spill.
    # Smaller droplets start at a lower depth than larger

    wd = WeibullDistribution(alpha=1.8, lambda_=.00456,
                             min_=.0002)  # 200 micron min
    end_time = start_time + timedelta(hours=24)
    spill = point_line_release_spill(num_elements=1000,
                                     volume=90,  # default volume_units=m^3
                                     start_position=(-76.126872, 37.680952,
                                                     1700),
                                     release_time=start_time,
                                     end_release_time=end_time,
                                     element_type=plume(distribution=wd))
    model.spills += spill

    wd = WeibullDistribution(alpha=1.8, lambda_=.00456,
                             max_=.0002)  # 200 micron max
    spill = point_line_release_spill(num_elements=1000, volume=10,
                                     start_position=(-76.126872, 37.680952,
                                                     1800),
                                     release_time=start_time,
                                     element_type=plume(distribution=wd))
    model.spills += spill

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

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

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

    # print 'adding a wind mover:'

    # series = np.zeros((2, ), dtype=gnome.basic_types.datetime_value_2d)
    # series[0] = (start_time, (30, 90))
    # series[1] = (start_time + timedelta(hours=23), (30, 90))

    # wind = Wind(timeseries=series, units='knot')
    #
    # default is .4 radians
    # w_mover = gnome.movers.WindMover(wind, uncertain_angle_scale=0)
    #
    # model.movers += w_mover

    print 'adding a simple mover:'
    s_mover = SimpleMover(velocity=(0.0, -.1, 0.0))
    model.movers += s_mover

    return model
开发者ID:JamesMakela-NOAA,项目名称:PyGnome,代码行数:85,代码来源:script_plume.py


注:本文中的gnome.outputters.Renderer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。