Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cortex.quickshow TypeError and ExpatError #438

Open
EllieMo opened this issue Apr 14, 2022 · 1 comment
Open

cortex.quickshow TypeError and ExpatError #438

EllieMo opened this issue Apr 14, 2022 · 1 comment

Comments

@EllieMo
Copy link

EllieMo commented Apr 14, 2022

Hello,
I'm trying to plot a flatmap and can't seem to get past quickshow. I've been following code from the example gallery; (https://gallantlab.github.io/pycortex/auto_examples/datasets/plot_volumeRGB.html#sphx-glr-auto-examples-datasets-plot-volumergb-py - but same problem with other examples) as that is what I'm aiming for. I seem to be having an error potentially related to my data and another one just
(macOS, python 3.9)

When I use the example data I do get part of the plot I would expect with this error message:

  File "/usr/local/lib/python3.9/site-packages/spyder_kernels/py3compat.py", line 356, in compat_exec
    exec(code, globals, locals)

  File "/usr/local/lib/python3.9/site-packages/nibabel/untitled0.py", line 39, in <module>
    cortex.quickshow(vol_data, with_colorbar=False)

  File "/usr/local/lib/python3.9/site-packages/cortex/quickflat/view.py", line 197, in make_figure
    roi_im = composite.add_rois(ax, dataview, extents=extents, height=height, linewidth=linewidth, linecolor=linecolor,

  File "/usr/local/lib/python3.9/site-packages/cortex/quickflat/composite.py", line 208, in add_rois
    svgobject = db.get_overlay(dataview.subject, overlay_file=overlay_file)

  File "/usr/local/lib/python3.9/site-packages/cortex/database.py", line 344, in get_overlay
    pts, polys = self.get_surf(subject, "flat", merge=True, nudge=True)

  File "/usr/local/lib/python3.9/site-packages/cortex/database.py", line 30, in memofn
    self._memocache[h] = fn(self, *args, **kwargs)

  File "/usr/local/lib/python3.9/site-packages/cortex/database.py", line 494, in get_surf
    left, right = [ self.get_surf(subject, type, hemisphere=h) for h in ["lh", "rh"]]

  File "/usr/local/lib/python3.9/site-packages/cortex/database.py", line 494, in <listcomp>
    left, right = [ self.get_surf(subject, type, hemisphere=h) for h in ["lh", "rh"]]

  File "/usr/local/lib/python3.9/site-packages/cortex/database.py", line 30, in memofn
    self._memocache[h] = fn(self, *args, **kwargs)

  File "/usr/local/lib/python3.9/site-packages/cortex/database.py", line 520, in get_surf
    return formats.read(fnm)

  File "cortex/formats.pyx", line 23, in cortex.formats.read

  File "cortex/formats.pyx", line 51, in cortex.formats.read_gii

  File "cortex/formats.pyx", line 56, in cortex.formats.read_gii

  File "/usr/local/lib/python3.9/site-packages/nibabel/loadsave.py", line 52, in load
    img = image_klass.from_filename(filename, **kwargs)

  File "/usr/local/lib/python3.9/site-packages/nibabel/gifti/gifti.py", line 904, in from_filename
    img = klass.from_file_map(file_map, buffer_size=buffer_size)

  File "/usr/local/lib/python3.9/site-packages/nibabel/gifti/gifti.py", line 898, in from_file_map
    parser.parse(fptr=file_map['image'].get_prepare_fileobj('rb'))

  File "/usr/local/lib/python3.9/site-packages/nibabel/xmlutils.py", line 103, in parse
    parser.ParseFile(fptr)

  File "/private/tmp/pythonA3.9-20220326-99703-2lqkv4/Python-3.9.12/Modules/pyexpat.c", line 407, in StartElement

  File "/usr/local/lib/python3.9/site-packages/nibabel/gifti/parse_gifti_fast.py", line 119, in StartElementHandler
    self.img = GiftiImage()

  File "/usr/local/lib/python3.9/site-packages/nibabel/gifti/gifti.py", line 576, in __init__
    super(GiftiImage, self).__init__(header=header, extra=extra,

TypeError: super(type, obj): obj must be an instance or subtype of type

when using my own data it fails at a similar place (empty plot though) with a different error:

File "/usr/local/lib/python3.9/site-packages/spyder_kernels/py3compat.py", line 356, in compat_exec
    exec(code, globals, locals)

  File "/Users/me/Desktop/RGB_MAP.py", line 53, in <module>
    cortex.quickshow(vol_data, with_colorbar=False)

  File "/usr/local/lib/python3.9/site-packages/cortex/quickflat/view.py", line 142, in make_figure
    data_im, extents = composite.add_data(ax, dataview, pixelwise=pixelwise, thick=thick, sampler=sampler,

  File "/usr/local/lib/python3.9/site-packages/cortex/quickflat/composite.py", line 162, in add_data
    im, extents = make_flatmap_image(dataview, recache=recache, pixelwise=pixelwise, sampler=sampler,

  File "/usr/local/lib/python3.9/site-packages/cortex/quickflat/utils.py", line 44, in make_flatmap_image
    mask, extents = get_flatmask(braindata.subject, height=height, recache=recache)

  File "/usr/local/lib/python3.9/site-packages/cortex/quickflat/utils.py", line 126, in get_flatmask
    mask, extents = _make_flatmask(subject, height=height)

  File "/usr/local/lib/python3.9/site-packages/cortex/quickflat/utils.py", line 350, in _make_flatmask
    pts, polys = db.get_surf(subject, "flat", merge=True, nudge=True)

  File "/usr/local/lib/python3.9/site-packages/cortex/database.py", line 30, in memofn
    self._memocache[h] = fn(self, *args, **kwargs)

  File "/usr/local/lib/python3.9/site-packages/cortex/database.py", line 494, in get_surf
    left, right = [ self.get_surf(subject, type, hemisphere=h) for h in ["lh", "rh"]]

  File "/usr/local/lib/python3.9/site-packages/cortex/database.py", line 494, in <listcomp>
    left, right = [ self.get_surf(subject, type, hemisphere=h) for h in ["lh", "rh"]]

  File "/usr/local/lib/python3.9/site-packages/cortex/database.py", line 30, in memofn
    self._memocache[h] = fn(self, *args, **kwargs)

  File "/usr/local/lib/python3.9/site-packages/cortex/database.py", line 520, in get_surf
    return formats.read(fnm)

  File "cortex/formats.pyx", line 23, in cortex.formats.read

  File "cortex/formats.pyx", line 51, in cortex.formats.read_gii

  File "cortex/formats.pyx", line 56, in cortex.formats.read_gii

  File "/usr/local/lib/python3.9/site-packages/nibabel/loadsave.py", line 52, in load
    img = image_klass.from_filename(filename, **kwargs)

  File "/usr/local/lib/python3.9/site-packages/nibabel/gifti/gifti.py", line 904, in from_filename
    img = klass.from_file_map(file_map, buffer_size=buffer_size)

  File "/usr/local/lib/python3.9/site-packages/nibabel/gifti/gifti.py", line 898, in from_file_map
    parser.parse(fptr=file_map['image'].get_prepare_fileobj('rb'))

  File "/usr/local/lib/python3.9/site-packages/nibabel/xmlutils.py", line 103, in parse
    parser.ParseFile(fptr)

ExpatError: not well-formed (invalid token): line 1, column 0

Has anyone seen either of these before and how did you solve them?

@mvdoc
Copy link
Contributor

mvdoc commented Apr 14, 2022

Hmmm, I've never seen this before, but from the error you posted it seems to come from nibabel. For some reason there are some issues with nibabel not being able to load giftis. Can you confirm that loading a gifti file with nibabel fails? e.g., using the example subject provided with pycortex

import cortex
import nibabel as nib

filestore_path = cortex.database.default_filestore
gii = nib.load(f"{filestore_path}/S1/surfaces/pia_lh.gii")
pts = gii.get_arrays_from_intent('pointset')[0].data
polys = gii.get_arrays_from_intent('triangle')[0].data

If I read your traceback correctly, it should fail at the nib.load line.

If that's the case, I would try reinstalling nibabel or post an issue/check for closed issues in https://github.com/nipy/nibabel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants