Closed mkkubins closed 2 years ago
Hi, really sorry for taking 11 days to respond here. I missed the email.
It looks like a bug that can turn up with templateflow (e.g. https://neurostars.org/t/templateflow-error-loading-map/21365)
The advice there is try deleting that file and rerunning. Let me know if it works.
If that does not work, try updating your python api of templateflow.
Hi! Thanks so much for the answer. None of the above suggestions worked but I download this manually from TemplateFlow and this is working. However, I have to replace this file each time when I am running code.
If you download the file manually to a non-templateflow directory. The input to netplotbrain just needs to be:
netplotbrain.plot(tempalte='path/to/local/file.nii.gz')
Which means you do not need to keep downloading manually.
But why templateflow is not working for you is strange and could be some bug there.
I tried this one that you suggest. This is my code:
netplotbrain.plot(template = './template3D/tpl-MNI152NLin2009cAsym_res-01_desc-brain_T1w.nii', templatestyle = 'surface', view = 'S', nodes = nodes, nodecolor ='grey', nodesize = 5, edges = threshold_edges, highlightlevel = 0.1, fig = fig, edgecolor = edge_color, edgewidthscale = 2, showlegend = False, ax = ax, kwargs = {'edgealpha':1}) plt.show()
and this returns the error as below. I have tried to pass this also as a list but then it also returns the error UnboundLocalError: local variable 'img' referenced before assignment
.
c:\Users\kubin\Desktop\opto\BCGLAR\Connectivity\plot_brain.py in <module>
[83](file:///c%3A/Users/kubin/Desktop/opto/BCGLAR/Connectivity/plot_brain.py?line=82) # ax2 = fig.add_subplot(133, projection='3d')
[84](file:///c%3A/Users/kubin/Desktop/opto/BCGLAR/Connectivity/plot_brain.py?line=83)
----> [85](file:///c%3A/Users/kubin/Desktop/opto/BCGLAR/Connectivity/plot_brain.py?line=84) netplotbrain.plot(template = './template3D/tpl-MNI152NLin2009cAsym_res-01_desc-brain_T1w.nii',
[86](file:///c%3A/Users/kubin/Desktop/opto/BCGLAR/Connectivity/plot_brain.py?line=85) templatestyle = 'surface',
[87](file:///c%3A/Users/kubin/Desktop/opto/BCGLAR/Connectivity/plot_brain.py?line=86) view = 'S',
c:\Users/kubin/Desktop/opto/netplotbrain\netplotbrain\plot.py in plot(nodes, fig, ax, view, frames, edges, template, templatestyle, arrowaxis, arroworigin, edgecolor, nodesize, nodecolor, nodetype, nodecolorby, nodecmap, edgeweights, nodeimg, hemisphere, title, highlightnodes, highlightedges, showlegend, **kwargs)
197 affine = None
198 if template is not None:
--> 199 affine = _plot_template(ax, templatestyle, template,
200 voxsize=profile['templatevoxsize'],
201 azim=azim[fi], elev=elev[fi],
c:\Users/kubin/Desktop/opto/netplotbrain\netplotbrain\plotting\plot_templates.py in _plot_template(ax, style, template, voxsize, azim, elev, hemisphere, **kwargs)
158 # This may lead to suboptimal performence for some templates
159 if isinstance(template, list):
--> 160 template = template[0]
161 img = nib.load(template)
162 elif isinstance(template, (nib.Nifti1Image, nib.Nifti2Image)):
IndexError: list index out of range
Thanks for this. Sorry that you are still getting an error.
I’ll check this out and see if I can replicate the error.
Should be fixed now if you update from github.
There was a little bug there. Sorry, most testing is done with templateflow as the background.
i.e. netplotbrain.plot(template = './template3D/tpl-MNI152NLin2009cAsym_res-01_desc-brain_T1w.nii', templatestyle = 'surface', view = 'S', nodes = nodes, nodecolor ='grey', nodesize = 5, edges = threshold_edges, highlightlevel = 0.1, fig = fig, edgecolor = edge_color, edgewidthscale = 2, showlegend = False, ax = ax, kwargs = {'edgealpha':1}) plt.show()
should work.
Let me know if it does/does not
Thanks so much!
Provided template files are not load.
ImageFileError: Cannot work out file type of ".cache\templateflow\tpl-MNI152NLin2009cAsym\tpl-MNI152NLin2009cAsym_res-01_desc-brain_T1w.nii.gz"
Code that I am using:
netplotbrain.plot(template='MNI152NLin2009cAsym', templatestyle='surface', nodes=new_nodes, edges=edges, templatealpha=1, nodecolor='blue', templatecolor='gray', view='L') plt.show()
I have tried also to download the file and load this as a template but then the surface is not showing.