Ejemplo n.º 1
0
def main():

    ap = buildArgumentParser()
    args = ap.parse_args()

    if (args.domain != "synth-synth" and args.domain != "real-synth" and args.domain != "real-real"):
        print("Error, the domain of dataset must be one of: synth-synth, real-synth, real-real.")
        return
    if (args.fov_type != "fixed" and args.fov_type != "real"):
        print("Error, field-of-view option might be either fixed, or real.")
        return
    dc = PatchesDatasetCreator(args)
    dc.createDataset()
Ejemplo n.º 2
0
def main(argv):
    options = argparse.parse_args(args)    
    appdirs = AppDirs(APPNAME, APPAUTHOR)
    init_log(options.debug[0].lower(), appdirs)

    # We need to initialize the data directories if this is a first-run
    if not isdir(appdirs.user_data_dir):
        from core import first_run
        first_run.main(appdirs.user_data_dir)

    # Now that the database exists, we can safely open the connection
    open_db(appdirs)
    if options.no_gui:
        launch_console(options)
    else:
        launch_gui(options)    
Ejemplo n.º 3
0
def main(argv=sys.argv[1:]):
    args = argparse.parse_args(argv)
    legal_commands = {
        "init": cmd_init,
        # "add": cmd_add,
        "cat-file": cmd_cat_file,
        # "checkout": cmd_checkout,
        # "commit": cmd_commit,
        # "hash-object": cmd_hash_object,
        # "log": cmd_log,
        # "ls-tree": cmd_ls_tree,
        # "merge": cmd_merge,
        # "rebase": cmd_rebase,
        # "rev-parse": cmd_rev_parse,
        # "rm": cmd_rm,
        # "show-ref": cmd_show_ref,
        # "tag": cmd_tag,
    }
    if args.command in legal_commands:
        fn = legal_commands.get(args.command, cmd_not_found)
        fn(args)
Ejemplo n.º 4
0
import argparse as ap
if __name__ == "__main__":
    parser = ap.ArgumentParser()
    # parser.add_argument("test", help="this is a test")
    parser.add_argument("-v", help="run with debug logging", action="store_true")  # optional
    parser.add_argument("-action", help="specify action to take on EC2 instance: create, stop, start, delete, list, list-running",
                        default="list")
    args = parser.parse_args()
    # print(args.echo)
    print("all arguments={}".format(args))


import argparse

if __name__ == "__main__":
    ap = argparse.ArgumentParser()
    ap.add_argument("--action", type=str, default="list-all", choices=["list-all", "list-running"], help="legume")
    my_args = ap.parse_args()

    print(my_args.action)

    # todo below
    # list-all is default
    # start / stop - can take optional pem
    # key - can take optional filename
    # default filename needs to be set
    #
    # create - can take # of instances (not yet)
Ejemplo n.º 5
0
import sys
from itertools import groupby 
from operator import itemgetter 
from collections import Counter, OrderedDict 
from rugis import dbscan, Distance, GPS2GCJ
import json
import argparse as parser
sys.path.append("./scipy")
from sklearn.cluster import MeanShift

parser = parser.ArgumentParser()
parser.add_argument("-a", "--act", type=str, required = True)
parser.add_argument("-d", "--date", type=str, help="run date")
parser.add_argument("-w", "--window", type=int, default=90, help="date window")
args = parser.parse_args()

"""
offline version, after mapper, you need groupby by the key
useage:
    1. [calculate all location]
      cat training_data.TXT|python aoi_loc_cluster_model_local.py --act "m"|sort -n |python aoi_loc_cluster_model_local.py --act "runModel" --date "20160516" --window 90 

    2. [calculate weekend location]
      cat training_data.TXT|python aoi_loc_cluster_model_local.py --act "mWeekend"|sort -n |python aoi_loc_cluster_model_local.py --act "runModel" --date "20160516" --window 90 

    3. [calculate weekday location] 
      cat training_data.TXT|python aoi_loc_cluster_model_local.py --act "mWeekday"|sort -n |python aoi_loc_cluster_model_local.py --act "runModel" --date "20160516" --window 90 

"""
Ejemplo n.º 6
0
def main():
    global STATS
    global VERSION_KEY
    global CHANGEDCT
    global shutdown_event
    global finished_event
    global bulkError_event

    parser = argparse.ArgumentParser()


    dataSource = parser.add_mutually_exclusive_group(required=True)
    dataSource.add_argument("-f", "--file", action="store", dest="file",
        default=None, help="Input CSV file")
    dataSource.add_argument("-d", "--directory", action="store", dest="directory",
        default=None, help="Directory to recursively search for CSV files -- mutually exclusive to '-f' option")
    parser.add_argument("-e", "--extension", action="store", dest="extension",
        default='csv', help="When scanning for CSV files only parse files with given extension (default: 'csv')")

    parser.add_argument("-r", "--redo", action="store_true", dest="redo",
        default=False, help="Attempt to re-import a failed import or import more data, uses stored metatdata from previous import (-o, -n, and -x not required and will be ignored!!)")
    parser.add_argument("-v", "--verbose", action="store_true", dest="verbose",
        default=False, help="Be verbose")
    parser.add_argument("--vverbose", action="store_true", dest="vverbose",
        default=False, help="Be very verbose (Prints status of every domain parsed, very noisy)")
    parser.add_argument("-s", "--stats", action="store_true", dest="stats",
        default=False, help="Print out Stats after running")

    updateMethod = parser.add_mutually_exclusive_group()
    updateMethod.add_argument("-x", "--exclude", action="store", dest="exclude",
        default="", help="Comma separated list of keys to exclude if updating entry")
    updateMethod.add_argument("-n", "--include", action="store", dest="include",
        default="", help="Comma separated list of keys to include if updating entry (mutually exclusive to -x)")

    parser.add_argument("-o", "--comment", action="store", dest="comment",
        default="", help="Comment to store with metadata")
    parser.add_argument("-u", "--es-uri", nargs="*", dest="es_uri",
        default=['localhost:9200'], help="Location(s) of ElasticSearch Server (e.g., foo.server.com:9200) Can take multiple endpoints")
    parser.add_argument("-p", "--index-prefix", action="store", dest="index_prefix",
        default='whois', help="Index prefix to use in ElasticSearch (default: whois)")
    parser.add_argument("-i", "--identifier", action="store", dest="identifier", type=int,
        default=None, help="Numerical identifier to use in update to signify version (e.g., '8' or '20140120')")
    parser.add_argument("-B", "--bulk-size", action="store", dest="bulk_size", type=int,
        default=5000, help="Size of Bulk Elasticsearch Requests")
    parser.add_argument("--optimize-import", action="store_true", dest="optimize_import",
        default=False, help="If enabled, will change ES index settings to speed up bulk imports, but if the cluster has a failure, data might be lost permanently!")

    parser.add_argument("-t", "--threads", action="store", dest="threads", type=int,
        default=2, help="Number of workers, defaults to 2. Note that each worker will increase the load on your ES cluster since it will try to lookup whatever record it is working on in ES")
    parser.add_argument("--bulk-serializers", action="store", dest="bulk_serializers", type=int,
        default=1, help="How many threads to spawn to combine messages from workers. Only increase this if you're are running a lot of workers and one cpu is unable to keep up with the load")
    parser.add_argument("--bulk-threads", action="store", dest="bulk_threads", type=int,
        default=1, help="How many threads to spawn to send bulk ES messages. The larger your cluster, the more you can increase this")
    parser.add_argument("--enable-delta-indexes", action="store_true", dest="enable_delta_indexes",
        default=False, help="If enabled, will put changed entries in a separate index. These indexes can be safely deleted if space is an issue, also provides some other improvements")

    options = parser.parse_args()

    if options.vverbose:
        options.verbose = True

    options.firstImport = False

    threads = []
    work_queue = jmpQueue(maxsize=options.bulk_size * options.threads)
    insert_queue = jmpQueue(maxsize=options.bulk_size * options.bulk_threads)
    bulk_request_queue = jmpQueue(maxsize = 2 * options.bulk_threads)
    stats_queue = mpQueue()

    meta_index_name = '@' + options.index_prefix + "_meta"

    data_template = None
    template_path = os.path.dirname(os.path.realpath(__file__))
    with open("%s/es_templates/data.template" % template_path, 'r') as dtemplate:
        data_template = json.loads(dtemplate.read())

    if options.identifier is None and options.redo is False:
        print("Identifier required\n")
        argparse.parse_args(['-h'])
    elif options.identifier is not None and options.redo is True:
        print("Redo requested and Identifier Specified. Please choose one or the other\n")
        argparse.parse_args(['-h'])

    es = connectElastic(options.es_uri)
    metadata = None
    previousVersion = 0

    #Create the metadata index if it doesn't exist
    if not es.indices.exists(meta_index_name):
        if options.redo:
            print("Cannot redo when no initial data exists")
            sys.exit(1)

        if data_template is not None:
            data_template["template"] = "%s-*" % options.index_prefix
            es.indices.put_template(name='%s-template' % options.index_prefix, body = data_template)

        #Create the metadata index with only 1 shard, even with thousands of imports
        #This index shouldn't warrant multiple shards
        #Also use the keyword analyzer since string analsysis is not important
        es.indices.create(index=meta_index_name, body = {"settings" : {
                                                                "index" : {
                                                                    "number_of_shards" : 1,
                                                                    "analysis" : {
                                                                        "analyzer" : {
                                                                            "default" : {
                                                                                "type" : "keyword"
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                         }
                                                        })
        #Create the 0th metadata entry
        metadata = { "metadata": 0,
                     "firstVersion": options.identifier,
                     "lastVersion": options.identifier,
                     "deltaIndexes": options.enable_delta_indexes,
                    }
        es.create(index=meta_index_name, doc_type='meta', id = 0, body = metadata)

        #Specially create the first index to have 2x the shards than normal
        #since future indices should be diffs of the first index (ideally)
        index_name = "%s-%s" % (options.index_prefix, options.identifier)
        if options.enable_delta_indexes:
            index_name += "-o"
        es.indices.create(index=index_name,
                            body = {"settings": { 
                                        "index": { 
                                            "number_of_shards": int(data_template["settings"]["number_of_shards"]) * 2
                                        }
                                    }
                            })
        options.firstImport = True
    else:
        try:
            result = es.get(index=meta_index_name, id=0)
            if result['found']:
                metadata = result['_source']
            else:
                raise Exception("Not Found")
        except:
            print("Error fetching metadata from index")
            sys.exit(1)

        if options.redo is False: #Identifier is auto-pulled from db, no need to check
            # Pre-emptively create index
            index_name = "%s-%s" % (options.index_prefix, options.identifier)
            if options.enable_delta_indexes:
                index_name += "-o"
            es.indices.create(index=index_name)

            if options.identifier < 1:
                print("Identifier must be greater than 0")
                sys.exit(1)
            if metadata['lastVersion'] >= options.identifier:
                print("Identifier must be 'greater than' previous identifier")
                sys.exit(1)

            previousVersion = metadata['lastVersion']

            # Pre-emptively create delta index
            if options.enable_delta_indexes and previousVersion > 0:
                index_name = "%s-%s-d" % (options.index_prefix, previousVersion)
                es.indices.create(index=index_name)
        else:
            result = es.search(index=meta_index_name,
                               body = { "query": {
                                            "match_all": {}
                                        },
                                        "sort":[
                                            {"metadata": {"order": "asc"}}
                                        ]
                                      })

            if result['hits']['total'] == 0:
                print("Unable to fetch entries from metadata index")
                sys.exit(1)

            previousVersion = result['hits']['hits'][-2]['_id']

    options.previousVersion = previousVersion

    # Change Index settings to better suit bulk indexing
    optimizeIndexes(es, options)

    index_list = es.search(index=meta_index_name,
                           body = { "query": {
                                        "match_all": {}
                                    },
                                    "_source": "metadata",
                                    "sort":[
                                        {"metadata": {"order": "desc"}}
                                    ]
                                  })

    index_list = [entry['_source']['metadata'] for entry in index_list['hits']['hits'][:-1]]
    options.INDEX_LIST = []
    for index_name in index_list:
        if options.enable_delta_indexes:
            options.INDEX_LIST.append('%s-%s-o' % (options.index_prefix, index_name))
        else:
            options.INDEX_LIST.append('%s-%s' % (options.index_prefix, index_name))

    if options.redo is False:
        if options.exclude != "":
            options.exclude = options.exclude.split(',')
        else:
            options.exclude = None

        if options.include != "":
            options.include = options.include.split(',')
        else:
            options.include = None

        #Start worker threads
        if options.verbose:
            print("Starting %i worker threads" % options.threads)

        for i in range(options.threads):
            t = Process(target=process_worker,
                        args=(work_queue, 
                              insert_queue, 
                              stats_queue,
                              options), 
                        name='Worker %i' % i)
            t.daemon = True
            t.start()
            threads.append(t)

        #Upate the lastVersion in the metadata
        es.update(index=meta_index_name, id=0, doc_type='meta', body = {'doc': {'lastVersion': options.identifier}} )

        #Create the entry for this import
        meta_struct = {  
                        'metadata': options.identifier,
                        'comment' : options.comment,
                        'total' : 0,
                        'new' : 0,
                        'updated' : 0,
                        'unchanged' : 0,
                        'duplicates': 0,
                        'changed_stats': {} 
                       }

        if options.exclude != None:
            meta_struct['excluded_keys'] = options.exclude
        elif options.include != None:
            meta_struct['included_keys'] = options.include
            
        es.create(index=meta_index_name, id=options.identifier, doc_type='meta',  body = meta_struct)

    else: #redo is True
        #Get the record for the attempted import
        options.identifier = int(metadata['lastVersion'])
        try:
            redo_record = es.get(index=meta_index_name, id=options.identifier)['_source']
        except:
           print("Unable to retrieve information for last import")
           sys.exit(1) 

        if 'excluded_keys' in redo_record:
            options.exclude = redo_record['excluded_keys']
        else:
            options.exclude = None

        if 'included_keys' in redo_record:
            options.include = redo_record['included_keys']
        else:
            options.include = None

        options.comment = redo_record['comment']
        STATS['total'] = int(redo_record['total'])
        STATS['new'] = int(redo_record['new'])
        STATS['updated'] = int(redo_record['updated'])
        STATS['unchanged'] = int(redo_record['unchanged'])
        STATS['duplicates'] = int(redo_record['duplicates'])
        CHANGEDCT = redo_record['changed_stats']

        if options.verbose:
            print("Re-importing for: \n\tIdentifier: %s\n\tComment: %s" % (options.identifier, options.comment))

        for ch in CHANGEDCT.keys():
            CHANGEDCT[ch] = int(CHANGEDCT[ch])

        #Start the reworker threads
        if options.verbose:
            print("Starting %i reworker threads" % options.threads)

        for i in range(options.threads):
            t = Process(target=process_reworker,
                        args=(work_queue, 
                              insert_queue, 
                              stats_queue,
                              options), 
                        name='Worker %i' % i)
            t.daemon = True
            t.start()
            threads.append(t)
        #No need to update lastVersion or create metadata entry

    # Start up the Elasticsearch Bulk Serializers
    # Its job is just to combine work into bulk-sized chunks to be sent to the bulk API
    # One serializer should be enough for a lot of workers, but anyone with a super large cluster might
    # be able to run a lot of workers which can subsequently overwhelm a single serializer
    es_serializers = []
    for i in range(options.bulk_serializers):
        es_serializer = Process(target=es_serializer_proc, args=(insert_queue, bulk_request_queue, options))
        es_serializer.start()
        es_serializers.append(es_serializer)

    # Start up ES Bulk Shippers, each in their own process
    # As far as I can tell there's an issue (bug? feature?) that causes every request made to ES to hinder the entire process even if it's in a separate python thread
    # not sure if this is GIL related or not, but instead of debugging how the elasticsearch library or urllib does things
    # its easier to just spawn a separate process for every connection being made to ES
    for i in range(options.bulk_threads):
        es_bulk_shipper = Process(target=es_bulk_shipper_proc, args=(bulk_request_queue, i, options))
        es_bulk_shipper.daemon = True
        es_bulk_shipper.start()

    stats_worker_thread = Thread(target=stats_worker, args=(stats_queue,), name = 'Stats')
    stats_worker_thread.daemon = True
    stats_worker_thread.start()

    #Start up Reader Thread
    reader_thread = Thread(target=reader_worker, args=(work_queue, options), name='Reader')
    reader_thread.daemon = True
    reader_thread.start()

    try:
        while True:
            reader_thread.join(.1)
            if not reader_thread.is_alive():
                break
            # If bulkError occurs stop reading from the files
            if bulkError_event.is_set():
                sys.stdout.write("Bulk API error -- forcing program shutdown \n")
                raise KeyboardInterrupt("Error response from ES worker, stopping processing")

        if options.verbose:
            sys.stdout.write("All files ingested ... please wait for processing to complete ... \n")
            sys.stdout.flush()

        while not work_queue.empty():
            # If bulkError occurs stop processing
            if bulkError_event.is_set():
                sys.stdout.write("Bulk API error -- forcing program shutdown \n")
                raise KeyboardInterrupt("Error response from ES worker, stopping processing")

        work_queue.join()

        try:
            # Since this is the shutdown section, ignore Keyboard Interrupts
            # especially since the interrupt code (below) does effectively the same thing
            insert_queue.join()

            finished_event.set()
            for t in threads:
                t.join()

            # Wait for the es serializer(s) to package up all of the bulk requests
            for es_serializer in es_serializers:
                es_serializer.join()

            # Wait for shippers to send all bulk requests
            bulk_request_queue.join()

            # Change settings back
            unOptimizeIndexes(es, data_template, options)

            stats_queue.put('finished')
            stats_worker_thread.join()

            #Update the stats
            try:
                es.update(index=meta_index_name, id=options.identifier,
                                                 doc_type='meta',
                                                 body = { 'doc': {
                                                          'total' : STATS['total'],
                                                          'new' : STATS['new'],
                                                          'updated' : STATS['updated'],
                                                          'unchanged' : STATS['unchanged'],
                                                          'duplicates': STATS['duplicates'],
                                                          'changed_stats': CHANGEDCT
                                                        }}
                                                );
            except Exception as e:
                sys.stdout.write("Error attempting to update stats: %s\n" % str(e))
        except KeyboardInterrupt:
            pass

        if options.verbose:
            sys.stdout.write("Done ...\n\n")
            sys.stdout.flush()


        if options.stats:
            print("Stats: ")
            print("Total Entries:\t\t %d" % STATS['total'])
            print("New Entries:\t\t %d" % STATS['new'])
            print("Updated Entries:\t %d" % STATS['updated'])
            print("Duplicate Entries\t %d" % STATS['duplicates'])
            print("Unchanged Entries:\t %d" % STATS['unchanged'])

    except KeyboardInterrupt as e:
        sys.stdout.write("\rCleaning Up ... Please Wait ...\nWarning!! Forcefully killing this might leave Elasticsearch in an inconsistent state!\n")
        shutdown_event.set()

        # Flush the queue if the reader is alive so it can see the shutdown_event
        # in case it's blocked on a put
        sys.stdout.write("\tShutting down input reader threads ...\n")
        while reader_thread.is_alive():
            try:
                work_queue.get_nowait()
                work_queue.task_done()
            except queue.Empty:
                break

        reader_thread.join()

        # Don't join on the work queue, we don't care if the work has been finished
        # The worker threads will exit on their own after getting the shutdown_event

        # Joining on the insert queue is important to ensure ES isn't left in an inconsistent state if delta indexes are being used
        # since it 'moves' documents from one index to another which involves an insert and a delete
        insert_queue.join()

        # All of the workers should have seen the shutdown event and exited after finishing whatever they were last working on
        sys.stdout.write("\tStopping workers ... \n")
        for t in threads:
            t.join()

        # Send the finished message to the stats queue to shut it down
        stats_queue.put('finished')
        stats_worker_thread.join()

        sys.stdout.write("\tWaiting for ElasticSearch bulk uploads to finish ... \n")
        # The ES serializer does not recognize the shutdown event only the graceful finished_event
        # so set the event so it can gracefully shutdown
        finished_event.set()

        # Wait for es serializer(s) to package up all bulk requests
        for es_serializer in es_serializers:
            es_serializer.join()

        # Wait for shippers to send all bulk requests, otherwise ES might be left in an inconsistent state
        bulk_request_queue.join()

        #Attempt to update the stats
        #XXX
        try:
            sys.stdout.write("\tFinalizing metadata\n")
            es.update(index=meta_index_name, id=options.identifier,
                                             body = { 'doc': {
                                                        'total' : STATS['total'],
                                                        'new' : STATS['new'],
                                                        'updated' : STATS['updated'],
                                                        'unchanged' : STATS['unchanged'],
                                                        'duplicates': STATS['duplicates'],
                                                        'changed_stats': CHANGEDCT
                                                    }
                                            })
        except:
            pass

        sys.stdout.write("\tFinalizing settings\n")
        # Make sure to de-optimize the indexes for import
        unOptimizeIndexes(es, data_template, options)

        try:
            work_queue.close()
            insert_queue.close()
            stats_queue.close()
        except:
            pass

        sys.stdout.write("... Done\n")
        sys.exit(0)
Ejemplo n.º 7
0
            logging.info('Error: response text {}'.format(r.text))
            raise e


if __name__ == "__main__":
    argParser = argParser.ArgumentParser(
        description='Process a csv file for rollback. '
        'The csv file should have the following columns'
        '(some are not used and can be left empty, but structure is important here):\n'
        '1. Date\n'
        '2. User name\n'
        '3. User email (not used)\n'
        '4. IP Address (not used)\n'
        '5. Action (not used)\n'
        '6. item name (file or folder name)\n'
        '7. Size (not used)\n'
        '8. Parent folder\n'
        '9. Change details\n')
    argParser.add_argument('--csv',
                           dest='csv_file',
                           required=True,
                           help='csv file to process')
    args = argParser.parse_args()
    print "CSVFile Processing {}".format(args.csv_file)
    if (args.csv_file):
        restore = Restore(shouldAuthenticate=True)
        restore.rollbackFilesInCSV(args.csv_file)
    else:
        print "Error: Requires csv_file to process"
        argParser.print_help()
Ejemplo n.º 8
0
'''Import the necessary packages'''
import numpy
import argparse
import cv2
import imutils
from imutils import contours as ct
'''Get the image'''
argparse = argparse.ArgumentParser()
argparse.add_argument("-i",
                      "--image",
                      required=True,
                      help="Adds the image from the command line")
image = vars(argparse.parse_args())
'''Define the answer key that maps to the question number
The answers are
A, B, C, D, E, E, D, C, B, A
'''
ANSWER_KEY = {0: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 4, 6: 3, 7: 2, 8: 1, 9: 0}
'''Preprocess the input image'''
image = cv2.imread(image["image"])
#change the width and height of the original image
imageCopy = imutils.resize(image, height=500)
#Start main preprocessing
gray = cv2.cvtColor(imageCopy, cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray, (1, 1), 0)
edged = cv2.Canny(blur, 105, 150)
'''Display each image when it was processed'''
cv2.imshow("Original Image", imageCopy)
cv2.waitKey(0)

cv2.imshow("Grayed Image", gray)
Ejemplo n.º 9
0
 def __init__(self):
     ap = make_argument_parser()
     arguments = vars(ap.parse_args())
     super(NewZasimWindow, self).__init__(ap, arguments)
    nucs = {'A', 'G', 'T', 'C'}
    if d == 0:
        return [pattern]
    if len(pattern) == 1:
        return nucs
    neighborhood = set()
    suffix_neighbors = neighbors(pattern[1:], d)
    for suffix in suffix_neighbors:
        if hamming_distance(pattern[1:], suffix) < d:
            for nuc in nucs:
                neighborhood.add(nuc + suffix)
        else:
            neighborhood.add(pattern[0] + suffix)
    return neighborhood

def hamming_distance(p, q):
    hamming_distance = 0
    p_len = len(p)
    q_len = len(q)
    for i in range(0, p_len):
        if i < p_len and i < q_len and p[i] != q[i]:
            hamming_distance += 1
        elif not i < p_len:
            hamming_distance = hamming_distance + q_len - 1
        elif not i < q_len:
            hamming_distance = hamming_distance + p_len - 1
    return hamming_distance

if __name__ == '__main__':
    sequence, k, d = parse_args(sys.argv[1:])
    print(*find_kmers_with_mismatches_and_reverse_complements(sequence, k, d))
Ejemplo n.º 11
0
import argparse
import sys

argparse = argparse.ArgumentParser()
argparse.add_argument("f_sp_input")
argparse.add_argument("e_sp_input")
argparse.add_argument("align_file")
argparse.add_argument("--debug", action='store_true')
args = argparse.parse_args()

DELIMITER = "▁"


def main():
    exit_status = 0
    for line, (f_sp, e_sp, align) in enumerate(
            iter_input(args.f_sp_input, args.e_sp_input, args.align_file)):
        # Grouping piece together
        f_sp_word = []
        for i, piece in enumerate(f_sp):
            if DELIMITER in piece:
                f_sp_word.append([])
            f_sp_word[-1].append((piece, i))
        e_sp_word = []
        for i, piece in enumerate(e_sp):
            if DELIMITER in piece:
                e_sp_word.append([])
            e_sp_word[-1].append((piece, i))

        align = align_missings(len(f_sp_word), len(e_sp_word), align)
Ejemplo n.º 12
0
    # execute
    batch_split(os.path.join(processed_dir, 'Before'), join(dst, 'Before'))
    batch_split(os.path.join(processed_dir, 'After'), join(dst, 'After'))
    print("IMAGE SPLIT COMPLETED")

# def batch_split(id_dir, dst):
#     print(dst)
#     for bundel in os.walk(id_dir):
#         if bundel[2]:
#             copy_dst = join(dst, bundel[0].split('Processed')[-1])
#             print(copy_dst)
#             copy_dst_right = join(copy_dst, 'right')
#             copy_dst_left = join(copy_dst, 'left')
#             os.makedirs(copy_dst_right, exist_ok=True)
#             os.makedirs(copy_dst_left, exist_ok=True)

#             mode = 0 if 'masks' in bundel[0] else 1
#             for fn in bundel[2]:
#                 if os.path.splitext(fn)[-1] == 'png':
#                     img_p = join(bundel[0], fn)
#                     split_one(img_p, copy_dst, mode=mode)
#                 elif os.path.splitext(fn)[-1] == 'xlsx':
#                     shutil.copy(join(bundel[0], fn), join(copy_dst_right, fn))
#                     shutil.copy(join(bundel[0], fn), join(copy_dst_left, fn))

if __name__ == "__main__":
    argparse = argparse.ArgumentParser(description='Split one set of evaluation and masks into right and left')
    argparse.add_argument('-i', required=True)
    argparse.add_argument('-o', required=True)
    commands = argparse.parse_args()
    main(commands.i, commands.o)
Ejemplo n.º 13
0
#!/usr/bin/python

import os
import numpy as np
import nibabel as nib
import argparse as ap

ap = ap.ArgumentParser(description="fast split of 4D nifti image")

ap.add_argument("-i", "--input", nargs=1, help="[4D_image]", metavar=('*.nii.gz'), required=True)
#ap.add_argument("-o", "--output", nargs=1, help="[outname]", metavar=('vol_????.nii.gz'), default=('vol'))
opts = ap.parse_args()

os.system("zcat %s > temp_4d.nii" % opts.input[0])
img_all = nib.load('temp_4d.nii')
data_all = img_all.get_data()
affine_all = img_all.get_affine()
header_all = img_all.get_header()
numImages=data_all.shape[3]
#outhead=str(opts.output[0])

for i in range(int(numImages)):
	nib.save(nib.Nifti1Image(data_all[:,:,:,i],affine_all),"vol%05d.nii.gz" % (i))
os.system("rm temp_4d.nii")
Ejemplo n.º 14
0
    csv_file.next()     # read the first line and discard

    if args.to_stdout:
        out = sys.stdout
    else:
        out = open(os.path.splitext(csv_name)[0] + ".vcf", "w+")

    out.write(header())
    write_fields(csv_file, out)

    os.remove(csv_name)
    out.close()

if __name__ == '__main__':
    argparse = argparse.ArgumentParser()
    argparse.add_argument("files", nargs='+',
        help="the xls(x) files to process")
    argparse.add_argument("--stdout", action="store_true", dest="to_stdout",
        help="output goes to stdout instead of a file")
    args = argparse.parse_args()

    # Constants
    FORMAT = "GT:COV:QS:TS:CM:PM:OAS:EAS"
    # fields from the csv
    cols = ["CHR", "CO", "REF", "VAR", "COV", "QS", "ZYG", "GENE", "TRANS",
            "CM", "PM", "DB", "OAS", "EAS"]
    FIELDS = dict(zip(cols, range(len(cols))))

    for xls in args.files:
        process_xls(xls)
Ejemplo n.º 15
0
if parallel:
    from llll import MultithreadedMapper, PoolMaster
    pm = PoolMaster('lineenv.py', is_filename=True, nproc=ncpu)

    def to_optimize(v):
        return pm.call(v)

    vv = mc.to_vec()
    for i in range(100):
        pm.call(vv, mc.indices) # assure indices propagated to all slaves


import argparse as ap
ap = ap.ArgumentParser()
ap.add_argument('filename')
d = ap.parse_args()

# le = StrokeEnv(grayscale=False)
# le = LineEnvCMYK()
# le = LineEnv2()
le = LineEnv4()
# le.load_image('hjt.jpg', target_width=256)
le.load_image(d.filename, target_width=256)
# le.load_image('fruits.jpg', target_width=256)
# le.load_image('jeff.jpg', target_width=256)
# le.load_image('forms.jpg', target_width=128)
# le.load_image('forms.jpg', target_width=64)
le.init_segments(num_segs=1000)

# le.set_metric(SSIMLoss)
# le.set_metric(LabPyramidLoss)
Ejemplo n.º 16
0
def main():
  '''
  `main' is entrance of this program.
  Do not call it DIRECTLY.

  [return code]:
    - If all successful, return 0.
    - If it has some issues, but no big deal,
      still return 0
    - If it has some issues which makes problem
      can't run successfuly, return 1.
    - If it has some fatal issues, return 2.
    - If exception has been triggered, return 1.
  '''
  argList = arg.parse_args()

  # BRANCH PART: If user specified `branch', it will
  # check whether `branch' is valid or not, otherwise
  # let users choose branch.
  branch = ""
  if argList.branch:
    branch = parseBranch(argList.branch)
  else:
    branch = parseBranch()

  # DOWNLOAD PART: It will download the templates
  # of those ts files.
  # If user specified `all', then it will reversive
  # compList.
  mergeFn = {}
  if argList.component_name == "all":
    for comp in compList:
      untranFn = filenameFormat.format(component=comp, langcode=untranslatedFilename)
      mergeFn.update({untranFn: filenameFormat.format(component=comp, langcode=argList.language_name)})
      # http://l10n-files.qt.io/l10n-files/{branch_name}/{untranFn}
      downFile(f"{downloadURL.format(branch_name=branch)}{untranFn}", untranFn, _("The template of {comp}").format(comp=comp))
  else:
      untranFn = filenameFormat.format(component=argList.component_name, langcode=untranslatedFilename)
      mergeFn.update({untranFn: filenameFormat.format(component=argList.component_name, langcode=argList.language_name)})
      # http://l10n-files.qt.io/l10n-files/{branch_name}/{untranFn}
      downFile(f"{downloadURL.format(branch_name=branch)}{untranFn}", untranFn, _("The template of {comp}").format(comp=argList.component_name))

  # MERGE PART: It will merge the translate file with template file.
  # It will make a backup like "qtbase-zh_TW.ts~" first, and then to merge.
  for templateFn in mergeFn:
    tranFn = mergeFn[templateFn]
    if argList.toMerge:
      if os.path.exists(tranFn) != True or os.path.isfile(tranFn) != True:
        print(_("Creating: {translate_file}...").format(translate_file=tranFn), end=" ")
        shutil.copy(templateFn, tranFn)
        print(_("Success."))
      else:
        if argList.backup:
          shutil.copy(tranFn, f"{tranFn}~")

        mergeTS(templateFn, tranFn, argList.language_name, preserveLocation= argList.cleanTags)

      # Remove template file
      print(_("Removing: {template_file}...").format(template_file=templateFn), end=" ")
      os.remove(templateFn)
      print(_("Success."))
    else:
      print(_("You can merge {translate_file} manually now. The template filename: {template_file}").format(translate_file=tranFn, template_file=templateFn))
Ejemplo n.º 17
0
parser.add_argument('--imagedir',
                    action='store',
                    dest='imagedir',
                    help='Image directory for logo search',
                    default=None)
parser.add_argument('--no-entropy',
                    action='store_true',
                    dest='no_entropy',
                    help="Don't search for high entropy",
                    default=None)
parser.add_argument('--no-cc',
                    action='store_true',
                    dest='no_cc',
                    help="Don't search for credit card",
                    default=None)
parser.add_argument('--no-keyword',
                    action='store_true',
                    dest='no_keyword',
                    help="Don't search for keywords",
                    default=None)
argv = parser.parse_args()

if argv.no_entropy:
    argv.no_entropy = True
if argv.no_cc:
    argv.no_cc = True
if argv.no_keyword:
    argv.no_keyword = True

action(argv.code, argv.imagedir, argv.no_entropy, argv.no_cc, argv.no_keyword)
Ejemplo n.º 18
0
import numpy as np

# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-v", "--video", help="path to the video file")
ap.add_argument("-a",
                "--min-area",
                type=int,
                default=5000,
                help="minimum area size")
ap.add_argument('-t',
                "--tempfolder",
                help="Folder for temp files",
                required=True)

args = vars(ap.parse_args())

# if the video argument is None, then we are reading from webcam
if args.get("video", None) is None:
    camera = cv2.VideoCapture(0)
    time.sleep(0.25)

# otherwise, we are reading from a video file
else:
    camera = cv2.VideoCapture(args["video"])

# initialize the first frame in the video stream
firstFrame = None

_object_type = "Car"
_temp_path = args["tempfolder"]
Ejemplo n.º 19
0
import argparse
from datetime import datetime, timedelta

import pandas
import matplotlib.pyplot as plt

from container import Container
from model.DataSource import DataSource


argparse = argparse.ArgumentParser()
argparse.add_argument("-d", "--days-behind", required=True, dest="days_behind", type=int,
                      help="Days behind to be taken into account")
args = vars(argparse.parse_args())

container = Container()
datapoints_repository = container.datapoints_repository()
start_date = datetime.today() - timedelta(days=args['days_behind'])
end_date = datetime.today()
extracted_data = datapoints_repository.get(DataSource.WEATHER_STATION.value, start_date, end_date)
dataframe = pandas.DataFrame(extracted_data).set_index('_id')


fig, axes = plt.subplots(5, figsize=(13, 8))
dataframe.plot(subplots=True, kind='line', x='date', y='temperature', ax=axes[0])
dataframe.plot(subplots=True, kind='line', x='date', y='pressure', color='red', ax=axes[1])
dataframe.plot(subplots=True, kind='line', x='date', y='humidity', color='blue', ax=axes[2])
dataframe.plot(subplots=True, kind='line', x='date', y='light', color='purple', ax=axes[3])
dataframe.plot(subplots=True, kind='line', x='date', y='rain', color='black', ax=axes[4])

plt.show()
Ejemplo n.º 20
0
        results_with_input, results_no_input = main_module.main_executor()
        if df1 is None:
            df1 = results_with_input
        else:
            df1 = df1.append(results_with_input, ignore_index=True)
        if df2 is None:
            df2 = results_no_input
        else:
            df2 = df2.append(results_no_input, ignore_index=True)

    plot_figure(df1, df2)
    return


# ---------------------------------------------
parser = argparse.parse_args()
parser.add_argument('--DIR',
                    choices=[
                        'us_import1', 'us_import2', 'us_import3', 'us_import4',
                        'us_import5', 'us_import6'
                    ],
                    default=None)
parser.add_argument('--feedback_size', type=int, default=10)
parser.add_argument(
    '--top_K',
    type=int,
    default=10,
)

args = parser.parse_args()
DIR = args.DIR
Ejemplo n.º 21
0
        command.type = data_arr[0]
        command.posx = round(float(data_arr[1]), 3)
        command.posy = round(float(data_arr[2]), 3)

        self.pub.publish(command)


if __name__ == '__main__':

    rospy.init_node('yumi_eneroth_bridge')

    argparse = argparse.ArgumentParser(prog='eneroth_bridge.py')
    argparse.add_argument("--host", type=str, help='Host address')
    argparse.add_argument("--port", type=int, help='Host port', default=5000)

    args = argparse.parse_args(rospy.myargv(argv=sys.argv)[1:])

    enerothclient = EnerothYumiClient(host=args.host, port=args.port)

    if (not enerothclient.connect()):
        rospy.signal_shutdown("Communication Error with the Server")

    rospy.loginfo("Yumi Eneroth bridge started...")

    while not rospy.is_shutdown():
        data = enerothclient.listen()
        if len(data) > 0:
            enerothclient.parsedata(data)

    enerothclient.close()
from skimage.feature import hog
from sklearn.externals import joblib
import argparse as ap
from nms import nms
from config import *
from PIL import Image
from resizeimage import resizeimage
import numpy as np

# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-v", "--video", help="path to the video file")
ap.add_argument("-a", "--min-area", type=int, default=5000, help="minimum area size")
ap.add_argument('-t', "--tempfolder", help="Folder for temp files", required=True)

args = vars(ap.parse_args())

# if the video argument is None, then we are reading from webcam
if args.get("video", None) is None:
	camera = cv2.VideoCapture(0)
	time.sleep(0.25)

# otherwise, we are reading from a video file
else:
	camera = cv2.VideoCapture(args["video"])

# initialize the first frame in the video stream
firstFrame = None

_object_type = "Car"
_temp_path = args["tempfolder"]
Ejemplo n.º 23
-1
        except Exception as e:
            logging.info( 'Error: delete did not work.. on file {}'.format(fileItem['name']) )
            logging.info( 'Error: response text {}'.format(r.text) )
            raise e


if __name__ == "__main__":
    argParser = argParser.ArgumentParser(description='Process a csv file for rollback. '
                                                     'The csv file should have the following columns'
                                                     '(some are not used and can be left empty, but structure is important here):\n'
                                                 '1. Date\n'
                                                 '2. User name\n'
                                                 '3. User email (not used)\n'
                                                 '4. IP Address (not used)\n'
                                                 '5. Action (not used)\n'
                                                 '6. item name (file or folder name)\n'
                                                 '7. Size (not used)\n'
                                                 '8. Parent folder\n'
                                                 '9. Change details\n')
    argParser.add_argument('--csv', dest='csv_file', required=True, help='csv file to process')
    args = argParser.parse_args()
    print "CSVFile Processing {}".format(args.csv_file)
    if (args.csv_file):
        restore = Restore(shouldAuthenticate=True)
        restore.rollbackFilesInCSV(args.csv_file)
    else:
        print "Error: Requires csv_file to process"
        argParser.print_help()