Ejemplo n.º 1
0
def test_agg_data():
    surf_gii_img = nib.load(test_data('gifti', 'ascii.gii'))
    func_gii_img = nib.load(test_data('gifti', 'task.func.gii'))
    shape_gii_img = nib.load(test_data('gifti', 'rh.shape.curv.gii'))
    # add timeseries data with intent code ``none``

    point_data = surf_gii_img.get_arrays_from_intent('pointset')[0].data
    triangle_data = surf_gii_img.get_arrays_from_intent('triangle')[0].data
    func_da = func_gii_img.get_arrays_from_intent('time series')
    func_data = np.column_stack(tuple(da.data for da in func_da))
    shape_data = shape_gii_img.get_arrays_from_intent('shape')[0].data

    assert_equal(surf_gii_img.agg_data(), (point_data, triangle_data))
    assert_array_equal(func_gii_img.agg_data(), func_data)
    assert_array_equal(shape_gii_img.agg_data(), shape_data)

    assert_array_equal(surf_gii_img.agg_data('pointset'), point_data)
    assert_array_equal(surf_gii_img.agg_data('triangle'), triangle_data)
    assert_array_equal(func_gii_img.agg_data('time series'), func_data)
    assert_array_equal(shape_gii_img.agg_data('shape'), shape_data)

    assert_equal(surf_gii_img.agg_data('time series'), ())
    assert_equal(func_gii_img.agg_data('triangle'), ())
    assert_equal(shape_gii_img.agg_data('pointset'), ())

    assert_equal(surf_gii_img.agg_data(('pointset', 'triangle')),
                 (point_data, triangle_data))
    assert_equal(surf_gii_img.agg_data(('triangle', 'pointset')),
                 (triangle_data, point_data))
Ejemplo n.º 2
0
def test_default(tmpdir):
    infile = test_data(fname="anatomical.nii")
    outfile = tmpdir / "output.nii.gz"
    main([str(infile), str(outfile)])
    assert outfile.isfile()
    c = nib.load(outfile)
    assert c.shape == (256, 256, 256)
    assert c.header.get_zooms() == (1, 1, 1)
    assert nib.orientations.aff2axcodes(c.affine) == ('R', 'A', 'S')

    with pytest.raises(FileExistsError):
        main([str(infile), str(outfile)])

    main([str(infile), str(outfile), "--force"])
    assert outfile.isfile()
Ejemplo n.º 3
0
def test_nondefault(tmpdir):
    infile = test_data(fname="anatomical.nii")
    outfile = tmpdir / "output.nii.gz"
    out_shape = (100, 100, 150)
    voxel_size = (1, 2, 4)
    orientation = "LAS"
    args = "{} {} --out-shape {} --voxel-size {} --orientation {}".format(
        infile, outfile, " ".join(map(str, out_shape)),
        " ".join(map(str, voxel_size)), orientation)
    main(args.split())
    assert outfile.isfile()
    c = nib.load(outfile)
    assert c.shape == out_shape
    assert c.header.get_zooms() == voxel_size
    assert nib.orientations.aff2axcodes(c.affine) == tuple(orientation)