<commit_before>#!/usr/bin/env python3

"""A simple example which loads a SEG Y file and saves it again.

Usage:

    loadsave.py <in.segy> <out.segy>

"""

from __future__ import print_function

import os

import sys
import traceback

from segpy.reader import create_reader
from segpy.writer import write_segy


def make_progress_indicator(name):

    previous_integer_progress = -1

    def progress(p):
        nonlocal previous_integer_progress
        percent = p * 100.0
        current_integer_progress = int(percent)
        if current_integer_progress != previous_integer_progress:
            print("{} : {}%".format(name, current_integer_progress))
        previous_integer_progress = current_integer_progress

    return progress


def catalog_progress(p):
    print("Cataloging {:.0f}%".format(p * 100.0))


def copy_progress(p):
    print("Copying {:.0f}%".format(p * 100.0))


def load_save(in_filename, out_filename):
    with open(in_filename, 'rb') as in_file, \
         open(out_filename, 'wb') as out_file:

        segy_reader = create_reader(in_file, progress=make_progress_indicator("Cataloging"))
        write_segy(out_file, segy_reader, progress=make_progress_indicator("Copying"))


def main(argv=None):
    if argv is None:
        argv = sys.argv[1:]

    try:
        in_filename = argv[0]
        out_filename = argv[1]
    except IndexError:
        print(globals()['__doc__'], file=sys.stderr)
        return os.EX_USAGE

    try:
        load_save(in_filename, out_filename)
    except (FileNotFoundError, IsADirectoryError) as e:
        print(e, file=sys.stderr)
        return os.EX_NOINPUT<commit_msg>Removes unnecessary code from the loadsave.py example.<commit_after>#!/usr/bin/env python3

"""A simple example which loads a SEG Y file and saves it again.

Usage:

    loadsave.py <in.segy> <out.segy>

"""

from __future__ import print_function

import os

import sys
import traceback

from segpy.reader import create_reader
from segpy.writer import write_segy


def make_progress_indicator(name):

    previous_integer_progress = -1

    def progress(p):
        nonlocal previous_integer_progress
        percent = p * 100.0
        current_integer_progress = int(percent)
        if current_integer_progress != previous_integer_progress:
            print("{} : {}%".format(name, current_integer_progress))
        previous_integer_progress = current_integer_progress

    return progress


def load_save(in_filename, out_filename):
    with open(in_filename, 'rb') as in_file, \
         open(out_filename, 'wb') as out_file:

        segy_reader = create_reader(in_file, progress=make_progress_indicator("Cataloging"))
        write_segy(out_file, segy_reader, progress=make_progress_indicator("Copying"))


def main(argv=None):
    if argv is None:
        argv = sys.argv[1:]

    try:
        in_filename = argv[0]
        out_filename = argv[1]
    except IndexError:
        print(globals()['__doc__'], file=sys.stderr)
        return os.EX_USAGE

    try:
        load_save(in_filename, out_filename)
    except (FileNotFoundError, IsADirectoryError) as e:
        print(e, file=sys.stderr)
        return os.EX_NOINPUT
{'fraction_non_alphanumeric': 0.09713024282560706, 'fraction_numerical': 0.008830022075055188, 'mean_word_length': 3.411682892906815, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6846166', 'n_tokens_mistral': 1025, 'n_tokens_neox': 983, 'n_words': 233}