コード例 #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
ファイル: test_tideflat_map.py プロジェクト: nilodna/PyGnome
def test_refloat_elements():
    tfm = TideflatMap(get_gnomemap(), get_simple_tideflat())

    # Fake spill_container
    sc = {
        'next_positions':
        np.array((
            (12, 11, 0),  # in water
            (13.5, 13.5, 0),  # on_land (if the map did that)
            (12.5, 12.5, 0),  # still on tideflat
            (11.5, 12.5, 0),  # no longer on tideflat
            (12.5, 13.5, 0),  # in water
        )),
        'status_codes':
        np.array((
            oil_status.in_water,
            oil_status.on_land,
            oil_status.on_tideflat,
            oil_status.on_tideflat,
            oil_status.in_water,
        ))
    }

    tfm.refloat_elements(sc, gs.minutes(10), datetime(2018, 1, 1, 12, 30))
    assert np.all(sc['status_codes'] == np.array((
        oil_status.in_water,
        oil_status.on_land,
        oil_status.on_tideflat,
        oil_status.in_water,
        oil_status.in_water,
    )))
コード例 #3
0
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
コード例 #4
0
def test_refloat_elements():
    tfm = TideflatMap(get_gnomemap(), get_simple_tideflat())

    # Fake spill_container
    sc = {'next_positions': np.array(((12, 11, 0),  # in water
                                      (13.5, 13.5, 0),  # on_land (if the map did that)
                                      (12.5, 12.5, 0),  # still on tideflat
                                      (11.5, 12.5, 0),  # no longer on tideflat
                                      (12.5, 13.5, 0),  # in water
                                      )),
          'status_codes': np.array((oil_status.in_water,
                                    oil_status.on_land,
                                    oil_status.on_tideflat,
                                    oil_status.on_tideflat,
                                    oil_status.in_water,
                                    ))}

    tfm.refloat_elements(sc, gs.minutes(10), datetime(2018, 1, 1, 12, 30))
    assert np.all(sc['status_codes'] == np.array((oil_status.in_water,
                                                  oil_status.on_land,
                                                  oil_status.on_tideflat,
                                                  oil_status.in_water,
                                                  oil_status.in_water,
                                                  ))
                  )
コード例 #5
0
def test_model_full_run_output_short_interval(model, output_dir):
    '''
    Test weathering outputter with a model since simplest to do that

    (I'm being impatient -- I hope I don't regret that)
    '''

    outfilename = os.path.join(output_dir, "test_oil_budget2.csv")

    model.outputters += OilBudgetOutput(outfilename,
                                        output_timestep=gs.minutes(30))

    print OilBudgetOutput.clean_output_files

    model.rewind()

    model.full_run()

    # was the file created?

    out_filename = os.path.join(output_dir, outfilename)
    assert os.path.isfile(out_filename)

    # read the file in and test a couple things
    csv_file = open(out_filename).readlines()

    print "file is:",
    print csv_file

    print len(csv_file)

    assert len(csv_file) == 50

    assert csv_file[0].split(",")[0] == "Model Time"

    assert csv_file[1].split(",")[0].strip() == "0:00"
    assert csv_file[2].split(",")[0].strip() == "0:30"

    print csv_file[-1]
    assert csv_file[-1].split(",")[0].strip() == "24:00"
コード例 #6
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
コード例 #7
0
from gnome.utilities.time_utils import asdatetime

from wadden_mudflats_matroos import Matroos_Mudflats

data_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../"))

# Simulation outputs:
# use this place to script the folder based on test number or something
# it will be a relative path to this script
out_dir = 'mudflat_matroos_test_real'

# Model parameters:
start_time = "2018-10-11 05:00"  # time 00:00 if you don't specify
model_duration = gs.hours(24)

dT_OUT = gs.minutes(30)

currentfile = 'MatroosRect.nc'

# constant wind (in both time and space)
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):
コード例 #8
0
def test_full_model_run():
    """
    This will have a couple movers, and make sure that the
    on_tideflat status code stops all movers.

    only winds and currents for now
    """
    start_time = "2018-09-10T12:00"

    model = Model(
        start_time=start_time,
        time_step=sc.minutes(10),
    )

    #                   start_time=round_time(datetime.now(), 3600),

    #                   duration=timedelta(days=1),
    #                  weathering_substeps=1,
    #                  map=None,
    #                  uncertain=False,
    #                  cache_enabled=False,
    #                  mode=None,
    #                  location=[],
    #                  environment=[],
    #                  outputters=[],
    #                  movers=[],
    #                  weatherers=[],
    #                  spills=[],
    #                  uncertain_spills=[],
    #                  **kwargs):
    # )

    model.movers += constant_wind_mover(speed=10, direction=225, units='m/s')

    model.movers += RandomMover()  # defaults are fine

    model.spills += point_line_release_spill(
        num_elements=10,
        start_position=(0.0, 0.0, 0.0),
        release_time=start_time,
    )

    # fixme: should maybe add currents -- though if the currents are smart,
    #        they should be zero on the tideflats

    # run one step:
    print model.step()
    # step zero -- should be released, but not yet moved
    positions = model.get_spill_property('positions').copy()
    assert np.all(positions == 0.0)
    prev_positions = positions

    print model.step()
    # step one -- all elements should have moved in horizontal
    positions = model.get_spill_property('positions').copy()
    assert np.all(positions[:, 0:1] != prev_positions[:, 0:1])
    assert np.all(positions[:, 2] == prev_positions[:, 2])
    prev_positions = positions

    # Now set the flags for half of the elements
    status_codes = model.get_spill_property('status_codes')
    new_status_codes = np.array([oil_status.on_tideflat] * 5 +
                                [oil_status.in_water] * 5)
    status_codes[:] = new_status_codes

    # make sure it took
    assert np.all(model.get_spill_property('status_codes') == new_status_codes)

    # step the model again
    model.step()
    positions = model.get_spill_property('positions').copy()
    delta = positions - prev_positions
    # first five should not have moved
    assert np.all(delta[:5, 0:1] == 0.0)
    assert np.all(delta[5:, 0:1] != 0.0)
    prev_positions = positions

    # reset status codes to in_water:
    model.get_spill_property('status_codes')[:] = oil_status.in_water

    # step the model again
    print model.step()
    positions = model.get_spill_property('positions').copy()
    delta = positions - prev_positions
    # they all should have moved again
    assert np.all(delta[:, 0:1] != 0.0)
コード例 #9
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
コード例 #10
0
ファイル: mudflat_example.py プロジェクト: WaddenseaOILS/OILS
# SpillPosition = (5.122382, 53.327899, 0) # tussen VL en TX
SpillPosition = (5.210218, 53.231510, 0)  # route Harlingen Terschelling
##

# 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(30))

bounds = (
    (5.399281, 53.283564),
    (5.323750, 53.279459),
    (5.246845, 53.243314),
    (5.204273, 53.195623),
    (5.197407, 53.137170),
    (5.226246, 53.096783),
    (5.307270, 53.093485),
    (5.413014, 53.113272),
    (5.447346, 53.190687),
    (5.525624, 53.245779),
)
tideflat = SimpleTideflat(bounds, "2009-01-01T09:00", "2009-01-01T018:00")