EtienneCmb / visbrain

A multi-purpose GPU-accelerated open-source suite for brain data visualization
http://visbrain.org
Other
241 stars 65 forks source link

Text of sources not shown #90

Open zhengliuer opened 3 years ago

zhengliuer commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

image It works

EtienneCmb commented 3 years ago

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 commented 3 years ago

Interesting, this works. image

EtienneCmb commented 3 years ago

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 commented 3 years ago

Sadly, still the same, no text.

EtienneCmb commented 3 years ago

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

zhengliuer commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

EtienneCmb commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

Thanks a lot

zhengliuer commented 3 years ago

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 commented 3 years ago

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

zhengliuer commented 3 years ago

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 commented 3 years ago

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

EtienneCmb commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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.