Exemplo n.º 1
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
Exemplo n.º 2
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
Exemplo n.º 3
0
def main(RootDir, Data_Dir, StartSite, RunSite, NumStarts, RunStarts,
         ReleaseLength, TrajectoryRunLength, StartTimeFiles, TrajectoriesPath,
         NumLEs, MapFileName, refloat, current_files, wind_files,
         diffusion_coef, model_timestep, windage_range, windage_persist,
         OutputTimestep):

    timingRecord = open(os.path.join(RootDir, "timing.txt"), "w")
    count = len(StartTimeFiles) * len(RunStarts)
    timingRecord.write("This file tracks the time to process " + str(count) +
                       " gnome runs")

    # model timing
    release_duration = timedelta(hours=ReleaseLength)
    run_time = timedelta(hours=TrajectoryRunLength)

    # initiate model
    model = Model(duration=run_time, time_step=model_timestep, uncertain=False)

    # determine boundary for model
    print "Adding the map:", MapFileName
    mapfile = get_datafile(os.path.join(Data_Dir, MapFileName))
    # model.map = MapFromBNA(mapfile, refloat_halflife=refloat) no, model map needs to inclde mudflats. later

    # loop through seasons
    for Season in StartTimeFiles:
        timer1 = datetime.now()

        SeasonName = Season[1]
        start_times = open(Season[0], 'r').readlines()[:NumStarts]
        SeasonTrajDir = os.path.join(RootDir, TrajectoriesPath, SeasonName)
        if not os.path.isdir(SeasonTrajDir):
            print "Creating directory: ", SeasonTrajDir
            make_dir(SeasonTrajDir)
        print "  Season:", SeasonName

        # get and parse start times in this season
        start_dt = []
        for start_time in start_times:
            start_time = [int(i) for i in start_time.split(',')]
            start_time = datetime(start_time[0], start_time[1], start_time[2],
                                  start_time[3], start_time[4])
            start_dt.append(start_time)

        ## loop through start times
        for time_idx in RunStarts:
            timer2 = datetime.now()

            gc.collect()
            model.movers.clear()

            ## set the start location
            start_time = start_dt[time_idx]
            end_time = start_time + run_time
            model.start_time = start_time
            print "  ", start_time, "to", end_time

            ## get a list of the only data files needed for the start time (less data used)
            ## note: requires data files in year increments
            #Todo: needs fixing before real run
            years = range(start_time.year, end_time.year + 1)
            years = [str(i) for i in years]
            wind = [s for s in wind_files if any(xs in s for xs in years)]
            current = [
                s for s in current_files if any(xs in s for xs in years)
            ]

            #Todo: add mudflats. Does it work like this?
            topology = {'node_lon': 'x', 'node_lat': 'y'}

            ## add wind movers
            w_mover = PyWindMover(filename=wind)
            model.movers += w_mover

            ## add current movers
            current_mover = gs.GridCurrent.from_netCDF(current,
                                                       grid_topology=topology)
            c_mover = PyCurrentMover(current=current_mover)
            model.movers += c_mover

            tideflat = Matroos_Mudflats(current, grid_topology=topology)
            land_map = gs.MapFromBNA(mapfile)
            model.map = TideflatMap(land_map, tideflat)

            ## add diffusion
            model.movers += RandomMover(diffusion_coef=diffusion_coef)

            ## loop through start locations
            timer3 = datetime.now()

            #Todo: can it deal with the test.location.txt file??
            start_position = [float(i) for i in StartSite.split(',')]

            OutDir = os.path.join(RootDir, TrajectoriesPath, SeasonName,
                                  'pos_%03i' % (RunSite + 1))
            make_dir(OutDir)

            print "    ", RunSite, time_idx
            print "    Running: start time:", start_time,
            print "at start location:", start_position

            ## set the spill to the location
            spill = surface_point_line_spill(
                num_elements=NumLEs,
                start_position=(start_position[0], start_position[1], 0.0),
                release_time=start_time,
                end_release_time=start_time + release_duration,
                windage_range=windage_range,
                windage_persist=windage_persist)

            # print "adding netcdf output"
            netcdf_output_file = os.path.join(
                OutDir,
                'pos_%03i-t%03i_%08i.nc' %
                (RunSite + 1, time_idx, int(start_time.strftime('%y%m%d%H'))),
            )
            model.outputters.clear()
            model.outputters += NetCDFOutput(
                netcdf_output_file,
                output_timestep=timedelta(hours=OutputTimestep))

            model.spills.clear()
            model.spills += spill

            model.full_run(rewind=True)

            timer4 = datetime.now()
            diff = round((timer4 - timer3).total_seconds() / 60, 2)
            timingRecord.write("\t\t" + str(RunSite) + " took " + str(diff) +
                               " minutes to complete")
        diff = round((timer4 - timer1).total_seconds() / 3600, 2)
        count = len(RunStarts)
        timingRecord.write("\t" + str(SeasonName) + " took " + str(diff) +
                           " hours to finish " + str(count) + " Gnome runs")
    #OutDir.close
    timingRecord.close
Exemplo n.º 4
0
print 'Adding current'
model.movers += current_mover

print 'Adding RandomMover'
model.movers += gs.RandomMover(diffusion_coeff=50000)

print 'adding a wind mover:'

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),
Exemplo n.º 5
0
            #                                  end_position=( start_position[0]+0.4, start_position[1]+0.2, 0.0 ),
            #                                  release_time=start_time,
            #                                  end_release_time=start_time+release_duration
            #                                  )
            # spill = point_line_release_spill(num_elements=setup.NumLEs,
            #                                  start_position=( start_position[0], start_position[1], 0.0 ),
            #                                  release_time=start_time,
            #                                  end_release_time=start_time+release_duration,
            #                                  windage_range=(setup.Windage),
            #                                  windage_persist=setup.WindagePersist
            #                                  )

            spill = surface_point_line_spill(
                num_elements=setup.NumLEs,
                start_position=(start_position[0], start_position[1], 0.0),
                release_time=start_time,
                end_release_time=start_time + release_duration,
                windage_range=(setup.Windage),
                windage_persist=setup.WindagePersist)

            # set up the renderer location
            image_dir = os.path.join(
                setup.RootDir, 'Images', SeasonName,
                'images_pos_%03i-time_%03i' % (pos_idx + 1, time_idx))
            renderer = Renderer(
                os.path.join(setup.RootDir, setup.MapFileName),
                image_dir,
                image_size=(800, 600),
                output_timestep=timedelta(hours=setup.out_delta))
            renderer.graticule.set_DMS(True)
            #renderer.viewport = ((-120.6666, 33.75),(-119.25, 34.5))