def run_faulthandler(): try: import faulthandler logs = op.join(mmvt_utils.get_user_fol(), 'logs') mmvt_utils.make_dir(logs) fault_handler = open(op.join(logs, 'faulthandler_{}.txt'.format(mmvt_utils.rand_letters(5))), 'w') faulthandler.enable(fault_handler) except: print('Cannot create faulthandler log!') mmvt_utils.print_last_error_line()
def slices_update(self, context): if not SlicerPanel.init: return try: clim = (bpy.context.scene.slices_x_min, bpy.context.scene.slices_x_max) if _addon().get_slicer_state( bpy.context.scene.slices_modality) is not None: _addon().create_slices( modality=bpy.context.scene.slices_modality, zoom_around_voxel=bpy.context.scene.slices_zoom_around_voxel, zoom_voxels_num=bpy.context.scene.slices_zoom_voxels_num, smooth=bpy.context.scene.slices_zoom_interpolate, clim=clim, plot_cross=bpy.context.scene.slices_plot_cross, mark_voxel=bpy.context.scene.slices_mark_voxel) except: mu.print_last_error_line()
def load_labels_contours(atlas=''): labels_contours = {} if atlas == '': atlas = bpy.context.scene.contours_coloring for hemi in mu.HEMIS: fnames = glob.glob( op.join(mu.get_user_fol(), 'labels', '{}*contours*{}.npz'.format(atlas, hemi))) if len(fnames) == 0: print('No contour was found for {} {}'.format(atlas, hemi)) continue labels_contours[hemi] = np.load(fnames[0]) try: if len(np.where(labels_contours[hemi]['contours'])[0]) == 0: print('No contours in {} {}!'.format(atlas, hemi)) except: print('Error in loading contours!') mu.print_last_error_line() return labels_contours
def check_script(script_name, return_all=False): try: lib = importlib.import_module(script_name) importlib.reload(lib) run_func = getattr(lib, 'run') func_signature = inspect.signature(run_func) if len(func_signature.parameters) >= 1: init_func = get_func(lib, 'init') draw_func = get_func(lib, 'draw') ScriptsPanel.funcs[script_name] = (run_func, init_func, draw_func, func_signature.parameters) ScriptsPanel.libs[script_name] = lib if return_all: return lib, ScriptsPanel.funcs[script_name] else: return True else: return None if return_all else False except: if script_name != '__init__': print('Problem with loading {}!'.format(script_name)) mu.print_last_error_line() return None if return_all else False