def main(): parser = ArgumentParser(description=DESCRIP, epilog=EPILOG, formatter_class=RawDescriptionHelpFormatter) parser.add_argument('filename', type=str, help='4D image filename') parser.add_argument('--out-path', type=str, help='path for output image files') parser.add_argument('--out-fname-label', type=str, help='mid part of output image filenames') parser.add_argument('--ncomponents', type=int, default=10, help='number of PCA components to write') # parse the command line args = parser.parse_args() # process inputs filename = args.filename out_path = args.out_path out_root = args.out_fname_label ncomps = args.ncomponents # collect extension for output images froot, ext, gz = splitext_addext(filename) pth, fname = os.path.split(froot) if out_path is None: out_path = pth if out_root is None: out_root = fname img = nipy.load_image(filename) res = nads.screen(img, ncomps) nads.write_screen_res(res, out_path, out_root, ext + gz)
def main(): parser = ArgumentParser(description=DESCRIP, epilog=EPILOG, formatter_class=RawDescriptionHelpFormatter) parser.add_argument('examples_path', type=str, help='filename of example or directory containing ' 'examples to run') parser.add_argument('--log-path', type=str, default='', help='path for output logs (default is cwd)') parser.add_argument('--excludex', type=str, action='append', default=[], help='regex for files to exclude (add more than one ' '--excludex option for more than one regex filter') args = parser.parse_args() # Proc runner eg_path = abspath(expanduser(args.examples_path)) if args.log_path == '': log_path = abspath(os.getcwd()) else: log_path = abspath(expanduser(args.log_path)) excludexes = [re.compile(s) for s in args.excludex] if isfile(eg_path): # example was a file proc_logger = PyProcLogger(log_path=log_path, working_path=dirname(eg_path)) print("Running " + eg_path) stdout, stderr, code = proc_logger.run_pipes(eg_path) print('==== Stdout ====') print(stdout) print('==== Stderr ====') print(stderr) sys.exit(code) # Multi-run with logging to file proc_logger = PyProcLogger(log_path=log_path, working_path=eg_path) fails = 0 with open(pjoin(log_path, 'summary.txt'), 'wt') as f: for dirpath, dirnames, filenames in os.walk(eg_path): for fname in filenames: full_fname = pjoin(dirpath, fname) if fname.endswith(".py"): print(fname, end=': ') sys.stdout.flush() for excludex in excludexes: if excludex.search(fname): _record('SKIP', fname, f) break else: # run test cmd_name = full_fname.replace(eg_path + psep, '') cmd_name = cmd_name.replace(psep, '-') code = proc_logger(cmd_name, full_fname, cwd=dirpath) if code == 0: _record('OK', fname, f) else: fails += 1 _record('FAIL', fname, f) sys.exit(fails if fails < 255 else 255)
for k in range(3): pk = gold_ppm[mask][:, k] qk = ppm[mask][:, k] PQ = np.sum(np.sqrt(np.maximum(pk * qk, 0))) P = np.sum(pk) Q = np.sum(qk) dices[k] = 2 * PQ / float(P + Q) return dices # Parse command line description = 'Perform brain tissue classification from skull stripped T1 \ image in CSF, GM and WM. If no mask image is provided, the mask is defined by \ thresholding the input image above zero (strictly).' parser = ArgumentParser(description=description) parser.add_argument('img', metavar='img', nargs='+', help='input image') parser.add_argument('--mask', dest='mask', help='mask image') parser.add_argument('--niters', dest='niters', help='number of iterations (default=%d)' % 25) parser.add_argument('--beta', dest='beta', help='Markov random field beta parameter (default=%f)' % 0.5) parser.add_argument('--ngb_size', dest='ngb_size', help='Markov random field neighborhood system (default=%d)' % 6) parser.add_argument('--probc', dest='probc', help='csf probability map') parser.add_argument('--probg', dest='probg', help='gray matter probability map') parser.add_argument('--probw', dest='probw', help='white matter probability map') args = parser.parse_args()
positive-valued. See the `nipy.algorithms.group.ParcelAnalysis` class for more general usage information. """ from os.path import join from glob import glob from nipy import load_image from nipy.algorithms.group import parcel_analysis from nipy.externals.argparse import ArgumentParser # Parse command line description = 'Run a parcel-based second-level analysis from a set of\ first-level effect images.' parser = ArgumentParser(description=description) parser.add_argument('con_path', metavar='con_path', help='directory where 1st-level images are to be found') parser.add_argument('msk_file', metavar='msk_file', help='group mask file') parser.add_argument('parcel_file', metavar='parcel_file', help='parcellation image file') args = parser.parse_args() # Load first-level images con_files = glob(join(args.con_path, '*.nii')) con_imgs = [load_image(f) for f in con_files] # Load group mask msk_img = load_image(args.msk_file)
for k in range(3): pk = gold_ppm[mask][:, k] qk = ppm[mask][:, k] PQ = np.sum(np.sqrt(np.maximum(pk * qk, 0))) P = np.sum(pk) Q = np.sum(qk) dices[k] = 2 * PQ / float(P + Q) return dices # Parse command line description = 'Perform brain tissue classification from skull stripped T1 \ image in CSF, GM and WM. If no mask image is provided, the mask is defined by \ thresholding the input image above zero (strictly).' parser = ArgumentParser(description=description) parser.add_argument('img', metavar='img', nargs='+', help='input image') parser.add_argument('--mask', dest='mask', help='mask image') parser.add_argument('--niters', dest='niters', help='number of iterations (default=%d)' % 25) parser.add_argument('--beta', dest='beta', help='Markov random field beta parameter (default=%f)' % 0.5) parser.add_argument( '--ngb_size', dest='ngb_size', help='Markov random field neighborhood system (default=%d)' % 6) parser.add_argument('--probc', dest='probc', help='csf probability map') parser.add_argument('--probg',
positive-valued. See the `nipy.algorithms.group.ParcelAnalysis` class for more general usage information. """ from os.path import join from glob import glob from nipy import load_image from nipy.algorithms.group import parcel_analysis from nipy.externals.argparse import ArgumentParser # Parse command line description = "Run a parcel-based second-level analysis from a set of\ first-level effect images." parser = ArgumentParser(description=description) parser.add_argument("con_path", metavar="con_path", help="directory where 1st-level images are to be found") parser.add_argument("msk_file", metavar="msk_file", help="group mask file") parser.add_argument("parcel_file", metavar="parcel_file", help="parcellation image file") args = parser.parse_args() # Load first-level images con_files = glob(join(args.con_path, "*.nii")) con_imgs = [load_image(f) for f in con_files] # Load group mask msk_img = load_image(args.msk_file) # Load parcellation parcel_img = load_image(args.parcel_file)
for k in range(3): pk = gpm[k].get_data()[mask] qk = ppm.get_data()[mask][:, k] PQ = np.sum(np.sqrt(np.maximum(pk * qk, 0))) P = np.sum(pk) Q = np.sum(qk) dices[k] = 2 * PQ / float(P + Q) return dices # Parse command line description = 'Perform brain tissue classification from skull stripped T1 \ image in CSF, GM and WM. If no mask image is provided, the mask is defined by \ thresholding the input image above zero (strictly).' parser = ArgumentParser(description=description) parser.add_argument('img', metavar='img', nargs='+', help='input image') parser.add_argument('--mask', dest='mask', help='mask image') parser.add_argument('--k_csf', dest='k_csf', help='number of CSF classes (default=%d)' % K_CSF) parser.add_argument('--k_gm', dest='k_gm', help='number of GM classes (default=%d)' % K_GM) parser.add_argument('--k_wm', dest='k_wm', help='number of WM classes (default=%d)' % K_WM) parser.add_argument('--niters', dest='niters', help='number of iterations (default=%d)' % NITERS) parser.add_argument('--beta', dest='beta', help='Markov random field beta parameter (default=%f)' % BETA) parser.add_argument('--scheme', dest='scheme', help='message passing scheme (mf, icm or bp, default=%s)' % SCHEME) parser.add_argument('--noise', dest='noise',