Esempio n. 1
0
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.mrc output_directory" % basename(argv[0]))
    print ""
    print "Supports numerous file formats based on extension. Not all types can be saved to with all options."
    print ""
    print "Optional arguments:"
    print tw.fill("  -h  --help      Display this help")
    print tw.fill(
        "  -e  --ext=      The extension (type) of the files to save, defaults to 'png'"
    )
    print tw.fill(
        "  -b  --base=     The base filename (without extension) to use, needs to have a %d to replace with slice number, defaults to '%04d'"
    )
    print tw.fill(
        "  -x #-#          The x coordinate to extract given as two integers seperated by a dash"
    )
    print tw.fill(
        "  -y #-#          The y coordinate to extract given as two integers seperated by a dash"
    )
    print tw.fill(
        "  -z indices      The slice indices to use, accepts integers with commas and dashes between them"
    )
    for l in imfilter_util.usage:
        print tw.fill(l) if len(l) > 20 and l[0] == ' ' else l
    exit(err)
Esempio n. 2
0
 def train(self):
     for n in range(FLAGS.epochs):
         for _ in tqdm(iterable=range(FLAGS.steps_per_epoch),
                       ncols=int(get_terminal_width() * .9),
                       desc=tqdm.write(f'Epoch {n + 1} / {FLAGS.epochs}'),
                       unit=' steps'):
             self.train_step(self.img)
         save_img(self.img.read_value(), n + 1)
Esempio n. 3
0
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
    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 input.pts [input2.pts ...] output.pts" % basename(argv[0]))
    print ""
    print "Optional arguments:"
    print tw.fill("  -h  --help      Display this help")
    exit(err)
Esempio n. 4
0
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)
Esempio n. 5
0
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] input1.xxx [input2.xxx ...] output.mrc" % basename(argv[0]))
    print ""
    print "You may also use a glob-like syntax for any of the input files, such as 'folder/*.png' or '[0-9][0-9][0-9].png'"
    print ""
    print "Supports numerous file formats. MHA/MHD files must have the proper file extension. Other files will have their data examined to determine type. All images must have the same dimensions and pixel format. Not all pixel formats all supported."
    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)
Esempio n. 6
0
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] input1.xxx [input2.xxx ...] output.txt" % basename(argv[0]))
    print ""
    print tw.fill("You may also use a glob-like syntax for any of the input files, such as 'folder/*.png' or '[0-9][0-9][0-9].png'. Outputs to stdout if output is -.")
    print ""
    print tw.fill("Supports numerous file formats. Sums the histogram from all given images. Saves a list of integers to the output file.")
    print ""
    print "Optional arguments:"
    print tw.fill("  -h  --help      Display this help")
    print tw.fill("  -n  --nbins=    Number of bins in the histogram, defaults to 256")
    for l in imfilter_util.usage: print tw.fill(l)
    exit(err)
Esempio n. 7
0
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] input1.xxx [input2.xxx ...] output.mrc" %
                  basename(argv[0]))
    print ""
    print "You may also use a glob-like syntax for any of the input files, such as 'folder/*.png' or '[0-9][0-9][0-9].png'"
    print ""
    print "Supports numerous file formats. MHA/MHD files must have the proper file extension. Other files will have their data examined to determine type. All images must have the same dimensions and pixel format. Not all pixel formats all supported."
    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)
Esempio n. 8
0
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.mrc output_directory" % basename(argv[0]))
    print ""
    print "Supports numerous file formats based on extension. Not all types can be saved to with all options."
    print ""
    print "Optional arguments:"
    print tw.fill("  -h  --help      Display this help")
    print tw.fill("  -e  --ext=      The extension (type) of the files to save, defaults to 'png'")
    print tw.fill("  -b  --base=     The base filename (without extension) to use, needs to have a %d to replace with slice number, defaults to '%04d'")
    print tw.fill("  -x #-#          The x coordinate to extract given as two integers seperated by a dash")
    print tw.fill("  -y #-#          The y coordinate to extract given as two integers seperated by a dash")
    print tw.fill("  -z indices      The slice indices to use, accepts integers with commas and dashes between them")
    for l in imfilter_util.usage: print tw.fill(l) if len(l) > 20 and l[0] == ' ' else l
    exit(err)
def get_help(parser):
    """
    Return help text for the parser.

    :param parser: parser
    :type parser: ArgumentParser
    :return: fully formatted help string
    :rtype: str
    """
    # Code almost identical with parser.print_help() with next changes:
    # it return text instead print
    # it place group 'command arguments' to the first place
    width = min(get_terminal_width(), 100)
    formatter = HelpFormatter(prog=parser.prog,
                              max_help_position=30,
                              width=width)
    # usage
    formatter.add_usage(parser.usage, parser._actions,
                        parser._mutually_exclusive_groups)
    # description
    formatter.add_text(parser.description)

    # positionals, optionals and user-defined groups
    groups = list(parser._action_groups)
    groups.sort(key=lambda x: x.title != 'command arguments')
    for action_group in groups:
        formatter.start_section(action_group.title)
        formatter.add_text(action_group.description)
        formatter.add_arguments(action_group._group_actions)
        formatter.end_section()

    # epilog
    formatter.add_text(parser.epilog)

    # determine help from format above
    return formatter.format_help()