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

Text of sources not shown #90

Open
zhengliuer opened this issue Feb 19, 2021 · 23 comments
Open

Text of sources not shown #90

zhengliuer opened this issue Feb 19, 2021 · 23 comments

Comments

@zhengliuer
Copy link

I ran the code in http://visbrain.org/auto_examples/gui_brain/03_sources.html#sphx-glr-auto-examples-gui-brain-03-sources-py, and no text shown.
image
When I used SourceObj and set the parameter text, also no text.

@EtienneCmb
Copy link
Owner

I encountered the same issue in the past and it was coming from the TextVisual object of vispy. Can you try this example and see if it works?

@zhengliuer
Copy link
Author

image
It works

@EtienneCmb
Copy link
Owner

Can you try the following code :

import numpy as np
from visbrain.objects import SourceObj

xyz = np.random.rand(100, 3)
text = [f"s{k}" for k in range(100)]
s_obj = SourceObj('test', xyz, text=text, text_size=20, text_translate=(0., .2, 0.))
s_obj.preview()

@zhengliuer
Copy link
Author

Interesting, this works.
image

@EtienneCmb
Copy link
Owner

Ok, so I guess it comes from the font size. By default, the font size in the example is really small (kwargs['text_size'] = 1.5 ) you can try to set it to 20?

@zhengliuer
Copy link
Author

Sadly, still the same, no text.

@EtienneCmb
Copy link
Owner

Ok, final test, can you try to increase it drastically to kwargs['text_size'] = 1000?

@zhengliuer
Copy link
Author

zhengliuer commented Feb 19, 2021

If I use s_obj.preview(), it shows the text,
image
But vb.show() shows me nothing.
image
And if I don't use s_object.preview(), still no text

@zhengliuer
Copy link
Author

And font size do is one of the problems, for if I set it to 100, s_object.preview() still no text. Does it have sth to do with the operating system? Mine is win10

@zhengliuer
Copy link
Author

zhengliuer commented Feb 19, 2021

OK, font size is the key problem. It seems that the Brain needs much bigger size. I set it to 10000, it shows a little text.
And when using my own data, I need to set it to 100000.

@zhengliuer
Copy link
Author

zhengliuer commented Feb 19, 2021

By the way, how do we calculate the connectivity of electrodes? I used mne, are there any other packages?

@EtienneCmb
Copy link
Owner

EtienneCmb commented Feb 19, 2021

I don't think it comes from your system, because I've the same issue. I guess vispy changed the way the TextVisual is handle, in particular the proportion with the displayed scene. In general, I would say that the GUI of visbrain are not as stable as the object level. If you want to "reproduce" the figure, you can try the following code :

import numpy as np

from visbrain.gui import Brain
from visbrain.objects import SourceObj, BrainObj, SceneObj
from visbrain.io import download_file

kwargs = {}

mat = np.load(download_file('xyz_sample.npz', astype='example_data'))
xyz, subjects = mat['xyz'], mat['subjects']

"""The "subjects" list is composed of 6 diffrents subjects and here we set one
unique color (u_color) per subject.
"""
u_color = ["#9b59b6", "#3498db", "white", "#e74c3c", "#34495e", "#2ecc71"]
kwargs['color'] = [u_color[int(k[1])] for k in subjects]
kwargs['alpha'] = 0.7

"""
Now we attach data to each source.
"""
kwargs['data'] = np.arange(len(subjects))

"""The source's radius is proportional to the data attached. But this
proportion can be controlled using a minimum and maximum radius
(s_radiusmin, s_radiusmax)
"""
kwargs['radius_min'] = 2               # Minimum radius
kwargs['radius_max'] = 15              # Maximum radius
kwargs['edge_color'] = (1, 1, 1, 0.5)  # Color of the edges
kwargs['edge_width'] = .5              # Width of the edges
kwargs['symbol'] = 'square'            # Source's symbol

"""
Next, we mask source's data that are comprised between [-20, 20] and color
each source to orange
"""
mask = np.logical_and(xyz[:, 0] >= -20., xyz[:, 0] <= 20)
kwargs['mask'] = mask
kwargs['mask_color'] = 'orange'

"""It's also possible to add text to each source. Here, we show the name of the
subject in yellow.
To avoid a superposition between the text and sources sphere, we introduce an
offset to the text using the s_textshift input
"""
kwargs['text'] = subjects              # Name of the subject
kwargs['text_color'] = "#f39c12"       # Set to yellow the text color
kwargs['text_size'] = 200000              # Size of the text
kwargs['text_translate'] = (1.5, 1.5, 0)
kwargs['text_bold'] = True

"""Create the source object. If you want to previsualize the result without
opening Brain, use s_obj.preview()
"""
s_obj = SourceObj('SourceExample', xyz, **kwargs)

"""Color sources according to the data
"""
# s_obj.color_sources(data=kwargs['data'], cmap='viridis')

"""Colorbar properties
"""
cb_kw = dict(cblabel="Project source activity", cbtxtsz=3., border=False, )

"""Define a brain object with the B3 template and project source's activity
onto the surface
"""
b_obj = BrainObj('B3', **cb_kw)
b_obj.project_sources(s_obj, cmap='viridis', vmin=50., under='orange',
                      vmax=550., over='darkred')

sc = SceneObj()
sc.add_to_subplot(s_obj)
sc.add_to_subplot(b_obj, use_this_cam=True)
sc.preview()

@EtienneCmb
Copy link
Owner

About the connectivity, yes, MNE provides several ways to do it. I can also recommend IDTxl and a package that I'm currently developing, Frites

@zhengliuer
Copy link
Author

Thanks a lot

@zhengliuer
Copy link
Author

Hi, I noticed that the repo of Brainets, and I found seegpy. I am doing some analysis based on sEEG, so I am interested in this package. I found that the data format in this package is TRC? What kind of data format is this? And if I've got .edf data, how do I used this package. Some modules, like contacts, may be useful regardless of the format.

@EtienneCmb
Copy link
Owner

If you want to talk about seegpy, or in general sEEG data analysis, I propose to move to emails

@zhengliuer
Copy link
Author

If you want to talk about seegpy, or in general sEEG data analysis, I propose to move to emails

Excellent! And I just found your e-mail.

@zhengliuer
Copy link
Author

Hi, is there a way that I can set the default size of brains?

@EtienneCmb
Copy link
Owner

The brain included in visbrain are usually in the MNI system. That being said, if you have your own template, you can provide the vertices and faces to the BrainObj

@zhengliuer
Copy link
Author

Sorry, I should be more clear.
image
In this pic, the brain is a little small, I am thinking to make it bigger using code if there is a method supporting this. I don't find some method related to this.

@zhengliuer
Copy link
Author

And did you get my e-mail which is a Gmail address? I am afraid I didn't send it successfully for I did encounter this situation.

@EtienneCmb
Copy link
Owner

EtienneCmb commented Feb 19, 2021

Ah ok, try with BrainObj('B1'), or B2, it should be better.

Yes I received your email and I answered four hours ago, you didn't get my reply?

@zhengliuer
Copy link
Author

zhengliuer commented Feb 19, 2021

Oh, I get it! My phone didn't remind me of that. I shouldn't have believed it, reminding me of Junk emails always, not important ones.

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