Example #1
0
def test_io_orientation():
    shape = (2,3,4)
    for in_arr, out_ornt in zip(IN_ARRS, OUT_ORNTS):
        ornt = io_orientation(in_arr)
        yield assert_array_equal(ornt, out_ornt)
        taff = orientation_affine(ornt, shape)
        yield assert_true(same_transform(taff, ornt, shape))
        for axno in range(3):
            arr = in_arr.copy()
            ex_ornt = out_ornt.copy()
            # flip the input axis in affine
            arr[:,axno] *= -1
            # check that result shows flip
            ex_ornt[axno, 1] *= -1
            ornt = io_orientation(arr)
            yield assert_array_equal(ornt, ex_ornt)
            taff = orientation_affine(ornt, shape)
            yield assert_true(same_transform(taff, ornt, shape))
Example #2
0
def test_drop_coord():
    # given a 5x4 affine from slicing an fmri,
    # the orientations code should easily reorder and drop the t
    # axis

    # this affine has output coordinates '-y','z','x' and is at t=16
    sliced_fmri_affine = np.array([[0,-1,0,3],
                                   [0,0,2,5],
                                   [3,0,0,4],
                                   [0,0,0,16],
                                   [0,0,0,1]])
    ornt = io_orientation(sliced_fmri_affine)
    affine_that_drops_t_reorders_and_flips = _ornt_to_affine(ornt)
    final_affine = np.dot(affine_that_drops_t_reorders_and_flips, 
                          sliced_fmri_affine)
    # the output will be diagonal
    # with the 'y' row having been flipped and the 't' row dropped
    assert_array_equal(final_affine, 
                       np.array([[3,0,0,4],
                                 [0,1,0,-3],
                                 [0,0,2,5],
                                 [0,0,0,1]]))