def invoke(self, context, event=None): # self.current_root_path = bpy.path.abspath(bpy.context.scene.conf_path) parent_obj = bpy.data.objects['Deep_electrodes'] base_path = mu.get_user_fol() data, meta = None, None source_file = op.join(base_path, 'electrodes', 'electrodes{}_data_diff.npz'.format( '_bipolar' if bpy.context.scene.bipolar else '')) # 'avg' if bpy.context.scene.selection_type == 'conds' else 'diff')) if op.isfile(source_file): meta = np.load(source_file) data = meta['data'] else: source_file = op.join(base_path, 'electrodes', 'electrodes{}_data_{}_data.npy'.format( '_bipolar' if bpy.context.scene.bipolar else '', 'avg' if bpy.context.scene.selection_type == 'conds' else 'diff')) meta_file = op.join(base_path, 'electrodes', 'electrodes{}_data_{}_meta.npz'.format( '_bipolar' if bpy.context.scene.bipolar else '', 'avg' if bpy.context.scene.selection_type == 'conds' else 'diff')) if op.isfile(source_file) and op.isfile(meta_file): data = np.load(source_file) meta = np.load(meta_file) else: print('No electrodes data file!') if not data is None and not meta is None: print('Loading electordes data from {}'.format(source_file)) conditions = add_data_to_electrodes(data, meta) selection_panel.set_conditions_enum(conditions) add_data_to_electrodes_parent_obj(parent_obj, data, meta) bpy.types.Scene.electrodes_data_exist = True if bpy.data.objects.get(' '): bpy.context.scene.objects.active = bpy.data.objects[' '] return {"FINISHED"}
def load_conditions(): stim_fname = 'stim_electrodes_{}.npz'.format( bpy.context.scene.stim_files.replace(' ', '_')) stim_data_fname = op.join(mu.get_user_fol(), 'electrodes', stim_fname) stim_data = np.load(stim_data_fname) conditions = sorted(stim_data['conditions'], key=lambda x: int(x.split('-')[0])) selection_panel.set_conditions_enum(conditions)
def add_data_to_brain(base_path='', files_prefix='', objs_prefix=''): if base_path == '': base_path = mu.get_user_fol() source_files = [op.join(base_path, '{}labels_data_lh.npz'.format(files_prefix)), op.join(base_path, '{}labels_data_rh.npz'.format(files_prefix)), op.join(base_path, '{}sub_cortical_activity.npz'.format(files_prefix))] print('Adding data to Brain') number_of_maximal_time_steps = -1 obj_counter = 0 conditions = [] for input_file in source_files: if not op.isfile(input_file): mu.message(None, '{} does not exist!'.format(input_file)) continue f = np.load(input_file) print('{} loaded'.format(input_file)) number_of_maximal_time_steps = max(number_of_maximal_time_steps, len(f['data'][0])) for obj_name, data in zip(f['names'], f['data']): # print('in label loop') obj_name = obj_name.astype(str) if not bpy.context.scene.import_unknown and 'unknown' in obj_name: continue obj_name = '{}{}'.format(objs_prefix, obj_name) print(obj_name) cur_obj = bpy.data.objects[obj_name] # print('cur_obj name = '+cur_obj.name) for cond_ind, cond_str in enumerate(f['conditions']): # cond_str = str(cond_str) # if cond_str[1] == "'": # cond_str = cond_str[2:-1] cond_str = cond_str.astype(str) # Set the values to zeros in the first and last frame for current object(current label) mu.insert_keyframe_to_custom_prop(cur_obj, obj_name + '_' + cond_str, 0, 1) mu.insert_keyframe_to_custom_prop(cur_obj, obj_name + '_' + cond_str, 0, len(f['data'][0]) + 2) print('keyframing ' + obj_name + ' object') # For every time point insert keyframe to current object for ind, timepoint in enumerate(data[:, cond_ind]): # print('keyframing '+obj_name+' object') mu.insert_keyframe_to_custom_prop(cur_obj, obj_name + '_' + cond_str, timepoint, ind + 2) # remove the orange keyframe sign in the fcurves window fcurves = bpy.data.objects[obj_name].animation_data.action.fcurves[cond_ind] mod = fcurves.modifiers.new(type='LIMITS') conditions.extend(f['conditions']) try: bpy.ops.graph.previewrange_set() except: pass bpy.types.Scene.maximal_time_steps = number_of_maximal_time_steps for obj in bpy.data.objects: obj.select = False if bpy.data.objects.get(' '): bpy.context.scene.objects.active = bpy.data.objects[' '] selection_panel.set_conditions_enum(conditions) print('Finished keyframing!!')
def invoke(self, context, event=None): # self.current_root_path = bpy.path.abspath(bpy.context.scene.conf_path) parent_obj = bpy.data.objects['Deep_electrodes'] base_path = mu.get_user_fol() source_file = op.join(base_path, 'electrodes', 'electrodes_data_{}.npz'.format( 'avg' if bpy.context.scene.selection_type == 'conds' else 'diff')) if not op.isfile(source_file): source_file = op.join(base_path, 'electrodes', 'electrodes_data.npz') if not op.isfile(source_file): print('No electrodes data file!') else: print('Loading electordes data from {}'.format(source_file)) conditions = add_data_to_electrodes([source_file]) selection_panel.set_conditions_enum(conditions) add_data_to_electrodes_parent_obj(self, parent_obj, [source_file], STAT_DIFF) bpy.types.Scene.electrodes_data_exist = True if bpy.data.objects.get(' '): bpy.context.scene.objects.active = bpy.data.objects[' '] return {"FINISHED"}
def invoke(self, context, event=None): # self.current_root_path = bpy.path.abspath(bpy.context.scene.conf_path) parent_obj = bpy.data.objects['Deep_electrodes'] base_path = mu.get_user_fol() source_file = op.join( base_path, 'electrodes', 'electrodes{}_data_diff.npz'.format( '_bipolar' if bpy.context.scene.bipolar else '')) # 'avg' if bpy.context.scene.selection_type == 'conds' else 'diff')) meta_file = None if not op.isfile(source_file): source_file = op.join( base_path, 'electrodes', 'electrodes{}_data_{}_data.npy'.format( '_bipolar' if bpy.context.scene.bipolar else '', 'avg' if bpy.context.scene.selection_type == 'conds' else 'diff')) colors_file = op.join( base_path, 'electrodes', 'electrodes{}_data_{}_colors.npy'.format( '_bipolar' if bpy.context.scene.bipolar else '', 'avg' if bpy.context.scene.selection_type == 'conds' else 'diff')) meta_file = op.join( base_path, 'electrodes', 'electrodes{}_data_{}_meta.npz'.format( '_bipolar' if bpy.context.scene.bipolar else '', 'avg' if bpy.context.scene.selection_type == 'conds' else 'diff')) # source_file = op.join(base_path, 'electrodes', 'electrodes_data.npz') if not op.isfile(source_file): print('No electrodes data file!') else: print('Loading electordes data from {}'.format(source_file)) conditions = add_data_to_electrodes(source_file, meta_file) selection_panel.set_conditions_enum(conditions) add_data_to_electrodes_parent_obj(parent_obj, source_file, meta_file) bpy.types.Scene.electrodes_data_exist = True if bpy.data.objects.get(' '): bpy.context.scene.objects.active = bpy.data.objects[' '] return {"FINISHED"}
def load_conditions(): stim_fname = 'stim_electrodes_{}.npz'.format(bpy.context.scene.stim_files.replace(' ', '_')) stim_data_fname = op.join(mu.get_user_fol(), 'electrodes', stim_fname) stim_data = np.load(stim_data_fname) conditions = sorted(stim_data['conditions'], key=lambda x:int(x.split('-')[0])) selection_panel.set_conditions_enum(conditions)
def add_data_to_brain(base_path='', files_prefix='', objs_prefix=''): if base_path == '': base_path = mu.get_user_fol() source_files = [ op.join(base_path, '{}labels_data_lh.npz'.format(files_prefix)), op.join(base_path, '{}labels_data_rh.npz'.format(files_prefix)), op.join(base_path, '{}sub_cortical_activity.npz'.format(files_prefix)) ] print('Adding data to Brain') number_of_maximal_time_steps = -1 obj_counter = 0 conditions = [] for input_file in source_files: if not op.isfile(input_file): print('{} does not exist!'.format(input_file)) continue f = np.load(input_file) print('{} loaded'.format(input_file)) number_of_maximal_time_steps = max(number_of_maximal_time_steps, len(f['data'][0])) for obj_name, data in zip(f['names'], f['data']): # print('in label loop') obj_name = obj_name.astype(str) if not bpy.context.scene.import_unknown and 'unknown' in obj_name: continue # obj_name = '{}{}'.format(objs_prefix, obj_name) # print(obj_name) cur_obj = bpy.data.objects[obj_name] # print('cur_obj name = '+cur_obj.name) print('keyframing {}'.format(obj_name)) for cond_ind, cond_str in enumerate(f['conditions']): # cond_str = str(cond_str) # if cond_str[1] == "'": # cond_str = cond_str[2:-1] cond_str = cond_str.astype(str) # Set the values to zeros in the first and last frame for current object(current label) mu.insert_keyframe_to_custom_prop(cur_obj, obj_name + '_' + cond_str, 0, 1) mu.insert_keyframe_to_custom_prop(cur_obj, obj_name + '_' + cond_str, 0, len(f['data'][0]) + 2) # For every time point insert keyframe to current object for ind, timepoint in enumerate(data[:, cond_ind]): # print('keyframing '+obj_name+' object') mu.insert_keyframe_to_custom_prop( cur_obj, obj_name + '_' + cond_str, timepoint, ind + 2) # remove the orange keyframe sign in the fcurves window fcurves = bpy.data.objects[ obj_name].animation_data.action.fcurves[cond_ind] mod = fcurves.modifiers.new(type='LIMITS') conditions.extend(f['conditions']) try: bpy.ops.graph.previewrange_set() except: pass bpy.types.Scene.maximal_time_steps = number_of_maximal_time_steps for obj in bpy.data.objects: obj.select = False if bpy.data.objects.get(' '): bpy.context.scene.objects.active = bpy.data.objects[' '] selection_panel.set_conditions_enum(conditions) print('Finished keyframing!!')