def invoke(self, context, event=None): cmd = '{} -m src.preproc.anatomy_preproc -s {} -a {}'.format( bpy.context.scene.python_cmd, mu.get_user(), bpy.context.scene.atlas) print('Running {}'.format(cmd)) mu.run_command_in_new_thread(cmd, False) return {"FINISHED"}
def invoke(self, context, event=None): packetsender_cmd = StreamingPanel.config['packetsender'] ip = StreamingPanel.config['ip'] port = StreamingPanel.config['port'] num = StreamingPanel.config['num'] mu.run_command_in_new_thread('{} -a -u {} {} "stim {}"'.format(packetsender_cmd, ip, port, num), queues=False, shell=True, read_stdin=False, read_stdout=False, read_stderr=False) return {"FINISHED"}
def create_movie(): output_file = op.join(bpy.context.scene.output_path, 'combine_images_cmd.txt') if op.isfile(output_file): os.remove(output_file) cmd = '{} -m src.utils.movies_utils --fol {} --copy_files 1 --frame_rate {}'.format( bpy.context.scene.python_cmd, bpy.context.scene.output_path, bpy.context.scene.frames_num) print('Running {}'.format(cmd)) mu.run_command_in_new_thread(cmd, False)
def invoke(self, context, event=None): electrodes_pos_fname = op.join(mu.get_user_fol(), 'electrodes', 'electrodes{}_positions.npz'.format( '_bipolar' if bpy.context.scene.bipolar else '')) cmd = '{} -m src.preproc.freeview -s {} -a {} -b {} --electrodes_pos_fname {} --ignore_missing 1'.format( bpy.context.scene.python_cmd, mu.get_user(), bpy.context.scene.atlas, bpy.context.scene.bipolar, electrodes_pos_fname) mu.run_command_in_new_thread(cmd, False) bpy.context.scene.freeview_messages = 'Preparing...' return {"FINISHED"}
def run_hnn(): hnn_folder = op.abspath(bpy.path.abspath(bpy.context.scene.hnn_folder)) hnn_cmd = '{} -dataf {} -paramf {}'.format( op.join(hnn_folder, 'hnn.sh'), op.join(hnn_folder, 'data', '{}.txt'.format(bpy.context.scene.hnn_data_files)), op.join(hnn_folder, 'param', '{}.param'.format(bpy.context.scene.hnn_param_files))) mu.run_command_in_new_thread(hnn_cmd, False, cwd=hnn_folder)
def open_freeview(): root = mu.get_user_fol() sig_cmd = '' if bpy.context.scene.fMRI_files_exist and bpy.context.scene.freeview_load_fMRI: sig_fnames = glob.glob(op.join(root, 'freeview', '*{}*.mgz'.format(bpy.context.scene.fmri_files))) + \ glob.glob(op.join(root, 'freeview', '*{}*.nii'.format(bpy.context.scene.fmri_files))) if len(sig_fnames) > 0: sig_fname = sig_fnames[0] sig_cmd = '-v "{}":colormap=heat:heatscale=2,3,6 '.format( sig_fname) if op.isfile(sig_fname) else '' ct_cmd = '' if bpy.context.scene.freeview_load_CT: mmvt_ct_fname = op.join(root, 'ct', 'ct_reg_to_mr.mgz') if FreeviewPanel.CT_files_exist: ct_cmd = '-v "{}":opacity=0 '.format(mmvt_ct_fname) else: print("Can't find CT {}!".format(mmvt_ct_fname)) dura_cmd = '' if bpy.context.scene.freeview_load_dura: dura_fname = FreeviewPanel.dura_srf_fname if FreeviewPanel.dura_srf_exist: dura_cmd = '-f "{}":edgecolor=blue "{}":edgecolor=blue '.format( dura_fname.format(hemi='rh'), dura_fname.format(hemi='lh')) T1 = op.join(root, 'freeview', 'T1.mgz') # sometimes 'orig.mgz' is better if not op.isfile(T1): T1 = op.join(root, 'freeview', 'orig.mgz') if not op.isfile(T1): print( 'No T1 / orig files in freeview folder. Running preproc.freeview') bpy.context.scene.freeview_messages = 'Preparing... Try to run again' cmd = '{} -m src.preproc.freeview -s {} -a {} -b {} --ignore_missing 1'.format( bpy.context.scene.python_cmd, mu.get_user(), bpy.context.scene.atlas, bpy.context.scene.bipolar) mu.run_command_in_new_thread(cmd, False) return {'RUNNING_MODAL'} bpy.context.scene.freeview_messages = '' aseg = op.join(root, 'freeview', '{}+aseg.mgz'.format(bpy.context.scene.atlas)) if op.isfile(aseg): lut = op.join(root, 'freeview', '{}ColorLUT.txt'.format(bpy.context.scene.atlas)) aseg_cmd = '"{}":opacity=0.05:colormap=lut:lut="{}"'.format(aseg, lut) else: aseg_cmd = '' electrodes_cmd = get_electrodes_command(root) cmd = '{} "{}":opacity=0.5 {}{}{}{}{}{}{}'.format( FreeviewPanel.addon_prefs.freeview_cmd, T1, aseg_cmd, electrodes_cmd, sig_cmd, ct_cmd, dura_cmd, ' -verbose' if FreeviewPanel.addon_prefs.freeview_cmd_verbose else '', ' -stdin' if FreeviewPanel.addon_prefs.freeview_cmd_stdin else '') print(cmd) FreeviewPanel.freeview_in_queue, FreeviewPanel.freeview_out_queue = mu.run_command_in_new_thread( cmd ) #, read_stderr=reading_freeview_stderr_func, read_stdin=reading_freeview_stdin_func,
def grow_a_label(): closest_mesh_name, vertex_ind, _, _ = \ _addon().find_vertex_index_and_mesh_closest_to_cursor(use_shape_keys=True) hemi = closest_mesh_name[len('infalted_'):] if _addon().is_inflated( ) else closest_mesh_name subject, atlas = mu.get_user(), bpy.context.scene.subject_annot_files label_name, label_r = bpy.context.scene.new_label_name, bpy.context.scene.new_label_r cmd = '{} -m src.preproc.anatomy -s {} -a {} -f grow_label '.format( bpy.context.scene.python_cmd, subject, atlas) cmd += '--vertice_indice {} --hemi {} --label_name {} --label_r {}'.format( vertex_ind, hemi, label_name, label_r) mu.run_command_in_new_thread(cmd, False)
def invoke(self, context, event=None): self._time = time.time() self._obj = bpy.data.objects['LMF6'] if StreamingPanel.first_time: StreamingPanel.first_time = False context.window_manager.modal_handler_add(self) self._timer = context.window_manager.event_timer_add(0.01, context.window) StreamingPanel.is_streaming = not StreamingPanel.is_streaming print(__name__) script = 'src.mmvt_addon.streaming_panel' cmd = '{} -m {} -s {}'.format(bpy.context.scene.python_cmd, script) FreeviewPanel.freeview_in_queue, FreeviewPanel.freeview_out_queue mu.run_command_in_new_thread(cmd, queues=True) return {'RUNNING_MODAL'}
def render_image(image_name='', image_fol='', quality=0, use_square_samples=None, render_background=None): bpy.context.scene.render.resolution_percentage = bpy.context.scene.quality if quality == 0 else quality bpy.context.scene.cycles.use_square_samples = bpy.context.scene.smooth_figure if use_square_samples is None \ else use_square_samples if not render_background is None: bpy.context.scene.render_background = render_background # print('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@') print('use_square_samples: {}'.format(use_square_samples)) # print('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@') cur_frame = bpy.context.scene.frame_current if image_name == '': image_name = 't{}'.format(cur_frame) image_fol = bpy.path.abspath( bpy.context.scene.output_path) if image_fol == '' else image_fol print('file name: {}'.format(op.join(image_fol, image_name))) bpy.context.scene.render.filepath = op.join(image_fol, image_name) # Render and save the rendered scene to file. ------------------------------ print('Image quality:') print(bpy.context.scene.render.resolution_percentage) print("Rendering...") if not bpy.context.scene.render_background: bpy.ops.render.render(write_still=True) else: grab_camera() mu.change_fol_to_mmvt_root() electrode_marked = RenderingMakerPanel.addon.is_current_electrode_marked( ) script = 'src.mmvt_addon.scripts.render_image' cmd = '{} -m {} -s {} -a {} -q {} -b {} '.format( bpy.context.scene.python_cmd, script, mu.get_user(), bpy.context.scene.atlas, bpy.context.scene.render.resolution_percentage, bpy.context.scene.bipolar) + \ '--hide_lh {} --hide_rh {} --hide_subs {} --show_elecs {} --curr_elec {} --show_only_lead {} '.format( bpy.context.scene.objects_show_hide_lh, bpy.context.scene.objects_show_hide_rh, bpy.context.scene.objects_show_hide_sub_cortical, bpy.context.scene.appearance_show_electrodes_layer, bpy.context.scene.electrodes if electrode_marked else None, bpy.context.scene.show_only_lead if electrode_marked else None) + \ '--show_connections {}'.format( RenderingMakerPanel.addon.connections_visible()) print('Running {}'.format(cmd)) mu.save_blender_file() mu.run_command_in_new_thread(cmd, queues=False) print("Finished")
def combine_four_brain_perspectives(): data_min, data_max = _addon().get_colorbar_max_min() background = bpy.context.scene.background_color figure_name = 'splitted_lateral_medial_{}_{}.png'.format( 'inflated' if _addon().is_inflated() else 'pial', background) figure_fname = op.join(mu.get_user_fol(), 'figures', figure_name) colors_map = _addon().get_colormap_name().replace('-', '_') x_left_crop, x_right_crop, y_top_crop, y_buttom_crop = (300, 300, 0, 0) w_fac, h_fac = (1.5, 1) cmd = '{} -m src.utils.figures_utils '.format(bpy.context.scene.python_cmd) + \ '-f combine_four_brain_perspectives,combine_brain_with_color_bar --fol {} --data_max {} --data_min {} '.format( op.join(mu.get_user_fol(), 'figures'), data_max, data_min) + \ '--figure_fname {} --colors_map {} --x_left_crop {} --x_right_crop {} --y_top_crop {} --y_buttom_crop {} '.format( figure_fname, colors_map, x_left_crop, x_right_crop, y_top_crop, y_buttom_crop) + \ '--w_fac {} --h_fac {} --facecolor {}'.format(w_fac, h_fac, background) mu.run_command_in_new_thread(cmd, False)
def render_in_background(image_name, image_fol, camera_fname, hide_subcorticals, overwrite=True): hide_subs_in_background = True if hide_subcorticals else bpy.context.scene.objects_show_hide_sub_cortical mu.change_fol_to_mmvt_root() electrode_marked = _addon().is_current_electrode_marked() script = 'src.mmvt_addon.scripts.render_image' cmd = '{} -m {} -s {} -a {} -i {} -o {} -q {} -b {} -c "{}"'.format( bpy.context.scene.python_cmd, script, mu.get_user(), bpy.context.scene.atlas, image_name, image_fol, bpy.context.scene.render.resolution_percentage, bpy.context.scene.bipolar, camera_fname) + \ ' --hide_lh {} --hide_rh {} --hide_subs {} --show_elecs {} --curr_elec {} --show_only_lead {}'.format( bpy.context.scene.objects_show_hide_lh, bpy.context.scene.objects_show_hide_rh, hide_subs_in_background, bpy.context.scene.show_hide_electrodes, bpy.context.scene.electrodes if electrode_marked else None, bpy.context.scene.show_only_lead if electrode_marked else None) + \ ' --show_connections {} --interactive 0 --overwrite {}'.format( _addon().connections_visible(), overwrite) print('Running {}'.format(cmd)) RenderingMakerPanel.background_rendering = True mu.save_blender_file() _, RenderingMakerPanel.render_in_queue = mu.run_command_in_new_thread( cmd, read_stderr=False, read_stdin=False, stdout_func=reading_from_rendering_stdout_func)
def invoke(self, context, event=None): root = mu.get_user_fol() if bpy.context.scene.fMRI_files_exist and bpy.context.scene.freeview_load_fMRI: sig_fnames = glob.glob( op.join(root, 'freeview', '*{}*.mgz'.format(bpy.context.scene.fmri_files))) if len(sig_fnames) > 0: sig_fname = sig_fnames[0] sig_cmd = '-v "{}":colormap=heat:heatscale=2,3,6'.format( sig_fname) if op.isfile(sig_fname) else '' else: sig_cmd = '' else: sig_cmd = '' T1 = op.join(root, 'freeview', 'T1.mgz') # sometimes 'orig.mgz' is better aseg = op.join(root, 'freeview', '{}+aseg.mgz'.format(bpy.context.scene.atlas)) lut = op.join(root, 'freeview', '{}ColorLUT.txt'.format(bpy.context.scene.atlas)) electrodes_cmd = self.get_electrodes_command(root) cmd = '{} {} "{}":opacity=0.3 "{}":opacity=0.05:colormap=lut:lut="{}"{}{}{}'.format( FreeviewPanel.addon_prefs.freeview_cmd, sig_cmd, T1, aseg, lut, electrodes_cmd, ' -verbose' if FreeviewPanel.addon_prefs.freeview_cmd_verbose else '', ' -stdin' if FreeviewPanel.addon_prefs.freeview_cmd_stdin else '') print(cmd) FreeviewPanel.freeview_in_queue, FreeviewPanel.freeview_out_queue = mu.run_command_in_new_thread( cmd) context.window_manager.modal_handler_add(self) self._updating = False self._timer = context.window_manager.event_timer_add( 0.1, context.window) return {'RUNNING_MODAL'}
def invoke(self, context, event=None): root = mu.get_user_fol() if bpy.context.scene.fMRI_files_exist and bpy.context.scene.freeview_load_fMRI: sig_fnames = glob.glob(op.join(root, 'freeview', '*{}*.mgz'.format(bpy.context.scene.fmri_files))) + \ glob.glob(op.join(root, 'freeview', '*{}*.nii'.format(bpy.context.scene.fmri_files))) if len(sig_fnames) > 0: sig_fname = sig_fnames[0] sig_cmd = '-v "{}":colormap=heat:heatscale=2,3,6'.format(sig_fname) if op.isfile(sig_fname) else '' else: sig_cmd = '' else: sig_cmd = '' T1 = op.join(root, 'freeview', 'T1.mgz') # sometimes 'orig.mgz' is better aseg = op.join(root, 'freeview', '{}+aseg.mgz'.format(bpy.context.scene.atlas)) lut = op.join(root, 'freeview', '{}ColorLUT.txt'.format(bpy.context.scene.atlas)) electrodes_cmd = self.get_electrodes_command(root) cmd = '{} {} "{}":opacity=0.3 "{}":opacity=0.05:colormap=lut:lut="{}"{}{}{}'.format( FreeviewPanel.addon_prefs.freeview_cmd, sig_cmd, T1, aseg, lut, electrodes_cmd, ' -verbose' if FreeviewPanel.addon_prefs.freeview_cmd_verbose else '', ' -stdin' if FreeviewPanel.addon_prefs.freeview_cmd_stdin else '') print(cmd) FreeviewPanel.freeview_in_queue, FreeviewPanel.freeview_out_queue = mu.run_command_in_new_thread(cmd) context.window_manager.modal_handler_add(self) self._updating = False self._timer = context.window_manager.event_timer_add(0.1, context.window) return {'RUNNING_MODAL'}
def load_surf_files(nii_fname): fmri_file_template = '' user_fol = mu.get_user_fol() nii_fol = mu.get_fname_folder(nii_fname) fmri_hemis = mu.get_both_hemis_files(nii_fname) hemi = mu.get_hemi_from_full_fname(nii_fname) local_fname = build_local_fname(nii_fname, user_fol) mu.make_dir(op.join(user_fol, 'fmri')) if nii_fol != op.join(user_fol, 'fmri'): mu.make_link(nii_fname, local_fname, True) other_hemi = mu.other_hemi(hemi) other_hemi_fname = fmri_hemis[other_hemi] if op.isfile(other_hemi_fname): local_other_hemi_fname = build_local_fname(other_hemi_fname, user_fol) if nii_fol != op.join(user_fol, 'fmri'): mu.make_link(other_hemi_fname, local_other_hemi_fname, True) fmri_file_template = mu.get_template_hemi_label_name(mu.namesbase_with_ext(local_fname)) cmd = '{} -m src.preproc.fMRI -s {} -f load_surf_files --fmri_file_template "{}"'.format( bpy.context.scene.python_cmd, mu.get_user(), fmri_file_template) mu.run_command_in_new_thread(cmd, False) return fmri_file_template, hemi
def render_image(image_name='', image_fol='', quality=0, use_square_samples=None, render_background=None): bpy.context.scene.render.resolution_percentage = bpy.context.scene.quality if quality == 0 else quality bpy.context.scene.cycles.use_square_samples = bpy.context.scene.smooth_figure if use_square_samples is None \ else use_square_samples if not render_background is None: bpy.context.scene.render_background = render_background # print('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@') print('use_square_samples: {}'.format(use_square_samples)) # print('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@') cur_frame = bpy.context.scene.frame_current if image_name == '': image_name = 't{}'.format(cur_frame) image_fol = bpy.path.abspath(bpy.context.scene.output_path) if image_fol == '' else image_fol print('file name: {}'.format(op.join(image_fol, image_name))) bpy.context.scene.render.filepath = op.join(image_fol, image_name) # Render and save the rendered scene to file. ------------------------------ print('Image quality:') print(bpy.context.scene.render.resolution_percentage) print("Rendering...") if not bpy.context.scene.render_background: bpy.ops.render.render(write_still=True) else: mu.change_fol_to_mmvt_root() electrode_marked = RenderingMakerPanel.addon.is_current_electrode_marked() script = 'src.mmvt_addon.scripts.render_image' cmd = '{} -m {} -s {} -a {} -q {} -b {} --hide_lh {} --hide_rh {} --hide_subs {} --show_elecs {} --curr_elec {} --show_only_lead {}'.format( bpy.context.scene.python_cmd, script, mu.get_user(), bpy.context.scene.atlas, bpy.context.scene.render.resolution_percentage, bpy.context.scene.bipolar, bpy.context.scene.objects_show_hide_lh, bpy.context.scene.objects_show_hide_rh, bpy.context.scene.objects_show_hide_sub_cortical, bpy.context.scene.appearance_show_electrodes_layer, bpy.context.scene.electrodes if electrode_marked else None, bpy.context.scene.show_only_lead if electrode_marked else None) print('Running {}'.format(cmd)) mu.save_blender_file() mu.run_command_in_new_thread(cmd, queues=False) print("Finished")
def invoke(self, context, event=None): subject = mu.get_user() threshold = bpy.context.scene.fmri_clustering_threshold contrast = bpy.context.scene.fmri_clusters_labels_files atlas = bpy.context.scene.atlas task = contrast.split('_')[0] context.window_manager.modal_handler_add(self) self._timer = context.window_manager.event_timer_add(0.1, context.window) mu.change_fol_to_mmvt_root() cmd = '{} -m src.preproc.fMRI_preproc -s {} -T {} -c {} -t {} -a {} -f find_clusters'.format( bpy.context.scene.python_cmd, subject, task, contrast, threshold, atlas) print('Running {}'.format(cmd)) self.in_q, self.out_q = mu.run_command_in_new_thread(cmd) return {'RUNNING_MODAL'}
def invoke(self, context, event=None): self._time = time.time() self._obj = bpy.data.objects['LMF6'] if StreamingPanel.first_time: StreamingPanel.first_time = False context.window_manager.modal_handler_add(self) self._timer = context.window_manager.event_timer_add(0.01, context.window) # script = op.join(mu.get_mmvt_code_root(), 'src', 'misc', 'udp_listener.py') script = 'src.misc.udp_listener' cmd = '{} -m {}'.format(bpy.context.scene.python_cmd, script) StreamingPanel.in_queue, StreamingPanel.out_queue = mu.run_command_in_new_thread(cmd, queues=True) StreamingPanel.is_streaming = not StreamingPanel.is_streaming return {'RUNNING_MODAL'}
def color_manually(): ColoringMakerPanel.what_is_colored.add(WIC_MANUALLY) init_activity_map_coloring('FMRI') subject_fol = mu.get_user_fol() objects_names, colors, data = defaultdict(list), defaultdict(list), defaultdict(list) for line in mu.csv_file_reader(op.join(subject_fol, 'coloring', '{}.csv'.format(bpy.context.scene.coloring_files))): obj_name, color_name = line[0], line[1:] if obj_name[0] == '#': continue if isinstance(color_name, list) and len(color_name) == 1: color_name = color_name[0] obj_type = mu.check_obj_type(obj_name) if isinstance(color_name, str) and color_name.startswith('mark'): import filter_panel filter_panel.filter_roi_func(obj_name, mark=color_name) else: if isinstance(color_name, str): color_rgb = cu.name_to_rgb(color_name) # Check if the color is already in RBG elif len(color_name) == 3: color_rgb = color_name else: print('Unrecognize color! ({})'.format(color_name)) continue color_rgb = list(map(float, color_rgb)) if obj_type is not None: objects_names[obj_type].append(obj_name) colors[obj_type].append(color_rgb) data[obj_type].append(1.) color_objects(objects_names, colors, data) if op.isfile(op.join(subject_fol, 'coloring', '{}_legend.jpg'.format(bpy.context.scene.coloring_files))): cmd = '{} -m src.preproc.electrodes_preproc -s {} -a {} -f show_labeling_coloring'.format( bpy.context.scene.python_cmd, mu.get_user(), bpy.context.scene.atlas) print('Running {}'.format(cmd)) mu.run_command_in_new_thread(cmd, False)
def start_slicer_server(): cmd = '{} -m src.listeners.slicer_listener'.format(bpy.context.scene.python_cmd) mu.run_command_in_new_thread(cmd, False)
def start_listener(): cmd = 'python {}'.format( op.join(mmvt_utils.current_path(), 'addon_listener.py')) listener_in_queue, listener_out_queue = mmvt_utils.run_command_in_new_thread( cmd) return listener_in_queue, listener_out_queue
def start_listener(): cmd = 'python {}'.format(op.join(mmvt_utils.current_path(), 'addon_listener.py')) listener_in_queue, listener_out_queue = mmvt_utils.run_command_in_new_thread(cmd) return listener_in_queue, listener_out_queue