<commit_before>#! /usr/bin/python
# -*- coding: utf-8 -*-

import logging
logger = logging.getLogger(__name__)

import argparse

# import time
import pickle

# import sys
import os
# """ import modules from lar-cc/lib """
# sys.path.insert(0, os.path.expanduser('~/projects/lar-cc/lib/py'))
# sys.path.insert(0, '/home/mjirik/projects/lar-cc/lib/py')

from larcc import * # noqa


# input of test file nrn100.py (with definetion of V and FV)
# V = vertex coordinates
# FV = lists of vertex indices of every face (1-based, as required by pyplasm)
#
# sys.path.insert(1, '/Users/paoluzzi/Documents/RICERCA/pilsen/ricerca/')
# from nrn100 import *


def writeFile(filename, vertexes, faces, ftype='auto'):
    """
    filename
    vertexes
    faces
    """
    if ftype == 'auto':
        _, ext = os.path.splitext(filename)
        ftype = ext[1:]

    if ftype in ('pkl', 'pickle', 'p'):
        pickle.dump([vertexes, faces], open(filename, 'wb'))
    elif ftype == 'obj':
        with open(filename, "w") as f:
            for i, vertex in enumerate(vertexes):
                try:
                    f.write("v %s %s %s\n" % (
                        str(vertex[0]),
                        str(vertex[1]),
                        str(vertex[2])
                    ))
                except:
                    logger.warning('empty vertex %i ' % (i))
                    f.write("v 0 0 0")
                    # import ipdb; ipdb.set_trace() #  noqa BREAKPOINT

            for face in faces:
                fstr = "f"
                for i in range(0, len(face)):
                    fstr += " %i" % (face[i])

                fstr += "\n"

                f.write(fstr)


def readFile(filename, ftype='auto'):
    if ftype == 'auto':
        _, ext = os.path.splitext(filename)
        ftype = ext[1:]

    if ftype in ('pkl', 'pickle', 'p'):
        fdata = pickle.load(open(filename, "rb"))
        vertexes, faces = fdata
    elif ftype == 'obj':
        vertexes = []
        faces = []
        with open(filename, "r") as f:
            for line in f.readlines():
                lnarr = line.strip().split(' ')
                if lnarr[0] == 'v':
                    vertexes.append([
                        int(lnarr[1]),
                        int(lnarr[2]),
                        int(lnarr[3])
                    ])
                if lnarr[0] == 'f':
                    face = [0] * (len(lnarr) - 1)
                    for i in range(1, len(lnarr)):
                        face[i - 1] = int(lnarr[i])
                    faces.append(face)

    return vertexes, faces


def main():

    logger = logging.getLogger()
    logger.setLevel(logging.WARNING)
    ch = logging.StreamHandler()
    logger.addHandler(ch)

    # logger.debug('input params')

    # input parser
    parser = argparse.ArgumentParser(
        description="Laplacian smoothing"
    )
    parser.add_argument(
        '-i', '--inputfile',
        default=None,
        required=True,
        help='input file'
    )
    parser.add_argument(
        '-o', '--outputfile',
        default='smooth.obj',
        help='input file'
    )
    parser.add_argument(
        '-mib', '--moveindexbasis',
        type=int,
        default=0,
        help='indexes are 0-based or 1-based')
    parser.add_argument(
        '-d', '--debug', action='store_true',
        help='Debug mode')

    args = parser.parse_args()
    if args.debug:
        logger.setLevel(logging.DEBUG)

    # t0 = time.time()
    V, FV = readFile(args.inputfile)
    logger.info("Data readed from '%s'" % (args.inputfile))
    if args.moveindexbasis is not 0:
        FV = (np.array(FV) + args.moveindexbasis).tolist()

    writeFile(args.outputfile, V, FV)
    logger.info("Data stored to '%s'" % (args.outputfile))

if __name__ == "__main__":
    main()<commit_msg>console mode<commit_after>#! /usr/bin/python
# -*- coding: utf-8 -*-

import logging
logger = logging.getLogger(__name__)

import argparse

# import time
import pickle

import sys
import os
# """ import modules from lar-cc/lib """
sys.path.insert(0, os.path.expanduser('~/projects/lar-cc/lib/py'))
# sys.path.insert(0, '/home/mjirik/projects/lar-cc/lib/py')

from larcc import * # noqa


# input of test file nrn100.py (with definetion of V and FV)
# V = vertex coordinates
# FV = lists of vertex indices of every face (1-based, as required by pyplasm)
#
# sys.path.insert(1, '/Users/paoluzzi/Documents/RICERCA/pilsen/ricerca/')
# from nrn100 import *


def writeFile(filename, vertexes, faces, ftype='auto'):
    """
    filename
    vertexes
    faces
    """
    if ftype == 'auto':
        _, ext = os.path.splitext(filename)
        ftype = ext[1:]

    if ftype in ('pkl', 'pickle', 'p'):
        pickle.dump([vertexes, faces], open(filename, 'wb'))
    elif ftype == 'obj':
        with open(filename, "w") as f:
            for i, vertex in enumerate(vertexes):
                try:
                    f.write("v %s %s %s\n" % (
                        str(vertex[0]),
                        str(vertex[1]),
                        str(vertex[2])
                    ))
                except:
                    logger.warning('empty vertex %i ' % (i))
                    f.write("v 0 0 0")
                    # import ipdb; ipdb.set_trace() #  noqa BREAKPOINT

            for face in faces:
                fstr = "f"
                for i in range(0, len(face)):
                    fstr += " %i" % (face[i])

                fstr += "\n"

                f.write(fstr)


def readFile(filename, ftype='auto'):
    if ftype == 'auto':
        _, ext = os.path.splitext(filename)
        ftype = ext[1:]

    if ftype in ('pkl', 'pickle', 'p'):
        fdata = pickle.load(open(filename, "rb"))
        vertexes, faces = fdata
    elif ftype == 'obj':
        vertexes = []
        faces = []
        with open(filename, "r") as f:
            for line in f.readlines():
                lnarr = line.strip().split(' ')
                if lnarr[0] == 'v':
                    vertexes.append([
                        int(lnarr[1]),
                        int(lnarr[2]),
                        int(lnarr[3])
                    ])
                if lnarr[0] == 'f':
                    face = [0] * (len(lnarr) - 1)
                    for i in range(1, len(lnarr)):
                        face[i - 1] = int(lnarr[i])
                    faces.append(face)

    return vertexes, faces


def main():

    logger = logging.getLogger()
    logger.setLevel(logging.WARNING)
    ch = logging.StreamHandler()
    logger.addHandler(ch)

    # logger.debug('input params')

    # input parser
    parser = argparse.ArgumentParser(
        description="Laplacian smoothing"
    )
    parser.add_argument(
        '-i', '--inputfile',
        default=None,
        required=True,
        help='input file'
    )
    parser.add_argument(
        '-o', '--outputfile',
        default='smooth.obj',
        help='input file'
    )
    parser.add_argument(
        '-mib', '--moveindexbasis',
        type=int,
        default=0,
        help='indexes are 0-based or 1-based')
    parser.add_argument(
        '-d', '--debug', action='store_true',
        help='Debug mode')
    parser.add_argument(
        '--console', action='store_true',
        help='Debug mode')

    args = parser.parse_args()
    if args.debug:
        logger.setLevel(logging.DEBUG)

    # t0 = time.time()
    V, FV = readFile(args.inputfile)
    logger.info("Data readed from '%s'" % (args.inputfile))
    if args.moveindexbasis is not 0:
        FV = (np.array(FV) + args.moveindexbasis).tolist()

    if args.console:
        import ipdb; ipdb.set_trace() #  noqa BREAKPOINT


    writeFile(args.outputfile, V, FV)
    logger.info("Data stored to '%s'" % (args.outputfile))

if __name__ == "__main__":
    main()
{'fraction_non_alphanumeric': 0.14440894568690096, 'fraction_numerical': 0.008690095846645367, 'mean_word_length': 1.7183049670024313, 'pattern_counts': {'":': 2, '<': 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': '1390465', 'n_tokens_mistral': 2585, 'n_tokens_neox': 2423, 'n_words': 578}