def create_conncection_for_both_conditions(d, layers_rods, indices, mask, windows_num, norm_fac, T, radius): N = len(indices) parent_obj = bpy.data.objects[PARENT_OBJ] print('Create connections for both conditions') now = time.time() for run, (ind, conn_name, (i, j)) in enumerate( zip(indices, d.con_names[mask], d.con_indices[mask])): mu.time_to_go(now, run, N, runs_num_to_print=10) if d.con_colors.ndim == 3: con_color = np.hstack((d.con_colors[ind, 0, :], [0.])) else: con_color = np.hstack((d.con_colors[ind, :], [0.])) p1, p2 = d.locations[i, :] * 0.1, d.locations[j, :] * 0.1 mu.cylinder_between(p1, p2, radius, layers_rods) # mu.create_material('{}_mat'.format(conn_name), (0, 0, 1, 1), 1) mu.create_material('{}_mat'.format(conn_name), con_color, 1) cur_obj = bpy.context.active_object cur_obj.name = conn_name cur_obj.parent = parent_obj # cur_obj.animation_data_clear() if windows_num == 1: continue for cond_id, cond in enumerate(d.conditions): # insert_frame_keyframes(cur_obj, '{}-{}'.format(conn_name, cond), d.con_values[ind, -1, cond_id], T) for t in range(windows_num): extra_time_points = 0 if norm_fac == 1 else 2 timepoint = t * norm_fac + extra_time_points mu.insert_keyframe_to_custom_prop( cur_obj, '{}-{}'.format(conn_name, cond), d.con_values[ind, t, cond_id], timepoint) finalize_fcurves(cur_obj)
def create_conncection_for_both_conditions(d, layers_rods, indices, mask, windows_num, norm_fac, T, radius): N = len(indices) parent_obj = bpy.data.objects[PARENT_OBJ] print('Create connections for both conditions') now = time.time() for run, (ind, conn_name, (i, j)) in enumerate(zip(indices, d.con_names[mask], d.con_indices[mask])): mu.time_to_go(now, run, N, runs_num_to_print=10) if d.con_colors.ndim == 3: con_color = np.hstack((d.con_colors[ind, 0, :], [0.])) else: con_color = np.hstack((d.con_colors[ind, :], [0.])) p1, p2 = d.locations[i, :] * 0.1, d.locations[j, :] * 0.1 mu.cylinder_between(p1, p2, radius, layers_rods) # mu.create_material('{}_mat'.format(conn_name), (0, 0, 1, 1), 1) mu.create_material('{}_mat'.format(conn_name), con_color, 1) cur_obj = bpy.context.active_object cur_obj.name = conn_name cur_obj.parent = parent_obj # cur_obj.animation_data_clear() if windows_num == 1: continue for cond_id, cond in enumerate(d.conditions): # insert_frame_keyframes(cur_obj, '{}-{}'.format(conn_name, cond), d.con_values[ind, -1, cond_id], T) for t in range(windows_num): extra_time_points = 0 if norm_fac ==1 else 2 timepoint = t * norm_fac + extra_time_points mu.insert_keyframe_to_custom_prop(cur_obj, '{}-{}'.format(conn_name, cond), d.con_values[ind, t, cond_id], timepoint) finalize_fcurves(cur_obj)
def plot_connections(self, context, d, plot_time, connections_type, condition, threshold, abs_threshold=True): windows_num = d.con_values.shape[1] # xs, ys = get_fcurve_values('RPT3-RAT5') # cond_id = [i for i, cond in enumerate(d.conditions) if cond == condition][0] t = int(plot_time / ConnectionsPanel.addon.get_max_time_steps() * windows_num) if windows_num > 1 else 0 print('plotting connections for t:{}'.format(t)) if t >= d.con_colors.shape[1] and windows_num > 1: mu.message(self, 'time out of bounds! {}'.format(plot_time)) else: # for conn_name, conn_colors in colors.items(): # vals = [] selected_objects, selected_indices = get_all_selected_connections(d) for ind, con_name in zip(selected_indices, selected_objects): # print(con_name, d.con_values[ind, t, 0], d.con_values[ind, t, 1], np.diff(d.con_values[ind, t, :])) cur_obj = bpy.data.objects.get(con_name) color = d.con_colors[ ind, t, :] if d.con_colors.ndim == 3 else d.con_colors[ind, :] con_color = np.hstack((color, [0.])) bpy.context.scene.objects.active = cur_obj mu.create_material('{}_mat'.format(con_name), con_color, 1, False) # vals.append(np.diff(d.con_values[ind, t])[0]) bpy.data.objects[PARENT_OBJ].select = True ConnectionsPanel.addon.show_hide_connections()
def create_conncection_per_condition(d, layers_rods, indices, mask, windows_num, norm_fac, T, radius): N = len(indices) parent_obj = bpy.data.objects[get_connections_parent_name()] print('Create connections for both conditions') con_color = (1, 1, 1, 1) now = time.time() for run, (ind, conn_name, (i, j)) in enumerate(zip(indices, d.con_names[mask], d.con_indices[mask])): mu.time_to_go(now, run, N, runs_num_to_print=10) p1, p2 = d.locations[i, :] * 0.1, d.locations[j, :] * 0.1 mu.cylinder_between(p1, p2, radius, layers_rods) mu.create_material('{}_mat'.format(conn_name), con_color, 1) cur_obj = bpy.context.active_object cur_obj.name = conn_name cur_obj.parent = parent_obj # cur_obj.animation_data_clear() if windows_num == 1: continue for cond_id, cond in enumerate(d.conditions): # insert_frame_keyframes(cur_obj, '{}-{}'.format(conn_name, cond), d.con_values[ind, -1, cond_id], T) for t in range(windows_num): extra_time_points = 0 if norm_fac == 1 else 2 timepoint = t * norm_fac + extra_time_points mu.insert_keyframe_to_custom_prop(cur_obj, '{}-{}'.format(conn_name, cond), d.con_values[ind, t, cond_id], timepoint) fcurve = cur_obj.animation_data.action.fcurves[cond_id] fcurve.keyframe_points[0].co[1] = 0 fcurve.keyframe_points[-1].co[1] = 0 finalize_fcurves(cur_obj) mu.change_fcurves_colors(parent_obj.children)
def plot_connections(d, plot_time, threshold=None): _addon().show_hide_connections() windows_num = d.con_values.shape[1] if d.con_values.ndim >= 2 else 1 t = int(plot_time / ConnectionsPanel.T * windows_num) if windows_num > 1 else 0 print('plotting connections for t:{}'.format(t)) if 1 < windows_num <= t: print('time out of bounds! {}'.format(plot_time)) else: # selected_objects, selected_indices = get_all_selected_connections(d) selected_objects = ConnectionsPanel.selected_objects selected_indices = ConnectionsPanel.selected_indices if len(selected_objects) == 0: selected_objects, selected_indices = get_all_selected_connections(d) if _addon().colorbar_values_are_locked(): data_min = _addon().get_colorbar_min() data_max = _addon().get_colorbar_max() else: # Should set the percentile in GUI data_min, data_max = ConnectionsPanel.data_minmax _addon().set_colorbar_max_min(data_max, data_min) colors_ratio = 256 / (data_max - data_min) stat_vals = [calc_stat_data(d.con_values[ind, t], STAT_DIFF) if d.con_values.ndim >= 2 else d.con_values[ind] for ind in selected_indices] colors = _addon().calc_colors(np.array(stat_vals).squeeze(), data_min, colors_ratio) colors = np.concatenate((colors, np.zeros((len(colors), 1))), 1) _addon().show_hide_connections() if threshold is None: threshold = bpy.context.scene.coloring_threshold for ind, con_name in enumerate(selected_objects): cur_obj = bpy.data.objects.get(con_name) if bpy.context.scene.hide_connection_under_threshold: if abs(stat_vals[ind]) < threshold: cur_obj.hide = True cur_obj.hide_render = True bpy.context.scene.objects.active = cur_obj mu.create_material('{}_mat'.format(con_name), colors[ind], 1, False) if bpy.context.scene.hide_connection_under_threshold: filter_nodes() parent_obj_name = get_connections_parent_name() bpy.data.objects[parent_obj_name].select = True connectivity_method = d['connectivity_method'] if 'connectivity_method' in d else 'connectivity' # if 'corr' in connectivity_method: # _addon().set_colorbar_max_min(1, -1) # else: # data_max, data_min = np.max(d.con_values[selected_indices]), np.min(d.con_values[selected_indices]) modality_names = dict(electrodes='Electrodes', meg='MEG', fmri='fMRI') colorbar_title = 'Electrodes {}'.format(connectivity_method) \ if 'electrodes' in bpy.context.scene.connectivity_files else \ '{} {}'.format(bpy.context.scene.connectivity_files, connectivity_method) # Cortical labels _addon().set_colorbar_title(colorbar_title)
def create_vertices(d, mask, verts_color='pink'): layers = [False] * 20 layers[_addon().CONNECTIONS_LAYER] = True vert_color = np.hstack((cu.name_to_rgb(verts_color), [0.])) parent_name = 'connections_vertices' parent_obj = mu.create_empty_if_doesnt_exists(parent_name, _addon().BRAIN_EMPTY_LAYER, None, get_connections_parent_name()) for vertice in ConnectionsPanel.vertices: # for ind in range(len(d.names[mask])): # for indice in indices: p1 = d.locations[vertice, :] * 0.1 vert_name = '{}_vertice'.format(d.labels[vertice]) mu.create_ico_sphere(p1, layers, vert_name) mu.create_material('{}_mat'.format(vert_name), vert_color, 1) cur_obj = bpy.context.active_object cur_obj.name = vert_name cur_obj.parent = parent_obj
def create_lead(p1, p2, lead_name, radius=0.03): if bpy.data.objects.get(lead_name) is not None: return bpy.data.objects.get(lead_name) layers = [False] * 20 lead_layer = _addon().ELECTRODES_LAYER layers[lead_layer] = True parent_name = 'leads' mu.create_empty_if_doesnt_exists(parent_name, _addon().BRAIN_EMPTY_LAYER, None, parent_name) mu.cylinder_between(p1, p2, radius, layers) color = tuple(np.concatenate((bpy.context.scene.electrodes_leads_color, [1]))) mu.create_material('{}_mat'.format(lead_name), color, 1) cur_obj = bpy.context.active_object cur_obj.name = lead_name cur_obj.parent = bpy.data.objects[parent_name] bpy.data.objects[lead_name].select = False return bpy.data.objects[lead_name]
def create_vertices(d, mask, verts_color='pink'): indices = set() layers = [False] * 20 layers[_addon().CONNECTIONS_LAYER] = True vert_color = np.hstack((cu.name_to_rgb(verts_color), [0.])) parent_name = 'connections_vertices' parent_obj = mu.create_empty_if_doesnt_exists(parent_name, _addon().BRAIN_EMPTY_LAYER, None, PARENT_OBJ) for (i, j) in d.con_indices[mask]: indices.add(i) indices.add(j) for indice in indices: p1 = d.locations[indice, :] * 0.1 vert_name = 'connection_{}'.format(indice) mu.create_ico_sphere(p1, layers, vert_name) mu.create_material('{}_mat'.format(vert_name), vert_color, 1) cur_obj = bpy.context.active_object cur_obj.name = vert_name cur_obj.parent = parent_obj
def plot_connections(self, context, d, plot_time, connections_type, condition, threshold, abs_threshold=True): windows_num = d.con_values.shape[1] # xs, ys = get_fcurve_values('RPT3-RAT5') # cond_id = [i for i, cond in enumerate(d.conditions) if cond == condition][0] t = int(plot_time / ConnectionsPanel.addon.get_max_time_steps() * windows_num) if windows_num > 1 else 0 print('plotting connections for t:{}'.format(t)) if t >= d.con_colors.shape[1] and windows_num > 1: mu.message(self, 'time out of bounds! {}'.format(plot_time)) else: # for conn_name, conn_colors in colors.items(): # vals = [] selected_objects, selected_indices = get_all_selected_connections(d) for ind, con_name in zip(selected_indices, selected_objects): # print(con_name, d.con_values[ind, t, 0], d.con_values[ind, t, 1], np.diff(d.con_values[ind, t, :])) cur_obj = bpy.data.objects.get(con_name) color = d.con_colors[ind, t, :] if d.con_colors.ndim == 3 else d.con_colors[ind, :] con_color = np.hstack((color, [0.])) bpy.context.scene.objects.active = cur_obj mu.create_material('{}_mat'.format(con_name), con_color, 1, False) # vals.append(np.diff(d.con_values[ind, t])[0]) bpy.data.objects[PARENT_OBJ].select = True ConnectionsPanel.addon.show_connections()