예제 #1
0
 def __call__(self, parser, namespace, values, option_string=None):
     # get the input file(s)
     input_files = namespace.input_file
     if input_files is None:
         # see if we should raise an error
         try:
             raise_err = not parser.no_input_file_err
         except AttributeError:
             raise_err = True
         if raise_err:
             raise NoInputFileError("must provide at least one input file")
         else:
             # just return to stop further processing
             return
     filesbytype = {}
     fileparsers = {}
     for fn in input_files:
         fp = loadfile(fn, 'r')
         try:
             filesbytype[fp.name].append(fn)
         except KeyError:
             filesbytype[fp.name] = [fn]
             # get any extra options
             fileparsers[fp.name], _ = fp.extra_args_parser(
                 skip_args=self.skip_args, add_help=False)
         fp.close()
     # now print information about the intersection of all parameters
     parameters = get_common_parameters(input_files, collection='all')
     print("\n" + textwrap.fill("Parameters available with this (these) "
                                "input file(s):"),
           end="\n\n")
     print(textwrap.fill(' '.join(sorted(parameters))), end="\n\n")
     # information about the pycbc functions
     pfuncs = sorted(FieldArray.functionlib.fget(FieldArray).keys())
     print(textwrap.fill("Available pycbc functions (see "
                         "http://pycbc.org/pycbc/latest/html for "
                         "more details):"),
           end="\n\n")
     print(textwrap.fill(', '.join(pfuncs)), end="\n\n")
     # numpy funcs
     npfuncs = sorted([
         name for (name, obj) in _numpy_function_lib.items()
         if isinstance(obj, numpy.ufunc)
     ])
     print(textwrap.fill("Available numpy functions:"), end="\n\n")
     print(textwrap.fill(', '.join(npfuncs)), end="\n\n")
     # misc
     consts = "e euler_gamma inf nan pi"
     print(textwrap.fill("Recognized constants:"), end="\n\n")
     print(consts, end="\n\n")
     print(textwrap.fill("Python arthimetic (+ - * / // ** %), "
                         "binary (&, |, etc.), and comparison (>, <, >=, "
                         "etc.) operators may also be used."),
           end="\n\n")
     # print out the extra arguments that may be used
     outstr = textwrap.fill("The following are additional command-line "
                            "options that may be provided, along with the "
                            "input files that understand them:")
     print("\n" + outstr, end="\n\n")
     for ftype, fparser in fileparsers.items():
         fnames = ', '.join(filesbytype[ftype])
         if fparser is None:
             outstr = textwrap.fill(
                 "File(s) {} use no additional options.".format(fnames))
             print(outstr, end="\n\n")
         else:
             fparser.usage = fnames
             fparser.print_help()
     parser.exit(0)
예제 #2
0
 def __call__(self, parser, namespace, values, option_string=None):
     # get the input file(s)
     input_files = namespace.input_file
     if input_files is None:
         # see if we should raise an error
         try:
             raise_err = not parser.no_input_file_err
         except AttributeError:
             raise_err = True
         if raise_err:
             raise NoInputFileError("must provide at least one input file")
         else:
             # just return to stop further processing
             return
     filesbytype = {}
     fileparsers = {}
     for fn in input_files:
         fp = loadfile(fn, 'r')
         try:
             filesbytype[fp.name].append(fn)
         except KeyError:
             filesbytype[fp.name] = [fn]
             # get any extra options
             fileparsers[fp.name], _ = fp.extra_args_parser(
                 skip_args=self.skip_args, add_help=False)
         fp.close()
     # now print information about the intersection of all parameters
     parameters = get_common_parameters(input_files, collection='all')
     print("\n"+textwrap.fill("Parameters available with this (these) "
                              "input file(s):"), end="\n\n")
     print(textwrap.fill(' '.join(sorted(parameters))),
           end="\n\n")
     # information about the pycbc functions
     pfuncs = sorted(FieldArray.functionlib.fget(FieldArray).keys())
     print(textwrap.fill("Available pycbc functions (see "
                         "http://pycbc.org/pycbc/latest/html for "
                         "more details):"), end="\n\n")
     print(textwrap.fill(', '.join(pfuncs)), end="\n\n")
     # numpy funcs
     npfuncs = sorted([name for (name, obj) in _numpy_function_lib.items()
                       if isinstance(obj, numpy.ufunc)])
     print(textwrap.fill("Available numpy functions:"),
           end="\n\n")
     print(textwrap.fill(', '.join(npfuncs)), end="\n\n")
     # misc
     consts = "e euler_gamma inf nan pi"
     print(textwrap.fill("Recognized constants:"),
           end="\n\n")
     print(consts, end="\n\n")
     print(textwrap.fill("Python arthimetic (+ - * / // ** %), "
                         "binary (&, |, etc.), and comparison (>, <, >=, "
                         "etc.) operators may also be used."), end="\n\n")
     # print out the extra arguments that may be used
     outstr = textwrap.fill("The following are additional command-line "
                            "options that may be provided, along with the "
                            "input files that understand them:")
     print("\n"+outstr, end="\n\n")
     for ftype, fparser in fileparsers.items():
         fnames = ', '.join(filesbytype[ftype])
         if fparser is None:
             outstr = textwrap.fill(
                 "File(s) {} use no additional options.".format(fnames))
             print(outstr, end="\n\n")
         else:
             fparser.usage = fnames
             fparser.print_help()
     parser.exit(0)