Esempio n. 1
0
def test_np_imagesrouce_rt():
    shape = (13, 17)
    test_data = np.array([np.ones(shape) * j for j in range(11)])
    np_snk = NPImageSink()
    with np_snk as snk:
        for j in range(11):
            snk.record_frame(test_data[j], j, {'md': j})
    np_src = np_snk.make_source()
    with np_src as src:
        for j in range(11):
            assert_true(np.all(src.get_frame(j) == j))
            assert_array_equal(src.get_frame(j), test_data[j])
            assert_equal(src.get_frame_metadata(j, 'md'), j)
Esempio n. 2
0
def _check_binary_op(op, tool, a, b):
    # set up constant arrays as testing sources, use floats
    srcA = NPImageSource(a * np.ones(_shape, dtype=np.float))
    srcB = NPImageSource(b * np.ones(_shape, dtype=np.float))
    # set up a sink
    snkC = NPImageSink()
    # init the tool and assign input/output
    T = tool()
    T.A = srcA
    T.B = srcB
    T.out = snkC
    # run the tool
    T.run()
    # compute what the answer should be
    c = op(a, b)
    # make and activate a source from the sink
    with snkC.make_source() as C:
        # loop over the output and check each frame
        for j in range(_shape[0]):
            # assert that all of the entries are equal
            # to the 'true' result
            assert_true(np.all(c == C.get_frame(j)))
def _check_binary_op(op, tool, a, b):
    # set up constant arrays as testing sources, use floats
    srcA = NPImageSource(a * np.ones(_shape, dtype=np.float))
    srcB = NPImageSource(b * np.ones(_shape, dtype=np.float))
    # set up a sink
    snkC = NPImageSink()
    # init the tool and assign input/output
    T = tool()
    T.A = srcA
    T.B = srcB
    T.out = snkC
    # run the tool
    T.run()
    # compute what the answer should be
    c = op(a, b)
    # make and activate a source from the sink
    with snkC.make_source() as C:
        # loop over the output and check each frame
        for j in range(_shape[0]):
            # assert that all of the entries are equal
            # to the 'true' result
            assert_true(np.all(c == C.get_frame(j)))