<commit_before>#!/usr/bin/env python
# __BEGIN_LICENSE__
# Copyright (C) 2006-2011 United States Government as represented by
# the Administrator of the National Aeronautics and Space Administration.
# All Rights Reserved.
# __END_LICENSE__


import optparse, sys, subprocess, math, os;
from math import cos, sin;
from multiprocessing import Pool

class Usage(Exception):
    def __init__(self, msg):
        self.msg = msg

def replace_extension( filename, ext ):
    i = filename.rfind('.')
    return filename[0:i+1]+ext

def extract_camera_position_func(cmd):
    p = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE);
    cmd_return = p.stdout.readline().strip();

    x = float(cmd_return.split()[0])
    y = float(cmd_return.split()[1])
    z = float(cmd_return.split()[2])
    length = math.sqrt( x*x + y*y + z*z )

    return [cmd.split()[1], x/length, y/length, z/length]

def main():
    try:
        try:
            usage = "usage: pairlist_degree.py [--help] <image files>"
            parser = optparse.OptionParser(usage=usage)
            parser.set_defaults(angle=6)
            parser.set_defaults(ext="")
            parser.set_defaults(threads=4)
            parser.add_option("-a", "--angle", dest="angle",
                              help="Max degree seperation between images.", type="float")
            parser.add_option("--iextension", dest="ext",
                              help="Output extension to use.", type="string")
            parser.add_option("-t", "--threads", dest="threads",
                              help="Number of threads to use.", type="int")

            (options,args) = parser.parse_args()

            if not args: parser.error("need input files")

        except optparse.OptionError, msg:
            raise Usage(msg)

        isis_position_extract = os.path.realpath(__file__)
        isis_position_extract = isis_position_extract[:isis_position_extract.rfind("/")] + "/../libexec/isis_position_extract"
        vw_position_extract   = os.path.realpath(__file__)
        vw_position_extract   = vw_position_extract[:vw_position_extract.rfind("/")] + "/../libexec/vw_position_extract"

        image_position = dict()
        position_extract_cmds = []
        step_size = 1;

        # Building position extraction commands
        if ( args[0].rfind(".cub") >= 0 ):
            if ( args[1].rfind(".isis_adjust") >= 0 ):
                step_size = 2;
            for i in range(0,len(args),step_size):
                # Fetching the Lat Long of the center pixel - We could at
                # some point fetch the corners and do something more
                # interesting
                cmd = isis_position_extract+" "+args[i];
                if ( step_size > 1):
                    cmd = cmd+" "+args[i+1]
                position_extract_cmds.append(cmd)
        else:
            for i in args:
                cmd = vw_position_extract+" "+i
                position_extract_cmds.append(cmd);

        # Processing extraction commands
        pool = Pool(processes=options.threads)
        results = [pool.apply_async(extract_camera_position_func, (cmd,)) for cmd in position_extract_cmds]
        for result in results:<commit_msg>Make pairlist_degree a little more user friendly.<commit_after>#!/usr/bin/env python
# __BEGIN_LICENSE__
# Copyright (C) 2006-2011 United States Government as represented by
# the Administrator of the National Aeronautics and Space Administration.
# All Rights Reserved.
# __END_LICENSE__


import optparse, sys, subprocess, math, os;
from math import cos, sin;
from multiprocessing import Pool

class Usage(Exception):
    def __init__(self, msg):
        self.msg = msg

def replace_extension( filename, ext ):
    i = filename.rfind('.')
    return filename[0:i+1]+ext

def extract_camera_position_func(cmd):
    p = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE);
    cmd_return = p.stdout.readline().strip();

    x = float(cmd_return.split()[0])
    y = float(cmd_return.split()[1])
    z = float(cmd_return.split()[2])
    length = math.sqrt( x*x + y*y + z*z )

    return [cmd.split()[1], x/length, y/length, z/length]

def main():
    try:
        try:
            usage = "usage: pairlist_degree.py [--help] <image files>"
            parser = optparse.OptionParser(usage=usage)
            parser.set_defaults(angle=6)
            parser.set_defaults(ext="")
            parser.set_defaults(threads=4)
            parser.add_option("-a", "--angle", dest="angle",
                              help="Max degree seperation between images.", type="float")
            parser.add_option("--iextension", dest="ext",
                              help="Output extension to use.", type="string")
            parser.add_option("-t", "--threads", dest="threads",
                              help="Number of threads to use.", type="int")

            (options,args) = parser.parse_args()

            if not args: parser.error("need input files")

        except optparse.OptionError, msg:
            raise Usage(msg)

        isis_position_extract = os.path.realpath(__file__)
        isis_position_extract = isis_position_extract[:isis_position_extract.rfind("/")] + "/../libexec/isis_position_extract"
        vw_position_extract   = os.path.realpath(__file__)
        vw_position_extract   = vw_position_extract[:vw_position_extract.rfind("/")] + "/../libexec/vw_position_extract"

        image_position = dict()
        position_extract_cmds = []
        step_size = 1;

        args.sort() # Make sure the isis_adjust are correctly placed

        # Building position extraction commands
        if ( args[0].rfind(".cub") >= 0 ):
            if ( args[1].rfind(".isis_adjust") >= 0 ):
                step_size = 2;
            sys.stderr.write("Found %d cameras." % (len(args)/step_size))
            for i in range(0,len(args),step_size):
                # Fetching the Lat Long of the center pixel - We could at
                # some point fetch the corners and do something more
                # interesting
                cmd = isis_position_extract+" "+args[i];
                if ( step_size > 1):
                    cmd = cmd+" "+args[i+1]
                position_extract_cmds.append(cmd)
        else:
            sys.stderr.write("Found %d cameras." % len(args))
            for i in args:
                cmd = vw_position_extract+" "+i
                position_extract_cmds.append(cmd);

        # Processing extraction commands
        pool = Pool(processes=options.threads)
        results = [pool.apply_async(extract_camera_position_func, (cmd,)) for cmd in position_extract_cmds]
        for result in results:
{'fraction_non_alphanumeric': 0.11978384869408586, 'fraction_numerical': 0.007505253677574302, 'mean_word_length': 2.351609657947686, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4540881', 'n_tokens_mistral': 1967, 'n_tokens_neox': 1891, 'n_words': 455}