def get_datafiles_in_flist(file_):
    """
    read flist1.txt, flist2.txt, gridcur_ts_hdr2.cur and download the netcdf datafiles from server if required
    
    helper function that reads each line of the file_ and gets an files that are defined by 
    [FILE] or [File] from the server
    
    NOTE: reading the text file and getting the names of the datafiles on the fly works fine. 
          It maybe simpler to define a dict containing all files required by these tests including
          the files listed in flist1.txt, flist2.txt ..currently this is the only place where this 
          needs to be done
    """

    flist = get_datafile(file_)
    with open(flist, 'r') as fh:
        while True:
            line = fh.readline()
            if len(line) == 0:
                break
            elif line[:6].lower() == '[file]':

                # read filename and download it from server if it required

                get_datafile(os.path.join(os.path.split(flist)[0],
                             line[6:].strip()))

    return flist
예제 #2
0
def CurrentsAndWinds(timeStep, start_time, duration, weatheringSteps, mapfile, uncertain, data_path, curr_path, wind_path, map_path, reFloatHalfLife, windFile, currFile, tidalFile, num_elements, depths, lat, lon, output_path, wind_scale, save_nc, timestep_outputs, weatherers, td):
    print 'initializing the model:'
    model = Model(time_step=timeStep, start_time=start_time, duration=duration)
    print 'adding the map:'
    print (data_path, map_path, mapfile)
    mapfile = get_datafile(os.path.join(data_path, map_path, mapfile))
    model.map = MapFromBNA(mapfile, refloat_halflife=reFloatHalfLife)
    print 'adding a renderer'
    model.outputters += Renderer(mapfile, output_path, size=(800, 600), output_timestep=timedelta(hours=timestep_outputs))
    if save_nc:
        nc_outputter = NetCDFOutput('currentsAndWinds_example.nc', which_data='standard', output_timestep=timedelta(hours=timestep_outputs))
        model.outputters += nc_outputter
    print 'adding a wind mover:'
    wind_file = get_datafile(os.path.join(data_path, wind_path, windFile))
    wind = GridWindMover(wind_file)
    wind.wind_scale = wind_scale
    model.movers += wind
    print 'adding a current mover: '
    curr_file = get_datafile(os.path.join(data_path, curr_path, currFile))
    model.movers += GridCurrentMover(curr_file, num_method='RK4')
    if td:
        random_mover = RandomMover(diffusion_coef=10000)
        model.movers += random_mover
    print 'adding spill'
    model.spills += point_line_release_spill(num_elements=num_elements, start_position=(lon, lat, 0), release_time=start_time, end_release_time=start_time + duration)
    return model
예제 #3
0
def make_model(images_dir=os.path.join(base_dir, 'images')):
    print 'initializing the model'

    start_time = datetime(2012, 9, 15, 12, 0)
    mapfile = get_datafile(os.path.join(base_dir, './LongIslandSoundMap.BNA'))

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

    # # the image output renderer
    # global renderer

    # one hour timestep
    model = Model(start_time=start_time,
                  duration=timedelta(hours=48),
                  time_step=3600,
                  map=gnome_map,
                  uncertain=True,
                  cache_enabled=True)

    netcdf_file = os.path.join(base_dir, 'script_long_island.nc')
    scripting.remove_netcdf(netcdf_file)

    print 'adding outputters'
    model.outputters += Renderer(mapfile, images_dir, size=(800, 600))
    model.outputters += NetCDFOutput(netcdf_file, which_data='all')

    print 'adding a spill'
    spill = point_line_release_spill(num_elements=1000,
                                     start_position=(-72.419992, 41.202120,
                                                     0.0),
                                     release_time=start_time)
    model.spills += spill

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

    print 'adding a wind mover:'
    series = np.zeros((5, ), dtype=datetime_value_2d)
    series[0] = (start_time, (10, 45))
    series[1] = (start_time + timedelta(hours=18), (10, 90))
    series[2] = (start_time + timedelta(hours=30), (10, 135))
    series[3] = (start_time + timedelta(hours=42), (10, 180))
    series[4] = (start_time + timedelta(hours=54), (10, 225))

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

    print 'adding a cats mover:'
    curr_file = get_datafile(os.path.join(base_dir, r"./LI_tidesWAC.CUR"))
    tide_file = get_datafile(os.path.join(base_dir, r"./CLISShio.txt"))

    c_mover = CatsMover(curr_file, tide=Tide(tide_file))
    model.movers += c_mover
    model.environment += c_mover.tide

    print 'viewport is:', [
        o.viewport for o in model.outputters if isinstance(o, Renderer)
    ]

    return model
예제 #4
0
def allWeatherers(timeStep, start_time, duration, weatheringSteps, map, uncertain, data_path, curr_path, wind_path, map_path, reFloatHalfLife, windFile, currFile, tidalFile, num_elements, depths, lat, lon, output_path, wind_scale, save_nc, timestep_outputs, weatherers, td):
    print 'initializing the model:'
    model = Model(time_step=timeStep, start_time=start_time, duration=duration)
    print 'adding the map:'
    map_folder = os.path.join(data_path, map_path)
    if not(os.path.exists(map_folder)):
        print('The map folder is incorrectly set:', map_folder)
    mapfile = get_datafile( os.path.join(map_folder,map) )
    model.map = MapFromBNA(mapfile, refloat_halflife=reFloatHalfLife)
    print 'adding a renderer'
    model.outputters += Renderer(mapfile, output_path, size=(800, 600), output_timestep=timedelta(hours=1))
    if save_nc:
        nc_outputter = NetCDFOutput(netcdf_file, which_data='most', output_timestep=timedelta(hours=1))
        model.outputters += nc_outputter
    print 'adding a wind mover:'
    wind_file = get_datafile(os.path.join(data_path, wind_path, windFile))
    wind = GridWindMover(wind_file)
    wind.wind_scale = wind_scale
    model.movers += wind
    print 'adding a current mover: '
    curr_file = get_datafile(os.path.join(data_path, curr_path, currFile))
    model.movers += GridCurrentMover(curr_file, num_method='RK4')
    if td:
        random_mover = RandomMover(diffusion_coef=10000)
        model.movers += random_mover
    print 'adding spill'
    model.spills += point_line_release_spill(num_elements=num_elements, start_position=(lon, lat, 0), release_time=start_time, end_release_time=start_time + duration)
    print 'adding weatherers'
    water = Water(280.92)
    wind = constant_wind(20.0, 117, 'knots')
    waves = Waves(wind, water)
    model.weatherers += Evaporation(water, wind)
    model.weatherers += Emulsification(waves)
    model.weatherers += NaturalDispersion(waves, water)
    return model
예제 #5
0
def make_model(coor, yr, month, day, period=46, dt=900 ,opt='SUNTANS', images_dir=os.getcwd()+"/images"):
    '''
    Run multiple GNOME;
    yr,month,day---oil spill start time;
    period---oil spill simulation duration;
    dt--oil spill time step in second
    '''    
    
    print "initializing the model"

    base_dir=os.getcwd()
    #start_time = datetime(2014,8,21,0)
    start_time = datetime(yr,month,day,0)
    model = Model(start_time = start_time,
                              duration = timedelta(hours=period),
                              time_step =dt,
                              uncertain = False,
                              )
    
    mapfile = os.path.join(base_dir, './coast.bna')
    print "adding the map"
    gnome_map = MapFromBNA(mapfile, refloat_halflife=6)  # hours
    
    print "adding renderer" 
    model.outputters += Renderer(mapfile, images_dir, size=(1800, 1600))

    
    print "adding a wind mover from a time-series"
    ## this is wind
    wind_file=get_datafile(os.path.join(base_dir, 'wind.WND'))
    wind = Wind(filename=wind_file)
    w_mover = WindMover(wind)
    model.movers += w_mover
    
    print "adding a current mover:"
    ## this is currents
    curr_file = get_datafile(os.path.join(base_dir, 'current_'+opt+'.txt'))
    model.movers += GridCurrentMover(curr_file)

    #model.movers += RandomMover(1000)
    ##
    ## Add some spills (sources of elements)
    ##
    print "adding 13 points in a cluster that has some small initial separation as the source of spill"
    
    for i in range(len(coor)):
        
        xcoor,ycoor=nctools.utmToLatLng(15,coor[i][0],coor[i][1],northernHemisphere=True)
        model.spills += point_line_release_spill(num_elements=1,
                                                start_position = (ycoor,xcoor, 0.0),
                                                release_time = start_time,
                                                )

    print "adding netcdf output"
    netcdf_output_file = os.path.join(base_dir,'GNOME_'+opt+'.nc')
    scripting.remove_netcdf(netcdf_output_file)
    model.outputters += NetCDFOutput(netcdf_output_file, which_data='all')
    
    return model
예제 #6
0
def make_model(images_dir=os.path.join(base_dir, 'images')):
    print 'initializing the model'

    start_time = datetime(2015, 9, 24, 1, 1)

    # 1 day of data in file
    # 1/2 hr in seconds
    model = Model(start_time=start_time,
                  duration=timedelta(hours=48),
                  time_step=900)

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

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

    # draw_ontop can be 'uncertain' or 'forecast'
    # 'forecast' LEs are in black, and 'uncertain' are in red
    # default is 'forecast' LEs draw on top
    renderer = Renderer(mapfile, images_dir, image_size=(600, 1200))
    renderer.graticule.set_DMS(True)
    #     renderer.viewport = ((-123.35, 45.6), (-122.68, 46.13))
    #     renderer.viewport = ((-122.9, 45.6), (-122.6, 46.0))

    print 'adding outputters'
    model.outputters += renderer

    print 'adding a spill'
    # for now subsurface spill stays on initial layer
    # - will need diffusion and rise velocity
    # - wind doesn't act
    # - start_position = (-76.126872, 37.680952, 5.0),
    spill1 = point_line_release_spill(num_elements=1000,
                                      start_position=(-122.625, 45.609, 0.0),
                                      release_time=start_time)

    model.spills += spill1

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

    print 'adding a wind mover:'

    model.movers += constant_wind_mover(0.5, 0, units='m/s')

    print 'adding a current mover:'
    curr_file = get_datafile(os.path.join(base_dir, 'COOPSu_CREOFS24.nc'))

    # uncertain_time_delay in hours
    # vec_field = TriVectorField('COOPSu_CREOFS24.nc')
    # u_mover = UGridCurrentMover(vec_field)
    c_mover = GridCurrentMover(curr_file)
    # c_mover.uncertain_cross = 0  # default is .25

    # model.movers += u_mover
    model.movers += c_mover
    model.save

    return model
예제 #7
0
def make_model(images_dir=os.path.join(base_dir, 'images')):

    print 'creating the maps'
    mapfile = get_datafile(os.path.join(base_dir, 'LowerMississippiMap.bna'))
    gnome_map = MapFromBNA(mapfile, refloat_halflife=6)  # hours

    print 'initializing the model'
    start_time = datetime(2012, 9, 15, 12, 0)

    # default to now, rounded to the nearest hour
    model = Model(time_step=600,
                  start_time=start_time,
                  duration=timedelta(days=1),
                  map=gnome_map,
                  uncertain=True)

    print 'adding outputters'
    model.outputters += Renderer(mapfile, images_dir, image_size=(800, 600))

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

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

    print 'adding a wind mover:'

    series = np.zeros((5, ), dtype=datetime_value_2d)
    series[0] = (start_time, (2, 45))
    series[1] = (start_time + timedelta(hours=18), (2, 90))
    series[2] = (start_time + timedelta(hours=30), (2, 135))
    series[3] = (start_time + timedelta(hours=42), (2, 180))
    series[4] = (start_time + timedelta(hours=54), (2, 225))

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

    print 'adding a cats mover:'
    curr_file = get_datafile(os.path.join(base_dir, 'LMiss.CUR'))
    c_mover = CatsMover(curr_file)

    # but do need to scale (based on river stage)
    c_mover.scale = True
    c_mover.scale_refpoint = (-89.699944, 29.494558)

    # based on stage height 10ft (range is 0-18)
    c_mover.scale_value = 1.027154

    model.movers += c_mover

    print 'adding a spill'
    spill = point_line_release_spill(num_elements=1000,
                                     start_position=(-89.699944, 29.494558,
                                                     0.0),
                                     release_time=start_time)
    model.spills += spill

    return model
예제 #8
0
def make_model(images_dir=os.path.join(base_dir, 'images')):
    print 'initializing the model'

    start_time = datetime(2012, 9, 15, 12, 0)
    mapfile = get_datafile(os.path.join(base_dir, 'LongIslandSoundMap.BNA'))

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

    # # the image output renderer
    # global renderer

    # one hour timestep
    model = Model(start_time=start_time,
                  duration=timedelta(hours=48), time_step=3600,
                  map=gnome_map, uncertain=True, cache_enabled=True)

    print 'adding outputters'
    model.outputters += Renderer(mapfile, images_dir, size=(800, 600))

    netcdf_file = os.path.join(base_dir, 'script_long_island.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=(-72.419992,
                                                     41.202120, 0.0),
                                     release_time=start_time)
    model.spills += spill

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

    print 'adding a wind mover:'
    series = np.zeros((5, ), dtype=datetime_value_2d)
    series[0] = (start_time, (10, 45))
    series[1] = (start_time + timedelta(hours=18), (10, 90))
    series[2] = (start_time + timedelta(hours=30), (10, 135))
    series[3] = (start_time + timedelta(hours=42), (10, 180))
    series[4] = (start_time + timedelta(hours=54), (10, 225))

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

    print 'adding a cats mover:'
    curr_file = get_datafile(os.path.join(base_dir, 'LI_tidesWAC.CUR'))
    tide_file = get_datafile(os.path.join(base_dir, 'CLISShio.txt'))

    c_mover = CatsMover(curr_file, tide=Tide(tide_file))

    model.movers += c_mover
    model.environment += c_mover.tide

    print 'viewport is:', [o.viewport
                           for o in model.outputters
                           if isinstance(o, Renderer)]

    return model
예제 #9
0
def make_model(images_dir=os.path.join(base_dir, 'images')):
    print 'initializing the model'

    start_time = datetime(2015, 9, 24, 1, 1)

    # 1 day of data in file
    # 1/2 hr in seconds
    model = Model(start_time=start_time,
                  duration=timedelta(hours = 48),
                  time_step=900)

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

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

    # draw_ontop can be 'uncertain' or 'forecast'
    # 'forecast' LEs are in black, and 'uncertain' are in red
    # default is 'forecast' LEs draw on top
    renderer = Renderer(mapfile, images_dir, image_size=(600, 1200))
    renderer.graticule.set_DMS(True)
#     renderer.viewport = ((-123.35, 45.6), (-122.68, 46.13))
#     renderer.viewport = ((-122.9, 45.6), (-122.6, 46.0))
    

    print 'adding outputters'
    model.outputters += renderer

    print 'adding a spill'
    # for now subsurface spill stays on initial layer
    # - will need diffusion and rise velocity
    # - wind doesn't act
    # - start_position = (-76.126872, 37.680952, 5.0),
    spill1 = point_line_release_spill(num_elements=5000,
                                     start_position=(-122.625,
                                                     45.609,
                                                     0.0),
                                     release_time=start_time)

    model.spills += spill1

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

    print 'adding a wind mover:'
   
#     model.movers += constant_wind_mover(8, 90, units='m/s')

    print 'adding a current mover:'
    curr_file = get_datafile(os.path.join(base_dir, 'COOPSu_CREOFS24.nc'))
   
    # uncertain_time_delay in hours
    c_mover = GridCurrentMover(curr_file)
    c_mover.uncertain_cross = 0  # default is .25
   
    model.movers += c_mover

    return model
예제 #10
0
def make_model(images_dir=os.path.join(base_dir, 'images')):

    print 'creating the maps'
    mapfile = get_datafile(os.path.join(base_dir, 'LowerMississippiMap.bna'))
    gnome_map = MapFromBNA(mapfile, refloat_halflife=6)  # hours

    print 'initializing the model'
    start_time = datetime(2012, 9, 15, 12, 0)

    # default to now, rounded to the nearest hour
    model = Model(time_step=600, start_time=start_time,
                  duration=timedelta(days=1),
                  map=gnome_map, uncertain=True)

    print 'adding outputters'
    model.outputters += Renderer(mapfile, images_dir, size=(800, 600))

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

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

    print 'adding a wind mover:'

    series = np.zeros((5, ), dtype=datetime_value_2d)
    series[0] = (start_time, (2, 45))
    series[1] = (start_time + timedelta(hours=18), (2, 90))
    series[2] = (start_time + timedelta(hours=30), (2, 135))
    series[3] = (start_time + timedelta(hours=42), (2, 180))
    series[4] = (start_time + timedelta(hours=54), (2, 225))

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

    print 'adding a cats mover:'
    curr_file = get_datafile(os.path.join(base_dir, 'LMiss.CUR'))
    c_mover = CatsMover(curr_file)

    # but do need to scale (based on river stage)
    c_mover.scale = True
    c_mover.scale_refpoint = (-89.699944, 29.494558)

    # based on stage height 10ft (range is 0-18)
    c_mover.scale_value = 1.027154

    model.movers += c_mover

    print 'adding a spill'
    spill = point_line_release_spill(num_elements=1000,
                                     start_position=(-89.699944, 29.494558,
                                                     0.0),
                                     release_time=start_time)
    model.spills += spill

    return model
예제 #11
0
def test_exception():
    """
    bogus file to raise an exception
    """

    bogus = os.path.join(here, 'bogus.txt')

    with pytest.raises(HTTPError):
        get_datafile(bogus)
예제 #12
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
    def test_move_tri_tide(self):
        """
        test move for a triangular grid (first time in file)
        """

        time = datetime.datetime(2014, 6, 9, 0)
        self.cm.model_time = time_utils.date_to_sec(time)
        self.cm.uncertain = True

        time_grid_file = get_datafile(os.path.join(cur_dir, 'PQBayCur.nc4'
                ))
        topology_file = get_datafile(os.path.join(cur_dir, 'PassamaquoddyTOP.dat'
                ))

        tide_file = get_datafile(os.path.join(tide_dir, 'EstesHead.txt'
                ))

        yeardata_path = os.path.join(os.path.dirname(gnome.__file__),
                'data/yeardata/')

        self.shio = cy_shio_time.CyShioTime(tide_file)
        self.ccm.set_shio(self.shio)
        self.ccm.text_read(time_grid_file, topology_file)
        self.shio.set_shio_yeardata_path(yeardata_path)
        self.cm.ref[:]['long'] = -66.991344  # for Passamaquoddy
        self.cm.ref[:]['lat'] = 45.059316
        #self.check_move()
        self.check_move_certain_uncertain(self.ccm.uncertain_time_delay)

        actual = np.empty((self.cm.num_le, ), dtype=world_point)
        actual[:]['lat'] = -.000440779
        actual[:]['long'] = .00016611
        tol = 1e-5

        msg = r"{0} move is not within a tolerance of {1}"
        np.testing.assert_allclose(
            self.cm.delta['lat'],
            actual['lat'],
            tol,
            tol,
            msg.format('ches_bay', tol),
            0,
            )
        np.testing.assert_allclose(
            self.cm.delta['long'],
            actual['long'],
            tol,
            tol,
            msg.format('ches_bay', tol),
            0,
            )
        #check that certain and uncertain are the same if uncertainty is time delayed
        #self.ccm.uncertain_time_delay = 3
        self.ccm.uncertain_time_delay = 10800 # cython expects time_delay in seconds
        self.check_move_certain_uncertain(self.ccm.uncertain_time_delay)
예제 #14
0
def test_callback_add_mover():
    'Test callback after add mover'
    units = 'meter per second'

    model = Model()
    model.start_time = datetime(2012, 1, 1, 0, 0)
    model.duration = timedelta(hours=10)
    model.time_step = timedelta(hours=1)

    # start_loc = (1.0, 2.0, 0.0)  # random non-zero starting points

    # add Movers
    model.movers += SimpleMover(velocity=(1., -1., 0.))
    series = np.array((model.start_time, (10, 45)),
                      dtype=datetime_value_2d).reshape((1, ))
    model.movers += WindMover(Wind(timeseries=series, units=units))

    # this should create a Wind object
    new_wind = Wind(timeseries=series, units=units)
    model.environment += new_wind
    assert new_wind in model.environment
    assert len(model.environment) == 2

    tide_file = get_datafile(os.path.join(tides_dir, 'CLISShio.txt'))
    tide_ = Tide(filename=tide_file)

    d_file = get_datafile(os.path.join(lis_dir, 'tidesWAC.CUR'))
    model.movers += CatsMover(d_file, tide=tide_)

    model.movers += CatsMover(d_file)

    for mover in model.movers:
        assert mover.active_start == inf_datetime.InfDateTime('-inf')
        assert mover.active_stop == inf_datetime.InfDateTime('inf')

        if hasattr(mover, 'wind'):
            assert mover.wind in model.environment

        if hasattr(mover, 'tide'):
            if mover.tide is not None:
                assert mover.tide in model.environment

    # Add a mover with user defined active_start / active_stop values
    # - these should not be updated

    active_on = model.start_time + timedelta(hours=1)
    active_off = model.start_time + timedelta(hours=4)
    custom_mover = SimpleMover(velocity=(1., -1., 0.),
                               active_start=active_on,
                               active_stop=active_off)
    model.movers += custom_mover

    assert model.movers[custom_mover.id].active_start == active_on
    assert model.movers[custom_mover.id].active_stop == active_off
예제 #15
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
예제 #16
0
def test_callback_add_mover():
    """ Test callback after add mover """

    units = 'meter per second'

    model = Model()
    model.time_step = timedelta(hours=1)
    model.duration = timedelta(hours=10)
    model.start_time = datetime(2012, 1, 1, 0, 0)

    # start_loc = (1.0, 2.0, 0.0)  # random non-zero starting points

    # add Movers

    model.movers += SimpleMover(velocity=(1., -1., 0.))
    series = np.array((model.start_time, (10, 45)),
                      dtype=datetime_value_2d).reshape((1, ))
    model.movers += WindMover(Wind(timeseries=series, units=units))

    tide_file = get_datafile(os.path.join(os.path.dirname(__file__),
                             r"sample_data", 'tides', 'CLISShio.txt'))
    tide_ = Tide(filename=tide_file)

    d_file = get_datafile(os.path.join(datadir,
                          r"long_island_sound/tidesWAC.CUR"))
    model.movers += CatsMover(d_file, tide=tide_)

    model.movers += CatsMover(d_file)

    for mover in model.movers:
        assert mover.active_start == inf_datetime.InfDateTime('-inf')
        assert mover.active_stop == inf_datetime.InfDateTime('inf')

        if isinstance(mover, WindMover):
            assert mover.wind.id in model.environment

        if isinstance(mover, CatsMover):
            if mover.tide is not None:
                assert mover.tide.id in model.environment

    # Add a mover with user defined active_start / active_stop values
    # - these should not be updated

    active_on = model.start_time + timedelta(hours=1)
    active_off = model.start_time + timedelta(hours=4)
    custom_mover = SimpleMover(velocity=(1., -1., 0.),
                               active_start=active_on,
                               active_stop=active_off)
    model.movers += custom_mover

    assert model.movers[custom_mover.id].active_start == active_on
    assert model.movers[custom_mover.id].active_stop == active_off
    def test_move_curv(self):
        """
        test move for a curvilinear grid (first time in file)
        """

        time = datetime.datetime(2006, 3, 31, 21)
        self.cm.model_time = date_to_sec(time)
        self.cm.uncertain = True

        time_grid_file = get_datafile(os.path.join(winds_dir,
                'WindSpeedDirSubset.nc'))
        topology_file = get_datafile(os.path.join(winds_dir,
                'WindSpeedDirSubsetTop.dat'))

        self.gcm.text_read(time_grid_file, topology_file)
        self.cm.ref[:]['long'] = -122.934656  # for NWS off CA
        self.cm.ref[:]['lat'] = 38.27594
        #self.check_move()
        self.check_move_certain_uncertain(self.gcm.uncertain_time_delay)

        actual = np.empty((self.cm.num_le, ), dtype=world_point)
        actual[:]['lat'] = 0.0009890068148185598
        actual[:]['long'] = 0.0012165959734995123
        actual[:]['z'] = 0.
        tol = 1e-5

        msg = '{0} move is not within a tolerance of {1}'
        np.testing.assert_allclose(
            self.cm.delta['lat'],
            actual['lat'],
            tol,
            tol,
            msg.format('WindSpeedDirSubset.nc', tol),
            0,
            )
        np.testing.assert_allclose(
            self.cm.delta['long'],
            actual['long'],
            tol,
            tol,
            msg.format('WindSpeedDirSubset.nc', tol),
            0,
            )

        #check that certain and uncertain are the same if uncertainty is time delayed
        #self.gcm.uncertain_time_delay = 3
        self.gcm.uncertain_time_delay = 10800 # cython expects time_delay in seconds
        self.check_move_certain_uncertain(self.gcm.uncertain_time_delay)
        # np.testing.assert_equal(self.cm.delta, actual,
        #                        "test_move_curv() failed", 0)

        np.all(self.cm.delta['z'] == 0)
예제 #18
0
def test_catsmover_update():
    curr_file = get_datafile(os.path.join(lis_dir, 'tidesWAC.CUR'))
    td_file = get_datafile(os.path.join(lis_dir, 'CLISShio.txt'))
    c_mv = movers.CatsMover(curr_file, tide=environment.Tide(td_file))
    c_dict = movers_schema.CatsMover().serialize(c_mv.to_dict())
    dict_ = movers_schema.CatsMover().deserialize(c_dict)

    # now let's say we want to update the Tide object, which is not part of the serialization

    tide = environment.Tide(td_file)
    dict_.update({'tide': tide})
    c_mv.from_dict(dict_)
    assert c_mv.tide.id == tide.id
예제 #19
0
def make_model(timeStep,start_time, duration, weatheringSteps, map, uncertain, data_path, reFloatHalfLife, windFile, currFile, tidalFile,
               num_elements, depths, lat, lon, output_path, evaporation):
    #initalizing the model
    print 'initializing the model:'
    # model = Model(time_step = timeStep, start_time= start_time, duration=duration, uncertain = uncertain)
    model = Model(time_step = timeStep, start_time= start_time, duration=duration)

    #adding the map
    print 'adding the map:'
    print 'pinche path', data_path
    mapfile = get_datafile(os.path.join(data_path, map))
    model.map = MapFromBNA(mapfile, refloat_halflife = reFloatHalfLife)
    #model.map = GnomeMap()


    print 'adding a renderer'
    # renderer is a class that writes map images for GNOME results
    model.outputters += Renderer(mapfile, output_path, size=(800, 600), output_timestep=timedelta(hours=1))
    ##scripting.remove_netcdf(netcdf_file)
    #nc_outputter = NetCDFOutput(netcdf_file, which_data='most', output_timestep=timedelta(hours=1))
    #model.outputters += nc_outputter
    #adding the movers

    print 'adding a wind mover:'
    wind_file = get_datafile(os.path.join(data_path, windFile))
    wind = GridWindMover(wind_file)
    wind.wind_scale = 2
    model.movers += wind

    print 'adding a current mover: '
    curr_file = get_datafile(os.path.join(data_path,currFile))
    model.movers+= GridCurrentMover(curr_file, num_method='RK4')
    #random_mover = RandomMover(diffusion_coef=10000) #in cm/sdfd
    #model.movers += random_mover

    if evaporation:
    
     #wind for evaporation
	print'adding evaporation'
    	wind = constant_wind(1, 0, 'knots')
    	water = Water(temperature=300.0, salinity=35.0)
    	model.weatherers += Evaporation(wind=wind, water=water)
    #

    print 'adding a spill'
    # for i in depths:
    #     model.spills+= point_line_release_spill(num_elements=num_elements, start_position=(lon,lat,i), release_time=start_time)
    model.spills+= point_line_release_spill(num_elements=num_elements, start_position=(lon,lat,0), release_time=start_time,
                                            end_release_time=start_time+timedelta(days=93))

    return model
예제 #20
0
def test_exception():
    """
    bogus file to raise an exception - do this if we have an internet
    connection before testing it
    """

    bogus = os.path.join(here, 'bogus.txt')

    try:
        with pytest.raises(HTTPError):
            get_datafile(bogus)
    except URLError, u:
        'no internet connection'
        return
예제 #21
0
def make_model(images_dir=os.path.join(base_dir, "images")):
    print "initializing the model"

    start_time = datetime(2006, 3, 31, 21, 0)
    model = gnome.model.Model(
        start_time=start_time, duration=timedelta(days=3), time_step=30 * 60, uncertain=True
    )  # 1 day of data in file
    # 1/2 hr in seconds

    mapfile = get_datafile(os.path.join(base_dir, "./coastSF.bna"))
    print "adding the map"
    model.map = gnome.map.MapFromBNA(mapfile, refloat_halflife=1)  # seconds

    renderer = gnome.renderer.Renderer(mapfile, images_dir, size=(800, 600))
    renderer.viewport = ((-124.5, 37.0), (-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 += gnome.netcdf_outputter.NetCDFOutput(netcdf_file, all_data=True)

    print "adding a spill"

    spill = gnome.spill.PointLineSource(
        num_elements=1000,
        start_position=(-123.57152, 37.369436, 0.0),
        release_time=start_time,
        windage_range=(0.3, 0.3),
    )

    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 = gnome.movers.GridWindMover(wind_file, topology_file)
    # w_mover.uncertain_time_delay=6
    # w_mover.uncertain_duration=6
    w_mover.uncertain_speed_scale = 0.5
    w_mover.set_uncertain_angle(0, "rad")  # default is .4
    model.movers += w_mover

    return model
예제 #22
0
def test_exception():
    """
    bogus file to raise an exception - do this if we have an internet
    connection before testing it
    """

    bogus = 'bogus.txt'

    try:
        with pytest.raises(HTTPError):
            get_datafile(bogus)
    except URLError:
        'no internet connection'
        return
예제 #23
0
def make_model(images_dir=os.path.join(base_dir,"images")):
    print "initializing the model"

    start_time = datetime(2013, 7, 23, 0)
    model = Model(start_time = start_time,
                              duration = timedelta(hours=47),	# n+1 of data in file
                              time_step = 900, # 4 hr in seconds
                              uncertain = False,
                              )
    
    mapfile = os.path.join(base_dir, './coast.bna')
    print "adding the map"
    gnome_map = MapFromBNA(mapfile, refloat_halflife=6)  # hours
    
    print "adding renderer" 
    model.outputters += Renderer(mapfile, images_dir, size=(1800, 1600))

    print "adding a wind mover from a time-series"
    ## this is wind
    wind_file=get_datafile(os.path.join(base_dir, 'wind.WND'))
    wind = Wind(filename=wind_file)
    w_mover = WindMover(wind)
    model.movers += w_mover
    
    print "adding a current mover:"
    ## this is currents
    curr_file = get_datafile(os.path.join(base_dir, 'current.txt'))
    model.movers += GridCurrentMover(curr_file)

    ##
    ## Add some spills (sources of elements)
    ##
    print "adding 13 points in a cluster that has some small initial separation as the source of spill"
    
    for i in range(len(coor)):
        
        aaa=utmToLatLng(14,coor[i][0],coor[i][1],northernHemisphere=True)
        model.spills += point_line_release_spill(num_elements=1,
                                                start_position = (aaa[1],aaa[0], 0.0),
                                                release_time = start_time,
                                                )

    print "adding netcdf output"
    netcdf_output_file = os.path.join(base_dir,'GNOME_output.nc')
    scripting.remove_netcdf(netcdf_output_file)
    model.outputters += NetCDFOutput(netcdf_output_file, which_data='all')

    return model
예제 #24
0
def make_model(images_dir=os.path.join(base_dir, 'images')):
    print 'initializing the model'

    start_time = datetime(2012, 10, 25, 0, 1)
    # start_time = datetime(2015, 12, 18, 06, 01)

    # 1 day of data in file
    # 1/2 hr in seconds
    model = Model(start_time=start_time,
                  duration=timedelta(hours=6),
                  time_step=900)

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

    print 'adding the map'
    '''TODO: sort out MapFromBna's map_bounds parameter...
    it does nothing right now, and the spill is out of bounds'''
    model.map = MapFromBNA(mapfile, refloat_halflife=0.0)  # seconds

    # draw_ontop can be 'uncertain' or 'forecast'
    # 'forecast' LEs are in black, and 'uncertain' are in red
    # default is 'forecast' LEs draw on top
    renderer = Renderer(mapfile, images_dir, image_size=(1024, 768))
    #     renderer.viewport = ((-73.5, 40.5), (-73.1, 40.75))
    #     renderer.viewport = ((-122.9, 45.6), (-122.6, 46.0))

    print 'adding outputters'
    model.outputters += renderer

    print 'adding a spill'
    # for now subsurface spill stays on initial layer
    # - will need diffusion and rise velocity
    # - wind doesn't act
    # - start_position = (-76.126872, 37.680952, 5.0),
    spill1 = point_line_release_spill(num_elements=1000,
                                      start_position=(-74.15, 40.5, 0.0),
                                      release_time=start_time)

    model.spills += spill1

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

    print 'adding a wind mover:'

    model.movers += constant_wind_mover(4, 270, units='m/s')

    print 'adding a current mover:'

    # url is broken, fix and include the following section
    #     url = ('http://geoport.whoi.edu/thredds/dodsC/clay/usgs/users/jcwarner/Projects/Sandy/triple_nest/00_dir_NYB05.ncml')
    # #     cf = roms_field('nos.tbofs.fields.n000.20160406.t00z_sgrid.nc')
    #     cf = GridCurrent.from_netCDF(url)
    #     renderer.add_grid(cf.grid)
    #     renderer.delay = 25
    #     u_mover = PyCurrentMover(cf, default_num_method='Euler')
    #     model.movers += u_mover
    #

    return model
예제 #25
0
def make_model(images_dir=os.path.join(base_dir, 'images')):
    print 'initializing the model'

    start_time = datetime(2015, 9, 24, 3, 0)

    # 1 day of data in file
    # 1/2 hr in seconds
    model = Model(start_time=start_time,
                  duration=timedelta(hours = 48),
                  time_step=3600)

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

    print 'adding the map'
    model.map = MapFromBNA(mapfile, refloat_halflife=1, raster_size=1024*1024)  # seconds

    # draw_ontop can be 'uncertain' or 'forecast'
    # 'forecast' LEs are in black, and 'uncertain' are in red
    # default is 'forecast' LEs draw on top
    renderer = Renderer(mapfile, images_dir, image_size=(800, 600),
                        output_timestep=timedelta(hours=1),
                        timestamp_attrib={'size': 'medium', 'color':'uncert_LE'})
    renderer.set_timestamp_attrib(format='%a %c')
    renderer.graticule.set_DMS(True)
#     renderer.viewport = ((-124.25, 47.5), (-122.0, 48.70))


    print 'adding outputters'
    model.outputters += renderer

    print 'adding a spill'
    # for now subsurface spill stays on initial layer
    # - will need diffusion and rise velocity
    # - wind doesn't act
    # - start_position = (-76.126872, 37.680952, 5.0),
    spill1 = point_line_release_spill(num_elements=5000,
                                     start_position=(0.0,
                                                     0.0,
                                                     0.0),
                                     release_time=start_time)

    model.spills += spill1

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

    print 'adding a wind mover:'

    model.movers += constant_wind_mover(13, 270, units='m/s')

    print 'adding a current mover:'
#     curr_file = get_datafile(os.path.join(base_dir, 'COOPSu_CREOFS24.nc'))
#
#     # uncertain_time_delay in hours
#     c_mover = GridCurrentMover(curr_file)
#     c_mover.uncertain_cross = 0  # default is .25
#
#     model.movers += c_mover

    return model
예제 #26
0
def make_db():
    from py.test import config

    # Only run database setup on master (in case of xdist/multiproc mode)

    if not hasattr(config, 'slaveinput'):
        try:
            from gnome.db.oil_library.initializedb import initialize_sql, \
                load_database

            oillib_file = get_datafile(os.path.join(data_dir,
                    'OilLib.smaller'))

            sqlalchemy_url = 'sqlite:///{0}'.format(db_file)
            settings = {'sqlalchemy.url': sqlalchemy_url,
                        'oillib.file': oillib_file}

            initialize_sql(settings)
            load_database(settings)
        except ImportError, ie:
            print '\nWarning: Required modules for database unit-testing not found.'
            dependant_modules = ('sqlalchemy', 'zope.sqlalchemy',
                                 'transaction')
            print ie
            print 'Also may need:',
            print '\t {0}\n'.format([m for m in dependant_modules
                                    if not m in sys.modules])
예제 #27
0
def test_get_datafile():
    """
    downloads CLISShio.txt to make sure get_datafile works as expected
    Uses testdata['CatsMover']['tide'] as test file. If it exists, it moves
    it '*.renamed'. It then trys to download file and if it fails for any
    reason (most likely internet connection is missing), then copy the
    file back from '*.renamed' to testdata['CatsMover']['tide']
    At the end also, move the renamed file back
    """

    file_ = testdata['CatsMover']['tide']
    renamed = None
    if os.path.exists(file_):
        renamed = file_ + '.renamed'
        shutil.move(file_, renamed)

    num_calls = 0
    while num_calls < 2:
        # do this twice to make sure it still works as expected after file has
        # been downloaded in 1st call
        try:
            r_file = get_datafile(file_)
            assert os.path.exists(r_file)
        except:
            if renamed is not None:
                shutil.move(renamed, file_)
            reason = ("Most likely urllib2.HTTPError exception in "
                      "get_datafile(). Check internet connectivity.")
            pytest.xfail(reason=reason)
            return
        num_calls += 1
    # do not delete file_
    if renamed is not None:
        shutil.move(renamed, file_)
예제 #28
0
def test_get_datafile():
    """
    downloads CLISShio.txt to make sure get_datafile works as expected

    removes the file sample_data/CLISShio.txt after downloading it to leave it
    in clean _state
    """

    file_ = os.path.join(here, r'sample_data/CLISShio.txt')
    if os.path.exists(file_):
        os.remove(file_)

    for i in range(2):

        # do this twice to make sure it still works as expected after file has been downloaded in 1st call
        try:
            r_file = get_datafile(file_)
        except:
            return

        assert os.path.exists(r_file)

    # clean up file_ that was downloaded just for this test

    os.remove(file_)
예제 #29
0
def make_model(images_dir=os.path.join(base_dir, 'images')):
    print 'initializing the model'

    start_time = datetime(2015, 9, 24, 3, 0)

    # 1 day of data in file
    # 1/2 hr in seconds
    model = Model(start_time=start_time,
                  duration=timedelta(hours = 48),
                  time_step=3600)

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

    print 'adding the map'
    model.map = MapFromBNA(mapfile, refloat_halflife=1, raster_size=1024*1024)  # seconds

    # draw_ontop can be 'uncertain' or 'forecast'
    # 'forecast' LEs are in black, and 'uncertain' are in red
    # default is 'forecast' LEs draw on top
    renderer = Renderer(mapfile, images_dir, image_size=(800, 600),
                        output_timestep=timedelta(hours=1),
                        timestamp_attrib={'size': 'medium', 'color':'uncert_LE'})
    renderer.set_timestamp_attrib(format='%a %c')
    renderer.graticule.set_DMS(True)
#     renderer.viewport = ((-124.25, 47.5), (-122.0, 48.70))


    print 'adding outputters'
    model.outputters += renderer

    print 'adding a spill'
    # for now subsurface spill stays on initial layer
    # - will need diffusion and rise velocity
    # - wind doesn't act
    # - start_position = (-76.126872, 37.680952, 5.0),
    spill1 = point_line_release_spill(num_elements=5000,
                                     start_position=(0.0,
                                                     0.0,
                                                     0.0),
                                     release_time=start_time)

    model.spills += spill1

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

    print 'adding a wind mover:'

    model.movers += constant_wind_mover(13, 270, units='m/s')

    print 'adding a current mover:'
#     curr_file = get_datafile(os.path.join(base_dir, 'COOPSu_CREOFS24.nc'))
#
#     # uncertain_time_delay in hours
#     c_mover = GridCurrentMover(curr_file)
#     c_mover.uncertain_cross = 0  # default is .25
#
#     model.movers += c_mover

    return model
def make_model(images_dir=os.path.join(base_dir, 'images')):
    print 'initializing the model'

    start_time = datetime(2013, 1, 1, 1)  # data starts at 1:00 instead of 0:00
    model = Model(start_time=start_time, duration=timedelta(days=1),
                  time_step=900, uncertain=False)

    try:
        mapfile = get_datafile(os.path.join(base_dir, './pearl_harbor.bna'))
    except HTTPError:
        print ('Could not download Pearl Harbor data from server - '
               'returning empty model')
        return model

    print 'adding the map'
    model.map = MapFromBNA(mapfile, refloat_halflife=1)  # hours

    #
    # Add the outputters -- render to images, and save out as netCDF
    #

    print 'adding renderer and netcdf output'
    model.outputters += Renderer(mapfile, images_dir, size=(800, 600))

    netcdf_output_file = os.path.join(base_dir, 'pearl_harbor_output.nc')
    scripting.remove_netcdf(netcdf_output_file)
    model.outputters += NetCDFOutput(netcdf_output_file, which_data='all')

    # #
    # # Set up the movers:
    # #
    print 'adding a random mover:'
    model.movers += RandomMover(diffusion_coef=10000)

    print 'adding a wind mover:'
    series = np.zeros((3, ), dtype=datetime_value_2d)
    series[0] = (start_time, (4, 180))
    series[1] = (start_time + timedelta(hours=12), (2, 270))
    series[2] = (start_time + timedelta(hours=24), (4, 180))

    w_mover = WindMover(Wind(timeseries=series, units='knots'))
    model.movers += w_mover
    model.environment += w_mover.wind

    print 'adding a current mover:'
    # this is CH3D currents
    curr_file = os.path.join(base_dir, r"./ch3d2013.nc")
    topology_file = os.path.join(base_dir, r"./PearlHarborTop.dat")
    model.movers += GridCurrentMover(curr_file, topology_file)

    # #
    # # Add a spill (sources of elements)
    # #
    print 'adding spill'
    model.spills += point_line_release_spill(num_elements=1000,
                                             start_position=(-157.97064,
                                                             21.331524, 0.0),
                                             release_time=start_time)
    return model
    def __init__(self):
        wind_file = get_datafile(os.path.join(datadir, r"delaware_bay/ConstantWind.WND"))
        # self.ossm = cy_ossm_time.CyOSSMTime(wind_file,file_contains=basic_types.ts_format.magnitude_direction)
        wm = Wind(filename=wind_file)

        cats1_file = get_datafile(os.path.join(datadir, r"delaware_bay/NW30ktwinds.cur"))
        cats2_file = get_datafile(os.path.join(datadir, r"delaware_bay/SW30ktwinds.cur"))
        self.component = cy_component_mover.CyComponentMover()
        self.component.set_ossm(wm.ossm)
        # self.component.set_ossm(self.ossm)
        self.component.text_read(cats1_file, cats2_file)
        self.component.ref_point = (-75.262319, 39.142987)

        super(ComponentMove, self).__init__()
        self.ref[:] = (-75.262319, 39.142987, 0)
        self.component.prepare_for_model_run()
        self.component.prepare_for_model_step(self.model_time, self.time_step, 1, self.spill_size)
    def test_move_tri(self):
        """
        test move for a triangular grid (first time in file)
        """

        time = datetime.datetime(2004, 12, 31, 13)
        self.cm.model_time = time_utils.date_to_sec(time)
        self.cm.uncertain = True

        time_grid_file = get_datafile(os.path.join(cur_dir, 'ChesBay.nc'
                ))
        topology_file = get_datafile(os.path.join(cur_dir, 'ChesBay.dat'
                ))

        self.gcm.text_read(time_grid_file, topology_file)
        self.cm.ref[:]['long'] = -76.149368  # for ChesBay
        self.cm.ref[:]['lat'] = 37.74496
        #self.check_move()
        self.check_move_certain_uncertain(self.gcm.uncertain_time_delay)

        actual = np.empty((self.cm.num_le, ), dtype=world_point)
        actual[:]['lat'] = -.00170908
        actual[:]['long'] = -.0003672
        tol = 1e-5

        msg = r"{0} move is not within a tolerance of {1}"
        np.testing.assert_allclose(
            self.cm.delta['lat'],
            actual['lat'],
            tol,
            tol,
            msg.format('ches_bay', tol),
            0,
            )
        np.testing.assert_allclose(
            self.cm.delta['long'],
            actual['long'],
            tol,
            tol,
            msg.format('ches_bay', tol),
            0,
            )
        #check that certain and uncertain are the same if uncertainty is time delayed
        #self.gcm.uncertain_time_delay = 3
        self.gcm.uncertain_time_delay = 10800 # cython expects time_delay in seconds
        self.check_move_certain_uncertain(self.gcm.uncertain_time_delay)
예제 #33
0
def ug_data():
    base_dir = os.path.dirname(__file__)
    filename = get_datafile(os.path.join(base_dir,
                                         'sample_data',
                                         'currents',
                                         'ChesBay.nc'))

    return filename, nc.Dataset(filename)
예제 #34
0
    def __init__(self):
        file_ = get_datafile(os.path.join(datadir,
                             r"long_island_sound/CLISShio.txt"))
        self.shio = cy_shio_time.CyShioTime(file_)
        top_file = get_datafile(os.path.join(datadir,
                                r"long_island_sound/tidesWAC.CUR"))
        yeardata_path = os.path.join(os.path.dirname(gnome.__file__),
                'data/yeardata/')
        self.cats = cy_cats_mover.CyCatsMover()
        self.cats.set_shio(self.shio)
        self.cats.text_read(top_file)
        self.shio.set_shio_yeardata_path(yeardata_path)

        super(CatsMove, self).__init__()
        self.ref[:] = (-72.5, 41.17, 0)
        self.cats.prepare_for_model_run()
        self.cats.prepare_for_model_step(self.model_time,
                self.time_step, 1, self.spill_size)
예제 #35
0
def only_Winds(timeStep, start_time, duration, weatheringSteps, map, uncertain, data_path, curr_path, wind_path, map_path, reFloatHalfLife, windFile, currFile, tidalFile, num_elements, depths, lat, lon, output_path, wind_scale, save_nc, timestep_outputs, weatherers, td):
    print 'initializing the model:'
    model = Model(time_step=timeStep, start_time=start_time, duration=duration)
    print 'adding the map:'
    mapfile = get_datafile(os.path.join(data_path, map_path, map))
    model.map = MapFromBNA(mapfile, refloat_halflife=reFloatHalfLife)
    print 'adding a renderer'
    model.outputters += Renderer(mapfile, output_path, size=(800, 600), output_timestep=timedelta(hours=timestep_outputs))
    if save_nc:
        nc_outputter = NetCDFOutput(netcdf_file, which_data='most', output_timestep=timedelta(hours=timestep_outputs))
        model.outputters += nc_outputter
    print 'adding a wind mover:'
    wind_file = get_datafile(os.path.join(data_path, wind_path, windFile))
    wind = GridWindMover(wind_file)
    wind.wind_scale = wind_scale
    model.movers += wind
    print 'adding a spill'
    model.spills += point_line_release_spill(num_elements=num_elements, start_position=(lon, lat, 0), release_time=start_time, end_release_time=start_time + duration)
    return model
    def test_move_tri(self):
        """
        test move for a triangular grid (first time in file)
        """

        time = datetime.datetime(2014, 6, 9, 0)
        self.cm.model_time = time_utils.date_to_sec(time)

        time_grid_file = get_datafile(os.path.join(cur_dir, 'PQBayCur.nc4'))
        topology_file = get_datafile(os.path.join(cur_dir,
                r'PassamaquoddyTOP.dat'))

        self.ccm.text_read(time_grid_file, topology_file)

        # self.ccm.export_topology(topology_file2)

        self.cm.ref[:]['long'] = -66.991344  # for Passamaquoddy
        self.cm.ref[:]['lat'] = 45.059316
        self.check_move()

        actual = np.empty((self.cm.num_le, ), dtype=world_point)
        actual[:]['lat'] = .00020319
        actual[:]['long'] = -.0001276599
        tol = 1e-5

        msg = r"{0} move is not within a tolerance of {1}"
        np.testing.assert_allclose(
            self.cm.delta['lat'],
            actual['lat'],
            tol,
            tol,
            msg.format('PQBayCur.nc4', tol),
            0,
            )
        np.testing.assert_allclose(
            self.cm.delta['long'],
            actual['long'],
            tol,
            tol,
            msg.format('PQBayCur.nc4', tol),
            0,
            )
    def test_move_curv(self):
        """
        test move for a curvilinear grid (first time in file)
        """

        time = datetime.datetime(2008, 1, 29, 17)
        self.cm.model_time = time_utils.date_to_sec(time)

        time_grid_file = get_datafile(os.path.join(cur_dir, 'ny_cg.nc'))
        topology_file = get_datafile(os.path.join(cur_dir,
                r'NYTopology.dat'))

        self.gcm.text_read(time_grid_file, topology_file)

        # self.gcm.export_topology(topology_file2)

        self.cm.ref[:]['long'] = -74.03988  # for NY
        self.cm.ref[:]['lat'] = 40.536092
        self.check_move()

        actual = np.empty((self.cm.num_le, ), dtype=world_point)
        actual[:]['lat'] = .000911
        actual[:]['long'] = -.001288
        tol = 1e-5

        msg = r"{0} move is not within a tolerance of {1}"
        np.testing.assert_allclose(
            self.cm.delta['lat'],
            actual['lat'],
            tol,
            tol,
            msg.format('ny_cg.nc', tol),
            0,
            )
        np.testing.assert_allclose(
            self.cm.delta['long'],
            actual['long'],
            tol,
            tol,
            msg.format('ny_cg.nc', tol),
            0,
            )
예제 #38
0
def make_models():
    print 'initializing the model'

    # start_time = datetime(2015, 12, 18, 06, 01)

    # 1 day of data in file
    # 1/2 hr in seconds
    models = []
    start_time = datetime(2012, 10, 27, 0, 30)
    duration_hrs=23
    time_step=450
    num_steps = duration_hrs * 3600 / time_step
    names = [
             'Euler',
             'Trapezoid',
             'RK4',
             ]

    mapfile = get_datafile(os.path.join(base_dir, 'long_beach.bna'))
    print 'gen map'
    map = MapFromBNA(mapfile, refloat_halflife=0.0)  # seconds
    fn = ('00_dir_roms_display.ncml.nc4')
    curr = GridCurrent.from_netCDF(filename=fn)
    models = []
    for method in names:

        mod = Model(start_time=start_time,
                    duration=timedelta(hours=duration_hrs),
                    time_step=time_step)

        mod.map = map
        spill = point_line_release_spill(num_elements=1000,
                                         start_position=(-74.1,
                                                      39.7525,
                                                      0.0),
                                         release_time=start_time)
        mod.spills += spill
        mod.movers += RandomMover(diffusion_coef=100)
        mod.movers += PyGridCurrentMover(current=curr, default_num_method=method)

        images_dir = method + '-' + str(time_step / 60) + 'min-' + str(num_steps) + 'steps'
        renderer = Renderer(mapfile, images_dir, image_size=(1024, 768))
        renderer.delay = 25
#         renderer.add_grid(curr.grid)
        mod.outputters += renderer


        netCDF_fn = os.path.join(base_dir, images_dir + '.nc')
        mod.outputters += NetCDFOutput(netCDF_fn, which_data='all')
        models.append(mod)

    print 'returning models'
    return models
예제 #39
0
    def test_grid_map_cats(self):
        """
        Test a grid map - read and write out
        """

        # triangle grid

        gcm3 = CyGridMap()
        grid_map_file = get_datafile(os.path.join(cur_dir, "BigCombinedwMap.cur"))
        gcm3.text_read(grid_map_file)

        topology_file = os.path.join(cur_dir, "BigCombinedTop.dat")
        gcm3.export_topology(topology_file)
예제 #40
0
def make_model(base_dir='.'):
    #,images_dir=os.path.join(base_dir, 'images',gdat_dir='/data/dylan/ArcticTAP/data_gnome/ROMS_h2ouv/')):
    print 'initializing the model'
    print base_dir
    start_time = datetime(1985, 1, 1, 13, 31)
    # start with generic times...this will be changed when model is run
    model = Model(start_time=start_time, time_step=setup.time_step)

    mapfile = get_datafile(os.path.join(base_dir, setup.MapFileName))
    print mapfile
    print 'adding the map'
    model.map = MapFromBNA(mapfile, refloat_halflife=0.0)  # seconds

    return model
def test_ucode_char_in_grid_mover_filename(mover_test):

    # on windows

    file1_ = get_datafile(os.path.join(datadir, mover_test[1]))
    ufile1 = create_ucode_file(file1_)

    # invalid unicode for windows
    invalid_ufile1 = create_ucode_file(file1_, valid=False)

    if mover_test[2] is None:
        file2_ = None
        ufile2 = None
        invalid_ufile2 = None
    else:
        file2_ = get_datafile(os.path.join(datadir, mover_test[2]))
        ufile2 = create_ucode_file(file2_)

        # invalid unicode for windows
        invalid_ufile2 = create_ucode_file(file2_, valid=False)

    mover_test[0](file1_, file2_)
    
    # valid unicode names should work for both systems
    mover_test[0](ufile1, ufile2)

    if sys.platform == 'win32':
        with pytest.raises(UnicodeEncodeError):
            mover_test[0](invalid_ufile1, invalid_ufile2)
    elif sys.platform == 'darwin':
        # todo: also need a test case for linux2
        mover_test[0](invalid_ufile1, invalid_ufile2)

    print '{0}({1},{2}) passed the test'.format(mover_test[0],
            mover_test[1], mover_test[2])
    assert True
예제 #42
0
def make_modelF(timeStep, start_time, duration, weatheringSteps, map, uncertain, data_path, curr_path, wind_path, map_path, reFloatHalfLife, windFile, currFile, num_elements, depths, lat, lon, output_path, wind_scale, save_nc, timestep_outputs, weatherers, td, dif_coef,temp_water):
    print 'initializing the model:'
    model = Model(time_step=timeStep, start_time=start_time, duration=duration, uncertain=uncertain)
    print 'adding the map:'
    mapfile = get_datafile(os.path.join(data_path, map_path, map))
    model.map = MapFromBNA(mapfile, refloat_halflife=reFloatHalfLife)
    print 'adding a renderer'

    if save_nc:
        scripting.remove_netcdf(output_path+'/'+'output.nc')
        nc_outputter = NetCDFOutput(output_path+'/'+'output.nc', which_data='standard', output_timestep=timedelta(hours=timestep_outputs))
        model.outputters += nc_outputter

    print 'adding a wind mover:'
    wind_file = get_datafile(os.path.join(data_path, wind_path, windFile))
    wind = GridWindMover(wind_file)
    # wind.wind_scale = wind_scale
    model.movers += wind
    print 'adding a current mover:'
    curr_file = get_datafile(os.path.join(data_path, curr_path, currFile))
    model.movers += GridCurrentMover(curr_file, num_method='RK4')
    if td:
        random_mover = RandomMover(diffusion_coef=dif_coef)
        model.movers += random_mover
    print 'adding spill'
    model.spills += point_line_release_spill(num_elements=num_elements, start_position=(lon, lat, 0), release_time=start_time, end_release_time=start_time + duration)#, substance='AD04001', amount=9600000, units='kg')

    if weatherers:
        print 'adding weatherers'
        water = Water(temp_water)
        wind = constant_wind(0.0001, 0, 'knots')
        waves = Waves(wind, water)
        model.weatherers += Evaporation(water, wind)
    # model.weatherers += Emulsification(waves)
        model.weatherers += NaturalDispersion(waves, water)
    return model
예제 #43
0
def make_model(base_dir='.'):
    #,images_dir=os.path.join(base_dir, 'images',gdat_dir='/data/dylan/ArcticTAP/data_gnome/ROMS_h2ouv/')):
    print 'initializing the model'
    print base_dir
    start_time = datetime(1985, 1, 1, 13, 31)
    # start with generic times...this will be changed when model is run
    model = Model(start_time=start_time,
                  duration=timedelta(hours=96),
                  time_step=120*60)
    mapfile = get_datafile(os.path.join(base_dir, 'arctic_coast3.bna'))
    print mapfile
    print 'adding the map'
    model.map = MapFromBNA(mapfile, refloat_halflife=0.0)  # seconds

    return model
예제 #44
0
def test_ucode_char_in_grid_mover_filename(mover_test):

    # on windows

    file1_ = get_datafile(os.path.join(datadir, mover_test[1]))
    ufile1 = create_ucode_file(file1_)

    # invalid unicode for windows
    invalid_ufile1 = create_ucode_file(file1_, valid=False)

    if mover_test[2] is None:
        file2_ = None
        ufile2 = None
        invalid_ufile2 = None
    else:
        file2_ = get_datafile(os.path.join(datadir, mover_test[2]))
        ufile2 = create_ucode_file(file2_)

        # invalid unicode for windows
        invalid_ufile2 = create_ucode_file(file2_, valid=False)

    mover_test[0](file1_, file2_)

    # valid unicode names should work for both systems
    mover_test[0](ufile1, ufile2)

    if sys.platform == 'win32':
        with pytest.raises(UnicodeEncodeError):
            mover_test[0](invalid_ufile1, invalid_ufile2)
    elif sys.platform == 'darwin':
        # todo: also need a test case for linux2
        mover_test[0](invalid_ufile1, invalid_ufile2)

    print '{0}({1},{2}) passed the test'.format(mover_test[0], mover_test[1],
                                                mover_test[2])
    assert True
예제 #45
0
def test_ucode_char_in_filename(test_case):

    # on windows

    file_ = get_datafile(os.path.join(datadir, test_case[1]))

    # first check that it works with file without adding special character to filename

    test_case[0](filename=file_)

    ufile = create_ucode_file(file_)
    test_case[0](filename=ufile)  # This should read valid unicode filenames

    invalid_ufile = create_ucode_file(file_, False)
    if sys.platform == 'win32':
        with pytest.raises(UnicodeEncodeError):
            test_case[0](filename=invalid_ufile)
    elif sys.platform == 'darwin':
        test_case[0](filename=invalid_ufile)

    print '{0}({1}) passed the test'.format(test_case[0], test_case[1])
    assert True
예제 #46
0
def get_testdata():
    '''
    define all the testdata files here
    most of these are used in multiple modules. Some are not, but let's just
    define them all in one place, ie here.
    '''
    s_data = os.path.join(base_dir, 'sample_data')
    lis = os.path.join(s_data, 'long_island_sound')
    bos = os.path.join(s_data, 'boston_data')
    dbay = os.path.join(s_data, 'delaware_bay')
    curr_dir = os.path.join(s_data, 'currents')
    tide_dir = os.path.join(s_data, 'tides')
    wind_dir = os.path.join(s_data, 'winds')
    testmap = os.path.join(base_dir, '../sample_data', 'MapBounds_Island.bna')
    bna_sample = os.path.join(s_data, 'MapBounds_2Spillable2Islands2Lakes.bna')

    data = dict()

    data['CatsMover'] = \
        {'curr': get_datafile(os.path.join(lis, 'tidesWAC.CUR')),
         'tide': get_datafile(os.path.join(lis, 'CLISShio.txt'))}
    data['ComponentMover'] = \
        {'curr': get_datafile(os.path.join(dbay, 'NW30ktwinds.cur')),
         'curr2': get_datafile(os.path.join(dbay, 'SW30ktwinds.cur')),
         'wind': get_datafile(os.path.join(dbay, 'ConstantWind.WND'))}
    data['CurrentCycleMover'] = \
        {'curr': get_datafile(os.path.join(curr_dir, 'PQBayCur.nc4')),
         'top': get_datafile(os.path.join(curr_dir, 'PassamaquoddyTOP.dat')),
         'tide': get_datafile(os.path.join(tide_dir, 'EstesHead.txt')),
         'curr_bad_file': get_datafile(os.path.join(curr_dir,
                                                    'BigCombinedwMapBad.cur'))}
    data['GridCurrentMover'] = \
        {'curr_tri': get_datafile(os.path.join(curr_dir, 'ChesBay.nc')),
         'top_tri': get_datafile(os.path.join(curr_dir, 'ChesBay.dat')),
         'curr_reg': get_datafile(os.path.join(curr_dir, 'test.cdf')),
         'curr_curv': get_datafile(os.path.join(curr_dir, 'ny_cg.nc')),
         'top_curv': get_datafile(os.path.join(curr_dir, 'NYTopology.dat')),
         'ice_curr_curv': get_datafile(os.path.join(curr_dir,
                                                    'acnfs_example.nc')),
         'ice_top_curv': get_datafile(os.path.join(curr_dir,
                                                   'acnfs_topo.dat')),
         'ptCur': get_datafile(os.path.join(curr_dir, 'ptCurNoMap.cur')),
         'grid_ts': get_datafile(os.path.join(curr_dir, 'gridcur_ts.cur')),
         'series_gridCur': get_datafile(os.path.join(curr_dir,
                                                     'gridcur_ts_hdr2.cur')),
         'series_curv': get_datafile(os.path.join(curr_dir, 'file_series',
                                                  'flist2.txt')),
         'series_top': get_datafile(os.path.join(curr_dir, 'file_series',
                                                 'HiROMSTopology.dat'))}

    data['IceMover'] = \
        {'ice_curr_curv': get_datafile(os.path.join(curr_dir,
                                                    'acnfs_example.nc')),
         'ice_top_curv': get_datafile(os.path.join(curr_dir,
                                                   'acnfs_topo.dat'))}

    # get netcdf stored in fileseries flist2.txt, gridcur_ts_hdr2
    get_datafile(os.path.join(curr_dir, 'file_series', 'hiog_file1.nc'))
    get_datafile(os.path.join(curr_dir, 'file_series', 'hiog_file2.nc'))
    get_datafile(os.path.join(curr_dir, 'gridcur_tsA.cur'))
    get_datafile(os.path.join(curr_dir, 'gridcur_tsB.cur'))

    data['GridWindMover'] = \
        {'wind_curv': get_datafile(os.path.join(wind_dir,
                                                'WindSpeedDirSubset.nc')),
         'top_curv': get_datafile(os.path.join(wind_dir,
                                               'WindSpeedDirSubsetTop.dat')),
         'wind_rect': get_datafile(os.path.join(wind_dir, 'test_wind.cdf')),
         'grid_ts': get_datafile(os.path.join(wind_dir, 'gridwind_ts.wnd'))}
    data['MapFromBNA'] = {'testmap': testmap}
    data['Renderer'] = {'bna_sample': bna_sample,
                        'bna_star': os.path.join(s_data, 'Star.bna')}
    data['GridMap'] = \
        {'curr': get_datafile(os.path.join(curr_dir, 'ny_cg.nc')),
         'BigCombinedwMap':
            get_datafile(os.path.join(curr_dir, 'BigCombinedwMap.cur')),
         }

    # following are not on server, they are part of git repo so just set the
    # path correctly
    data['timeseries'] = \
        {'wind_ts': os.path.join(s_data, 'WindDataFromGnome.WND'),
         'wind_ts_av': os.path.join(s_data, 'WindDataFromGnomeAv.WND'),
         'wind_constant': os.path.join(s_data,
                                       'WindDataFromGnomeConstantWind.WND'),
         'wind_bad_units': os.path.join(s_data,
                                        'WindDataFromGnome_BadUnits.WND'),
         'wind_cardinal': os.path.join(s_data,
                                       'WindDataFromGnomeCardinal.WND'),
         'wind_kph': os.path.join(s_data, 'WindDataFromGnomeKPH.WND'),
         'tide_shio': get_datafile(os.path.join(tide_dir, 'CLISShio.txt')),
         'tide_ossm': get_datafile(os.path.join(tide_dir, 'TideHdr.FINAL'))
         }

    # data for boston model - used for testing save files/webapi
    data['boston_data'] = \
        {'map': get_datafile(os.path.join(bos, 'MassBayMap.bna')),
         'cats_curr1': get_datafile(os.path.join(bos, 'EbbTides.cur')),
         'cats_shio': get_datafile(os.path.join(bos, 'EbbTidesShio.txt')),
         'cats_curr2': get_datafile(os.path.join(bos,
                                                 'MerrimackMassCoast.cur')),
         'cats_ossm': get_datafile(os.path.join(bos,
                                                'MerrimackMassCoastOSSM.txt')),
         'cats_curr3': get_datafile(os.path.join(bos, 'MassBaySewage.cur')),
         'component_curr1': get_datafile(os.path.join(bos, "WAC10msNW.cur")),
         'component_curr2': get_datafile(os.path.join(bos, "WAC10msSW.cur"))
         }

    data['nc'] = {'nc_output':
                  get_datafile(os.path.join(s_data, 'nc', 'test_output.nc'))}
    data['lis'] = \
        {'map': get_datafile(os.path.join(lis, 'LongIslandSoundMap.BNA')),
         'cats_curr': get_datafile(os.path.join(lis, r"LI_tidesWAC.CUR")),
         'cats_tide': get_datafile(os.path.join(lis, r"CLISShio.txt"))
         }
    return data
예제 #47
0
def make_model(images_dir=os.path.join(base_dir, 'images')):

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

    renderer = Renderer(
        mapfile,
        images_dir,
        image_size=(800, 800),
    )

    print 'initializing the model'
    start_time = datetime(2016, 3, 9, 15)

    # 1 hour in seconds
    # Default to now, rounded to the nearest hour
    model = Model(time_step=3600,
                  start_time=start_time,
                  duration=timedelta(days=6),
                  map=gnome_map,
                  uncertain=True)

    print 'adding outputters'
    model.outputters += renderer

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

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

    print 'adding a RandomMover:'
    model.movers += 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=18), (5, 180))
    w = Wind(filename=os.path.join(base_dir, '22NM_WNW_PortAngelesWA.nws'))
    w_mover = WindMover(w)
    model.movers += w_mover
    model.environment += w_mover.wind

    # print 'adding a cats shio mover:'

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

    # c_mover = CatsMover(curr_file, tide=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 spill'

    end_time = start_time + timedelta(hours=12)
    spill = 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
예제 #48
0
def make_model(images_dir=os.path.join(base_dir, 'images')):
    print 'initializing the model'

    start_time = datetime(2015, 9, 24, 1, 1)
    # start_time = datetime(2015, 12, 18, 06, 01)

    # 1 day of data in file
    # 1/2 hr in seconds
    model = Model(start_time=start_time,
                  duration=timedelta(hours=47),
                  time_step=300)

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

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

    # draw_ontop can be 'uncertain' or 'forecast'
    # 'forecast' LEs are in black, and 'uncertain' are in red
    # default is 'forecast' LEs draw on top
    renderer = Renderer(mapfile, images_dir, image_size=(600, 1200))
    renderer.delay = 15
    #     renderer.viewport = ((-123.35, 45.6), (-122.68, 46.13))
    #     renderer.viewport = ((-122.9, 45.6), (-122.6, 46.0))

    print 'adding outputters'
    model.outputters += renderer

    print 'adding a spill'
    # for now subsurface spill stays on initial layer
    # - will need diffusion and rise velocity
    # - wind doesn't act
    # - start_position = (-76.126872, 37.680952, 5.0),
    spill1 = continuous_release_spill(initial_elements=10000,
                                      num_elements=400,
                                      start_position=(-122.625, 45.609, 0.0),
                                      release_time=start_time,
                                      end_position=(-122.6, 45.605, 0.0),
                                      end_release_time=start_time +
                                      timedelta(seconds=36000))

    model.spills += spill1

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

    print 'adding a wind mover:'
    series = []
    for i in [(1, (5, 90)), (7, (5, 180)), (13, (5, 270)), (19, (5, 0)),
              (25, (5, 90))]:
        series.append((start_time + timedelta(hours=i[0]), i[1]))

    wind1 = WindTS.constant_wind('wind1', 0.5, 0, 'm/s')
    wind2 = WindTS(timeseries=series, units='knots', extrapolate=True)

    #     wind = Wind(timeseries=series, units='knots')

    model.movers += PyWindMover(wind=wind1)

    print 'adding a current mover:'

    #     url = ('http://geoport.whoi.edu/thredds/dodsC/clay/usgs/users/jcwarner/Projects/Sandy/triple_nest/00_dir_NYB05.ncml')
    #     test = GridCurrent.from_netCDF(name='gc1', filename=url)

    curr_file = get_datafile('COOPSu_CREOFS24.nc')
    curr = GridCurrent.from_netCDF(
        name='gc2',
        filename=curr_file,
    )

    c_mover = PyGridCurrentMover(curr,
                                 extrapolate=True,
                                 default_num_method='Trapezoid')

    #     renderer.add_grid(curr.grid)
    #     renderer.add_vec_prop(curr)
    model.movers += c_mover

    print 'adding a random mover'
    model.movers += RandomMover(diffusion_coef=1000)

    # curr_file = get_datafile(os.path.join(base_dir, 'COOPSu_CREOFS24.nc'))
    # c_mover = GridCurrentMover(curr_file)
    # model.movers += c_mover

    return model
예제 #49
0
def make_model(images_dir=os.path.join(base_dir, 'images')):

    # create the maps:

    print 'creating the maps'
    mapfile = get_datafile(os.path.join(base_dir, './MassBayMap.bna'))
    gnome_map = MapFromBNA(mapfile, refloat_halflife=1)  # hours

    renderer = Renderer(mapfile,
                        images_dir,
                        size=(800, 800),
                        projection_class=GeoProjection)

    print 'initializing the model'
    start_time = datetime(2013, 3, 12, 10, 0)

    # 15 minutes in seconds
    # Default to now, rounded to the nearest hour
    model = Model(time_step=900,
                  start_time=start_time,
                  duration=timedelta(days=1),
                  map=gnome_map,
                  uncertain=False)

    print 'adding outputters'
    model.outputters += renderer

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

    print 'adding a RandomMover:'
    model.movers += 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=18), (5, 180))

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

    print 'adding a cats shio mover:'

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

    c_mover = CatsMover(curr_file, tide=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 = get_datafile(
        os.path.join(base_dir, r"./MerrimackMassCoast.cur"))
    tide_file = get_datafile(
        os.path.join(base_dir, r"./MerrimackMassCoastOSSM.txt"))
    c_mover = CatsMover(curr_file, tide=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 = get_datafile(os.path.join(base_dir, r"MassBaySewage.cur"))
    c_mover = 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 = get_datafile(os.path.join(base_dir, r"./WAC10msNW.cur"))
    component_file2 = get_datafile(os.path.join(base_dir, r"./WAC10msSW.cur"))
    comp_mover = 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 = start_time + timedelta(hours=12)
    spill = point_line_release_spill(num_elements=1000,
                                     start_position=(-70.911432, 42.369142,
                                                     0.0),
                                     release_time=start_time,
                                     end_release_time=end_time)

    model.spills += spill

    return model
예제 #50
0
def make_model(images_dir=os.path.join(base_dir, 'images')):
    print 'initializing the model'

    start_time = datetime(2012, 10, 25, 0, 1)
    # start_time = datetime(2015, 12, 18, 06, 01)

    # 1 day of data in file
    # 1/2 hr in seconds
    model = Model(start_time=start_time,
                  duration=timedelta(hours=24),
                  time_step=900)

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

    print 'adding the map'
    '''TODO: sort out MapFromBna's map_bounds parameter...
    it does nothing right now, and the spill is out of bounds'''
    model.map = MapFromBNA(mapfile, refloat_halflife=0.0)  # seconds

    # draw_ontop can be 'uncertain' or 'forecast'
    # 'forecast' LEs are in black, and 'uncertain' are in red
    # default is 'forecast' LEs draw on top
    renderer = Renderer(mapfile, images_dir, image_size=(1024, 768))
    #     renderer.viewport = ((-73.5, 40.5), (-73.1, 40.75))
    #     renderer.viewport = ((-122.9, 45.6), (-122.6, 46.0))

    print 'adding outputters'
    model.outputters += renderer

    print 'adding a spill'
    # for now subsurface spill stays on initial layer
    # - will need diffusion and rise velocity
    # - wind doesn't act
    # - start_position = (-76.126872, 37.680952, 5.0),
    spill1 = point_line_release_spill(num_elements=1000,
                                      start_position=(-74.15, 40.5, 0.0),
                                      release_time=start_time)

    model.spills += spill1

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

    print 'adding a wind mover:'

    series = []
    for i in [(1, (5, 90)), (7, (5, 180)), (13, (5, 270)), (19, (5, 0)),
              (25, (5, 90))]:
        series.append((start_time + timedelta(hours=i[0]), i[1]))

    wind1 = WindTS.constant_wind('wind1', 5, 270, 'knots')
    wind2 = WindTS(timeseries=series, units='knots', extrapolate=True)

    wind = Wind(timeseries=series, units='knots')

    model.movers += PyWindMover(wind=wind2)
    #     model.movers += WindMover(wind)

    #     print 'adding a current mover:'
    #
    #     url = ('http://geoport.whoi.edu/thredds/dodsC/clay/usgs/users/jcwarner/Projects/Sandy/triple_nest/00_dir_NYB05.ncml')
    # #     cf = roms_field('nos.tbofs.fields.n000.20160406.t00z_sgrid.nc')
    #     cf = roms_field(url)
    #     cf.set_appearance(on=True)
    #     renderer.grids += [cf]
    #     renderer.delay = 25
    #     u_mover = UGridCurrentMover(cf)
    #     model.movers += u_mover

    # curr_file = get_datafile(os.path.join(base_dir, 'COOPSu_CREOFS24.nc'))
    # c_mover = GridCurrentMover(curr_file)
    # model.movers += c_mover

    return model
예제 #51
0
def make_model(images_dir=os.path.join(base_dir, 'images')):
    print 'initializing the model'

    start_time = datetime(1985, 1, 1, 13, 31)

    # 1 day of data in file
    # 1/2 hr in seconds
    model = Model(start_time=start_time,
                  duration=timedelta(days=4),
                  time_step=7200)

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

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

    print 'adding a spill'
    # for now subsurface spill stays on initial layer
    # - will need diffusion and rise velocity
    # - wind doesn't act
    # - start_position = (-76.126872, 37.680952, 5.0),
    #     spill1 = point_line_release_spill(num_elements=10000,
    #                                       start_position=(-163.75,
    #                                                       69.75,
    #                                                       0.0),
    #                                       release_time=start_time)
    #
    spill1 = point_line_release_spill(num_elements=50000,
                                      start_position=(196.25, 69.75, 0.0),
                                      release_time=start_time)

    model.spills += spill1
    #     model.spills += spill2

    print 'adding a wind mover:'

    #     model.movers += constant_wind_mover(0.5, 0, units='m/s')

    print 'adding a current mover:'

    fn = ['arctic_avg2_0001_gnome.nc', 'arctic_avg2_0002_gnome.nc']

    #     fn = ['C:\\Users\\jay.hennen\\Documents\\Code\\pygnome\\py_gnome\\scripts\\script_TAP\\arctic_avg2_0001_gnome.nc',
    #           'C:\\Users\\jay.hennen\\Documents\\Code\\pygnome\\py_gnome\\scripts\\script_TAP\\arctic_avg2_0002_gnome.nc']

    gt = {'node_lon': 'lon', 'node_lat': 'lat'}
    #     fn='arctic_avg2_0001_gnome.nc'

    wind_method = 'Euler'
    method = 'RK2'
    print 'adding outputters'

    # draw_ontop can be 'uncertain' or 'forecast'
    # 'forecast' LEs are in black, and 'uncertain' are in red
    # default is 'forecast' LEs draw on top
    renderer = Renderer(mapfile, images_dir, image_size=(1024, 768))
    model.outputters += renderer
    netcdf_file = os.path.join(base_dir,
                               str(model.time_step / 60) + method + '.nc')
    scripting.remove_netcdf(netcdf_file)

    print 'adding movers'
    model.outputters += NetCDFOutput(netcdf_file, which_data='all')

    print 'loading entire current data'
    ice_aware_curr = IceAwareCurrent.from_netCDF(filename=fn, grid_topology=gt)

    #     env1 = get_env_from_netCDF(filename)
    #     mov = PyCurrentMover.from_netCDF(filename)

    ice_aware_curr.ice_velocity.variables[0].dimension_ordering = [
        'time', 'x', 'y'
    ]
    ice_aware_wind = IceAwareWind.from_netCDF(
        filename=fn,
        ice_velocity=ice_aware_curr.ice_velocity,
        ice_concentration=ice_aware_curr.ice_concentration,
        grid=ice_aware_curr.grid)

    curr = GridCurrent.from_netCDF(filename=fn)
    #     GridCurrent.is_gridded()

    #     import pprint as pp
    #     from gnome.utilities.orderedcollection import OrderedCollection
    #     model.environment = OrderedCollection(dtype=Environment)
    #     model.environment.add(ice_aware_curr)
    #     from gnome.environment import WindTS

    print 'loading entire wind data'

    #     i_c_mover = PyCurrentMover(current=ice_aware_curr)
    #     i_c_mover = PyCurrentMover(current=ice_aware_curr, default_num_method='Euler')
    i_c_mover = PyCurrentMover(current=ice_aware_curr,
                               default_num_method=method,
                               extrapolate=True)
    i_w_mover = PyWindMover(wind=ice_aware_wind,
                            default_num_method=wind_method)

    #     ice_aware_curr.grid.node_lon = ice_aware_curr.grid.node_lon[:]-360
    #     ice_aware_curr.grid.build_celltree()
    model.movers += i_c_mover
    model.movers += i_w_mover

    print 'adding an IceAwareRandomMover:'
    model.movers += IceAwareRandomMover(
        ice_concentration=ice_aware_curr.ice_concentration,
        diffusion_coef=1000)
    #     renderer.add_grid(ice_aware_curr.grid)
    #     renderer.add_vec_prop(ice_aware_curr)

    # curr_file = get_datafile(os.path.join(base_dir, 'COOPSu_CREOFS24.nc'))
    # c_mover = GridCurrentMover(curr_file)
    # model.movers += c_mover
    #     model.environment.add(WindTS.constant(10, 300))
    #     print('Saving')
    #     model.environment[0].ice_velocity.variables[0].serialize()
    #     IceVelocity.deserialize(model.environment[0].ice_velocity.serialize())
    #     model.save('.')
    #     from gnome.persist.save_load import load
    #     print('Loading')
    #     model2 = load('./Model.zip')

    return model
예제 #52
0
def make_model(images_dir=os.path.join(base_dir, 'images')):
    print 'initializing the model'

    start_time = datetime(2014, 6, 9, 0, 0)
    mapfile = get_datafile(os.path.join(base_dir, 'PassamaquoddyMap.bna'))

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

    # # the image output renderer
    # global renderer

    # one hour timestep
    model = Model(start_time=start_time,
                  duration=timedelta(hours=24), time_step=360,
                  map=gnome_map, uncertain=False, cache_enabled=True)

    print 'adding outputters'
    renderer = Renderer(mapfile, images_dir, size=(800, 600),
                        # output_timestep=timedelta(hours=1),
                        draw_ontop='uncertain')
    renderer.viewport = ((-67.15, 45.), (-66.9, 45.2))

    model.outputters += renderer

    netcdf_file = os.path.join(base_dir, 'script_passamaquoddy.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=(-66.991344, 45.059316,
                                                     0.0),
                                     release_time=start_time)
    model.spills += spill

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

    print 'adding a wind mover:'
    series = np.zeros((5, ), dtype=datetime_value_2d)
    series[0] = (start_time, (5, 90))
    series[1] = (start_time + timedelta(hours=18), (5, 180))
    series[2] = (start_time + timedelta(hours=30), (5, 135))
    series[3] = (start_time + timedelta(hours=42), (5, 180))
    series[4] = (start_time + timedelta(hours=54), (5, 225))

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

    print 'adding a current mover:'
    curr_file = get_datafile(os.path.join(base_dir, 'PQBayCur.nc4'))
    topology_file = get_datafile(os.path.join(base_dir, 'PassamaquoddyTOP.dat')
                                 )
    tide_file = get_datafile(os.path.join(base_dir, 'EstesHead.txt'))

    cc_mover = CurrentCycleMover(curr_file, topology_file,
                                 tide=Tide(tide_file))

    model.movers += cc_mover
    model.environment += cc_mover.tide

    print 'viewport is:', [o.viewport
                           for o in model.outputters
                           if isinstance(o, Renderer)]

    return model
예제 #53
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
예제 #54
0
def make_model(images_dir=os.path.join(base_dir, 'images')):
    print 'initializing the model'

    start_time = datetime(2012, 9, 15, 12, 0)
    mapfile = get_datafile(os.path.join(base_dir, './LongIslandSoundMap.BNA'))

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

    # # the image output renderer
    # global renderer

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

    print 'adding a spill'
    et = floating_weathering(substance='FUEL OIL NO.6')
    spill = point_line_release_spill(num_elements=1000,
                                     start_position=(-72.419992,
                                                     41.202120, 0.0),
                                     release_time=start_time,
                                     amount=1000,
                                     units='kg',
                                     element_type=et)
    spill.amount_uncertainty_scale = 1.0
    model.spills += spill

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

    print 'adding a wind mover:'
    series = np.zeros((5, ), dtype=datetime_value_2d)
    series[0] = (start_time, (10, 45))
    series[1] = (start_time + timedelta(hours=18), (10, 90))
    series[2] = (start_time + timedelta(hours=30), (10, 135))
    series[3] = (start_time + timedelta(hours=42), (10, 180))
    series[4] = (start_time + timedelta(hours=54), (10, 225))

    wind = Wind(timeseries=series, units='m/s',
                speed_uncertainty_scale=0.5)
    model.movers += WindMover(wind)

    print 'adding a cats mover:'
    curr_file = get_datafile(os.path.join(base_dir, r"./LI_tidesWAC.CUR"))
    tide_file = get_datafile(os.path.join(base_dir, r"./CLISShio.txt"))

    c_mover = CatsMover(curr_file, tide=Tide(tide_file))
    model.movers += c_mover

    model.environment += c_mover.tide

    print 'adding Weatherers'
    water_env = Water(311.15)
    model.environment += water_env
    model.weatherers += [Evaporation(water_env, wind),
                         Dispersion(),
                         Burn(),
                         Skimmer()]

    print 'adding outputters'
    model.outputters += WeatheringOutput()

    return model
예제 #55
0
def make_model(images_dir=os.path.join(base_dir, 'images')):

    # create the maps:

    print 'creating the maps'
    mapfile = get_datafile(os.path.join(base_dir, 'DelawareRiverMap.bna'))
    gnome_map = MapFromBNA(mapfile, refloat_halflife=1)  # hours

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

    print 'initializing the model'
    start_time = datetime(2012, 8, 20, 13, 0)

    # 15 minutes in seconds
    # Default to now, rounded to the nearest hour
    model = Model(time_step=900, start_time=start_time,
                  duration=timedelta(days=1),
                  map=gnome_map, uncertain=False)

    print 'adding outputters'
    model.outputters += renderer

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

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

    print 'adding a wind mover:'

    # wind_file = get_datafile(os.path.join(base_dir, 'ConstantWind.WND'))
    # wind = Wind(filename=wind_file)

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

    wind = Wind(timeseries=series, units='m/s')

    # w_mover = WindMover(Wind(timeseries=series, units='knots'))
    w_mover = WindMover(wind)
    model.movers += w_mover

    print 'adding a cats shio mover:'

    curr_file = get_datafile(os.path.join(base_dir, 'FloodTides.cur'))
    tide_file = get_datafile(os.path.join(base_dir, 'FloodTidesShio.txt'))

    c_mover = CatsMover(curr_file, tide=Tide(tide_file))

    # this is the value in the file (default)
    c_mover.scale_refpoint = (-75.081667, 38.7995)
    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 mover:'

    curr_file = get_datafile(os.path.join(base_dir, 'Offshore.cur'))
    c_mover = CatsMover(curr_file)

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

    c_mover.scale = True
    c_mover.scale_refpoint = (-74.7483333, 38.898333)
    c_mover.scale_value = .03
    model.movers += c_mover
    #
    # these are from windows they don't match Mac values...
    # pat1Angle 315;
    # pat1Speed 30; pat1SpeedUnits knots;
    # pat1ScaleToValue 0.314426
    #
    # pat2Angle 225;
    # pat2Speed 30; pat2SpeedUnits knots;
    # pat2ScaleToValue 0.032882
    # scaleBy WindStress

    print 'adding a component mover:'

    # if only using one current pattern
    # comp_mover = ComponentMover(curr_file1, None, wind)
    #
    # todo: following is not working when model is saved out - fix
    # comp_mover = ComponentMover(curr_file1, curr_file2,
    #                             Wind(timeseries=series, units='m/s'))
    # comp_mover = ComponentMover(curr_file1, curr_file2,
    #                             wind=Wind(filename=wind_file))

    curr_file1 = get_datafile(os.path.join(base_dir, 'NW30ktwinds.cur'))
    curr_file2 = get_datafile(os.path.join(base_dir, 'SW30ktwinds.cur'))
    comp_mover = ComponentMover(curr_file1, curr_file2, wind)

    comp_mover.scale_refpoint = (-75.263166, 39.1428333)

    comp_mover.pat1_angle = 315
    comp_mover.pat1_speed = 30
    comp_mover.pat1_speed_units = 1
    # comp_mover.pat1ScaleToValue = .314426
    comp_mover.pat1_scale_to_value = .502035

    comp_mover.pat2_angle = 225
    comp_mover.pat2_speed = 30
    comp_mover.pat2_speed_units = 1
    # comp_mover.pat2ScaleToValue = .032882
    comp_mover.pat2_scale_to_value = .021869

    model.movers += comp_mover

    print 'adding a spill'

    end_time = start_time + timedelta(hours=12)
    spill = point_line_release_spill(num_elements=1000,
                                     release_time=start_time,
                                     # end_release_time=end_time,
                                     start_position=(-75.262319,
                                                     39.142987, 0.0),
                                     )

    model.spills += spill

    return model
예제 #56
0
def make_model(images_dir=os.path.join(base_dir, 'images')):
    print 'initializing the model'

    start_time = datetime(2013, 5, 18, 0)

    model = Model(start_time=start_time,
                  duration=timedelta(days=8),
                  time_step=4 * 3600,
                  uncertain=False)

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

    print 'adding the map'
    model.map = MapFromBNA(mapfile, refloat_halflife=6)  # hours

    #
    # Add the outputters -- render to images, and save out as netCDF
    #

    print 'adding renderer'
    model.outputters += Renderer(
        mapfile,
        images_dir,
        size=(800, 600),
    )
    #                                 draw_back_to_fore=True)

    # print "adding netcdf output"
    # netcdf_output_file = os.path.join(base_dir,'mariana_output.nc')
    # scripting.remove_netcdf(netcdf_output_file)
    # model.outputters += NetCDFOutput(netcdf_output_file, which_data='all')

    #
    # Set up the movers:
    #

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

    print 'adding a simple wind mover:'
    model.movers += constant_wind_mover(5, 315, units='m/s')

    print 'adding a current mover:'

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

    # #
    # # Add some spills (sources of elements)
    # #

    print 'adding four spill'
    model.spills += point_line_release_spill(num_elements=NUM_ELEMENTS // 4,
                                             start_position=(145.25, 15.0,
                                                             0.0),
                                             release_time=start_time)
    model.spills += point_line_release_spill(num_elements=NUM_ELEMENTS // 4,
                                             start_position=(146.25, 15.0,
                                                             0.0),
                                             release_time=start_time)
    model.spills += point_line_release_spill(num_elements=NUM_ELEMENTS // 4,
                                             start_position=(145.75, 15.25,
                                                             0.0),
                                             release_time=start_time)
    model.spills += point_line_release_spill(num_elements=NUM_ELEMENTS // 4,
                                             start_position=(145.75, 14.75,
                                                             0.0),
                                             release_time=start_time)

    return model
예제 #57
0
def make_model(images_dir=os.path.join(base_dir, 'images')):
    print 'initializing the model'

    start_time = datetime(1985, 1, 1, 13, 31)

    # 1 day of data in file
    # 1/2 hr in seconds
    model = Model(start_time=start_time,
                  duration=timedelta(days=4),
                  time_step=3600 * 2)

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

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

    print 'adding a spill'
    # for now subsurface spill stays on initial layer
    # - will need diffusion and rise velocity
    # - wind doesn't act
    # - start_position = (-76.126872, 37.680952, 5.0),
    #     spill1 = point_line_release_spill(num_elements=10000,
    #                                       start_position=(-163.75,
    #                                                       69.75,
    #                                                       0.0),
    #                                       release_time=start_time)
    #
    spill1 = point_line_release_spill(num_elements=100,
                                      start_position=(196.25, 69.75, 0.0),
                                      release_time=start_time)

    model.spills += spill1
    #     model.spills += spill2

    print 'adding a wind mover:'

    #     model.movers += constant_wind_mover(0.5, 0, units='m/s')

    print 'adding a current mover:'

    fn = ['arctic_avg2_0001_gnome.nc', 'arctic_avg2_0002_gnome.nc']

    gt = {'node_lon': 'lon', 'node_lat': 'lat'}
    #     fn='arctic_avg2_0001_gnome.nc'

    wind_method = 'Euler'
    method = 'Trapezoid'
    print 'adding outputters'

    # draw_ontop can be 'uncertain' or 'forecast'
    # 'forecast' LEs are in black, and 'uncertain' are in red
    # default is 'forecast' LEs draw on top
    #     renderer = Renderer(mapfile, images_dir, image_size=(1024, 768))
    #     model.outputters += renderer
    netcdf_file = os.path.join(base_dir,
                               str(model.time_step / 60) + method + '.nc')
    scripting.remove_netcdf(netcdf_file)

    print 'adding movers'
    model.outputters += NetCDFOutput(netcdf_file, which_data='all')

    ice_aware_curr = IceAwareCurrent.from_netCDF(filename=fn, grid_topology=gt)
    ice_aware_wind = IceAwareWind.from_netCDF(
        filename=fn,
        ice_var=ice_aware_curr.ice_var,
        ice_conc_var=ice_aware_curr.ice_conc_var,
        grid=ice_aware_curr.grid,
    )

    #     i_c_mover = PyGridCurrentMover(current=ice_aware_curr)
    #     i_c_mover = PyGridCurrentMover(current=ice_aware_curr, default_num_method='Euler')
    i_c_mover = PyGridCurrentMover(current=ice_aware_curr,
                                   default_num_method=method)
    i_w_mover = PyWindMover(wind=ice_aware_wind,
                            default_num_method=wind_method)

    #     ice_aware_curr.grid.node_lon = ice_aware_curr.grid.node_lon[:]-360
    #     ice_aware_curr.grid.build_celltree()
    model.movers += i_c_mover
    model.movers += i_w_mover

    print 'adding an IceAwareRandomMover:'
    model.movers += IceAwareRandomMover(
        ice_conc_var=ice_aware_curr.ice_conc_var, diffusion_coef=1000)
    #     renderer.add_grid(ice_aware_curr.grid)
    #     renderer.add_vec_prop(ice_aware_curr)

    #     renderer.set_viewport(((-190.9, 60), (-72, 89)))
    # curr_file = get_datafile(os.path.join(base_dir, 'COOPSu_CREOFS24.nc'))
    # c_mover = GridCurrentMover(curr_file)
    # model.movers += c_mover

    return model