svgoverlay.py (bytes-like object is required, not ‘str’)
Hi, I'm using pycortex in a python 3.6 environment, after creating my database importing my subject from freesurfer together with the full flatmaps I received an error such as:
File “/Users/szinte/pycortex/cortex/svgoverlay.py”, line 589, in get_overlay fp.write(make_svg(pts.copy(), polys)) TypeError: a bytes-like object is required, not ‘str’
I tryed to go around it and used an encoder in ascii.
fp.write(make_svg(pts.copy(), polys).encode('ascii'))
Although this worked, I end up with overaly.svg containing only the flatten left hemisphere. Note that if I run the same codes to create my database with a python 2.7, I then correctly have an overaly.svg with 2 hemispheres.
Can you think of how to fix this in py3.6? Thanks.
This seems like a pretty typical python3 error. I think we've fixed most of them in the glrework-merged branch (which will replace master some time.. soon.. definitely..), can you try this again after checking that branch out?
Thanks Alex for your reply. Indeed, I was using the pycortex from the glrework-merged branch. I agree that it looks like a typical python3 error, I'm however not sure how to fix it as my fix (see above) introduced this "weird" error of having one visual hemisphere (the left) in the overlay... I hope you can find the issue. Let me know if you need more info.
Hi, here is an addition to the problem above, that I believe is certainly linked. I noticed that if I create the overlay.svg file with python 2.7 then adding input is possible without losing the right hemisphere. However, strangely, I no longer can draw the ROI in Inkscape on the flat map of the right hemisphere (drawing is simply not doing anything, as if I drew on a non visible back layer), on the contrary of the left hemisphere for which no problem occurs. Then if I now add input with py2.7, I can draw on both hemisphere.
Is this still an issue in the current master branch?
Hi, sorry for my late reply. I installed the last master branch and still have the problem only with python 3.6 not with 2.7.
This is an odd one. More questions: Are you sure that the flattening process did succeed for both hemispheres for the subject in question? (Seems like it must have, if python2.7 works) - but also: can you list the files in the surfaces/ directory in this subject's folder in your pycortex_store folder? Do both flat_lh.gii and flat_rh.gii exist there? There's a chance that as the subject was created, some error came up with import of one of the flat files, and now there is something different about the two files for the L/R hemisphere. And on that note - Have you tried all this with a fresh start? (importing the subject as a different name should be sufficient) And: can you please post screenshots of the problem, if none of that leads you to a solution? (Both of the output, and of how you are editing the overlays.svg file, please)
Hi,
I believe the flattening works (see log_import.txt), I got 8 .gii files in the surface folder, 2 per hemisphere for flat, inflated, pia and wm. You can get the files at this dropbox link (note that the subject is me, so no anonymity problem): https://www.dropbox.com/sh/oqr424pg18lqnem/AADgvdkCesDi2m9SUtvL0uZna?dl=0
I have now tried with a changed name of the subject, it is not working. In general it doesn't work with any subject when I use python 3.6 but works perfectly with python2.7. Interestingly if the overlay.svg is first created in 2.7, every other pycortex plots or functions I use do work well.
I send you here a log of the error I got (see log_error.txt) I'm editing the overlay with Inkscape, but if I use python 3.6 the file is not opening at all. Note that in the new git version of pycortex, the modification I used to do (see original message) is not working anymore. I just cannot have an overlay. But the new version with python 2.7 works perfect.
Thanks, Log_error.txt Log_import.txt
Hi Martin, I downloaded your subject (er, you), deleted the (empty) overlays.svg file, and created a new one. I did this by simply calling cortex.Vertex('subejct_name'); frankly, the code to generate overlays.svg for the first time needs some tlc and usage examples; it's not a step that is done that frequently among regular users and people have thus far just muddled through. Anyway - that seems to create a totally viable overlays.svg file for me (on python 3.5, linux machine), with both hemispheres visible and editable. How are you trying to add ROIs? If you've used a previous version of pycortex that had an rois.svg file instead of an overlays.svg file, things have changed a bit. The ROI layers must be added as sub-layers to the shapes sub-layer inside the rois layer in the inkscape file. If you use cortex.add_roi() with some data to use as the basis for your ROI, the correct layering scheme will be automatically added. Please try all this and LMK specifically what is going wrong for you if you still have problems. If you still do, I will re-test with python3.6 on a mac (which should also work...)