Esempio n. 1
0
def _load_surf_files_gifti_gzip(surf_file):
    """Load surface data Gifti files which are gzipped. This
    function is used by load_surf_mesh and load_surf_data for
    extracting gzipped files.

    Part of the code can be removed while bumping nibabel 2.0.2

    """
    with gzip.open(surf_file) as f:
        as_bytes = f.read()
    if LooseVersion(nibabel.__version__) >= LooseVersion('2.1.0'):
        parser = gifti.GiftiImage.parser()
        parser.parse(as_bytes)
        gifti_img = parser.img
    else:
        from nibabel.gifti.parse_gifti_fast import ParserCreate, Outputter
        parser = ParserCreate()
        parser.buffer_text = True
        out = Outputter()
        parser.StartElementHandler = out.StartElementHandler
        parser.EndElementHandler = out.EndElementHandler
        parser.CharacterDataHandler = out.CharacterDataHandler
        parser.Parse(as_bytes)
        gifti_img = out.img
    return gifti_img
Esempio n. 2
0
def test_parse_deprecated():

    # Test deprecation
    with clear_and_catch_warnings() as w:
        warnings.filterwarnings('always', category=DeprecationWarning)
        op = Outputter()
        assert_equal(len(w), 1)
        op.initialize()  # smoke test--no error.

    with clear_and_catch_warnings() as w:
        warnings.filterwarnings('always', category=DeprecationWarning)
        assert_raises(ValueError, parse_gifti_file)
        assert_equal(len(w), 1)