コード例 #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
def make_model():

    print 'initializing the model'
    model = gs.Model(duration=gs.days(5))


    print 'adding outputters'
    budget_file = os.path.join(base_dir, 'GNOME_oil_budget.csv')
    model.outputters += gs.OilBudgetOutput(budget_file)

    print 'adding a spill'
    # We need a spill at the very least
    spill = gs.point_line_release_spill(num_elements=10,  # no need for a lot of elements for a instantaneous release
                                        start_position=(0.0, 0.0, 0.0),
                                        release_time=model.start_time,
                                        amount=1000,
                                        substance='ALASKA NORTH SLOPE (MIDDLE PIPELINE, 1997)',
                                        units='bbl')

    model.spills += spill

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

    print 'adding a wind mover:'

    model.movers += gs.constant_wind_mover(speed=10, direction=0, units="m/s")


    model.environment += gs.Water(25, units={"temperature": "C"})

    waves = gs.Waves()
    model.environment += waves

    print 'adding the standard weatherers'
    model.add_weathering()

    return model
コード例 #3
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
コード例 #4
0
Wind = {"speed": 10, "direction": 270, "units": "m/s"}

SpillPosition = (5.122382, 53.327899, 0)  # tussen VL en TX
# SpillPosition = (5.210218, 53.231510, 0)  # route Harlingen Terschelling
# SpillPosition = (4.834194, 52.936454, 0)

# Model Parameters:
base_dir = os.path.dirname(__file__)
newpath = os.path.join(base_dir, out_dir)

if not os.path.exists(newpath):
    os.makedirs(newpath)

print 'init model'
model = gs.Model(start_time=start_time,
                 duration=model_duration,
                 time_step=gs.minutes(1))

print 'Loading current'
topology = {'grid_type': 'rgrid', 'node_lon': 'x', 'node_lat': 'y'}
current = gs.GridCurrent.from_netCDF(os.path.join(data_dir, currentfile),
                                     grid_topology=topology)
angle = TimeseriesData.constant(name='angle', data=17.0, units='degrees')

current.angle = angle
current_mover = PyCurrentMover(current=current)

print 'Adding  map'

tideflat = Matroos_Mudflats(os.path.join(data_dir, currentfile),
                            grid_topology=topology)
コード例 #5
0
# define base directory
base_dir = os.path.dirname(__file__)
images_dir = os.path.join(base_dir, 'images')

WINDAGE = 0.03
print "running with windage:", WINDAGE

# gs.set_verbose('info')
# pf = gs.PrintFinder()

rel_time = "2019-04-18T21:00:00"

model = gs.Model(
    name='Whale Drift',
    time_step=3600,
    start_time=rel_time,
    duration=gs.days(3),
)

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

model.map = gs.MapFromBNA(mapfile, refloat_halflife=float("inf"))

# nam = gs.PyWindMover("NAM_5K.nc")
# nam.active_range = (gs.MinusInfTime(),
#                     gs.asdatetime("2019-04-19T22:00"))
# model.movers += nam

# gfs = gs.PyWindMover("GFS_Global_0p5deg-4-18.nc")
# model.movers += gfs
コード例 #6
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
コード例 #7
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