Exemplo n.º 1
0
Illustration of the main functionalities and inputs of the volume object.

.. image:: ../../picture/picobjects/ex_vol_obj.png
"""
from visbrain.objects import VolumeObj, SceneObj
from visbrain.io import download_file


sc = SceneObj()

print("""
# =============================================================================
#                              MIP rendering
# =============================================================================
""")
v_obj_mip = VolumeObj('brodmann', method='mip', cmap='OpaqueFire')
sc.add_to_subplot(v_obj_mip, row=0, col=0, title='MIP rendering')

print("""
# =============================================================================
#                              Translucent rendering
# =============================================================================
""")
v_obj_trans = VolumeObj('aal', method='translucent', cmap='TransFire')
sc.add_to_subplot(v_obj_trans, row=0, col=1, title='Translucent rendering')

print("""
# =============================================================================
#                              Additive rendering
# =============================================================================
""")
Exemplo n.º 2
0
    def __init__(self, canvas, **kwargs):
        """Init."""
        # Create a root node :
        self._vbNode = scene.Node(name='Engram')
        self._vbNode.transform = vist.STTransform(scale=[self._gl_scale] * 3)
        logger.debug("Engram rescaled " + str([self._gl_scale] * 3))
        PROFILER("Root node", level=1)

        # ========================= SOURCES =========================
        self.sources = CombineSources(kwargs.get('source_obj', None))
        if self.sources.name is None:
            self._obj_type_lst.model().item(4).setEnabled(False)
            # Disable menu :
            self.menuDispSources.setChecked(False)
            self.menuTransform.setEnabled(False)
        self.sources.parent = self._vbNode
        PROFILER("Sources object", level=1)

        # ========================= CONNECTIVITY =========================
        self.connect = CombineConnect(kwargs.get('connect_obj', None))
        if self.connect.name is None:
            self._obj_type_lst.model().item(5).setEnabled(False)
            self.menuDispConnect.setEnabled(False)
        self.connect.parent = self._vbNode
        PROFILER("Connect object", level=1)

        # ========================= TIME-SERIES =========================
        self.tseries = CombineTimeSeries(kwargs.get('time_series_obj', None))
        if self.tseries.name is None:
            self._obj_type_lst.model().item(6).setEnabled(False)
        self.tseries.parent = self._vbNode
        PROFILER("Time-series object", level=1)

        # ========================= PICTURES =========================
        self.pic = CombinePictures(kwargs.get('picture_obj', None))
        if self.pic.name is None:
            self._obj_type_lst.model().item(7).setEnabled(False)
        self.pic.parent = self._vbNode
        PROFILER("Pictures object", level=1)

        # ========================= VECTORS =========================
        self.vectors = CombineVectors(kwargs.get('vector_obj', None))
        if self.vectors.name is None:
            self._obj_type_lst.model().item(8).setEnabled(False)
        self.vectors.parent = self._vbNode
        PROFILER("Vectors object", level=1)

        # ========================= VOLUME =========================
        # ----------------- Volume -----------------
        if kwargs.get('vol_obj', None) is None:
            self.volume = VolumeObj('brodmann')
            self.volume.visible_obj = False
        else:
            self.volume = kwargs.get('vol_obj')
        if self.volume.name not in self.volume.list():
            self.volume.save(tmpfile=True)
        self.volume.parent = self._vbNode
        PROFILER("Volume object", level=1)
        # ----------------- ROI -----------------
        if kwargs.get('roi_obj', None) is None:
            self.roi = RoiObj('brodmann')
            self.roi.visible_obj = False
        else:
            self.roi = kwargs.get('roi_obj')
        if self.roi.name not in self.roi.list():
            self.roi.save(tmpfile=True)
        self.roi.parent = self._vbNode
        PROFILER("ROI object", level=1)
        # ----------------- Cross-sections -----------------
        if kwargs.get('cross_sec_obj', None) is None:
            self.cross_sec = CrossSecObj('brodmann')
        else:
            self.cross_sec = kwargs.get('cross_sec_obj')
        if self.cross_sec.name not in self.cross_sec.list():
            self.cross_sec.save(tmpfile=True)
        self.cross_sec.visible_obj = False
        self.cross_sec.text_size = 2.
        self.cross_sec.parent = self._csView.wc.scene
        self._csView.camera = self.cross_sec._get_camera()
        self.cross_sec.set_shortcuts_to_canvas(self._csView)
        PROFILER("Cross-sections object", level=1)

        # ========================= ENGRAM =========================
        if kwargs.get('engram_obj', None) is None:
            self.atlas = BrainObj('B1')
        else:
            self.atlas = kwargs['engram_obj']
        if self.atlas.name not in self.atlas.list():
            self.atlas.save(tmpfile=True)
        self.atlas.scale = self._gl_scale
        self.atlas.parent = self._vbNode
        PROFILER("Engram object", level=1)
Exemplo n.º 3
0
See : https://brainder.org/download/flair/

.. image:: ../../picture/picbrain/ex_crossec_and_volume.png
"""
from visbrain import Brain
from visbrain.objects import CrossSecObj, VolumeObj
from visbrain.io import download_file
"""Import the volume and the associated affine transformation
"""
volume_name = 'GG-853-WM-0.7mm.nii.gz'  # 'GG-853-GM-0.7mm.nii.gz'
"""Download the file.
"""
path = download_file(volume_name)
"""Define a cross-section object

Go to the Objects tab and select 'Cross-section' in the combo box. You can also
press x to display the cross-section panel.
"""
cs_obj = CrossSecObj(path, section=(70, 171, 80), cmap='gist_stern')
"""Define a volume object.

Go to the Objects tab and select 'Volume' in the combo box. You can also
press x to display the volume panel.
"""
v_obj = VolumeObj(path)
"""Create the GUI and pass the cross-section and the volume object
"""
vb = Brain(cross_sec_obj=cs_obj, vol_obj=v_obj)
vb.show()
from visbrain.objects import VolumeObj, CrossSecObj, SourceObj
from visbrain.io import download_file

"""Download two NIFTI files
"""
path_1 = download_file('GG-853-GM-0.7mm.nii.gz')
path_2 = download_file('GG-853-WM-0.7mm.nii.gz')

"""Define four sources sources and a Source object
"""
s_xyz = np.array([[29.9, -37.3, -19.3],
                  [-5.33, 14.00, 20.00],
                  [25.99, 14.00, 34.66],
                  [0., -1.99, 10.66]])
s_obj = SourceObj('MySources', s_xyz)

"""Define a volume object and a cross-section object
"""
vol_obj = VolumeObj(path_1)
cross_sec_obj = CrossSecObj(path_2)

"""Localize a source in the cross-section object
"""
cross_sec_obj.localize_source(s_xyz[2, :])

"""Define a Brain instance and pass the source, volume and cross-section
object
"""
vb = Brain(source_obj=s_obj, vol_obj=vol_obj, cross_sec_obj=cross_sec_obj)
vb.show()
Exemplo n.º 5
0
ts_obj1 = TimeSeries3DObj('TS1', ts_data, xyz_1, select=ts_select)
ts_obj2 = TimeSeries3DObj('TS2', ts_data, xyz_2, select=ts_select)

# ---------------- Pictures ----------------
pic_data = 100. * np.random.rand(10, 20, 17)

p_obj1 = Picture3DObj('P1', pic_data, xyz_1)
p_obj2 = Picture3DObj('P2', 2 * pic_data, xyz_2)

# ---------------- ROI // Volume // Cross-sections ----------------
# ROI :
roi_obj = RoiObj('brodmann')
roi_obj.select_roi([4, 6])
# Volume :
vol_obj = VolumeObj('aal')
# Cross-sections :
cs_obj = CrossSecObj('aal')
cs_obj.cut_coords((50, 60, 70))

# ---------------- Application  ----------------
vb = Brain(source_obj=[s_obj1, s_obj2], connect_obj=[c_obj, c_obj2],
           time_series_obj=[ts_obj1, ts_obj2], picture_obj=[p_obj1, p_obj2],
           roi_obj=roi_obj, vol_obj=vol_obj, cross_sec_obj=cs_obj,
           verbose='debug')


class TestBrain(_TestVisbrain):
    """Test brain.py."""

    ###########################################################################
Exemplo n.º 6
0
 def test_save(self):
     """Test function save."""
     v_obj = VolumeObj(download_file('GG-853-GM-0.7mm.nii.gz',
                                     astype='example_data'))
     v_obj.save()
     v_obj.save(tmpfile=True)
Exemplo n.º 7
0
 def test_remove(self):
     """Test function remove."""
     v_obj = VolumeObj('GG-853-GM-0.7mm')
     v_obj.remove()
     clean_tmp()
Exemplo n.º 8
0
 def test_nii_definition(self):
     """Test function nii_definition."""
     VolumeObj(download_file('GG-853-GM-0.7mm.nii.gz',
                             astype='example_data'))
Exemplo n.º 9
0
 def test_definition(self):
     """Test function definition."""
     for k in ['aal', 'brodmann', 'talairach']:
         VolumeObj(k)
     VolumeObj('vol', vol=np.random.rand(10, 20, 30))
Exemplo n.º 10
0
 def test_nii_definition(self):
     """Test function nii_definition."""
     VolumeObj(download_file('GG-853-GM-0.7mm.nii.gz'))
Exemplo n.º 11
0
    def __init__(self, canvas, **kwargs):
        """Init."""
        # Create a root node :
        self._vbNode = scene.Node(name='Brain')
        self._vbNode.transform = vist.STTransform(scale=[self._gl_scale] * 3)
        logger.debug("Brain rescaled " + str([self._gl_scale] * 3))
        PROFILER("Root node", level=1)

        # ========================= SOURCES =========================
        self.sources = CombineSources(kwargs.get('source_obj', None))
        if self.sources.name is None:
            self._obj_type_lst.model().item(4).setEnabled(False)
            # Disable menu :
            self.menuDispSources.setChecked(False)
            self.menuTransform.setEnabled(False)
        self.sources.parent = self._vbNode
        PROFILER("Sources object", level=1)

        # ========================= CONNECTIVITY =========================
        self.connect = CombineConnect(kwargs.get('connect_obj', None))
        if self.connect.name is None:
            self._obj_type_lst.model().item(5).setEnabled(False)
            self.menuDispConnect.setEnabled(False)
        self.connect.parent = self._vbNode
        PROFILER("Connect object", level=1)

        # ========================= TIME-SERIES =========================
        self.tseries = CombineTimeSeries(kwargs.get('time_series_obj', None))
        if self.tseries.name is None:
            self._obj_type_lst.model().item(6).setEnabled(False)
        self.tseries.parent = self._vbNode
        PROFILER("Time-series object", level=1)

        # ========================= PICTURES =========================
        self.pic = CombinePictures(kwargs.get('picture_obj', None))
        if self.pic.name is None:
            self._obj_type_lst.model().item(7).setEnabled(False)
        self.pic.parent = self._vbNode
        PROFILER("Pictures object", level=1)

        # ========================= VECTORS =========================
        self.vectors = CombineVectors(kwargs.get('vector_obj', None))
        if self.vectors.name is None:
            self._obj_type_lst.model().item(8).setEnabled(False)
        self.vectors.parent = self._vbNode
        PROFILER("Vectors object", level=1)

        # ========================= VOLUME =========================
        # ----------------- Volume -----------------
        if kwargs.get('vol_obj', None) is None:
            self.volume = VolumeObj('brodmann')
            self.volume.visible_obj = False
        else:
            self.volume = kwargs.get('vol_obj')
        if self.volume.name not in self.volume.list():
            self.volume.save(tmpfile=True)
        self.volume.parent = self._vbNode
        PROFILER("Volume object", level=1)
        # ----------------- ROI -----------------
        if kwargs.get('roi_obj', None) is None:
            self.roi = RoiObj('brodmann')
            self.roi.visible_obj = False
        else:
            self.roi = kwargs.get('roi_obj')
        if self.roi.name not in self.roi.list():
            self.roi.save(tmpfile=True)
        self.roi.parent = self._vbNode
        PROFILER("ROI object", level=1)
        # ----------------- Cross-sections -----------------
        if kwargs.get('cross_sec_obj', None) is None:
            self.cross_sec = CrossSecObj('brodmann')
        else:
            self.cross_sec = kwargs.get('cross_sec_obj')
        if self.cross_sec.name not in self.cross_sec.list():
            self.cross_sec.save(tmpfile=True)
        self.cross_sec.visible_obj = False
        self.cross_sec.text_size = 2.
        self.cross_sec.parent = self._csView.wc.scene
        self._csView.camera = self.cross_sec._get_camera()
        self.cross_sec.set_shortcuts_to_canvas(self._csView)
        PROFILER("Cross-sections object", level=1)

        # ========================= BRAIN =========================
        if kwargs.get('brain_obj', None) is None:
            self.atlas = BrainObj('B1')
        else:
            self.atlas = kwargs['brain_obj']
        if self.atlas.name not in self.atlas.list():
            self.atlas.save(tmpfile=True)
        self.atlas.scale = self._gl_scale
        self.atlas.parent = self._vbNode
        PROFILER("Brain object", level=1)
Exemplo n.º 12
0
class Visuals(object):
    """Initialize Brain objects.

    Initialize sources / connectivity / areas / colorbar / projections.
    Organize them at diffrent levels and make the link with the graphical
    user interface (if no object is detected, the corresponding panel in the
    GUI has to be deactivate).
    """
    def __init__(self, canvas, **kwargs):
        """Init."""
        # Create a root node :
        self._vbNode = scene.Node(name='Brain')
        self._vbNode.transform = vist.STTransform(scale=[self._gl_scale] * 3)
        logger.debug("Brain rescaled " + str([self._gl_scale] * 3))
        PROFILER("Root node", level=1)

        # ========================= SOURCES =========================
        self.sources = CombineSources(kwargs.get('source_obj', None))
        if self.sources.name is None:
            self._obj_type_lst.model().item(4).setEnabled(False)
            # Disable menu :
            self.menuDispSources.setChecked(False)
            self.menuTransform.setEnabled(False)
        self.sources.parent = self._vbNode
        PROFILER("Sources object", level=1)

        # ========================= CONNECTIVITY =========================
        self.connect = CombineConnect(kwargs.get('connect_obj', None))
        if self.connect.name is None:
            self._obj_type_lst.model().item(5).setEnabled(False)
            self.menuDispConnect.setEnabled(False)
        self.connect.parent = self._vbNode
        PROFILER("Connect object", level=1)

        # ========================= TIME-SERIES =========================
        self.tseries = CombineTimeSeries(kwargs.get('time_series_obj', None))
        if self.tseries.name is None:
            self._obj_type_lst.model().item(6).setEnabled(False)
        self.tseries.parent = self._vbNode
        PROFILER("Time-series object", level=1)

        # ========================= PICTURES =========================
        self.pic = CombinePictures(kwargs.get('picture_obj', None))
        if self.pic.name is None:
            self._obj_type_lst.model().item(7).setEnabled(False)
        self.pic.parent = self._vbNode
        PROFILER("Pictures object", level=1)

        # ========================= VECTORS =========================
        self.vectors = CombineVectors(kwargs.get('vector_obj', None))
        if self.vectors.name is None:
            self._obj_type_lst.model().item(8).setEnabled(False)
        self.vectors.parent = self._vbNode
        PROFILER("Vectors object", level=1)

        # ========================= VOLUME =========================
        # ----------------- Volume -----------------
        if kwargs.get('vol_obj', None) is None:
            self.volume = VolumeObj('brodmann')
            self.volume.visible_obj = False
        else:
            self.volume = kwargs.get('vol_obj')
        if self.volume.name not in self.volume.list():
            self.volume.save(tmpfile=True)
        self.volume.parent = self._vbNode
        PROFILER("Volume object", level=1)
        # ----------------- ROI -----------------
        if kwargs.get('roi_obj', None) is None:
            self.roi = RoiObj('brodmann')
            self.roi.visible_obj = False
        else:
            self.roi = kwargs.get('roi_obj')
        if self.roi.name not in self.roi.list():
            self.roi.save(tmpfile=True)
        self.roi.parent = self._vbNode
        PROFILER("ROI object", level=1)
        # ----------------- Cross-sections -----------------
        if kwargs.get('cross_sec_obj', None) is None:
            self.cross_sec = CrossSecObj('brodmann')
        else:
            self.cross_sec = kwargs.get('cross_sec_obj')
        if self.cross_sec.name not in self.cross_sec.list():
            self.cross_sec.save(tmpfile=True)
        self.cross_sec.visible_obj = False
        self.cross_sec.text_size = 2.
        self.cross_sec.parent = self._csView.wc.scene
        self._csView.camera = self.cross_sec._get_camera()
        self.cross_sec.set_shortcuts_to_canvas(self._csView)
        PROFILER("Cross-sections object", level=1)

        # ========================= BRAIN =========================
        if kwargs.get('brain_obj', None) is None:
            self.atlas = BrainObj('B1')
        else:
            self.atlas = kwargs['brain_obj']
        if self.atlas.name not in self.atlas.list():
            self.atlas.save(tmpfile=True)
        self.atlas.scale = self._gl_scale
        self.atlas.parent = self._vbNode
        PROFILER("Brain object", level=1)