def test_no_destination():
    src = Rectilinear([0, 1, 2], [0, 2])
    dst = Rectilinear([0.5, 1.5, 2.5], [0.25, 1.25])

    mapper = NearestVal()
    mapper.initialize(dst, src)

    src_vals = np.arange(src.get_point_count())
    dst_vals = mapper.run(src_vals)
    assert_array_almost_equal(dst_vals, np.array([0.0, 1.0, 2.0, 3.0, 4.0, 5.0]))
def test_bad_destination():
    src = Rectilinear([0, 1, 2], [0, 2])
    dst = Rectilinear([0.5, 1.5, 2.5], [0.25, 1.25])

    mapper = NearestVal()
    mapper.initialize(dst, src)

    src_vals = np.arange(src.get_point_count())
    dst_vals = [0.0] * src.get_point_count()
    with pytest.raises(TypeError):
        mapper.run(src_vals, dst_vals)
Ejemplo n.º 3
0
def test_destination_init_zero():
    src = Rectilinear([0, 1, 2], [0, 2])
    dst = Rectilinear([.5, 1.5, 2.5], [.25, 1.25])

    mapper = NearestVal()
    mapper.initialize(dst, src)

    src_vals = np.arange(src.get_point_count())
    src_vals[2] = -999
    dst_vals = mapper.run(src_vals)
    assert_array_almost_equal(dst_vals, np.array([0., 1., 0., 3., 4., 5.]))
Ejemplo n.º 4
0
def test_all_good():
    src = Rectilinear([0, 1, 2], [0, 2])
    dst = Rectilinear([.5, 1.5, 2.5], [.25, 1.25])

    src_vals = np.arange(src.get_point_count ())

    mapper = NearestVal()
    mapper.initialize(dst, src)
    dst_vals = mapper.run(src_vals)

    assert_array_almost_equal(dst_vals, np.array([0., 1., 2., 3., 4., 5.]))
def test_some_bad():
    src = Rectilinear([0, 1, 2], [0, 2])
    dst = Rectilinear([0.5, 1.5, 2.5], [0.25, 1.25])

    mapper = NearestVal()
    mapper.initialize(dst, src)

    src_vals = np.arange(src.get_point_count())
    src_vals[2] = -999
    dst_vals = np.zeros(dst.get_point_count()) - 1
    rv = mapper.run(src_vals, dst_vals=dst_vals)

    assert rv is dst_vals
    assert_array_almost_equal(dst_vals, np.array([0.0, 1.0, -1.0, 3.0, 4.0, 5.0]))