def run(self, args, extra_args): if args.items: items = [] for path in args.items: items.append(os.path.realpath(path)) data = SimpleDataInfo.from_paths(items) else: data = SimpleDataInfo.from_paths([os.getcwd()]) to_file = None if args.to_file: to_file = os.path.realpath(args.to_file) config = None if args.config: filename = os.path.realpath(args.config) if os.path.exists(filename): with open(filename, 'r') as f: config = f.read() figure_options = {} if to_file: if args.width: figure_options.update({'width': args.width}) if args.height: figure_options.update({'height': args.height}) if args.dpi: figure_options.update({'dpi': args.dpi}) view_maps(data, config, figure_options=figure_options, save_filename=to_file) else: view_maps(data, config, show_maximized=args.maximize)
def check_registration(): map_configs = '' maps = {} particularly_bad_subjects = [ 'mgh_1002', 'mgh_1004', 'mgh_1008', 'mgh_1009', 'mgh_1012', 'mgh_1013', 'mgh_1015', 'mgh_1017', 'mgh_1021', 'mgh_1022', 'mgh_1032' ] for subject in os.listdir(output_pjoin()): # for subject in particularly_bad_subjects: point_map = mdt.load_nifti( output_pjoin(subject, 'warped_BinghamNODDI_r1_w_in0.w')).get_data() std_map = mdt.load_nifti( output_pjoin(subject, 'warped_BinghamNODDI_r1_w_in0.w.std')).get_data() maps[subject + '.std'] = std_map maps[subject] = point_map map_configs += ''' {0}: scale: {{use_max: true, use_min: true, vmax: 0.8, vmin: 0.0}} {0}.std: scale: {{use_max: true, use_min: true, vmax: 0.1, vmin: 0.0}} '''.format(subject) config = ''' colorbar_settings: location: right nmr_ticks: 4 power_limits: [-3, 4] round_precision: 3 visible: false grid_layout: - Rectangular - cols: null rows: 4 spacings: {bottom: 0.03, hspace: 0.15, left: 0.1, right: 0.86, top: 0.97, wspace: 0.4} slice_index: 90 zoom: p0: {x: 16, y: 14} p1: {x: 161, y: 200} colormap_masked_color: 'k' ''' if map_configs: config += ''' map_plot_options: ''' + map_configs + ''' ''' config += ''' maps_to_show: [''' + ', '.join(sorted(maps)) + '''] ''' mdt.view_maps(maps, config=config)
def run(self, args): if args.dir: data = DataInfo.from_dir(os.path.realpath(args.dir)) else: data = DataInfo.from_dir(os.getcwd()) to_file = None if args.to_file: to_file = os.path.realpath(args.to_file) config = None if args.config: filename = os.path.realpath(args.config) if os.path.exists(filename): with open(filename, 'r') as f: config = f.read() view_maps(data, config, show_maximized=args.maximize, to_file=to_file)
def check_registration(): map_configs = '' maps = {} for subject in os.listdir(output_pjoin()): fa_map = mdt.load_nifti(output_pjoin(subject, 'warped_Tensor_Tensor.FA')).get_data() maps[subject] = fa_map map_configs += ''' {}: scale: {{use_max: true, use_min: true, vmax: 0.5, vmin: 0.0}} '''.format(subject) config = ''' colorbar_settings: location: right nmr_ticks: 4 power_limits: [-3, 4] round_precision: 3 visible: false grid_layout: - Rectangular - cols: null rows: 4 spacings: {bottom: 0.03, hspace: 0.15, left: 0.1, right: 0.86, top: 0.97, wspace: 0.4} slice_index: 90 zoom: p0: {x: 16, y: 14} p1: {x: 161, y: 200} colormap_masked_color: 'k' ''' config += ''' map_plot_options: ''' + map_configs + ''' maps_to_show: [''' + ', '.join(sorted(maps)) + '''] ''' mdt.view_maps(maps, config=config)
def plot_maps(dataset_name, model_name, voxel_volume_ind, maps, out_name): scales = {'point_vmin': 0, 'point_vmax': 1, 'std_vmin': 0, 'std_vmax': 0.04} if model_name == 'Tensor': scales['std_vmax'] = 0.15 maps['diff'] = np.abs(maps['mcmc'] - maps['mle']) plot_config = dedent(''' font: {{family: sans-serif, size: 20}} maps_to_show: [mle, mle_std, mcmc, mcmc_std] map_plot_options: mle: title: FR (MLE) scale: {{use_max: true, use_min: true, vmax: {point_vmax}, vmin: {point_vmin}}} colorbar_settings: {{round_precision: 2}} mle_std: title: FR std. (MLE) scale: {{use_max: true, use_min: true, vmax: {std_vmax}, vmin: {std_vmin}}} colorbar_settings: {{round_precision: 3}} mcmc: title: FR (MCMC) scale: {{use_max: true, use_min: true, vmax: {point_vmax}, vmin: {point_vmin}}} colorbar_settings: {{round_precision: 2}} mcmc_std: title: FR std. (MCMC) scale: {{use_max: true, use_min: true, vmax: {std_vmax}, vmin: {std_vmin}}} colorbar_settings: {{round_precision: 3}} '''.format(map_title=map_titles[model_name], **scales)) if dataset_name == 'mgh': plot_config += ''' rotate: 270 zoom: p0: {x: 19, y: 17} p1: {x: 117, y: 128} ''' else: plot_config += dedent(''' annotations: - arrow_width: 0.6 font_size: 14 marker_size: 3.0 text_distance: 0.05 text_location: top left text_template: '{value:.3f}' voxel_index: [''' + ', '.join(map(str, voxel_volume_ind)) + '''] colorbar_settings: location: right nmr_ticks: 4 power_limits: [-3, 4] round_precision: 2 visible: true grid_layout: - Rectangular - cols: null rows: null spacings: {bottom: 0.03, hspace: 0.0, left: 0.1, right: 0.86, top: 0.97, wspace: 0.5} zoom: p0: {x: 19, y: 6} p1: {x: 87, y: 97} title_spacing: 0.03 ''') mdt.view_maps( maps, save_filename=out_name, figure_options={'width': 520, 'dpi': 80}, config=plot_config)
mdt.view_maps(maps, config=''' colorbar_settings: location: right nmr_ticks: 4 power_limits: [-3, 4] round_precision: 3 visible: false colormap_masked_color: k font: {family: sans-serif, size: 21} grid_layout: - Rectangular - cols: 2 rows: null spacings: {bottom: 0.03, hspace: 0.1, left: 0.1, right: 0.86, top: 0.97, wspace: 0.1} map_plot_options: mgh_1005: colorbar_settings: {location: bottom, nmr_ticks: 3, power_limits: null, round_precision: null, visible: true} scale: {use_max: true, use_min: true, vmax: 0.9, vmin: 0.1} title: ' ' mgh_1005.std: colorbar_settings: {location: bottom, nmr_ticks: 3, power_limits: null, round_precision: null, visible: true} clipping: {use_max: true, use_min: true, vmax: 0.045, vmin: 0.0} scale: {use_max: true, use_min: true, vmax: 0.05, vmin: 0.0} title: ' ' mgh_1016: colorbar_settings: {location: bottom, nmr_ticks: 3, power_limits: null, round_precision: null, visible: false} scale: {use_max: true, use_min: true, vmax: 0.9, vmin: 0.1} title: ' ' mgh_1016.std: clipping: {use_max: true, use_min: true, vmax: 0.04, vmin: 0.0} colorbar_settings: {location: bottom, nmr_ticks: 3, power_limits: null, round_precision: null, visible: false} scale: {use_max: true, use_min: true, vmax: 0.05, vmin: 0.0} title: ' ' mgh_1017: scale: {use_max: true, use_min: true, vmax: 0.9, vmin: 0.1} title: Mean mgh_1017.std: clipping: {use_max: true, use_min: true, vmax: 0.045, vmin: 0.0} scale: {use_max: true, use_min: true, vmax: 0.05, vmin: 0.0} title: std. maps_to_show: [mgh_1017, mgh_1017.std, mgh_1016, mgh_1016.std, mgh_1005, mgh_1005.std] slice_index: 90 zoom: p0: {x: 23, y: 25} p1: {x: 155, y: 191} ''')
mdt.view_maps( all_maps, # save_filename='/tmp/uncertainty_paper/bingham_noddi.png', config=''' annotations: - arrow_width: 1.0 font_size: null marker_size: 3.0 text_distance: 0.08 text_location: upper left text_template: '{value:.2g}' voxel_index: [60, 149, 90] colorbar_settings: location: right nmr_ticks: 4 power_limits: [-3, 4] round_precision: 3 visible: true colormap: hot colormap_masked_color: k dimension: 2 flipud: false font: {family: sans-serif, size: 21} grid_layout: - Rectangular - cols: null rows: 3 spacings: {bottom: 0.03, hspace: 0.23, left: 0.1, right: 0.86, top: 0.97, wspace: 0} interpolation: bilinear map_plot_options: point_diff_BinghamNODDI_r1: clipping: {use_max: false, use_min: false, vmax: 0.0, vmin: 0.0} colorbar_label: null colorbar_settings: {location: bottom, nmr_ticks: 3, power_limits: null, round_precision: null, visible: null} colormap: BrBG_r colormap_masked_color: null colormap_order: null colormap_weight_map: null interpret_as_colormap: false mask_name: null scale: {use_max: true, use_min: true, vmax: 10.0, vmin: -10.0} show_title: null title: '% difference mean' title_spacing: null regular_BinghamNODDI_r1_w_in0.w: clipping: {use_max: false, use_min: false, vmax: 0.0, vmin: 0.0} colorbar_label: null colorbar_settings: {location: null, nmr_ticks: null, power_limits: null, round_precision: null, visible: false} colormap: null colormap_masked_color: null colormap_order: null colormap_weight_map: null interpret_as_colormap: false mask_name: null scale: {use_max: true, use_min: true, vmax: 0.8, vmin: 0.2} show_title: null title: Regular mean title_spacing: null regular_BinghamNODDI_r1_w_in0.w.std: clipping: {use_max: false, use_min: false, vmax: 0.0, vmin: 0.0} colorbar_label: null colorbar_settings: {location: null, nmr_ticks: null, power_limits: null, round_precision: null, visible: false} colormap: null colormap_masked_color: null colormap_order: null colormap_weight_map: null interpret_as_colormap: false mask_name: null scale: {use_max: true, use_min: true, vmax: 0.15, vmin: 0.0} show_title: null title: Regular std. title_spacing: null std_diff_BinghamNODDI_r1: clipping: {use_max: false, use_min: false, vmax: 0.0, vmin: 0.0} colorbar_label: null colorbar_settings: {location: bottom, nmr_ticks: 3, power_limits: null, round_precision: null, visible: null} colormap: BrBG_r colormap_masked_color: null colormap_order: null colormap_weight_map: null interpret_as_colormap: false mask_name: null scale: {use_max: true, use_min: true, vmax: 20.0, vmin: -20.0} show_title: null title: '% difference std.' title_spacing: null weighted_BinghamNODDI_r1_w_in0.w: clipping: {use_max: false, use_min: false, vmax: 0.0, vmin: 0.0} colorbar_label: null colorbar_settings: {location: bottom, nmr_ticks: 3, power_limits: null, round_precision: null, visible: null} colormap: null colormap_masked_color: null colormap_order: null colormap_weight_map: null interpret_as_colormap: false mask_name: null scale: {use_max: true, use_min: true, vmax: 0.8, vmin: 0.2} show_title: null title: Weighted mean title_spacing: null weighted_BinghamNODDI_r1_w_in0.w.std: clipping: {use_max: false, use_min: false, vmax: 0.0, vmin: 0.0} colorbar_label: null colorbar_settings: {location: bottom, nmr_ticks: 3, power_limits: null, round_precision: null, visible: null} colormap: null colormap_masked_color: null colormap_order: null colormap_weight_map: null interpret_as_colormap: false mask_name: null scale: {use_max: true, use_min: true, vmax: 0.15, vmin: 0.0} show_title: null title: Weighted std. title_spacing: null maps_to_show: [regular_BinghamNODDI_r1_w_in0.w, regular_BinghamNODDI_r1_w_in0.w.std, weighted_BinghamNODDI_r1_w_in0.w, weighted_BinghamNODDI_r1_w_in0.w.std, point_diff_BinghamNODDI_r1, std_diff_BinghamNODDI_r1] mask_name: null rotate: 90 show_axis: false show_titles: true slice_index: 90 title: null title_spacing: null volume_index: 0 zoom: p0: {x: 22, y: 24} p1: {x: 156, y: 192} ''')
mdt.view_maps(results['mgh'], config=''' annotations: [] colorbar_settings: {location: null, nmr_ticks: 3, power_limits: null, round_precision: null, visible: null} colormap: hot colormap_masked_color: null dimension: 2 flipud: false font: {family: sans-serif, size: 20} grid_layout: - Rectangular - cols: null rows: 2 spacings: {bottom: 0.03, hspace: 0.2, left: 0.01, right: 0.92, top: 0.94, wspace: 0.5} interpolation: bilinear map_plot_options: BallStick_r1: clipping: {use_max: false, use_min: false, vmax: 0.0, vmin: 0.0} colorbar_label: null colorbar_settings: {location: null, nmr_ticks: null, power_limits: null, round_precision: null, visible: false} colormap: null colormap_masked_color: null colormap_order: null colormap_weight_map: null interpret_as_colormap: false mask_name: null scale: {use_max: true, use_min: true, vmax: 0.03, vmin: 0.0} show_title: null title: 'BallStick_in1 - Stick0.w (std.)' title_spacing: null BallStick_r2: clipping: {use_max: false, use_min: false, vmax: 0.0, vmin: 0.0} colorbar_label: null colorbar_settings: {location: null, nmr_ticks: null, power_limits: null, round_precision: null, visible: false} colormap: null colormap_masked_color: null colormap_order: null colormap_weight_map: null interpret_as_colormap: false mask_name: null scale: {use_max: true, use_min: true, vmax: 0.03, vmin: 0.0} show_title: null title: 'BallStick_in2 - Stick0.w (std.)' title_spacing: null BallStick_r3: clipping: {use_max: true, use_min: true, vmax: 0.028, vmin: 0.0} colorbar_label: null colorbar_settings: location: null nmr_ticks: null power_limits: [-2, 5] round_precision: null visible: null colormap: null colormap_masked_color: null colormap_order: null colormap_weight_map: null interpret_as_colormap: false mask_name: null scale: {use_max: true, use_min: true, vmax: 0.03, vmin: 0.0} show_title: null title: 'BallStick_in3 - Stick0.w (std.)' title_spacing: null BinghamNODDI_r1: clipping: {use_max: false, use_min: false, vmax: 0.0, vmin: 0.0} colorbar_label: null colorbar_settings: location: null nmr_ticks: null power_limits: [-2, 5] round_precision: null visible: null colormap: null colormap_masked_color: null colormap_order: null colormap_weight_map: null interpret_as_colormap: false mask_name: null scale: {use_max: true, use_min: true, vmax: 0.04, vmin: 0.0} show_title: null title: 'Bingham-NODDI - FR (std.)' title_spacing: null CHARMED_r1: clipping: {use_max: false, use_min: false, vmax: 0.0, vmin: 0.0} colorbar_label: null colorbar_settings: location: null nmr_ticks: null power_limits: [-2, 5] round_precision: null visible: null colormap: null colormap_masked_color: null colormap_order: null colormap_weight_map: null interpret_as_colormap: false mask_name: null scale: {use_max: true, use_min: true, vmax: 0.04, vmin: 0.0} show_title: null title: 'CHARMED_in1 - FR (std.)' title_spacing: null NODDI: clipping: {use_max: false, use_min: false, vmax: 0.0, vmin: 0.0} colorbar_label: null colorbar_settings: {location: null, nmr_ticks: null, power_limits: null, round_precision: null, visible: false} colormap: null colormap_masked_color: null colormap_order: null colormap_weight_map: null interpret_as_colormap: false mask_name: null scale: {use_max: true, use_min: true, vmax: 0.04, vmin: 0.0} show_title: null title: 'NODDI (FR)' title_spacing: null Tensor: clipping: {use_max: false, use_min: false, vmax: 0.0, vmin: 0.0} colorbar_label: null colorbar_settings: {location: null, nmr_ticks: null, power_limits: null, round_precision: null, visible: null} colormap: null colormap_masked_color: null colormap_order: null colormap_weight_map: null interpret_as_colormap: false mask_name: null scale: {use_max: true, use_min: true, vmax: 0.12, vmin: 0.0} show_title: null title: 'Tensor - FA (std.)' title_spacing: null inverse_snr: clipping: {use_max: false, use_min: false, vmax: 0.0, vmin: 0.0} colorbar_label: null colorbar_settings: {location: null, nmr_ticks: null, power_limits: null, round_precision: null, visible: null} colormap: null colormap_masked_color: null colormap_order: null colormap_weight_map: null interpret_as_colormap: false mask_name: null scale: {use_max: true, use_min: true, vmax: 0.15, vmin: 0.0} show_title: null title: 1 / SNR title_spacing: null snr: clipping: {use_max: false, use_min: false, vmax: 0.0, vmin: 0.0} colorbar_label: null colorbar_settings: {location: null, nmr_ticks: null, power_limits: null, round_precision: null, visible: null} colormap: null colormap_masked_color: null colormap_order: null colormap_weight_map: null interpret_as_colormap: false mask_name: null scale: {use_max: true, use_min: true, vmax: 30.0, vmin: 0.0} show_title: null title: SNR title_spacing: null maps_to_show: [snr, BallStick_r1, BallStick_r2, BallStick_r3, inverse_snr, BinghamNODDI_r1, CHARMED_r1, Tensor] mask_name: null rotate: 270 show_axis: false show_titles: true slice_index: 0 title: null title_spacing: 0.03 volume_index: 0 zoom: p0: {x: 19, y: 17} p1: {x: 117, y: 128} ''')