question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ValueError when importing subject from Freesurfer

See original GitHub issue

Recently came across pycortex and decided to give it a try. I’m having troubles getting it to import data from freesurfer, though, as pycortex raises a ValueError, as shown in the backtrace below. Any suggestions on how to proceed would be welcome.

In [10]: import cortex.freesurfer as fs
In [11]: fs.import_subj("spat01", whitematter_surf="white")
Are you sure you want to overwrite this existing subject?
This will delete all files for this subject in the filestore, including all blender cuts. Type YES
YES
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-11-a8a458747a00> in <module>
----> 1 fs.import_subj("spat01", whitematter_surf="white")

/home/user/anaconda3/envs/cortex/lib/python3.7/site-packages/cortex/freesurfer.py in import_subj(subject, sname, freesurfer_subject_dir, whitematter_surf)
    174
    175     # Make the fiducial files. Just make them.
--> 176     make_fiducial(subject, freesurfer_subject_dir=freesurfer_subject_dir)
    177
    178     # Freesurfer uses FOV/2 for center, let's set the surfaces to use the

/home/user/anaconda3/envs/cortex/lib/python3.7/site-packages/cortex/freesurfer.py in make_fiducial(subject, freesurfer_subject_dir)
    312     """
    313     for hemi in ['lh', 'rh']:
--> 314         spts, polys, _ = get_surf(subject, hemi, "smoothwm", freesurfer_subject_dir=freesurfer_subject_dir)
    315         ppts, _, _ = get_surf(subject, hemi, "pial", freesurfer_subject_dir=freesurfer_subject_dir)
    316         fname = get_paths(subject, hemi, "surf", freesurfer_subject_dir=freesurfer_subject_dir).format(name="fiducial")

/home/user/anaconda3/envs/cortex/lib/python3.7/site-packages/cortex/freesurfer.py in get_surf(subject, hemi, type, patch, flatten_step, freesurfer_subject_dir)
    406         surf_file = get_paths(subject, hemi, 'surf', freesurfer_subject_dir=freesurfer_subject_dir).format(name=type)
    407
--> 408     pts, polys = parse_surf(surf_file)
    409
    410     if patch is not None:

/home/user/anaconda3/envs/cortex/lib/python3.7/site-packages/cortex/freesurfer.py in parse_surf(filename)
    328         print(comment)
    329         verts, faces = struct.unpack('>2I', fp.read(8))
--> 330         pts = np.fromstring(fp.read(4*3*verts), dtype='f4').byteswap()
    331         polys = np.fromstring(fp.read(4*3*faces), dtype='i4').byteswap()
    332

ValueError: string size must be a multiple of element size

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
dangomcommented, Aug 15, 2019

It seems there is a readline too much in parse_surf. Removing the line fixes the issue for me. I’m on Python 3.7.3

1reaction
dangomcommented, Aug 15, 2019

Uhm, interesting. The surfaces were reconstructed with Freesurfer version freesurfer-local-build-dev-20190709, and recon-all.log tells me that recon-all finished without error.

But I also cannot nib.freesurfer.read_geometry for the smoothwm surface, so I suppose there must be something wrong with it. The surfaces pial and smoothwm are “broken”, but all others work. Freeview can read and display them without issues though.

I’ll investigate further and report back when I find out what the issue is.

Read more comments on GitHub >

github_iconTop Results From Across the Web

cortex.segment — pycortex 1.2.4 documentation
This function creates a Freesurfer subject and runs autorecon-all, then (optionally) imports the subject into the pycortex database.
Read more >
source space does not contain any vertices for label unknown ...
Dear experts: I have the issue that I put in the subject of this email. The error occurs when trying to execute this...
Read more >
Source code for netneurotools.freesurfer
_measurements import _stats, labeled_comprehension except ImportError: ... Default: None subjects_dir : str, optional Path to FreeSurfer subject directory.
Read more >
source space does not contain any vertices for label unknown-lh
Previous message: [Mne_analysis] ValueError: source space does not ... cov = > mne.read_cov('/usr/local/freesurfer/subjects/fsaverage/ ...
Read more >
mne_bids.write — MNE-BIDS 0.8 documentation
BIDS_VERSION: raise ValueError('Previous BIDS version used, please redo the ' 'conversion ... Path | None The FreeSurfer subjects directory.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found