Ejemplo n.º 1
0
def test_serialize_deserialize():
    """
    test to_dict function for Ice object
    create a new ice object and make sure it has same properties
    """

    ice_grid = IceWindMover(ice_file, topology_file)
    serial = ice_grid.serialize()
    ice2 = IceWindMover.deserialize(serial)
    assert ice_grid == ice2
Ejemplo n.º 2
0
def test_serialize_deserialize():
    """
    test to_dict function for Ice object
    create a new ice object and make sure it has same properties
    """

    ice_grid = IceWindMover(ice_file, topology_file)
    serial = ice_grid.serialize()
    ice2 = IceWindMover.deserialize(serial)
    assert ice_grid == ice2
Ejemplo n.º 3
0
def test_loop():
    """
    test one time step with no uncertainty on the spill
    checks there is non-zero motion.
    also checks the motion is same for all LEs
    """

    pSpill = sample_sc_release(num_le,
                               start_pos,
                               rel_time,
                               windage_range=(0.03, 0.03))
    ice_mover = IceWindMover(ice_file, topology_file)
    delta = _certain_loop(pSpill, ice_mover)

    #_assert_move(delta)	# should get a new example that has some movement...

    #assert np.all(delta[:, 0] == delta[0, 0])  # lat move matches for all LEs
    #assert np.all(delta[:, 1] == delta[0, 1])  # long move matches for all LEs
    assert np.all(
        delta[:, 0] == 0)  # in this case ice coverage is > 80% so no wind
    assert np.all(
        delta[:, 1] == 0)  # in this case ice coverage is > 80% so no wind
    assert np.all(delta[:, 2] == 0)  # 'z' is zeros

    return delta
Ejemplo n.º 4
0
def test_ice_fields():
    """
    test that data is loaded
    checks there is non-zero motion.
    """

    #pSpill = sample_sc_release(num_le, start_pos, rel_time)
    #pSpill.spill.set('windage_range', (0.03, 0.03))
    ice_mover = IceWindMover(ice_file, topology_file)
    vels = ice_mover.get_ice_velocities(test_time)	#not sure if we can about ice velocity for wind...
    frac, thick = ice_mover.get_ice_fields(test_time)

    # fraction values between 0 and 1
    assert (np.all(frac[:] <= 1) and np.all(frac[:] >= 0) and not np.all(frac[:] == 0))

    # thickness >= 0, < 10 in this example...
    # this file uses 1e37 rather than a fill value?? should get a different example
    #assert (np.all(thick[:] <= 10) and np.all(thick[:] >= 0) and not np.all(thick[:] == 0))
    assert (np.all(thick[:] <= 1e38) and np.all(thick[:] > 0) and not np.all(thick[:] == 0))
Ejemplo n.º 5
0
def test_serialize_deserialize():
    """
    test to_dict function for Ice object
    create a new ice object and make sure it has same properties
    """

    ice_grid = IceWindMover(ice_file, topology_file)
    serial = ice_grid.serialize('webapi')
    dict_ = IceWindMover.deserialize(serial)
    ice2 = IceWindMover.new_from_dict(dict_)
    assert ice_grid == ice2

    ice_grid.update_from_dict(dict_)  # tests no failures
Ejemplo n.º 6
0
def test_serialize_deserialize():
    """
    test to_dict function for Ice object
    create a new ice object and make sure it has same properties
    """

    ice_grid = IceWindMover(ice_file, topology_file)
    serial = ice_grid.serialize('webapi')
    dict_ = IceWindMover.deserialize(serial)
    ice2 = IceWindMover.new_from_dict(dict_)
    assert ice_grid == ice2

    ice_grid.update_from_dict(dict_)  # tests no failures
Ejemplo n.º 7
0
#     """
#
#     delta = test_loop()
#     u_delta = test_uncertain_loop()
#     print
#     print delta
#     print u_delta
#     assert np.all(delta[:, :2] != u_delta[:, :2])
#     assert np.all(delta[:, 2] == u_delta[:, 2])
#     uncertain_time_delay = 3
#     u_delta = test_uncertain_loop(uncertain_time_delay)
#     print u_delta
#     assert np.all(delta[:, :2] == u_delta[:, :2])
#

ice_grid = IceWindMover(ice_file, topology_file)

# def test_default_props():
#     """
#     test default properties
#     """
#
#     assert ice_grid.wind_scale == 1
#     assert ice_grid.uncertain_time_delay == 0
#     assert ice_grid.uncertain_duration == 24
#     assert ice_grid.uncertain_cross == .25
#     assert ice_grid.uncertain_along == .5
#     assert ice_grid.extrapolate == False
#     assert ice_grid.time_offset == 0
#
Ejemplo n.º 8
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, 'arctic_coast3.bna'))

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

    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, 'script_old_TAPa.nc')
    scripting.remove_netcdf(netcdf_file)

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

    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=(196.25,
                                                      69.75,
                                                      0.0),
                                      release_time=start_time)
#
#     spill2 = point_line_release_spill(num_elements=5000,
#                                       start_position=(-163.75,
#                                                       69.5,
#                                                       0.0),
#                                       release_time=start_time)

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

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

    print 'adding a wind mover:'
     # winds from the ROMS Arctic run, provided by Walter Johnson
    wind_file = os.path.join(base_dir, 'arctic_filelist.txt')
    print wind_file
    topology_file = os.path.join(base_dir, 'arctic_subset_newtopo2.DAT')
    model.movers += IceWindMover(wind_file, topology_file)
    # model.movers += GridWindMover(wind_file, topology_file)
    # model.movers += GridWindMover(wind_file, topology_file)

    print 'adding an ice mover:'
  # ice from the ROMS Arctic run, provided by Walter Johnson
    ice_file = os.path.join(base_dir, 'arctic_filelist.txt')
    topology_file = os.path.join(base_dir, 'arctic_subset_newtopo2.DAT')
    model.movers += IceMover(ice_file, topology_file)
    # model.movers += IceMover(ice_file)
    print ice_file

    print 'adding a current mover:'
#
#     fn = ['N:\\Users\\Dylan.Righi\\OutBox\\ArcticROMS\\arctic_avg2_0001_gnome.nc',
#                  'N:\\Users\\Dylan.Righi\\OutBox\\ArcticROMS\\arctic_avg2_0002_gnome.nc']
#
#     gt = {'node_lon':'lon',
#           'node_lat':'lat'}
# #     fn='arctic_avg2_0001_gnome.nc'
#
#     ice_aware_curr = IceAwareCurrent.from_netCDF(filename=fn,
#                                                  grid_topology=gt)
#     ice_aware_wind = IceAwareWind.from_netCDF(filename=fn,
#                                               grid = ice_aware_curr.grid,)
#     method = 'Trapezoid'
#
# #     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=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
#     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
    model.save('.')
    return model