Пример #1
0
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,
                        image_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,
        substance=NonWeatheringSubstance(windage_range=(0.01, .04))
        #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, 'WindSpeedDirSubset.nc'))
    topology_file = get_datafile(
        os.path.join(base_dir, '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
Пример #2
0
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
Пример #3
0
def make_model(images_dir=os.path.join(base_dir, 'images')):

    print('get contiguous')

    kml_file = os.path.join(base_dir, 'contigua.kml')
    with open(kml_file) as f:
        contiguous = parser.parse(f).getroot().Document

    coordinates = contiguous.Placemark.LineString.coordinates.text.split(' ')
    cont_coord = []
    for x in coordinates:
        x = x.split(',')
        if len(x) > 1 and float(x[1]) > -12 and float(x[1]) < -3:
            cont_coord.append([float(x[0]), float(x[1])])

    print('initializing the model')

    start_time = datetime(2022, 1, 22, 12, 0)
    mapfile = get_datafile(os.path.join(base_dir, './brazil-coast.BNA'))

    gnome_map = MapFromBNA(mapfile, refloat_halflife=6)  # hours

    duration = timedelta(days=1)
    timestep = timedelta(minutes=5)
    end_time = start_time + duration

    steps = duration.total_seconds() / timestep.total_seconds()

    print("Total step: %.4i " % (steps))

    # one hour timestep
    model = Model(start_time=start_time,
                  duration=duration,
                  time_step=timestep,
                  map=gnome_map,
                  uncertain=False,
                  cache_enabled=False)

    oil_name = 'GENERIC MEDIUM CRUDE'

    wd = UniformDistribution(low=.0002, high=.0002)

    subs = GnomeOil(oil_name, initializers=plume_initializers(distribution=wd))

    #model.spills += point_line_release_spill(release_time=start_time, start_position=(-35.153, -8.999, 0.0), num_elements=1000, end_release_time=end_time, substance= subs, units='kg')
    #model.spills += point_line_release_spill(release_time=start_time, start_position=(-35.176, -9.135, 0.0), num_elements=1000, end_release_time=end_time, substance= subs, units='kg')
    #model.spills += point_line_release_spill(release_time=start_time, start_position=(-35.062, -9.112, 0.0), num_elements=1000, end_release_time=end_time, substance= subs, units='kg')
    #model.spills += point_line_release_spill(release_time=start_time, start_position=(-34.994, -9.248, 0.0), num_elements=1000, end_release_time=end_time, substance= subs, units='kg')

    for idx in range(0, len(cont_coord)):
        model.spills += point_line_release_spill(
            num_elements=500,
            start_position=(cont_coord[idx][0], cont_coord[idx][1], 0.0),
            release_time=start_time,
            end_release_time=start_time + timedelta(days=1),
            amount=500,
            substance=subs,
            units='kg')

    #shp_file = os.path.join(base_dir, 'surface_concentration')
    #scripting.remove_netcdf(shp_file + ".zip")
    #model.outputters += ShapeOutput(shp_file,
    #                                zip_output=False,
    #                                surface_conc="kde",
    #                                )

    print('adding movers:')

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

    print('adding a current mover:')

    # # this is HYCOM currents
    curr_file = get_datafile(os.path.join(base_dir, 'currents.nc'))
    model.movers += GridCurrentMover(curr_file, num_method='Euler')

    print('adding a grid wind mover:')
    wind_file = get_datafile(os.path.join(base_dir, 'wind.nc'))
    #topology_file = get_datafile(os.path.join(base_dir, 'WindSpeedDirSubsetTop.dat'))
    #w_mover = GridWindMover(wind_file, topology_file)
    w_mover = GridWindMover(wind_file)
    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

    print('adding outputters')

    renderer = Renderer(mapfile,
                        images_dir,
                        image_size=(900, 600),
                        output_timestep=timestep,
                        draw_ontop='forecast')
    #set the viewport to zoom in on the map:
    #renderer.viewport = ((-37, -11), (-34, -8)) #alagoas
    renderer.viewport = ((-36, -10), (-30, 5))
    model.outputters += renderer

    netcdf_file = os.path.join(base_dir, 'contigua.nc')
    scripting.remove_netcdf(netcdf_file)
    model.outputters += NetCDFOutput(netcdf_file,
                                     which_data='standard',
                                     surface_conc='kde')

    return model
Пример #4
0
def make_model(images_dir=os.path.join(base_dir, 'images2')):
    print('initializing the model')

    start_time = datetime(int(sys.argv[1]), int(sys.argv[2]), int(sys.argv[3]),
                          int(sys.argv[4]), int(sys.argv[5]))
    mapfile = get_datafile(os.path.join(base_dir, './brazil-coast.bna'))

    gnome_map = MapFromBNA(mapfile, refloat_halflife=6)  # hours

    # # the image output renderer
    # global renderer
    #duration = timedelta(minutes=5)
    #timestep = timedelta(minutes=5)
    duration = timedelta(minutes=5)
    timestep = timedelta(minutes=5)
    endtime = start_time + duration

    steps = duration.total_seconds() / timestep.total_seconds()

    print("Total step: %.4i " % (steps))

    model = Model(start_time=start_time,
                  duration=duration,
                  time_step=timestep,
                  map=gnome_map,
                  uncertain=False,
                  cache_enabled=False)

    oil_name = 'GENERIC MEDIUM CRUDE'

    wd = UniformDistribution(low=.0002, high=.0002)

    subs = GnomeOil(oil_name, initializers=plume_initializers(distribution=wd))

    #print 'adding a spill'
    #spill = point_line_release_spill(num_elements=122,
    #                                 start_position=(-35.14,
    #                                                 -9.40, 0.0),
    #                                 release_time=start_time)
    #model.spills += spill

    #spill2 = spatial_release_spill(-35.14,-9.40, 0.0, start_time)
    #model.spills += spill2

    #print 'load nc'
    #netcdf_file = os.path.join(base_dir, 'maceio.nc')
    #relnc = InitElemsFromFile(netcdf_file,release_time=start_time)
    #relnc = InitElemsFromFile(netcdf_file,index=5)
    #spillnc = Spill(release=relnc)
    #print spillnc.release.num_elements
    #print spillnc.release.name
    #print spillnc.substance
    #print relnc._init_data['age']
    #print relnc.release_time

    #model.spills += spillnc

    #model._load_spill_data()

    #for sc in model.spills.items():
    #    sc.prepare_for_model_run()

    #print(relnc.num_elements)
    #print(relnc.num_released)

    # add particles - it works
    print('adding particles')
    # Persistent oil spill in contiguous zone border
    if int(sys.argv[6]) == 1:
        release = release_from_splot_data(start_time, 'contiguous.txt')
        print("Adding new particles")
        model.spills += Spill(release=release, substance=subs)

    # Particles from previows simulation step
    try:
        f = open('step.txt')
        f.close()
        release2 = release_from_splot_data(start_time, 'step.txt')
        model.spills += Spill(release=release2, substance=subs)
    except IOError:
        print('No previous step, using only contiguous.txt')

    #assert rel.num_elements == exp_num_elems
    #assert len(rel.start_position) == exp_num_elems
    #cumsum = np.cumsum(exp)
    #for ix in xrange(len(cumsum) - 1):
    #    assert np.all(rel.start_position[cumsum[ix]] ==
    #                  rel.start_position[cumsum[ix]:cumsum[ix + 1]])
    #assert np.all(rel.start_position[0] == rel.start_position[:cumsum[0]])

    #spnc = Spill(release=None)
    #spnc.release = relnc

    print('adding a RandomMover:')
    #model.movers += RandomMover(diffusion_coef=10000, uncertain_factor=2)
    model.movers += RandomMover(diffusion_coef=10000)

    print('adding a current mover:')

    # # this is HYCOM currents
    curr_file = get_datafile(os.path.join(base_dir, 'corrente15a28de09.nc'))
    model.movers += GridCurrentMover(curr_file, num_method='Euler')

    print('adding a grid wind mover:')
    wind_file = get_datafile(os.path.join(base_dir, 'vento15a28de09.nc'))
    #topology_file = get_datafile(os.path.join(base_dir, 'WindSpeedDirSubsetTop.dat'))
    #w_mover = GridWindMover(wind_file, topology_file)
    w_mover = GridWindMover(wind_file)
    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

    print('adding outputters')

    renderer = Renderer(mapfile,
                        images_dir,
                        image_size=(900, 600),
                        output_timestep=timestep,
                        draw_ontop='forecast')
    #set the viewport to zoom in on the map:
    #renderer.viewport = ((-37, -11), (-34, -8)) #alagoas
    renderer.viewport = ((-55, -34), (-30, 5))  #1/4 N alagoas
    model.outputters += renderer

    netcdf_file = os.path.join(base_dir, 'step.nc')
    scripting.remove_netcdf(netcdf_file)
    model.outputters += NetCDFOutput(netcdf_file,
                                     which_data='standard',
                                     surface_conc='kde')

    return model