def init(addon, addon_prefs=None): FreeviewPanel.addon = addon # print('freeview command: {}'.format(addon_prefs.freeview_cmd)) # print('Use -verbose? {}'.format(addon_prefs.freeview_cmd_verbose)) # print('Use -stdin? {}'.format(addon_prefs.freeview_cmd_stdin)) FreeviewPanel.addon_prefs = addon_prefs bpy.context.scene.freeview_load_electrodes = False bpy.context.scene.freeview_listen_to_keyboard = False bpy.context.scene.freeview_listener_is_running = False bpy.context.scene.fMRI_files_exist = len( glob.glob(op.join(mu.get_user_fol(), 'fmri', '*_lh.npy'))) > 0 #mu.hemi_files_exists(op.join(mu.get_user_fol(), 'fmri_{hemi}.npy')) bpy.context.scene.electrodes_exist = bpy.data.objects.get( 'Deep_electrodes', None) is not None if bpy.context.scene.electrodes_exist: FreeviewPanel.electrodes_groups = set([ mu.elec_group(obj.name, bpy.context.scene.bipolar) for obj in bpy.data.objects['Deep_electrodes'].children ]) else: FreeviewPanel.electrodes_groups = [] bpy.context.scene.freeview_messages = '' root = mu.get_user_fol() mmvt_ct_fname = op.join(root, 'ct', 'ct_reg_to_mr.mgz') # if not op.isfile(mmvt_ct_fname): # subjects_ct_fname = op.join(mu.get_subjects_dir(), mu.get_user(), 'mri', 'ct_nas.nii.gz') # if op.isfile(subjects_ct_fname): # shutil.copy(subjects_ct_fname, mmvt_ct_fname) FreeviewPanel.CT_files_exist = op.isfile(mmvt_ct_fname) if mu.both_hemi_files_exist( op.join(mu.get_subjects_dir(), mu.get_user(), 'surf', '{hemi}.dural')): FreeviewPanel.dura_srf_exist = True FreeviewPanel.dura_srf_fname = op.join(mu.get_subjects_dir(), mu.get_user(), 'surf', '{hemi}.dural') elif mu.both_hemi_files_exist( op.join(mu.get_user_fol(), 'surf', '{hemi}.dural')): FreeviewPanel.dura_srf_exist = True FreeviewPanel.dura_srf_fname = op.join(mu.get_user_fol(), mu.get_user(), 'surf', '{hemi}.dural') else: FreeviewPanel.dura_srf_exist = False FreeviewPanel.init = True FreeviewPanel.freeview_is_open = False register()
def modal(self, context, event): if event.type == 'TIMER' and ChooseNiftiiFile.running: if mu.both_hemi_files_exist(op.join(mu.get_user_fol(), 'fmri', self.fmri_file_template)): _addon().plot_fmri_file(self.fmri_file_template) clean_nii_temp_files(self.fmri_file_template) ChooseNiftiiFile.running = False bpy.context.scene.nii_label_output = '' self.cancel(context) return {'PASS_THROUGH'}
def subject_annot_files_update(self, context): d = {} user_fol = mu.get_user_fol() contours_template = op.join(user_fol, 'labels', '{}_contours_{}.npz'.format( bpy.context.scene.subject_annot_files, '{hemi}')) if mu.both_hemi_files_exist(contours_template): for hemi in mu.HEMIS: d[hemi] = np.load(contours_template.format(hemi=hemi)) WhereAmIPanel.labels_contours = d else: WhereAmIPanel.labels_contours = None