<commit_before>#!/usr/bin/env python
''' Script to calculate and write results for diagnostic screen
'''
import os

import numpy as np

import nipy
import nipy.externals.argparse as argparse
import nipy.algorithms.diagnostics.screens as nads
from nipy.io.imageformats.filename_parser import splitext_addext

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt


if __name__ == '__main__':
    # create the parser
    parser = argparse.ArgumentParser()
    # add the arguments
    parser.add_argument('filename', type=str,
                        help='4D image filename')
    parser.add_argument('--out-path', type=str,
                        help='path for output image names')
    parser.add_argument('--out-fname-prefix', type=str,
                        help='prefix for output image names')
    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_prefix
    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)
    <commit_msg>Add more documentation to nipy_diagnose.<commit_after>#!/usr/bin/env python
''' Script to calculate and write results for diagnostic screen

nipy_diagnose will generate a series of diagnostic images for a 4D
fMRI image volume.  The following images will be generated:

    * components_<prefix>.png : plots of PCA basis vectors
    * max_<prefix>.nii : max image
    * mean_<prefix>.nii : mean image
    * min_<prefix>.nii : min image
    * pca_<prefix>.nii : 4D image of PCA component images
    * pcnt_var_<prefix>.png : XXX
    * std_<prefix>.nii : standard deviation image XXX
    * tsdiff_<prefix>.png : XXX

The generated files will be saved in the directory specified by the
--out-path parameter.  If the out-path directory is not specified,
generated images will be saved in the same directory as the input
image.

'''
import os

import numpy as np

import nipy
import nipy.externals.argparse as argparse
import nipy.algorithms.diagnostics.screens as nads
from nipy.io.imageformats.filename_parser import splitext_addext

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt

def main():
    # create the parser
    desc = __doc__.splitlines()[0]
    parser = argparse.ArgumentParser(description=desc)
    # add the arguments
    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-prefix', type=str,
                        help='prefix for output image names')
    parser.add_argument('--ncomponents', type=int, default=10,
                        help='number of PCA components to write')
    parser.add_argument('--extended-help', action='store_true',
                        help='print extended help')

    # HACK: Allow user to get additional help without having to
    # provide a filename (or any positional arg).  Could not find a
    # better way to do this with argparse.
    import sys
    if '--extended-help' in sys.argv:
        print __doc__
        return

    # parse the command line
    args = parser.parse_args()
    # process inputs
    filename = args.filename
    out_path = args.out_path
    out_root = args.out_fname_prefix
    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)
    
if __name__ == '__main__':
    main()
{'fraction_non_alphanumeric': 0.08843053579895685, 'fraction_numerical': 0.0021337126600284497, 'mean_word_length': 2.892066420664207, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6781240', 'n_tokens_mistral': 1300, 'n_tokens_neox': 1265, 'n_words': 390}