Exemplo n.º 1
0
def constuct_req_file(args):
    ''' read the input requirements from user and create a new txt
    file in the data_env that includes the requirements given by the user.
    if a value wasn't provided by the user, use the defaults'''
    print("Summarising the structural requirements...")
    req_dict = {}
    ## 1. Load default params:
    with open(os.path.join(args.sling_dir,"default.txt")) as f: ## get all the values from the req file
        for line in f:
            key, val = line.strip().split()
            if key != "order":
                val = int(val)
            req_dict[key] = val

    orders = ["upstream", "downstream", "either", "both"]

    args_dict = vars(args)
    for key in req_dict:
        if args_dict[key] is not None:
            if key == "order":
                args_dict[key] = args_dict[key].lower()
            req_dict[key] = args_dict[key]

    utils.check_reqs(req_dict)

    with open(os.path.join(args.sling_dir, args.name + ".txt"), "w") as out:
        for key in req_dict:
            out.write(key + "\t" + str(req_dict[key]) + "\n")
    return
Exemplo n.º 2
0
def get_requirements(args, data_env):
    # path to the requirement document of each built in DB
    reqs = utils.databases
    if args["hmm_db"] in reqs:  # built in collections
        req_file = os.path.join(data_env, args["hmm_db"] + ".txt")
    else:  # not a built in collection, take the default values
        req_file = os.path.join(data_env, "default.txt")

    with open(req_file) as f:  # get all the values from the req file
        for line in f:
            key, val = line.strip().split()
            if key != "order":
                val = int(val)
            if args[key] is None:  # otherwise, keep what the user gave
                args[key] = val
    utils.check_reqs(args)
    return
Exemplo n.º 3
0
#!/usr/bin/env python

from utils import check_reqs
check_reqs()

"""
Converts an image stack to an MRC file. Runs either as a command line program or as an importable function.
"""

def stack2mrc(stack, mrc, imfilter = lambda im: im):
    """
    Converts an image stack to an MRC file. Returns the new MRC file object.

    Arguments:
    stack    -- the images to read, an iterable of file names
    mrc      -- the MRC filename to save to
    
    Optional Arguments:
    imfilter  -- a function/callable that takes and returns an image
    """
    from mrc import MRC
    from images import imread

    stack = iter(stack)
    try: img = imfilter(imread(stack.next()))
    except StopIteration: raise ValueError("Must provide at least one image")
    mrc = MRC(mrc, nx=img.shape[1], ny=img.shape[0], dtype=img.dtype)
    mrc.append(img)
    mrc.append_all(imfilter(imread(img)) for img in stack) # will skip the first one
    mrc.write_header()
    return mrc
Exemplo n.º 4
0
    manager.types[person].override_property('occupant_age', MockFn(PERSON.get_age))
    manager.types[person].override_property('occupant_gender', MockFn(PERSON.get_sex))
    manager.types[person].override_property('occupant_name', MockFn(PERSON.get_name))

    for _ in range(SEED_ENTITIES):
        manager.register(person)
        for mocker in manager.types.values():
            if mocker.killed:
                manager.kill()
                return
            break

    manager.kill()


if __name__ == '__main__':
    check_reqs(reqs=['KERNEL_URL', 'KERNEL_USER', 'KERNEL_PASSWORD'])

    NAMES = file_to_json(f'{RESOURCES_DIR}/sample-names.json')
    POP_CENTERS = file_to_json(f'{RESOURCES_DIR}/sample-locations.json')

    args = sys.argv
    seed = 1000
    try:
        if len(args) > 1 and isinstance(int(args[1]), int):
            seed = int(args[1])
    except ValueError:
        pass

    main(seed_size=seed)
Exemplo n.º 5
0
#!/usr/bin/env python

from utils import check_reqs
check_reqs()
"""
Converts an image file to a new format.
"""


def help_msg(err=0, msg=None):
    from os.path import basename
    from sys import stderr, argv, exit
    from textwrap import fill, TextWrapper
    from utils import get_terminal_width
    import imfilter_util
    w = max(get_terminal_width(), 20)
    tw = TextWrapper(width=w, subsequent_indent=' ' * 18)
    if msg != None: print >> stderr, fill(msg, w)
    print "Usage:"
    print tw.fill("  %s [args] input.xxx output.xxx" % basename(argv[0]))
    print ""
    print "Supports numerous file formats based on extension. The extension should be accurate to the filetype otherwise it may not work."
    print ""
    print "Optional arguments:"
    print tw.fill("  -h  --help      Display this help")
    for l in imfilter_util.usage:
        print tw.fill(l) if len(l) > 20 and l[0] == ' ' else l
    exit(err)


if __name__ == "__main__":
Exemplo n.º 6
0
    schema_decorators = schema_decorator(project_id, schema_ids)
    LOGGER.debug(schema_decorators)

    ps_ids = {ps.name: ps.id for ps in schema_decorators.values()}
    ms = mappingset(project_id)
    sub_id = mapping(project_id, ms.id, ps_ids)
    LOGGER.debug(sub_id)


if __name__ == '__main__':

    check_reqs(reqs=[
        'KERNEL_URL',
        'KERNEL_USER',
        'KERNEL_PASSWORD',
        'PROJECT_NAME',
        'MAPPING_NAME',
    ])

    try:
        client = Client(KERNEL_URL,
                        KERNEL_USER,
                        KERNEL_PASSWORD,
                        log_level=CLIENT_LOGLEVEL,
                        realm=REALM,
                        keycloak_url=KEYCLOAK_URL)
    except Exception as err:
        LOGGER.error(f'Kernel is not ready. Please check '
                     f'''it's status or wait a moment and try again : {err}''')
        sys.exit(1)