def main(): parser = _build_arg_parser() args = parser.parse_args() if args.verbose: logging.basicConfig(level=logging.INFO) assert_gradients_filenames_valid(parser, args.mrtrix_enc, 'mrtrix') assert_gradients_filenames_valid(parser, [args.fsl_bval, args.fsl_bvec], 'fsl') assert_outputs_exist(parser, args, [args.fsl_bval, args.fsl_bvec]) mrtrix2fsl(args.mrtrix_enc, args.fsl_bval, args.fsl_bvec)
def main(): parser = _build_arg_parser() args = parser.parse_args() assert_inputs_exist(parser, args.gradient_sampling_file) if args.verbose: logging.basicConfig(level=logging.INFO) if len(args.gradient_sampling_file) == 2: assert_gradients_filenames_valid(parser, args.gradient_sampling_file, 'fsl') elif len(args.gradient_sampling_file) == 1: basename, ext = os.path.splitext(args.gradient_sampling_file[0]) if ext in ['.bvec', '.bvecs', '.bvals', '.bval']: parser.error('You should input two files for fsl format (.bvec ' 'and .bval).') else: assert_gradients_filenames_valid(parser, args.gradient_sampling_file, 'mrtrix') else: parser.error('Depending on the gradient format you should have ' 'two files for FSL format and one file for MRtrix') out_basename = None proj = args.enable_proj each = args.plot_shells if not (proj or each): parser.error('Select at least one type of rendering (proj or each).') if len(args.gradient_sampling_file) == 2: gradient_sampling_files = args.gradient_sampling_file gradient_sampling_files.sort() # [bval, bvec] # bvecs/bvals (FSL) format, X Y Z AND b (or transpose) points = np.genfromtxt(gradient_sampling_files[1]) if points.shape[0] == 3: points = points.T bvals = np.genfromtxt(gradient_sampling_files[0]) centroids, shell_idx = identify_shells(bvals) else: # MRtrix format X, Y, Z, b gradient_sampling_file = args.gradient_sampling_file[0] tmp = np.genfromtxt(gradient_sampling_file, delimiter=' ') points = tmp[:, :3] bvals = tmp[:, 3] centroids, shell_idx = identify_shells(bvals) if args.out_basename: out_basename, ext = os.path.splitext(args.out_basename) possible_output_paths = [ out_basename + '_shell_' + str(i) + '.png' for i in centroids ] possible_output_paths.append(out_basename + '.png') assert_outputs_exist(parser, args, possible_output_paths) for idx, b0 in enumerate(centroids[centroids < 40]): shell_idx[shell_idx == idx] = -1 centroids = np.delete(centroids, np.where(centroids == b0)) if len(shell_idx[shell_idx == -1]) > 0: shell_idx[shell_idx != -1] -= 1 sym = args.enable_sym sph = args.enable_sph same = args.same_color ms = build_ms_from_shell_idx(points, shell_idx) if proj: plot_proj_shell(ms, use_sym=sym, use_sphere=sph, same_color=same, rad=0.025, opacity=args.opacity, ofile=out_basename, ores=(args.res, args.res)) if each: plot_each_shell(ms, centroids, plot_sym_vecs=sym, use_sphere=sph, same_color=same, rad=0.025, opacity=args.opacity, ofile=out_basename, ores=(args.res, args.res))