<commit_before>#!/usr/bin/env python
"""
Calculates SN ratio of BOSS spectra
"""

import argparse
import qusp

def main():
    # parse command-line arguments
    parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument("-i","--input", type=str, default=None,
        help = "target list")
    parser.add_argument("-n","--ntargets", type=int, default=0,
        help = "number of targets to use, 0 for all")
    parser.add_argument("-o","--output", type=str, default="sn.txt",
        help = "output file name")
    parser.add_argument("--verbose", action="store_true",
        help = "more verbose output")
    qusp.Paths.addArgs(parser)
    args = parser.parse_args()

    # setup boss data directory path
    paths = qusp.Paths(**qusp.Paths.fromArgs(args))
    # read target list
    targets = qusp.target.loadTargetData(args.input)

    # trim target list if requested
    ntargets = args.ntargets if args.ntargets > 0 else len(targets)
    targets = targets[:ntargets]

    # loop over targets
    for target, spPlate in qusp.target.readTargetPlates(paths.boss_path,targets,verbose=args.verbose):
        plate, mjd, fiber = target['target'].split('-')
        # read this target's combined spectrum
        combined = qusp.readCombinedSpectrum(spPlate, int(fiber))
        # calculate median sn
        mediansn = combined.getMedianSignalToNoise(combined.wavelength[0],combined.wavelength[-1])
        target['mediansn'] = mediansn
    # save target list with sn column
    qusp.target.saveTargetData(args.output, targets, 'mediansn')


if __name__ == '__main__':
    main()<commit_msg>update sncalc to use updated module names<commit_after>#!/usr/bin/env python
"""
Calculates SN ratio of BOSS spectra
"""

import argparse
import qusp

def main():
    """
    Main program
    """
    # parse command-line arguments
    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument("-i", "--input", type=str, default=None,
                        help="target list")
    parser.add_argument("-n", "--ntargets", type=int, default=0,
                        help="number of targets to use, 0 for all")
    parser.add_argument("-o", "--output", type=str, default=None,
                        help="output file name")
    parser.add_argument("--verbose", action="store_true",
                        help="more verbose output")
    qusp.Paths.add_args(parser)
    args = parser.parse_args()

    # setup boss data directory path
    paths = qusp.Paths(**qusp.Paths.from_args(args))
    # read target list
    targets = qusp.target.load_target_list(args.input)

    # trim target list if requested
    ntargets = args.ntargets if args.ntargets > 0 else len(targets)
    targets = targets[:ntargets]

    # loop over targets
    target_plate_generator = qusp.target.read_target_plates(
        paths.boss_path, targets, verbose=args.verbose)
    for target, spplate in target_plate_generator:
        # read this target's combined spectrum
        combined = qusp.read_combined_spectrum(spplate, target)
        # calculate median sn
        mediansn = combined.median_signal_to_noise(
            combined.wavelength[0], combined.wavelength[-1])
        target['mediansn'] = mediansn
    if args.output:
        # save target list with sn column
        qusp.target.save_target_list(args.output, targets, 'mediansn')
    else:
        for target in targets:
            print '%s %.2f' % (target.to_string(), target['mediansn'])


if __name__ == '__main__':
    main()

{'fraction_non_alphanumeric': 0.11792584332311123, 'fraction_numerical': 0.0030666294954000556, 'mean_word_length': 3.095890410958904, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1502480', 'n_tokens_mistral': 1095, 'n_tokens_neox': 1063, 'n_words': 260}