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.""" ########################################################################### # BRAIN ###########################################################################
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.""" ########################################################################### # BRAIN ###########################################################################
print(""" # ============================================================================= # Connectivity # ============================================================================= """) arch = np.load(download_file('phase_sync_delta.npz')) nodes, edges = arch['nodes'], arch['edges'] c_count = ConnectObj('default', nodes, edges, select=edges > .7, color_by='count', antialias=True, line_width=2., dynamic=(.1, 1.)) s_obj_c = SourceObj('sources', nodes, color='#ab4642', radius_min=5.) sc.add_to_subplot(c_count, row=2, col=0, row_span=2, title='3D connectivity') sc.add_to_subplot(s_obj_c, row=2, col=0) sc.add_to_subplot(BrainObj('B3'), use_this_cam=True, row=2, col=0) print(""" ============================================================================= Cross-sections ============================================================================= """) cs_brod = CrossSecObj('brodmann', interpolation='nearest', coords=(70, 80, 90), cmap='viridis') cs_brod.localize_source((-10., -15., 20.)) sc.add_to_subplot(cs_brod, row=2, col=1, col_span=2, row_span=2, title='Cross-sections') sc.preview()
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)
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()
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)
pic_height=21., cmap='viridis') sc.add_to_subplot(pic_obj, row=1, col=2, title='3D pictures') sc.add_to_subplot(BrainObj('B2'), use_this_cam=True, row=1, col=2) ############################################################################### # Connectivity ############################################################################### arch = np.load(download_file('phase_sync_delta.npz', astype='example_data')) nodes, edges = arch['nodes'], arch['edges'] c_count = ConnectObj('default', nodes, edges, select=edges > .7, color_by='count', antialias=True, line_width=2., dynamic=(.1, 1.)) s_obj_c = SourceObj('sources', nodes, color='#ab4642', radius_min=5.) sc.add_to_subplot(c_count, row=2, col=0, row_span=2, title='3D connectivity') sc.add_to_subplot(s_obj_c, row=2, col=0) sc.add_to_subplot(BrainObj('B3'), use_this_cam=True, row=2, col=0) ############################################################################### # Cross-sections ############################################################################### cs_brod = CrossSecObj('brodmann', interpolation='nearest', coords=(70, 80, 90), cmap='viridis') cs_brod.localize_source((-10., -15., 20.)) sc.add_to_subplot(cs_brod, row=2, col=1, col_span=2, row_span=2, title='Cross-sections') sc.preview()
"""Test CrossSecObj.""" import numpy as np from visbrain.objects import CrossSecObj from visbrain.objects.tests._testing_objects import _TestObjects from visbrain.io import download_file, clean_tmp cs_obj = CrossSecObj('brodmann') class TestCrossSecObj(_TestObjects): """Test CrossSecObj.""" OBJ = cs_obj def test_definition(self): """Test class definition.""" for k in ['brodmann', 'aal', 'talairach']: CrossSecObj(k) CrossSecObj('test', vol=np.random.rand(100, 100, 100)) def test_cut_coords(self): """Test method cut_coords.""" cs_obj.cut_coords((14, 15, 50)) def test_localize_source(self): """Test function localize_source.""" cs_obj.localize_source((15., 12., 23.)) def test_nii_definition(self):
def test_definition(self): """Test class definition.""" for k in ['brodmann', 'aal', 'talairach']: CrossSecObj(k) CrossSecObj('test', vol=np.random.rand(100, 100, 100))
def test_remove(self): """Test function remove.""" v_obj = CrossSecObj('GG-853-GM-0.7mm') v_obj.remove() clean_tmp()
Illustration and main functionalities and inputs of the cross-section object. .. image:: ../../picture/picobjects/ex_cs_obj.png """ from visbrain.objects import CrossSecObj, SceneObj from visbrain.io import download_file sc = SceneObj() print(""" # ============================================================================= # Brodmann area # ============================================================================= """) cs_brod = CrossSecObj('brodmann', interpolation='nearest', coords=(70., 80., 90.)) cs_brod.localize_source((-10., -15., 20.)) sc.add_to_subplot(cs_brod, row=0, col=0, title='Brodmann area') print(""" # ============================================================================= # Nii.gz file # ============================================================================= """) path = download_file('GG-853-GM-0.7mm.nii.gz') cs_cust = CrossSecObj(path, coords=(0., 0., 0.), cmap='gist_stern') sc.add_to_subplot(cs_cust, row=0, col=1, title='Nii.gz file') sc.preview()
def test_save(self): """Test function save.""" v_obj = CrossSecObj(download_file('GG-853-GM-0.7mm.nii.gz', astype='example_data')) v_obj.save() v_obj.save(tmpfile=True)
def test_nii_definition(self): """Test function nii_definition.""" CrossSecObj( download_file('GG-853-GM-0.7mm.nii.gz', astype='example_data'))
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.set_data((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."""
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, coords=(0., 0., 0.), 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()
def test_nii_definition(self): """Test function nii_definition.""" CrossSecObj(download_file('GG-853-GM-0.7mm.nii.gz'))
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', astype='example_data') path_2 = download_file('GG-853-WM-0.7mm.nii.gz', astype='example_data') """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()
def test_save(self): """Test function save.""" v_obj = CrossSecObj(download_file('GG-853-GM-0.7mm.nii.gz')) v_obj.save() v_obj.save(tmpfile=True)
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()
def test_remove(self): """Test function remove.""" v_obj = CrossSecObj('GG-853-GM-0.7mm') v_obj.remove() clean_tmp()
Illustration and main functionalities and inputs of the cross-section object. .. image:: ../../picture/picobjects/ex_cs_obj.png """ from visbrain.objects import CrossSecObj, SceneObj from visbrain.io import download_file sc = SceneObj() print(""" # ============================================================================= # Brodmann area # ============================================================================= """) cs_brod = CrossSecObj('brodmann', interpolation='nearest', section=(70, 80, 90)) cs_brod.localize_source((-10., -15., 20.)) sc.add_to_subplot(cs_brod, row=0, col=0, title='Brodmann area') print(""" # ============================================================================= # Nii.gz file # ============================================================================= """) path = download_file('GG-853-GM-0.7mm.nii.gz') cs_cust = CrossSecObj(path, section=(90, 80, 100), cmap='gist_stern') sc.add_to_subplot(cs_cust, row=0, col=1, title='Nii.gz file') sc.preview()
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)