def test_serialize_deserialize(tide):
    """
    test to_dict function for Wind object
    create a new wind object and make sure it has same properties
    """

    c_cycle = CurrentCycleMover(curr_file, topology_file, tide=tide)
    toserial = c_cycle.serialize()
    c_cycle2 = c_cycle.deserialize(toserial)
    assert c_cycle == c_cycle2
def test_serialize_deserialize(tide):
    """
    test to_dict function for Wind object
    create a new wind object and make sure it has same properties
    """

    c_cycle = CurrentCycleMover(curr_file, topology_file, tide=tide)
    toserial = c_cycle.serialize()
    c_cycle2 = c_cycle.deserialize(toserial)
    assert c_cycle == c_cycle2
def test_uncertain_loop(uncertain_time_delay=0):
    """
    test one time step with uncertainty on the spill
    checks there is non-zero motion.
    """

    pSpill = sample_sc_release(num_le, start_pos, rel_time, uncertain=True)
    curr = CurrentCycleMover(curr_file, topology_file, tide=td)
    curr.uncertain_time_delay = uncertain_time_delay
    u_delta = _uncertain_loop(pSpill, curr)

    _assert_move(u_delta)

    return u_delta
def test_exceptions():
    """
    Test correct exceptions are raised
    """

    with pytest.raises(ValueError):
        'file does not exis'
        CurrentCycleMover(os.path.join('./', 'ChesBay.CUR'))

    with pytest.raises(OSError):
        CurrentCycleMover(testdata['CurrentCycleMover']['curr_bad_file'])

    with pytest.raises(TypeError):
        CurrentCycleMover(curr_file, topology_file=10)
def test_uncertain_loop(uncertain_time_delay=0):
    """
    test one time step with uncertainty on the spill
    checks there is non-zero motion.
    """

    pSpill = sample_sc_release(num_le, start_pos, rel_time,
                               uncertain=True)
    curr = CurrentCycleMover(curr_file, topology_file, tide=td)
    curr.uncertain_time_delay=uncertain_time_delay
    u_delta = _uncertain_loop(pSpill, curr)

    _assert_move(u_delta)

    return u_delta
示例#6
0
def test_serialize_deserialize(tide):
    """
    test to_dict function for Wind object
    create a new wind object and make sure it has same properties
    """

    c_cycle = CurrentCycleMover(curr_file, topology_file, tide=tide)
    toserial = c_cycle.serialize('webapi')
    dict_ = c_cycle.deserialize(toserial)
    if tide:
        #assert toserial['tide'] == td.serialize(json_)
        assert 'tide' in toserial
        dict_['tide'] = tide  # no longer updating properties of nested objects
        c_cycle.update_from_dict(dict_)
        assert c_cycle.tide is tide
    else:
        c_cycle.update_from_dict(dict_)
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)
    curr = CurrentCycleMover(curr_file, topology_file, tide=td)
    delta = _certain_loop(pSpill, curr)

    _assert_move(delta)

    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[:, 2] == 0)  # 'z' is zeros

    return delta
    """

    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])


c_cycle = CurrentCycleMover(curr_file, topology_file)


def test_default_props():
    """
    test default properties
    """

    assert c_cycle.current_scale == 1
    assert c_cycle.uncertain_time_delay == 0
    assert c_cycle.uncertain_duration == 24
    assert c_cycle.uncertain_cross == .25
    assert c_cycle.uncertain_along == .5
    assert c_cycle.extrapolate == False
    assert c_cycle.time_offset == 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
示例#10
0
    Evaporation(wind=constant_wind(1., 30.), water=Water(333.0)),
))
def test_save_load_wind_objs(saveloc_, obj):
    'test save/load functionality'
    _json_, zipfile_, _refs = obj.save(saveloc_, )
    obj2 = obj.__class__.load(zipfile_)

    assert obj == obj2


# Following movers fail on windows with fixture. This is causing an issue in
# windows for the NetCDF files - for some reason it is not able to delete the
# netcdf data files. All files are being closed in C++.
l_movers2 = (
    CurrentCycleMover(testdata['CurrentCycleMover']['curr'],
                      topology_file=testdata['CurrentCycleMover']['top'],
                      tide=Tide(testdata['CurrentCycleMover']['tide'])),
    CurrentCycleMover(testdata['CurrentCycleMover']['curr'],
                      topology_file=testdata['CurrentCycleMover']['top']),
    GridCurrentMover(testdata['GridCurrentMover']['curr_tri'],
                     testdata['GridCurrentMover']['top_tri']),
    GridWindMover(testdata['GridWindMover']['wind_curv'],
                  testdata['GridWindMover']['top_curv']),
)


@pytest.mark.parametrize("obj", l_movers2)
def test_serialize_deserialize_grids(saveloc_, obj):
    'test serialize/deserialize functionality'
    json_ = obj.serialize()
    obj2 = obj.__class__.deserialize(json_)