コード例 #1
0
ファイル: test_tideflat_map.py プロジェクト: nilodna/PyGnome
def simple_model(output_dir):
    start_time = "2018-09-20T12:00"
    model = gs.Model(
        start_time=start_time,
        duration=gs.days(1),
        time_step=gs.minutes(30),
        name="test model for tideflats",
    )
    model.map = MapFromBNA(bna_file)
    model.movers += gs.constant_wind_mover(10, 300, "m/s")

    model.spills += gs.surface_point_line_spill(
        num_elements=100,
        start_position=(5.4, 53.38, 0),
        end_position=(5.8, 53.4, 0),
        release_time=start_time,
    )
    model.outputters += gs.Renderer(
        output_timestep=gs.hours(1),
        map_filename=bna_file,
        output_dir=output_dir,
        formats=['gif'],  # ['gif', 'png']
        image_size=(800, 400),
        # viewport=((4.5, 53.0),
        #           (5.5, 53.5)),
    )

    return model
コード例 #2
0
ファイル: script_boston.py プロジェクト: simomartini/PyGnome
def make_model(images_dir=os.path.join(base_dir, 'images')):

    # create the maps:

    print 'creating the maps'
    mapfile = gs.get_datafile(os.path.join(base_dir, './MassBayMap.bna'))
    gnome_map = gs.MapFromBNA(
        mapfile,
        refloat_halflife=1,  # hours
        raster_size=2048 * 2048  # about 4 MB
    )

    renderer = gs.Renderer(mapfile,
                           images_dir,
                           image_size=(800, 800),
                           projection_class=GeoProjection)

    print 'initializing the model'
    # start_time = datetime(2013, 3, 12, 10, 0)
    start_time = "2013-03-12T10:00"
    # 15 minutes in seconds
    # Default to now, rounded to the nearest hour
    model = gs.Model(time_step=gs.minutes(15),
                     start_time=start_time,
                     duration=gs.days(1),
                     map=gnome_map,
                     uncertain=True)

    print 'adding outputters'
    model.outputters += renderer

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

    model.outputters += gs.KMZOutput(
        os.path.join(base_dir, 'script_boston.kmz'))

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

    print 'adding a wind mover:'

    # series = np.zeros((2, ), dtype=datetime_value_2d)
    # series[0] = (start_time, (5, 180))
    # series[1] = (start_time + timedelta(hours=25), (5, 180))

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

    w_mover = gs.constant_wind_mover(5, 180, units='m/s')
    model.movers += w_mover
    print 'adding a cats shio mover:'

    curr_file = gs.get_datafile(os.path.join(base_dir, r"./EbbTides.cur"))
    tide_file = gs.get_datafile(os.path.join(base_dir, r"./EbbTidesShio.txt"))

    c_mover = gs.CatsMover(curr_file, tide=gs.Tide(tide_file))
    # this is the value in the file (default)
    c_mover.scale_refpoint = (-70.8875, 42.321333)
    c_mover.scale = True
    c_mover.scale_value = -1

    model.movers += c_mover

    # TODO: cannot add this till environment base class is created
    # model.environment += c_mover.tide

    print 'adding a cats ossm mover:'

    # ossm_file = get_datafile(os.path.join(base_dir,
    #                          r"./MerrimackMassCoastOSSM.txt"))
    curr_file = gs.get_datafile(
        os.path.join(base_dir, "MerrimackMassCoast.cur"))
    tide_file = gs.get_datafile(
        os.path.join(base_dir, "MerrimackMassCoastOSSM.txt"))
    c_mover = gs.CatsMover(curr_file, tide=gs.Tide(tide_file))

    # but do need to scale (based on river stage)
    c_mover.scale = True
    c_mover.scale_refpoint = (-70.65, 42.58333)
    c_mover.scale_value = 1.
    model.movers += c_mover
    model.environment += c_mover.tide

    print 'adding a cats mover:'
    curr_file = gs.get_datafile(os.path.join(base_dir, "MassBaySewage.cur"))
    c_mover = gs.CatsMover(curr_file)

    # but do need to scale (based on river stage)

    c_mover.scale = True
    c_mover.scale_refpoint = (-70.78333, 42.39333)

    # the scale factor is 0 if user inputs no sewage outfall effects
    c_mover.scale_value = .04

    model.movers += c_mover

    # pat1Angle 315;
    # pat1Speed 19.44; pat1SpeedUnits knots;
    # pat1ScaleToValue 0.138855
    #
    # pat2Angle 225;
    # pat2Speed 19.44; pat2SpeedUnits knots;
    # pat2ScaleToValue 0.05121
    #
    # scaleBy WindStress

    print "adding a component mover:"
    component_file1 = gs.get_datafile(os.path.join(base_dir, "WAC10msNW.cur"))
    component_file2 = gs.get_datafile(os.path.join(base_dir, "WAC10msSW.cur"))
    comp_mover = gs.ComponentMover(component_file1, component_file2,
                                   w_mover.wind)

    # todo: callback did not work correctly below - fix!
    # comp_mover = ComponentMover(component_file1,
    #                             component_file2,
    #                             Wind(timeseries=series, units='m/s'))

    comp_mover.scale_refpoint = (-70.855, 42.275)
    comp_mover.pat1_angle = 315
    comp_mover.pat1_speed = 19.44
    comp_mover.pat1_speed_units = 1
    comp_mover.pat1ScaleToValue = .138855
    comp_mover.pat2_angle = 225
    comp_mover.pat2_speed = 19.44
    comp_mover.pat2_speed_units = 1
    comp_mover.pat2ScaleToValue = .05121

    model.movers += comp_mover

    print 'adding a spill'

    end_time = gs.asdatetime(start_time) + gs.hours(12)
    spill = gs.point_line_release_spill(num_elements=100,
                                        start_position=(-70.911432, 42.369142,
                                                        0.0),
                                        release_time=start_time,
                                        end_release_time=end_time)

    model.spills += spill

    return model
コード例 #3
0
model.movers += gs.constant_wind_mover(**Wind)

print 'adding spill'
spill = gs.surface_point_line_spill(num_elements=100,
                                    start_position=SpillPosition,
                                    end_position=(SpillPosition[0],
                                                  SpillPosition[1] - 0.1, 0),
                                    release_time=asdatetime(start_time),
                                    amount=5000,
                                    units='kg',
                                    name='My spill')
model.spills += spill

model.outputters += gs.NetCDFOutput(os.path.join(out_dir, 'test_output.nc'),
                                    which_data='most',
                                    output_timestep=dT_OUT)

renderer = gs.Renderer(
    output_timestep=dT_OUT,
    map_filename=mapfile,
    output_dir=out_dir,
    formats=['gif'],  # ['gif', 'png']
    image_size=(1280, 1024),
    viewport=((4.5, 53.0), (5.5, 53.5)))
model.outputters += renderer

gs.set_verbose()  # get some more info as the model runs

print "Doing a full run:"
model.full_run()
コード例 #4
0
    windage_persist=(-1),
    name='Whale Release Options',
)

model.movers += gs.RandomMover(diffusion_coef=10000)

model.outputters += gs.Renderer(
    map_filename=mapfile,
    output_dir=images_dir,
    image_size=(800, 800),
    projection=None,
    viewport=((-124.0, 36.0), (-122.0, 38.0)),
    map_BB=None,
    draw_back_to_fore=True,
    draw_map_bounds=False,
    draw_spillable_area=False,
    formats=['gif'],
    draw_ontop='forecast',
    output_timestep=None,
    output_zero_step=True,
    output_last_step=True,
    output_start_time=None,
    on=True,
    timestamp_attrib={},
)

outfilename = "whale_run_windage_{:.1f}.nc".format(WINDAGE * 100)
netcdf_file = os.path.join(base_dir, outfilename)
model.outputters += gs.NetCDFOutput(netcdf_file,
                                    which_data='standard',
                                    output_timestep=gs.hours(3),
コード例 #5
0
ファイル: script_ice.py プロジェクト: nilodna/PyGnome
def make_model(images_dir=os.path.join(base_dir, 'images')):
    print 'initializing the model'

    start_time = "1985-01-01T13:31"

    model = gs.Model(start_time=start_time,
                     duration=gs.days(2),
                     time_step=gs.hours(1))

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

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

    print 'adding outputters'
    renderer = gs.Renderer(mapfile, images_dir, image_size=(1024, 768))
    renderer.set_viewport(((-165, 69), (-161.5, 70)))

    # model.outputters += renderer

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

    print 'adding a spill'
    # For a subsurfce spill, you would need to add vertical movers:
    # - gs.RiseVelocityMover
    # - gs.RandomVerticalMover
    spill1 = gs.point_line_release_spill(num_elements=1000,
                                         start_position=(-163.75, 69.75, 0.0),
                                         release_time=start_time)

    model.spills += spill1

    print 'adding the ice movers'
    fn = [
        gs.get_datafile('arctic_avg2_0001_gnome.nc'),
        gs.get_datafile('arctic_avg2_0002_gnome.nc'),
    ]

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

    ice_aware_curr = gs.IceAwareCurrent.from_netCDF(filename=fn,
                                                    grid_topology=gt)
    ice_aware_wind = gs.IceAwareWind.from_netCDF(
        filename=fn,
        grid=ice_aware_curr.grid,
    )
    method = 'RK2'

    i_c_mover = gs.PyCurrentMover(current=ice_aware_curr,
                                  default_num_method=method)
    i_w_mover = gs.PyWindMover(wind=ice_aware_wind, default_num_method=method)

    # shifting to -360 to 0 longitude
    ice_aware_curr.grid.node_lon = ice_aware_curr.grid.node_lon[:] - 360
    model.movers += i_c_mover
    model.movers += i_w_mover

    print 'adding an Ice RandomMover:'
    model.movers += IceAwareRandomMover(
        ice_concentration=ice_aware_curr.ice_concentration,
        diffusion_coef=50000)

    # to visualize the grid and currents
    #     renderer.add_grid(ice_aware_curr.grid)
    #     renderer.add_vec_prop(ice_aware_curr)

    return model
コード例 #6
0
def make_model():
    """
    Set up a GNOME simulation that uses TAMOC

    Set up a spill scenario in GNOME that uses TAMOC to simulate a subsurface
    blowout and then pass the TAMOC solution to GNOME for the far-field
    particle tracking

    """
    # Set up the directory structure for the model
    base_dir, images_dir, outfiles_dir = set_directory_structure()

    # Set up the modeling environment
    print '\n-- Initializing the Model         --'
    start_time = "2019-06-01T12:00"
    model = gs.Model(start_time=start_time,
                     duration=gs.days(3),
                     time_step=gs.minutes(30),
                     uncertain=False)

    # Add a map
    print '\n-- Adding a Map                   --'
    model.map = gs.GnomeMap()

    # Add image output
    print '\n-- Adding Image Outputters        --'
    renderer = gs.Renderer(output_dir=images_dir,
                           image_size=(1024, 768),
                           output_timestep=gs.hours(1),
                           viewport=((-0.15, -0.35), (0.15, 0.35)))
    model.outputters += renderer

    # Add NetCDF output
    print '\n-- Adding NetCDF Outputter        --'
    if not os.path.exists(outfiles_dir):
        os.mkdir(outfiles_dir)
    netcdf_file = os.path.join(outfiles_dir, 'script_tamoc.nc')
    gs.remove_netcdf(netcdf_file)
    file_writer = gs.NetCDFOutput(netcdf_file,
                                  which_data='all',
                                  output_timestep=gs.hours(2))
    model.outputters += file_writer

    # Add a spill object
    print '\n-- Adding a Point Spill           --'
    end_release_time = model.start_time + gs.hours(12)
    point_source = ts.TamocSpill(num_elements=100,
                                 start_position=(0.0, 0.0, 1000.),
                                 release_duration=gs.hours(24),
                                 release_time=start_time,
                                 substance='AD01554',
                                 release_rate=20000.,
                                 units='bbl/day',
                                 gor=500.,
                                 d0=0.5,
                                 phi_0=-np.pi / 2.,
                                 theta_0=0.,
                                 windage_range=(0.01, 0.04),
                                 windage_persist=900,
                                 name='Oil Well Blowout')

    model.spills += point_source

    # Create an ocean environment
    water, wind, waves = base_environment(water_temp=273.15 + 21.,
                                          wind_speed=5.,
                                          wind_dir=225.)

    # Add a uniform current in the easterly direction
    print '\n-- Adding Currents                --'
    uniform_current = gs.SimpleMover(velocity=(0.1, 0.0, 0.))
    model.movers += uniform_current

    # Add a wind mover
    wind_mover = gs.WindMover(wind)
    model.movers += wind_mover

    # Add particle diffusion...note, units are in cm^2/s
    print '\n-- Adding Particle Diffusion      --'
    particle_diffusion = gs.RandomMover3D(
        horizontal_diffusion_coef_above_ml=100000.,
        horizontal_diffusion_coef_below_ml=10000.,
        vertical_diffusion_coef_above_ml=100.,
        vertical_diffusion_coef_below_ml=10.,
        mixed_layer_depth=15.)
    model.movers += particle_diffusion

    # Add rise velocity for droplets
    print '\n-- Adding Particle Rise Velocity  --'
    # fixme: we do have code for rise velocity:
    #  gnome.movers.RiseVelocityMover
    #  let's test that later
    slip_velocity = gs.SimpleMover(velocity=(0.0, 0.0, -0.1))
    model.movers += slip_velocity

    # Add dissolution
    print '\n-- Adding Weathering              --'
    evaporation = Evaporation(water=water, wind=wind)
    model.weatherers += evaporation

    dissolution = Dissolution(waves=waves, wind=wind)
    model.weatherers += dissolution

    return model