<commit_before>"""Converts a TAPE9 file to a sparse matrix on disk."""
import os
import argparse

from .util import save_sparse_csr
from .tape9utils import tape9_to_sparse, THRESHOLD


def make_parser():
    p = argparse.ArgumentParser('tape9sparse', formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    p.add_argument('tape9', help="path to the TAPE9 file.")
    p.add_argument('--phi', help='the neutron flux in [n/cm^2/sec]',
                   type=float, default=4e14)
    p.add_argument('-f', '--format', help='The sparse matrix format',
                   default='csr', dest='format')
    p.add_argument('-d', '--decay', help='path to the decay file, if needed',
                   default='decay.lib', dest='decaylib')
    p.add_argument('--include-fission', action='store_true', default=True,
                   dest='include_fission',
                   help='Include fission reactions in the matrix.')
    p.add_argument('--dont-include-fission', action='store_false',
                   dest='include_fission',
                   help="Don't include fission reactions in the matrix.")
    p.add_argument('-t', '--threshold', default=THRESHOLD, dest='threshold',
                   help='cutoff for ignoring reactions', type=float)
    p.add_argument('-o', '--output', dest='output', default=None,
                   help='The filename to write the matrix to, in npz format.')
    return p


def main(args=None):
    p = make_parser()
    ns = p.parse_args(args=args)
    save_sparse(**vars(ns))

def save_sparse(tape9, phi=4e14, output=None, format='csr',
    decaylib='decay.lib', include_fission=True, threshold=THRESHOLD):
    if output is None:
        base = os.path.basename(tape9)
        base, _ = os.path.splitext(base)
        os.makedirs('data', exist_ok=True)
        output = os.path.join('data', base + '_' + str(phi) + '.npz')
    if format != 'csr':
        raise ValueError('Only the CSR format is currently available from the '
                         'command line interface.')
    mat, nucs = tape9_to_sparse(tape9, phi, format=format,
                                decaylib=decaylib,
                                include_fission=include_fission,
                                threshold=threshold)
    save_sparse_csr(output, mat, nucs, phi)

if __name__ == '__main__':
    main()<commit_msg>Rearrange code<commit_after>"""Converts a TAPE9 file to a sparse matrix on disk."""
import os
import argparse

from .util import save_sparse_csr
from .tape9utils import tape9_to_sparse, THRESHOLD


def make_parser():
    p = argparse.ArgumentParser('tape9sparse', formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    p.add_argument('tape9', help="path to the TAPE9 file.")
    p.add_argument('--phi', help='the neutron flux in [n/cm^2/sec]',
                   type=float, default=4e14)
    p.add_argument('-f', '--format', help='The sparse matrix format',
                   default='csr', dest='format')
    p.add_argument('-d', '--decay', help='path to the decay file, if needed',
                   default='decay.lib', dest='decaylib')
    p.add_argument('--include-fission', action='store_true', default=True,
                   dest='include_fission',
                   help='Include fission reactions in the matrix.')
    p.add_argument('--dont-include-fission', action='store_false',
                   dest='include_fission',
                   help="Don't include fission reactions in the matrix.")
    p.add_argument('-t', '--threshold', default=THRESHOLD, dest='threshold',
                   help='cutoff for ignoring reactions', type=float)
    p.add_argument('-o', '--output', dest='output', default=None,
                   help='The filename to write the matrix to, in npz format.')
    return p

def save_sparse(tape9, phi=4e14, output=None, format='csr',
    decaylib='decay.lib', include_fission=True, threshold=THRESHOLD):
    if output is None:
        base = os.path.basename(tape9)
        base, _ = os.path.splitext(base)
        os.makedirs('data', exist_ok=True)
        output = os.path.join('data', base + '_' + str(phi) + '.npz')
    if format != 'csr':
        raise ValueError('Only the CSR format is currently available from the '
                         'command line interface.')
    mat, nucs = tape9_to_sparse(tape9, phi, format=format,
                                decaylib=decaylib,
                                include_fission=include_fission,
                                threshold=threshold)
    save_sparse_csr(output, mat, nucs, phi)

def main(args=None):
    p = make_parser()
    ns = p.parse_args(args=args)
    save_sparse(**vars(ns))

if __name__ == '__main__':
    main()
{'fraction_non_alphanumeric': 0.1311965811965812, 'fraction_numerical': 0.007264957264957265, 'mean_word_length': 2.6035411855273285, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '746817', 'n_tokens_mistral': 1475, 'n_tokens_neox': 1429, 'n_words': 336}