def filter_items_update(self, context): deselect_all_objects() if bpy.context.scene.filter_curves_type == 'Electrodes': filter_electrode_func(bpy.context.scene.filter_items) elif bpy.context.scene.filter_curves_type == 'MEG': filter_roi_func(bpy.context.scene.filter_items) mu.view_all_in_graph_editor(context)
def filter_graph(context, d, condition, threshold, threshold_type, connections_type, stat=STAT_DIFF): mu.show_hide_hierarchy(False, PARENT_OBJ) masked_con_names = calc_masked_con_names(d, threshold, threshold_type, connections_type, condition, stat) parent_obj = bpy.data.objects[PARENT_OBJ] for con_name in d.con_names: cur_obj = bpy.data.objects.get(con_name) if cur_obj: cur_obj.hide = con_name not in masked_con_names cur_obj.hide_render = con_name not in masked_con_names if bpy.context.scene.selection_type == 'conds': cur_obj.select = not cur_obj.hide if parent_obj.animation_data is None: return now = time.time() fcurves_num = len(parent_obj.animation_data.action.fcurves) for fcurve_index, fcurve in enumerate(parent_obj.animation_data.action.fcurves): # mu.time_to_go(now, fcurve_index, fcurves_num, runs_num_to_print=10) con_name = mu.fcurve_name(fcurve) # cur_obj = bpy.data.objects[con_name] # cur_obj.hide = con_name not in masked_con_names # cur_obj.hide_render = con_name not in masked_con_names if bpy.context.scene.selection_type != 'conds': fcurve.hide = con_name not in masked_con_names fcurve.select = not fcurve.hide parent_obj.select = True mu.view_all_in_graph_editor(context)
def filter_items_update(self, context): deselect_all_objects() if bpy.context.scene.filter_curves_type in ['Electrodes', 'EEG']: filter_electrode_func(bpy.context.scene.filter_items) elif bpy.context.scene.filter_curves_type == 'MEG': filter_roi_func(bpy.context.scene.filter_items) mu.view_all_in_graph_editor(context)
def filter_graph(context, d, condition, threshold, threshold_type, connections_type, stat=STAT_DIFF): mu.show_hide_hierarchy(False, PARENT_OBJ) masked_con_names = calc_masked_con_names(d, threshold, threshold_type, connections_type, condition, stat) parent_obj = bpy.data.objects[PARENT_OBJ] for con_name in d.con_names: cur_obj = bpy.data.objects.get(con_name) if cur_obj: cur_obj.hide = con_name not in masked_con_names cur_obj.hide_render = con_name not in masked_con_names if bpy.context.scene.selection_type == 'conds': cur_obj.select = not cur_obj.hide if parent_obj.animation_data is None: return now = time.time() fcurves_num = len(parent_obj.animation_data.action.fcurves) for fcurve_index, fcurve in enumerate( parent_obj.animation_data.action.fcurves): # mu.time_to_go(now, fcurve_index, fcurves_num, runs_num_to_print=10) con_name = mu.get_fcurve_name(fcurve) # cur_obj = bpy.data.objects[con_name] # cur_obj.hide = con_name not in masked_con_names # cur_obj.hide_render = con_name not in masked_con_names if bpy.context.scene.selection_type != 'conds': fcurve.hide = con_name not in masked_con_names fcurve.select = not fcurve.hide parent_obj.select = True mu.view_all_in_graph_editor(context)
def invoke(self, context, event=None): select_all_meg_sensors() SelectionMakerPanel.selection.append(SEL_MEG_SENSORS) mu.unfilter_graph_editor() mu.change_fcurves_colors(bpy.data.objects['MEG_sensors'].children) mu.view_all_in_graph_editor(context) return {"FINISHED"}
def _curves_sep_update(force=False): fcurves, data = get_selected_fcurves_and_data() if len(fcurves) == 0: return if data.ndim == 3: N, T, C = data.shape else: N, T = data.shape C = 1 get_data = lambda ind, t, c: data[ data_ind, t, c] if data.ndim == 3 else data[data_ind, t] sep_inds = np.tile(np.arange(0, N), (C, 1)).T.ravel() fcurve_ind = 0 for data_ind in range(N): data_mean = np.median( data[data_ind]) if bpy.context.scene.curves_sep > 0 else 0 for c in range(C): fcurve = fcurves[fcurve_ind] if not force and SelectionMakerPanel.curves_sep.get(mu.get_fcurve_name(fcurve), -1) == \ bpy.context.scene.curves_sep: fcurve_ind += 1 continue for t in range(T): fcurve.keyframe_points[t].co[1] = \ get_data(data_ind, t, c) - data_mean + (N / 2 - 0.5 - sep_inds[fcurve_ind]) * bpy.context.scene.curves_sep fcurve_ind += 1 if bpy.context.scene.curves_sep == 0: fcurve.keyframe_points[0].co[1] = fcurve.keyframe_points[T].co[ 1] = 0 for fcurve in fcurves: SelectionMakerPanel.curves_sep[mu.get_fcurve_name( fcurve)] = bpy.context.scene.curves_sep # mu.change_fcurves_colors(fcurves=fcurves) mu.view_all_in_graph_editor()
def modal(self, context, event): if event.type in {'RIGHTMOUSE', 'ESC'}: StreamingPanel.is_streaming = False bpy.context.scene.update() self.cancel(context) return {'PASS_THROUGH'} if event.type == 'TIMER': if StreamingPanel.is_streaming and time.time() - self._time > bpy.context.scene.streaming_buffer_size / 1000.0: print(time.time() - self._time) self._time = time.time() data = mu.queue_get(StreamingPanel.udp_queue) if not data is None: # if len(np.where(data)[0]) > 0: # print('spike!!!!!') # else: # print('only zeros!') change_graph_all_vals(data, StreamButton._channels_names, StreamButton._stim_channels, bpy.context.scene.stim_length) if bpy.context.scene.stream_type == 'offline' or self._first_time: mu.view_all_in_graph_editor() self._first_time = False # if self._first_timer and bpy.context.scene.frame_current > 10: # print('Setting _first_timer to False! ', bpy.context.scene.frame_current) # self._first_timer = False return {'PASS_THROUGH'}
def invoke(self, context, event=None): select_only_subcorticals() SelectionMakerPanel.selection.append(SEL_SUBS) mu.view_all_in_graph_editor(context) if bpy.context.scene.selection_type == 'diff': mu.change_fcurves_colors([bpy.data.objects['Subcortical_structures']]) else: mu.change_fcurves_colors(bpy.data.objects['Subcortical_structures'].children) return {"FINISHED"}
def invoke(self, context, event=None): select_all_rois() mu.view_all_in_graph_editor(context) if bpy.context.scene.selection_type == 'diff': mu.change_fcurves_colors([bpy.data.objects['Brain']]) else: corticals_labels = mu.get_corticals_labels() mu.change_fcurves_colors(corticals_labels) return {"FINISHED"}
def invoke(self, context, event=None): evoked_name = '{}_{}'.format(bpy.context.scene.meg_evoked_files, bpy.context.scene.evoked_objects) evoked_obj = bpy.data.objects.get(evoked_name) if not evoked_obj is None: evoked_obj.select = not evoked_obj.select mu.view_all_in_graph_editor(context) selected_objects = mu.get_selected_objects() mu.change_fcurves_colors(selected_objects) return {"FINISHED"}
def invoke(self, context, event=None): evoked_name = '{}_{}'.format(bpy.context.scene.meg_evoked_files, bpy.context.scene.evoked_objects) evoked_obj = bpy.data.objects.get(evoked_name) if not evoked_obj is None: evoked_obj.select = not evoked_obj.select mu.view_all_in_graph_editor(context) selected_objects = mu.get_selected_objects() mu.change_fcurves_colors(selected_objects) return {"FINISHED"}
def invoke(self, context, event=None): select_all_eeg() mu.unfilter_graph_editor() # if bpy.context.scene.selection_type == 'diff': # mu.change_fcurves_colors([bpy.data.objects['Deep_electrodes']]) # elif bpy.context.scene.selection_type == 'spec_cond': # mu.filter_graph_editor(bpy.context.scene.conditions_selection) # else: mu.change_fcurves_colors(bpy.data.objects['EEG_electrodes'].children) mu.view_all_in_graph_editor(context) return {"FINISHED"}
def add_data_to_parent_brain_obj(stat=STAT_DIFF, self=None): base_path = mu.get_user_fol() brain_obj = bpy.data.objects['Brain'] labels_data_file = 'labels_data_{hemi}.npz' # if stat else 'labels_data_no_conds_{hemi}.npz' brain_sources = [op.join(base_path, labels_data_file.format(hemi=hemi)) for hemi in mu.HEMIS] subcorticals_obj = bpy.data.objects['Subcortical_structures'] subcorticals_sources = [op.join(base_path, 'subcortical_meg_activity.npz')] add_data_to_parent_obj(brain_obj, brain_sources, stat, self) add_data_to_parent_obj(subcorticals_obj, subcorticals_sources, stat, self) mu.view_all_in_graph_editor()
def electrodes_sep_update(self, context): data = get_electrodes_data() # data_amp = np.max(data) - np.min(data) T = data.shape[1] - 1 parent_obj = bpy.data.objects['Deep_electrodes'] C = len(parent_obj.animation_data.action.fcurves) for fcurve_ind, fcurve in enumerate(parent_obj.animation_data.action.fcurves): elc_ind = fcurve_ind for t in range(T): fcurve.keyframe_points[t].co[1] = data[elc_ind, t] + \ (C / 2 - fcurve_ind) * bpy.context.scene.electrodes_sep mu.view_all_in_graph_editor()
def filter_graph(context, d, condition, threshold, threshold_type, connections_type, stat=STAT_DIFF): parent_obj_name = get_connections_parent_name() mu.show_hide_hierarchy(False, parent_obj_name) masked_con_names = calc_masked_con_names(d, threshold, threshold_type, connections_type, condition, stat) parent_obj = bpy.data.objects[parent_obj_name] bpy.context.scene.connections_num = min(len(masked_con_names), len(parent_obj.children) - 1) conn_show = 0 selected_objects, selected_indices = [], [] for con_ind, con_name in enumerate(d.con_names): cur_obj = bpy.data.objects.get(con_name) if cur_obj: if con_name in masked_con_names: selected_objects.append(cur_obj) selected_indices.append(con_ind) conn_show += 1 cur_obj.hide = con_name not in masked_con_names cur_obj.hide_render = con_name not in masked_con_names if bpy.context.scene.selection_type == 'conds': cur_obj.select = not cur_obj.hide ConnectionsPanel.selected_objects = selected_objects ConnectionsPanel.selected_indices = selected_indices print('Showing {} connections after filtering'.format(conn_show)) if conn_show > 0: bpy.context.scene.connections_min = np.min( d.con_values[selected_indices]) bpy.context.scene.connections_max = np.max( d.con_values[selected_indices]) if parent_obj.animation_data is None: return now = time.time() fcurves_num = len(parent_obj.animation_data.action.fcurves) for fcurve_index, fcurve in enumerate( parent_obj.animation_data.action.fcurves): # mu.time_to_go(now, fcurve_index, fcurves_num, runs_num_to_print=10) con_name = mu.get_fcurve_name(fcurve) # cur_obj = bpy.data.objects[con_name] # cur_obj.hide = con_name not in masked_con_names # cur_obj.hide_render = con_name not in masked_con_names if bpy.context.scene.selection_type != 'conds': fcurve.hide = con_name not in masked_con_names fcurve.select = not fcurve.hide parent_obj.select = True mu.view_all_in_graph_editor(context)
def add_data_to_parent_brain_obj(stat=STAT_DIFF, self=None): base_path = mu.get_user_fol() brain_obj = bpy.data.objects['Brain'] labels_data_file = 'labels_data_{hemi}.npz' # if stat else 'labels_data_no_conds_{hemi}.npz' brain_sources = [ op.join(base_path, labels_data_file.format(hemi=hemi)) for hemi in mu.HEMIS ] subcorticals_obj = bpy.data.objects['Subcortical_structures'] subcorticals_sources = [op.join(base_path, 'subcortical_meg_activity.npz')] add_data_to_parent_obj(brain_obj, brain_sources, stat, self) add_data_to_parent_obj(subcorticals_obj, subcorticals_sources, stat, self) mu.view_all_in_graph_editor()
def init(addon_prefs): set_play_to(get_max_time_steps()) mmvt_utils.view_all_in_graph_editor(bpy.context) bpy.context.window.screen = bpy.data.screens['Neuro'] bpy.context.scene.atlas = mmvt_utils.get_atlas() bpy.context.scene.python_cmd = addon_prefs.python_cmd # set default values figures_fol = op.join(mmvt_utils.get_user_fol(), 'figures') mmvt_utils.make_dir(figures_fol) set_render_output_path(figures_fol) set_render_quality(60) mmvt_utils.set_show_textured_solid() code_fol = mmvt_utils.get_parent_fol(mmvt_utils.get_parent_fol()) os.chdir(code_fol)
def select_all_clusters(): parent_obj = bpy.data.objects.get(PARENT_OBJ_NAME, None) if parent_obj is not None: parent_obj.select = True fcurves = mu.get_fcurves(PARENT_OBJ_NAME) filtered_fcurves_names = [ get_cluster_fcurve_name(c) for c in MEGPanel.clusters_labels_filtered ] for fcurve in fcurves: fcurve_name = mu.get_fcurve_name(fcurve) fcurve.hide = fcurve_name not in filtered_fcurves_names plot_all_clusters() mu.view_all_in_graph_editor()
def init(addon_prefs): set_play_to(get_max_time_steps()) mmvt_utils.view_all_in_graph_editor(bpy.context) bpy.context.window.screen = bpy.data.screens['Neuro'] bpy.context.scene.atlas = mmvt_utils.get_atlas() bpy.context.scene.python_cmd = addon_prefs.python_cmd # set default values figures_fol = op.join(mmvt_utils.get_user_fol(), 'figures') mmvt_utils.make_dir(figures_fol) set_render_output_path(figures_fol) set_render_quality(60) mmvt_utils.set_show_textured_solid() mmvt_utils.hide_relationship_lines() code_fol = mmvt_utils.get_parent_fol(mmvt_utils.get_parent_fol()) os.chdir(code_fol)
def select_brain_objects(parent_obj_name, children): parent_obj = bpy.data.objects[parent_obj_name] if bpy.context.scene.selection_type == 'diff': if parent_obj.animation_data is None: print('parent_obj.animation_data is None!') else: mu.show_hide_obj_and_fcurves(children, False) parent_obj.select = True for fcurve in parent_obj.animation_data.action.fcurves: fcurve.hide = False fcurve.select = True else: mu.show_hide_obj_and_fcurves(children, True) parent_obj.select = False mu.view_all_in_graph_editor()
def select_brain_objects(parent_obj_name, children=None, exclude=[]): if children is None: children = bpy.data.objects[parent_obj_name].children parent_obj = bpy.data.objects[parent_obj_name] children_have_fcurves = mu.count_fcurves(children) > 0 parent_have_fcurves = not parent_obj.animation_data is None if parent_have_fcurves and (bpy.context.scene.selection_type == 'diff' or not children_have_fcurves): mu.show_hide_obj_and_fcurves(children, False) parent_obj.select = True mu.show_hide_obj_and_fcurves(parent_obj, True, exclude) elif children_have_fcurves: if bpy.context.scene.selection_type == 'diff': bpy.context.scene.selection_type = 'conds' mu.show_hide_obj_and_fcurves(children, True, exclude) parent_obj.select = False mu.view_all_in_graph_editor()
def invoke(self, context, event=None): _addon().change_view3d() #todo: why should we call setup layers here?? # _addon().setup_layers() self.topK = bpy.context.scene.filter_topK self.filter_from = bpy.context.scene.filter_from self.filter_to = bpy.context.scene.filter_to self.current_activity_path = mu.get_user_fol( ) # bpy.path.abspath(bpy.context.scene.conf_path) # self.current_activity_path = bpy.path.abspath(bpy.context.scene.activity_path) self.type_of_filter = bpy.context.scene.filter_curves_type self.type_of_func = bpy.context.scene.filter_curves_func atlas = bpy.context.scene.atlas files_names = { 'MEG': op.join( 'meg', 'labels_data_{}_{}.npz'.format( bpy.context.scene.meg_labels_data_files, '{hemi}')), 'MEG_sensors': op.join('meg', 'meg_sensors_evoked_data.npy'), 'Electrodes': op.join('electrodes', 'electrodes_data_{stat}.npz'), 'EEG': op.join('eeg', 'eeg_data.npz') } current_file_to_upload = files_names[self.type_of_filter] if self.type_of_filter == 'Electrodes': data, meta = get_deep_electrodes_data() self.filter_electrodes_or_sensors('Deep_electrodes', data, meta) elif self.type_of_filter == 'EEG': data, meta = _addon().get_eeg_sensors_data() self.filter_electrodes_or_sensors('EEG_sensors', data, meta) elif self.type_of_filter == 'MEG': self.filter_rois(current_file_to_upload) elif self.type_of_filter == 'MEG_sensors': data, meta = _addon().get_meg_sensors_data() self.filter_electrodes_or_sensors('MEG_sensors', data, meta) if bpy.context.scene.filter_items_one_by_one: update_filter_items(self.topK, self.objects_indices, self.filter_objects) else: mu.view_all_in_graph_editor(context) # bpy.context.screen.areas[2].spaces[0].dopesheet.filter_fcurve_name = '*' return {"FINISHED"}
def _curves_sep_update(force=False): # if len(bpy.context.selected_objects) == 1: # return fcurves, data = get_selected_fcurves_and_data() if len(fcurves) == 0: return data = data.squeeze() if data.ndim == 3: N, T, C = data.shape get_data = lambda ind, t, c: data[data_ind, t, c] elif data.ndim == 2: N, T = data.shape if N - 10 < len(fcurves[0].keyframe_points) < N + 10: N, T = T, N # switch dims data = data.T C = 1 get_data = lambda ind, t, c: data[data_ind, t] elif data.ndim == 1: T = len(data) N, C = 1, 1 get_data = lambda ind, t, c: data[t] else: print('_curves_sep_update: Wrong number dims!') sep_inds = np.tile(np.arange(0, N), (C, 1)).T.ravel() for data_ind in range(N): fcurve_ind = 0 data_mean = np.median(data[data_ind]) if bpy.context.scene.curves_sep > 0 else 0 for c in range(C): fcurve = fcurves[fcurve_ind] fcurve_T = min(T, len(fcurve.keyframe_points)) - 1 if not force and SelectionMakerPanel.curves_sep.get(mu.get_fcurve_name(fcurve), -1) == \ bpy.context.scene.curves_sep: fcurve_ind += 1 continue for t in range(fcurve_T): fcurve.keyframe_points[t].co[1] = \ get_data(data_ind, t, c) - data_mean + (N / 2 - 0.5 - sep_inds[fcurve_ind]) * bpy.context.scene.curves_sep fcurve_ind += 1 if bpy.context.scene.curves_sep == 0: fcurve.keyframe_points[0].co[1] = fcurve.keyframe_points[fcurve_T].co[1] = 0 for fcurve in fcurves: SelectionMakerPanel.curves_sep[mu.get_fcurve_name(fcurve)] = bpy.context.scene.curves_sep # mu.change_fcurves_colors(fcurves=fcurves) mu.view_all_in_graph_editor()
def filter_electrodes_via_connections(context, do_filter): display_conds = bpy.context.scene.selection_type == 'conds' for elc_name in ConnectionsPanel.addon.play_panel.PlayPanel.electrodes_names: cur_obj = bpy.data.objects.get(elc_name) if cur_obj: cur_obj.hide = do_filter cur_obj.hide_render = do_filter cur_obj.select = not do_filter and display_conds for fcurve in cur_obj.animation_data.action.fcurves: fcurve.hide = do_filter fcurve.select = not do_filter elecs_parent_obj = bpy.data.objects['Deep_electrodes'] elecs_parent_obj.select = not display_conds for fcurve in elecs_parent_obj.animation_data.action.fcurves: fcurve.hide = do_filter fcurve.select = not do_filter if do_filter: selected_electrodes = set() for ind, con_name in enumerate(ConnectionsPanel.d.con_names): cur_obj = bpy.data.objects.get(con_name) if not cur_obj or cur_obj.hide: continue electrodes = con_name.split('-') for elc in electrodes: cur_elc = bpy.data.objects.get(elc) if not cur_elc or elc in selected_electrodes: continue selected_electrodes.add(elc) # if bpy.context.scene.selection_type == 'conds': cur_elc.hide = False cur_elc.hide_render = False cur_elc.select = display_conds for fcurve in cur_elc.animation_data.action.fcurves: fcurve.hide = False fcurve.select = True for fcurve in elecs_parent_obj.animation_data.action.fcurves: elc_name = mu.fcurve_name(fcurve) if elc_name in selected_electrodes: fcurve.hide = False fcurve.select = True mu.view_all_in_graph_editor(context)
def filter_electrodes_via_connections(context, do_filter): display_conds = bpy.context.scene.selection_type == 'conds' for elc_name in ConnectionsPanel.addon.play_panel.PlayPanel.electrodes_names: cur_obj = bpy.data.objects.get(elc_name) if cur_obj: cur_obj.hide = do_filter cur_obj.hide_render = do_filter cur_obj.select = not do_filter and display_conds for fcurve in cur_obj.animation_data.action.fcurves: fcurve.hide = do_filter fcurve.select = not do_filter elecs_parent_obj = bpy.data.objects['Deep_electrodes'] elecs_parent_obj.select = not display_conds for fcurve in elecs_parent_obj.animation_data.action.fcurves: fcurve.hide = do_filter fcurve.select = not do_filter if do_filter: selected_electrodes = set() for ind, con_name in enumerate(ConnectionsPanel.d.con_names): cur_obj = bpy.data.objects.get(con_name) if not cur_obj or cur_obj.hide: continue electrodes = con_name.split('-') for elc in electrodes: cur_elc = bpy.data.objects.get(elc) if not cur_elc or elc in selected_electrodes: continue selected_electrodes.add(elc) # if bpy.context.scene.selection_type == 'conds': cur_elc.hide = False cur_elc.hide_render = False cur_elc.select = display_conds for fcurve in cur_elc.animation_data.action.fcurves: fcurve.hide = False fcurve.select = True for fcurve in elecs_parent_obj.animation_data.action.fcurves: elc_name = mu.get_fcurve_name(fcurve) if elc_name in selected_electrodes: fcurve.hide = False fcurve.select = True mu.view_all_in_graph_editor()
def main(addon_prefs=None): show_electrodes(False) show_connections(False) mmvt_utils.view_all_in_graph_editor(bpy.context) bpy.context.window.screen = bpy.data.screens['Neuro'] bpy.context.scene.atlas = mmvt_utils.get_atlas() bpy.context.scene.python_cmd = addon_prefs.python_cmd # set default values figures_fol = op.join(mmvt_utils.get_user_fol(), 'figures') mmvt_utils.make_dir(figures_fol) set_render_output_path(figures_fol) set_render_quality(60) code_fol = mmvt_utils.get_parent_fol(mmvt_utils.get_parent_fol()) os.chdir(code_fol) try: # _listener_in_queue, _listener__out_queue = start_listener() current_module = sys.modules[__name__] appearance_panel.init(current_module) show_hide_panel.init(current_module) selection_panel.init(current_module) coloring_panel.init(current_module) electrodes_panel.init(current_module) play_panel.init(current_module) filter_panel.init(current_module) freeview_panel.init(current_module, addon_prefs) render_panel.init(current_module) fMRI_panel.init(current_module) search_panel.init(current_module) transparency_panel.init(current_module) where_am_i_panel.init(current_module) data_panel.init(current_module) stim_panel.init(current_module) dti_panel.init(current_module) connections_panel.init(current_module) # listener_panel.init(current_module) vertex_data_panel.init(current_module) except: print('The classes are already registered!') print(traceback.format_exc()) show_activity()
def modal(self, context, event): if event.type in {'RIGHTMOUSE', 'ESC'}: StreamingPanel.is_streaming = False bpy.context.scene.update() self.cancel(context) return {'PASS_THROUGH'} if event.type == 'TIMER': if StreamingPanel.is_streaming and time.time() - self._time > bpy.context.scene.streaming_buffer_size / 1000.0: self._time = time.time() data = mu.queue_get(StreamingPanel.udp_queue) if not data is None: change_graph_all_vals(data) if bpy.context.scene.stream_type == 'offline': mu.view_all_in_graph_editor() # if self._first_timer and bpy.context.scene.frame_current > 10: # print('Setting _first_timer to False! ', bpy.context.scene.frame_current) # self._first_timer = False return {'PASS_THROUGH'}
def init(addon_prefs): global settings run_faulthandler() print('filepath: {}'.format(bpy.data.filepath)) set_play_to(get_max_time_steps()) mmvt_utils.view_all_in_graph_editor(bpy.context) bpy.context.window.screen = bpy.data.screens['Neuro'] bpy.context.scene.atlas = mmvt_utils.get_atlas() bpy.context.scene.python_cmd = addon_prefs.python_cmd # bpy.data.screens['Neuro'].areas[1].spaces[0].region_3d.view_rotation = [1, 0, 0, 0] make_all_fcurve_visible() # set default values figures_fol = op.join(mmvt_utils.get_user_fol(), 'figures') mmvt_utils.make_dir(figures_fol) set_render_output_path(figures_fol) set_render_quality(60) mmvt_utils.set_show_textured_solid() mmvt_utils.hide_relationship_lines() code_fol = mmvt_utils.get_parent_fol(mmvt_utils.get_parent_fol()) settings = mmvt_utils.read_config_ini() os.chdir(code_fol) bpy.context.scene.mmvt_initialized = True
def invoke(self, context, event=None): FilteringMakerPanel.addon.change_view3d() #todo: why should we call setup layers here?? # FilteringMakerPanel.addon.setup_layers() self.topK = bpy.context.scene.filter_topK self.filter_from = bpy.context.scene.filter_from self.filter_to = bpy.context.scene.filter_to self.current_activity_path = mu.get_user_fol() # bpy.path.abspath(bpy.context.scene.conf_path) # self.current_activity_path = bpy.path.abspath(bpy.context.scene.activity_path) self.type_of_filter = bpy.context.scene.filter_curves_type self.type_of_func = bpy.context.scene.filter_curves_func files_names = {'MEG': 'labels_data_{hemi}.npz', 'Electrodes': op.join('electrodes', 'electrodes_data_{stat}.npz')} current_file_to_upload = files_names[self.type_of_filter] # print(self.current_root_path) # source_files = ["/homes/5/npeled/space3/ohad/mg79/electrodes_data.npz"] if self.type_of_filter == 'Electrodes': data_files = glob.glob(op.join(mu.get_user_fol(), 'electrodes', 'electrodes_data_*.npz')) if len(data_files) == 0: print('No data files!') elif len(data_files) == 1: current_file_to_upload = data_files[0] else: print('More the one data file!') current_file_to_upload = data_files[0] # todo: should decide which one to pick # current_file_to_upload = current_file_to_upload.format( # stat='avg' if bpy.context.scene.selection_type == 'conds' else 'diff') self.filter_electrodes(current_file_to_upload) elif self.type_of_filter == 'MEG': self.filter_rois(current_file_to_upload) if bpy.context.scene.filter_items_one_by_one: update_filter_items(self.topK, self.objects_indices, self.filter_objects) else: mu.view_all_in_graph_editor(context) # bpy.context.screen.areas[2].spaces[0].dopesheet.filter_fcurve_name = '*' return {"FINISHED"}
def select_roi(roi_name, change_selected_fcurves_colors=True): roi = bpy.data.objects.get(roi_name) if roi is None: return # check if MEG data is loaded and attahced to the obj if mu.count_fcurves(roi) > 0: roi.select = True labels_selection_coloring(roi_name) # mu.change_fcurves_colors(roi) else: # Check if dynamic fMRI data is loaded fmri_parent_obj = bpy.data.objects.get('fMRI') fcurves = mu.get_fcurves(fmri_parent_obj) for fcurve in fcurves: if mu.get_fcurve_name(fcurve) == roi_name: fcurve.hide = False fmri_parent_obj.select = True else: fcurve.hide = True if change_selected_fcurves_colors: mu.change_selected_fcurves_colors(mu.OBJ_TYPES_ROIS) mu.view_all_in_graph_editor()
def invoke(self, context, event=None): _addon().change_view3d() #todo: why should we call setup layers here?? # _addon().setup_layers() self.topK = bpy.context.scene.filter_topK self.filter_from = bpy.context.scene.filter_from self.filter_to = bpy.context.scene.filter_to self.current_activity_path = mu.get_user_fol( ) # bpy.path.abspath(bpy.context.scene.conf_path) # self.current_activity_path = bpy.path.abspath(bpy.context.scene.activity_path) self.type_of_filter = bpy.context.scene.filter_curves_type self.type_of_func = bpy.context.scene.filter_curves_func atlas = bpy.context.scene.atlas labels_extract_method = bpy.context.scene.labels_data_files files_names = { 'MEG': op.join( 'meg', 'labels_data_{}_{}_{}.npz'.format(atlas, labels_extract_method, '{hemi}')), 'MEG_sensors': op.join('meg', 'meg_sensors_evoked_data.npy'), 'Electrodes': op.join('electrodes', 'electrodes_data_{stat}.npz'), 'EEG': op.join('eeg', 'eeg_data.npz') } current_file_to_upload = files_names[self.type_of_filter] if self.type_of_filter == 'Electrodes': # todo: should be called once (maybe those files are already loaded? fol = op.join(mu.get_user_fol(), 'electrodes') bip = 'bipolar_' if bpy.context.scene.bipolar else '' meta_files = glob.glob( op.join(fol, 'electrodes_{}meta*.npz'.format(bip))) if len(meta_files) > 0: data_files = glob.glob( op.join(fol, 'electrodes_{}data*.npy'.format(bip))) print('Loading data file: {}'.format(data_files[0])) print('Loading meta data file: {}'.format(meta_files[0])) data = np.load(data_files[0]) meta = np.load(meta_files[0]) else: data_files = glob.glob( op.join(mu.get_user_fol(), 'electrodes', 'electrodes_{}data*.npz'.format(bip))) print('Loading data file: {}'.format(data_files[0])) meta = np.load(data_files[0]) data = meta['data'] if len(data_files) == 0: print('No data files!') elif len(data_files) == 1: current_file_to_upload = data_files[0] else: print('More the one data file!') current_file_to_upload = data_files[0] # todo: should decide which one to pick # current_file_to_upload = current_file_to_upload.format( # stat='avg' if bpy.context.scene.selection_type == 'conds' else 'diff') self.filter_electrodes_or_sensors('Deep_electrodes', data, meta) elif self.type_of_filter == 'EEG': data, meta = _addon().get_eeg_sensors_data() self.filter_electrodes_or_sensors('EEG_sensors', data, meta) elif self.type_of_filter == 'MEG': self.filter_rois(current_file_to_upload) elif self.type_of_filter == 'MEG_sensors': data, meta = _addon().get_meg_sensors_data() self.filter_electrodes_or_sensors('MEG_sensors', data, meta) if bpy.context.scene.filter_items_one_by_one: update_filter_items(self.topK, self.objects_indices, self.filter_objects) else: mu.view_all_in_graph_editor(context) # bpy.context.screen.areas[2].spaces[0].dopesheet.filter_fcurve_name = '*' return {"FINISHED"}
def invoke(self, context, event=None): select_all_connections() mu.view_all_in_graph_editor(context) return {"FINISHED"}
def modal(self, context, event): if self.left_clicked: self.left_clicked = False active_image, pos = click_inside_images_view(event) if active_image is not None: xyz = _addon().slices_were_clicked(active_image, pos) bpy.context.scene.cursor_location = tuple(xyz) set_cursor_pos() if bpy.context.scene.cursor_is_snapped: # and is_view_3d(): _addon().set_tkreg_ras( bpy.context.scene.cursor_location * 10, False) snap_cursor(True) if bpy.context.scene.slices_rotate_view_on_click: mu.rotate_view_to_vertice() # if bpy.context.scene.slices_zoom > 1: # ohad(pos/bpy.context.scene.slices_zoom) return {'PASS_THROUGH'} if not click_inside_3d_view(event): return {'PASS_THROUGH'} if _addon().meg.change_cursor_on_selection(): cluster = _addon().select_meg_cluster( event, context, bpy.context.scene.cursor_location) if cluster is not None: return {'PASS_THROUGH'} cursor_moved = np.linalg.norm( SelectionListener.cursor_pos - bpy.context.scene.cursor_location) > 1e-3 if cursor_moved and bpy.data.objects.get('inner_skull', None) is not None: _addon().find_point_thickness() return {'PASS_THROUGH'} if bpy.context.scene.cursor_is_snapped: # and is_view_3d(): snap_cursor(True) if _addon().fMRI_clusters_files_exist( ) and bpy.context.scene.plot_fmri_cluster_per_click: _addon().find_closest_cluster(only_within=True) tkreg_ras = _addon().calc_tkreg_ras_from_cursor() if tkreg_ras is not None: _addon().set_tkreg_ras(tkreg_ras, move_cursor=False) # if _addon().is_pial(): # tkreg_ras = bpy.context.scene.cursor_location * 10 # _addon().set_tkreg_ras(tkreg_ras) # elif bpy.context.scene.cursor_is_snapped: # tkreg_ras = _addon().calc_tkreg_ras_from_snapped_cursor() # _addon().set_tkreg_ras(tkreg_ras) if cursor_moved: set_cursor_pos() # print('cursor position was changed by the user!') _addon().create_slices(pos=tkreg_ras) _addon().freeview.save_cursor_position() clear_slice() if bpy.context.scene.find_closest_label_on_click: # coloring_panel.WIC_CONTOURS in _addon().what_is_colored(): _addon().find_closest_label( plot_contour=bpy.context.scene.plot_closest_label_contour) if self.right_clicked: self.right_clicked = False if not click_inside_3d_view(event): return {'PASS_THROUGH'} # print(bpy.context.selected_objects) # cluster = _addon().select_meg_cluster(event, context) # if cluster is not None: # return {'PASS_THROUGH'} if len(bpy.context.selected_objects): mu.unfilter_graph_editor() if bpy.context.scene.fit_graph_on_selection: mu.view_all_in_graph_editor() selected_obj = bpy.context.active_object # bpy.context.selected_objects[-1] selected_obj_name = selected_obj.name selected_obj_type = mu.check_obj_type(selected_obj_name) if selected_obj_type in [ mu.OBJ_TYPE_CORTEX_LH, mu.OBJ_TYPE_CORTEX_RH ]: _addon().select_roi(selected_obj_name) elif selected_obj_type in [ mu.OBJ_TYPE_CORTEX_INFLATED_LH, mu.OBJ_TYPE_CORTEX_INFLATED_RH ]: pial_obj_name = selected_obj_name[len('inflated_'):] pial_obj = bpy.data.objects.get(pial_obj_name) if not pial_obj is None: # pial_obj.select = True _addon().select_roi(pial_obj_name) # mu.change_selected_fcurves_colors(pial_obj) # mu.change_selected_fcurves_colors() elif selected_obj_type == mu.OBJ_TYPE_CON: _addon().select_connection(selected_obj_name) elif selected_obj_type == mu.OBJ_TYPE_CON_VERTICE: _addon().vertices_selected(selected_obj_name) elif selected_obj_type == mu.OBJ_TYPE_ELECTRODE: bpy.context.scene.cursor_is_snapped = False _addon().electode_was_manually_selected(selected_obj_name) try: _addon().dell.dell_ct_electrode_was_selected( selected_obj_name) except: pass if bpy.context.scene.find_curves_sep_auto: _addon().calc_best_curves_sep() elif bpy.context.scene.curves_sep > 0: _addon().curves_sep_update() else: _addon().clear_electrodes_selection() #todo: should call to _addon().clear_rois_selection() # if is_activity(): # bpy.context.scene.cursor_location = mouse_coo_to_3d_loc(event, context) # snap_cursor(True) # _addon().find_closest_label() if time.time() - self.press_time > 1 and event.value == 'PRESS': if event.type == 'RIGHTMOUSE': self.press_time = time.time() self.right_clicked = True if event.type == 'LEFTMOUSE': self.press_time = time.time() self.left_clicked = True if time.time() - self.press_time > 0.1: if event.type == 'TIMER': if bpy.context.scene.rotate_brain: if _addon().render.is_camera_view(): _addon().render.camera_mode('ORTHO') _addon().show_hide.rotate_brain() _addon().render.camera_mode('CAMERA') else: _addon().show_hide.rotate_brain() if _addon() and _addon().render_in_queue(): rendering_data = mu.queue_get(_addon().render_in_queue()) if not rendering_data is None: try: rendering_data = rendering_data.decode( sys.getfilesystemencoding(), 'ignore') if '*** finish rendering! ***' in rendering_data.lower(): print('Finish rendering!') _addon().finish_rendering() except: print("Can't read the stdout from the rendering") return {'PASS_THROUGH'}
def invoke(self, context, event=None): mu.view_all_in_graph_editor(context) return {"FINISHED"}
def fit_selection(context=None): mu.view_all_in_graph_editor(context)
def invoke(self, context, event=None): select_all_electrodes() SelectionMakerPanel.selection.append(SEL_ELECTRODES) # curves_sep_update() mu.view_all_in_graph_editor(context) return {"FINISHED"}
def invoke(self, context, event=None): select_all_connections() SelectionMakerPanel.selection.append(SEL_CONNECTIONS) mu.view_all_in_graph_editor(context) return {"FINISHED"}
def select_connection(connection_name): fcurves = mu.get_fcurves(connection_name) for fcurve in fcurves: fcurve.hide = False fcurve.select = True mu.view_all_in_graph_editor()