def config_web_parser(parser: argparse.ArgumentParser, is_primary=False): """Configure the argument parser for the web command Args: parser: The parser to configure is_primary: True if configuring as the main command. False if configuring as a sub-command. """ parser.description = parawrap.fill( 'Run builtin dev server or print a command that would run the server ' 'if the command were evaluated. Although the production server will ' 'not be run directly, it could be run with:\n' '\n' '\t\'eval $({}{} web [OPTIONS] <production-server>)\'' ''.format(cfg.PKG_NAME, '' if is_primary else ' web') ) parser.formatter_class = MixedHelpFormatter parser.add_argument('--debug', '-d', action='store_true', help='Run the dev server with debug web iface and ' 'reload server on source file changes') parser.add_argument('--host', default=cfg.WEB_HOST, help='Server host/name') parser.add_argument('--port', '-p', type=int, default=cfg.WEB_PORT, help='Port on which the server listens') parser.add_argument('server', choices=('builtin', 'eventlet', 'gunicorn'), default='builtin', help='Run builtin dev server or print command ' 'related to running a specific production server') parser.set_defaults(func=web_cmd)
def execute_command(): """ :return: """ parser = ArgumentParser() parser.description = cli.reformat(DESCRIPTION) parser.add_argument("list_command", type=str, help="The list command itself") parser.add_argument("report_type", type=str, nargs="?", default=None, help="The type of report to list.") args = vars(parser.parse_args()) report_type = args["report_type"] if not report_type: report_type = "all" else: report_type = report_type.lower() print("") if report_type[0] == "g": list_groups() elif report_type[0] == "t": list_trials() else: list_groups() print("") list_trials()
def create_argument_parser(): """Create the argument parser.""" parser = ArgumentParser(add_help=False) parser.usage = "gcovr [options] [search_paths...]" parser.description = \ "A utility to run gcov and summarize the coverage in simple reports." parser.epilog = "See <http://gcovr.com/> for the full manual." options = parser.add_argument_group('Options') options.add_argument( "-h", "--help", help="Show this help message, then exit.", action="help" ) options.add_argument( "--version", help="Print the version number, then exit.", action="store_true", dest="version", default=False ) argument_parser_setup(parser, options) return parser
def _getparser(self): parser = ArgumentParser(prog='pin ' + self.command, add_help=False) if self.__doc__: parser.description = self.__doc__.splitlines()[0] self.fire('pre-parser', parser) self.setup_parser(parser) self.fire('post-parser', parser) return parser
def parse_options(): stderr.write("reading options ...\n") parser = ArgumentParser() parser.description = "Test P (verification of '-hydrology distributed')." parser.add_argument("--pism_path", dest="PISM_PATH", default=".") parser.add_argument("--mpiexec", dest="MPIEXEC", default="") parser.add_argument("--Mx", dest="Mx", help="Horizontal grid size. Default corresponds to a 1km grid.", type=int, default=51) parser.add_argument("--keep", dest="keep", action="store_true", help="Keep the generated PISM input file.") return parser.parse_args()
def execute_command(): """ Runs the deploy command """ parser = ArgumentParser() parser.description = cli.reformat(DESCRIPTION) parser.add_argument( 'deploy', type=str, help='The deploy command to execute' ) parser.add_argument( 'root_path', type=str, help=cli.reformat(""" The folder in the S3 bucket where your files will be uploaded """) ) parser.add_argument( '-p', '--profile', dest='profile', type=str, default=None, help=cli.reformat(""" The name of the AWS credentials profile to use for access to the AWS S3 bucket resources """) ) parser.add_argument( '-b', '--bucket', dest='bucket', type=str, default=None, help=cli.reformat(""" The name of the S3 bucket where the files will be uploaded """) ) args = vars(parser.parse_args()) configs = system.load_configs() upload_in_folder( get_aws_settings(configs, **args), paths.results('report') ) system.log('[COMPLETE]: Trials have been deployed')
def execute_command(): """ :return: """ parser = ArgumentParser() parser.description = cli.reformat(DESCRIPTION) parser.add_argument( 'generate_command', type=str, help='The generate command itself' ) parser.add_argument( 'trial_or_group', type=str, help='Path to a trial or group file where the data source is specified' ) parser.add_argument( 'output_filename', type=str, help='Name of the csv file to be created' ) args = parser.parse_args() cli_configs = system.load_configs() path = get_path(args.trial_or_group, cli_configs) if path is None: system.log('ERROR: Invalid or missing trial/group path') sys.exit(1) settings = configs.load(None, path) out_path = os.path.join(settings['directory'], args.output_filename) simulate.load_trackway_positions( settings, save_as=out_path )
if 'vmax' in kwargsdict: self.vmax = kwargsdict['vmax'] if 'extend' in kwargsdict: self.extend = kwargsdict['extend'] if 'format' in kwargsdict: self.format = kwargsdict['format'] if 'colorbar_label' in kwargsdict: self.colorbar_label = kwargsdict['colorbar_label'] # Set up the option parser parser = ArgumentParser() parser.description = "A script to plot a variable in a netCDF file using imshow." parser.add_argument("FILE", nargs='*') parser.add_argument("--alpha", dest="alpha", help="transparency of overlay", default=1.) parser.add_argument("--bounds", dest="bounds", nargs=2, type=float, help="lower and upper bound for colorbar, eg. -1 1", default=None) parser.add_argument("--boundary_tol", dest="boundary_tol", nargs=1, type=float, help='''if set, color areas brown where obs <= boundary_tol but data >= boundary_tol, works for difference plots only.''', default=None) parser.add_argument("--colorbar_position", dest="colorbar_position", choices=['bottom', 'right', 'upper', 'left'], help="position of the colorbar for n x m plots", default='bottom') parser.add_argument("--obs_file", dest="obs_file", help=''' file with observations for difference plot, experiment - observation. Must be on same grid as experiments. Default is None''', default=None) parser.add_argument("--colormap", dest="colormap",
def setup_clargs(parser=None): """ Setup command line arguments for the bulk wrf2arl program. :param parser: if given, an argument parser. Generally used if adding this program as a subcommand for a larger program, create a new parser as a subparser and pass it to this function. If not given, an argument parser is created. :type parser: ArgumentParser :return: if ``parser`` is not given, the arguments specified on the command line are returned as a dictionary. If parser is given, then it is modified in-place to have all the desired command line arguments. In either case, the value for 'exec_fxn' will be the driver function to call with the other command line arguments as keyword values. :rtype: dict or None. """ description = 'Bulk convert WRF files to ARL format' if parser is None: parser = ArgumentParser(description=description) i_am_main = True else: parser.description = description i_am_main = False parser.add_argument( 'file_pattern', help='Convert files matching this pattern. Enclose in quotes to avoid ' 'expanding globs in the shell, e.g. %(prog)s "wrfout*".') parser.add_argument( 'arl_variable_file', help='Which variable file to use for converting WRF variables to ARL ' 'variables. If given as an absolute path or a path starting with ' '"./" or "../", then the file pointed to by that path is used. If ' 'given without a leading "./" or "../", then it will be looked for ' 'in the wrf2arl directory.') parser.add_argument( '-R', '--recursive', action='store_true', help= 'Search for files matching the given pattern recursively in the current directory. ' 'Output files will be stored in a directory tree under output_dir mimicing the directory ' 'structure here.') parser.add_argument( '-o', '--output-dir', default='.', help='The directory to store the output files in. Default ' 'is the current directory.') parser.add_argument( '-O', '--output-pattern', default=_default_output_pattern, help= 'The naming pattern to use for output files. Python datetime formatting can be used to ' 'specify how to include the date and its bracket formatting for the keyword "domain" ' 'will be replaced with the WRF domain number. Default is "%(default)s".' ) # TODO add subcommand to set up/view config parser.set_defaults(exec_fxn=drive_wrfnc2arl) if i_am_main: return vars(parser.parse_args())
# spark 环境初始化 conf = SparkConf().set("spark.ui.port", "44040") sc = SparkContext(conf=conf) sqlContext = SQLContext(sc) # 加载简历基本信息,教育经历,工作经历 results = dict() # statistic_profile(sqlContext.read.parquet(profile_path), results) # statistic_education(sqlContext.read.parquet(education_path), results) statistic_work(sqlContext.read.parquet(work_path), results) write2file(results, output_path, suggest) if __name__ == "__main__": parser = ArgumentParser(usage=__doc__) parser.description = "简历和职位数据预处理" parser.add_argument('-p', action='store', dest='profile_path', default=PROFILE_PATH, help='简历基本信息文件路径,parquet格式') parser.add_argument('-e', action='store', dest='education_path', default=EDUCATION_PATH, help='简历教育经历文件路径,parquet格式') parser.add_argument('-w', action='store', dest='work_path', default=WORK_PATH, help='简历工作经历文件路径,parquet格式')
#!/usr/bin/env python # # # Copyright (C) 2013 Andy Aschwanden, University of Alaska Fairbanks from argparse import ArgumentParser import numpy as np import pandas as pa from pyproj import Proj import datetime # Set up the argument parser parser = ArgumentParser() parser.description = '''A script to add lat/lon coordinates based on GPS marker.''' parser.add_argument("FILE", nargs='*') parser.add_argument("--avg_date",dest="avg_date", help='''A datetime a few measurements before the shift, for averaging, in UTC''', default='2013-06-27 01:48:29') parser.add_argument("--before_date",dest="before_date", help='''The datetime before the shift in UTC''', default='2013-06-27 03:04:17') parser.add_argument("--after_date",dest="after_date", help='''The datetime after the shift in UTC''', default='2013-06-27 03:19:07') options = parser.parse_args() inname = options.FILE[0] outname = options.FILE[1] avg_date = options.avg_date before_date = options.before_date
try: from netCDF4 import Dataset as NC except: from netCDF3 import Dataset as NC try: import pypismtools.pypismtools as ppt except: import pypismtools as ppt import PISM # Set up the option parser parser = ArgumentParser() parser.description = "A script to demonstrate how to convert temperature to enthalpy." parser.add_argument("FILE", nargs='*') options = parser.parse_args() args = options.FILE nc = NC(args[0], 'r') x = nc.variables['x'][:] y = nc.variables['y'][:] z = nc.variables['z'][:] # The enthalpy convert expects Kelvin inunits = nc.variables['temp'].units outunits = 'K' try:
#!/usr/bin/env python # Copyright (C) 2015 Andy Aschwanden import itertools from collections import OrderedDict import os from argparse import ArgumentParser from resources import * grid_choices = [9000, 6000, 4500, 3600, 1800, 1500, 1200, 900] # set up the option parser parser = ArgumentParser() parser.description = "Generating scripts for initMIP simulations." parser.add_argument("FILE", nargs=1) parser.add_argument("-n", '--n_procs', dest="n", type=int, help='''number of cores/processors. default=64.''', default=64) parser.add_argument("-w", '--wall_time', dest="walltime", help='''walltime. default: 12:00:00.''', default="12:00:00") parser.add_argument("-q", '--queue', dest="queue", choices=['standard_4', 'standard_16', 'standard', 'gpu', 'gpu_long', 'long', 'normal'], help='''queue. default=standard_4.''', default='standard_4') parser.add_argument("--calving", dest="calving", choices=['float_kill', 'ocean_kill', 'eigen_calving', 'thickness_calving'], help="claving", default='thickness_calving') parser.add_argument("-d", "--domain", dest="domain", choices=['gris', 'gris_ext'], help="sets the modeling domain", default='gris_ext') parser.add_argument("-f", "--o_format", dest="oformat", choices=['netcdf3', 'netcdf4_parallel', 'pnetcdf'], help="output format", default='netcdf4_parallel') parser.add_argument("-g", "--grid", dest="grid", type=int,
#!/usr/bin/env python # Copyright (C) 2015 Andy Aschwanden import os import numpy as np from argparse import ArgumentParser from netCDF4 import Dataset as NC try: import pypismtools.pypismtools as ppt except: import pypismtools as ppt # Set up the option parser parser = ArgumentParser() parser.description = "Create initMIP SMB anomalies." parser.add_argument("--topo_file", dest="topo_file", help='''Topo smb file''') parser.add_argument("--background_file", dest="background_file", help='''Background smb file''') parser.add_argument("OUTFILE", nargs=1) options = parser.parse_args() topo_file = options.topo_file background_file = options.background_file outfile = options.OUTFILE[0] nc_a = NC(topo_file, 'r') nc_b = NC(background_file, 'r') # RCM p values
def build_parser(cls, parser: ArgumentParser): parser.description = "Test all challenges in the set year for correctness" parser.add_argument("--strict", action="store_true", help="Limit all runs to 15 seconds")
from dateutil.parser import parse from datetime import datetime import time import numpy as np try: import netCDF4 as netCDF except: print("netCDF4 is not installed!") sys.exit(1) NC = netCDF.Dataset from netcdftime import utime # Set up the option parser parser = ArgumentParser() parser.description = '''Script creates a time file with time and time bounds that can be used to determine to force PISM via command line option -time_file''' parser.add_argument("FILE", nargs='*') parser.add_argument( "-p", "--periodicity", dest="periodicity", help='''periodicity, e.g. monthly, daily, etc. Default=monthly''', default="monthly") parser.add_argument("-a", "--start_date", dest="start_date", help='''Start date in ISO format. Default=1989-1-1''', default='1989-1-1') parser.add_argument("-e",
if len(selection) > 0: print("Selected chapters: ", end='\n\n') _print_chapters(all_selected, index=True, title=True, start=True, end=True) print() return all_selected if __name__ == '__main__': parser = ArgumentParser() parser.description = "Adds ID3v2 chapter tags to mp3 audiobook files downloaded from Overdrive" parser.add_argument('path', help='Path to audiobook directory') parser.add_argument( '-o', '--overwrite', action='store_const', const=True, default=False, help= 'Overwrite existing chapter information. Without this flag, mp3 files with ' 'existing chapter information will be ignored') parser.add_argument( '-s', '--select', action='store_const', const=True,
def prompt( message: str, start: str="::", default: bool=True, ) -> bool: indicator = "[Y/n]" if default else "[y/N]" choice = input(f"{start} {message} {indicator} ") if not choice: return default return choice.lower() in ["y", "yes"] parser = ArgumentParser() parser.description = "Interactively install a list of packages." parser.add_argument( "file", nargs="?", type=str, default="packages.txt", help="A text file containing newline delimited package names.", ) parser.add_argument( "-b", "--backend", type=str, default="pacman", choices=["pacman", "yaourt", "yay"], help="The package manager to be used as a backend." ) args = parser.parse_args() adapter = {
if __name__ == "__main__": from argparse import ArgumentParser import os import os.path import tempfile import shutil from time import time, asctime try: from netCDF4 import Dataset as NC except: PETSc.Sys.Print("netCDF4 is not installed!") sys.exit(1) parser = ArgumentParser() parser.description = "Fill missing values by solving the Laplace equation in on the missing values and using present values as Dirichlet B.C." parser.add_argument("INPUT", nargs=1, help="Input file name.") parser.add_argument("OUTPUT", nargs=1, help="Output file name.") parser.add_argument("-a", "--all", dest="all", action="store_true", help="Process all variables.") parser.add_argument("-v", "--vars", dest="variables", help="comma-separated list of variables to process") options, _ = parser.parse_known_args() input_filename = options.INPUT[0] output_filename = options.OUTPUT[0] if options.all: nc = NC(input_filename)
m = nc.variables[mvar][t, Ellipsis] try: m_fill_value = nc.variables[mvar]._FillValue except: m_fill_value = fill_value m[mt < self.params["threshold_masking_value"]] = m_fill_value nc.variables[mvar][t, Ellipsis] = m nc.close() if __name__ == "__main__": # set up the option parser parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter) parser.description = "Adding a hillshade to a netCDF file." parser.add_argument( "FILE", nargs=1, help="netCDF file with dimensions ('time', 'y', 'x'). Other permutations are currently not supported", ) parser.add_argument("-v", "--variable", dest="variable", help="Variable used for hillshade", default="usurf") parser.add_argument("--altitude", dest="altitude", type=float, help="Altitude for hillshade", default=45) parser.add_argument("--azimuth", dest="azimuth", type=float, help="Azimuth for hillshade", default=45) parser.add_argument("--fill_value", dest="fill_value", type=float, help="Fill value for masking", default=0) parser.add_argument( "--threshold_masking", dest="threshold_masking", action="store_false", help="Masking above threshold", default=True,
for out_format in out_formats: if out_file is None: ## out_file = "g" + str(grid_spacing) + grid_spacing_units + "_" + param1 + "_" + str(value1) + "_" + param2 + "_" + str(value2) + "." + out_format out_file = param1 + "_" + str(value1) + "_" + param2 + "_" + str(value2) + "." + out_format else: out_file = out_file + "." + out_format print " - writing image %s ..." % out_file fig.savefig(out_file ,bbox_inches='tight',pad_inches=pad_inches,dpi=out_res) plt.close() del fig if __name__ == "__main__": # Set up the argument parser parser = ArgumentParser() parser.description = "A script to compare model results and observations." parser.add_argument("FILE", nargs='*') parser.add_argument("--boot_file",dest="boot_file", help="file containing original ice thickness for masking and comparison",default="foo.nc") parser.add_argument("--obs_file",dest="obs_file", help="file containing observations",default="bar.nc") parser.add_argument("--debug",dest="DEBUG",action="store_true", help="Debugging mode",default=False) parser.add_argument("-f", "--output_format",dest="out_formats", help="Comma-separated list with output graphics suffix, default = pdf",default='pdf') parser.add_argument("--bins",dest="Nbins", help=" specifies the number of bins",default=NBINS) parser.add_argument("--histmax",dest="histmax", help=" max velocity (m/a) used in histogram",default=HISTMAX) parser.add_argument("--outlier",dest="outlier", help=" speed difference (m/a) above which velocities are not used in histogramm",default=OUTLIER_THRESHOLD)
def create_argument_parser(): """Create the argument parser.""" parser = ArgumentParser(add_help=False) parser.usage = "gcovr [options] [search_paths...]" parser.description = \ "A utility to run gcov and summarize the coverage in simple reports." parser.epilog = "See <http://gcovr.com/> for the full manual." # Style guide for option help messages: # - Prefer complete sentences. # - Phrase first sentence as a command: # “Print report”, not “Prints report”. # - Must be readable on the command line, # AND parse as reStructured Text. options = parser.add_argument_group('Options') options.add_argument("-h", "--help", help="Show this help message, then exit.", action="help") options.add_argument("--version", help="Print the version number, then exit.", action="store_true", dest="version", default=False) options.add_argument("-v", "--verbose", help="Print progress messages. " "Please include this output in bug reports.", action="store_true", dest="verbose", default=False) options.add_argument("-r", "--root", help="The root directory of your source files. " "Defaults to '%(default)s', the current directory. " "File names are reported relative to this root. " "The --root is the default --filter.", action="store", dest="root", default='.') options.add_argument( 'search_paths', help="Search these directories for coverage files. " "Defaults to --root and --object-directory.", nargs='*', ) options.add_argument( "--fail-under-line", type=check_percentage, metavar="MIN", help="Exit with a status of 2 " "if the total line coverage is less than MIN. " "Can be ORed with exit status of '--fail-under-branch' option.", action="store", dest="fail_under_line", default=0.0) options.add_argument( "--fail-under-branch", type=check_percentage, metavar="MIN", help="Exit with a status of 4 " "if the total branch coverage is less than MIN. " "Can be ORed with exit status of '--fail-under-line' option.", action="store", dest="fail_under_branch", default=0.0) options.add_argument( '--source-encoding', help="Select the source file encoding. " "Defaults to the system default encoding (%(default)s).", action='store', dest='source_encoding', default=locale.getpreferredencoding()) output_options = parser.add_argument_group( "Output Options", description="Gcovr prints a text report by default, " "but can switch to XML or HTML.") output_options.add_argument( "-o", "--output", help="Print output to this filename. Defaults to stdout. " "Required for --html-details.", action="store", dest="output", default=None) output_options.add_argument( "-b", "--branches", help="Report the branch coverage instead of the line coverage. " "For text report only.", action="store_true", dest="show_branch", default=None) output_options.add_argument( "-u", "--sort-uncovered", help="Sort entries by increasing number of uncovered lines. " "For text and HTML report.", action="store_true", dest="sort_uncovered", default=None) output_options.add_argument( "-p", "--sort-percentage", help="Sort entries by increasing percentage of uncovered lines. " "For text and HTML report.", action="store_true", dest="sort_percent", default=None) output_options.add_argument("-x", "--xml", help="Generate a Cobertura XML report.", action="store_true", dest="xml", default=False) output_options.add_argument( "--xml-pretty", help= "Pretty-print the XML report. Implies --xml. Default: %(default)s.", action="store_true", dest="prettyxml", default=False) output_options.add_argument("--html", help="Generate a HTML report.", action="store_true", dest="html", default=False) output_options.add_argument( "--html-details", help="Add annotated source code reports to the HTML report. " "Requires --output as a basename for the reports. " "Implies --html.", action="store_true", dest="html_details", default=False) output_options.add_argument( "--html-absolute-paths", help="Use absolute paths to link the --html-details reports. " "Defaults to relative links.", action="store_false", dest="relative_anchors", default=True) output_options.add_argument( '--html-encoding', help="Override the declared HTML report encoding. " "Defaults to %(default)s. " "See also --source-encoding.", action='store', dest='html_encoding', default='UTF-8') output_options.add_argument("-s", "--print-summary", help="Print a small report to stdout " "with line & branch percentage coverage. " "This is in addition to other reports. " "Default: %(default)s.", action="store_true", dest="print_summary", default=False) filter_options = parser.add_argument_group( "Filter Options", description="Filters decide which files are included in the report. " "Any filter must match, and no exclude filter must match. " "A filter is a regular expression that matches a path. " "Filter paths use forward slashes, even on Windows.") filter_options.add_argument( "-f", "--filter", help="Keep only source files that match this filter. " "Can be specified multiple times. " "If no filters are provided, defaults to --root.", action="append", dest="filter", default=[]) filter_options.add_argument( "-e", "--exclude", help="Exclude source files that match this filter. " "Can be specified multiple times.", action="append", dest="exclude", default=[]) filter_options.add_argument( "--gcov-filter", help="Keep only gcov data files that match this filter. " "Can be specified multiple times.", action="append", dest="gcov_filter", default=[]) filter_options.add_argument( "--gcov-exclude", help="Exclude gcov data files that match this filter. " "Can be specified multiple times.", action="append", dest="gcov_exclude", default=[]) filter_options.add_argument( "--exclude-directories", help="Exclude directories that match this regex " "while searching raw coverage files. " "Can be specified multiple times.", action="append", dest="exclude_dirs", default=[]) gcov_options = parser.add_argument_group( "GCOV Options", "The 'gcov' tool turns raw coverage files (.gcda and .gcno) " "into .gcov files that are then processed by gcovr. " "The gcno files are generated by the compiler. " "The gcda files are generated when the instrumented program is executed." ) gcov_options.add_argument("--gcov-executable", help="Use a particular gcov executable. " "Must match the compiler you are using, " "e.g. 'llvm-cov gcov' for Clang. " "Can include additional arguments. " "Defaults to the GCOV environment variable, " "or 'gcov': '%(default)s'.", action="store", dest="gcov_cmd", default=os.environ.get('GCOV', 'gcov')) gcov_options.add_argument( "--exclude-unreachable-branches", help="Exclude branch coverage with LCOV/GCOV exclude markers. " "Additionally, exclude branch coverage from lines " "without useful source code " "(often, compiler-generated \"dead\" code). " "Default: %(default)s.", action="store_true", dest="exclude_unreachable_branches", default=False) gcov_options.add_argument( "-g", "--use-gcov-files", help="Use existing gcov files for analysis. Default: %(default)s.", action="store_true", dest="gcov_files", default=False) gcov_options.add_argument( '--gcov-ignore-parse-errors', help="Skip lines with parse errors in GCOV files " "instead of exiting with an error. " "A report will be shown on stderr. " "Default: %(default)s.", action="store_true", dest="gcov_ignore_parse_errors", default=False) gcov_options.add_argument( '--object-directory', help="Override normal working directory detection. " "Gcovr needs to identify the path between gcda files " "and the directory where the compiler was originally run. " "Normally, gcovr can guess correctly. " "This option specifies either " "the path from gcc to the gcda file (i.e. gcc's '-o' option), " "or the path from the gcda file to gcc's working directory.", action="store", dest="objdir", default=None) gcov_options.add_argument( "-k", "--keep", help="Keep gcov files after processing. " "This applies both to files that were generated by gcovr, " "or were supplied via the --use-gcov-files option. " "Default: %(default)s.", action="store_true", dest="keep", default=False) gcov_options.add_argument( "-d", "--delete", help="Delete gcda files after processing. Default: %(default)s.", action="store_true", dest="delete", default=False) gcov_options.add_argument( "-j", help="Set the number of threads to use in parallel.", nargs="?", const=cpu_count(), type=int, dest="gcov_parallel", default=1) return parser
I.executable = "ssa_testi" I.name = "I" I.test = "plastic till ice stream (SSA)" I.path = "(lots of levels)" I.My = [51, 101, 151, 201, 401, 601, 801, 1001, 1501, 2001, 2501, 3073] I.Mx = [5] * len(I.My) I.opts = "-ssa_method fd -ssa_rtol %1.e -ssafd_ksp_rtol %1.e" % (SSARTOL, KSPRTOL) tests['I_manual'] = I return tests from argparse import ArgumentParser parser = ArgumentParser() parser.description = """PISM verification script""" parser.add_argument("--eta", dest="eta", action="store_true", help="to add '-eta' option to pismv call") parser.add_argument("-l", dest="levels", type=int, default=2, help="number of levels of verification; '-l 1' fast, '-l 5' slowest") parser.add_argument("--mpido", dest="mpido", default="mpiexec -np", help="specify MPI executable (e.g. 'mpirun -np' or 'aprun -n')") parser.add_argument("-n", dest="n", type=int, default=2, help="number of processors to use") parser.add_argument("--prefix", dest="prefix", default="", help="path prefix to pismv executable") parser.add_argument("-r", dest="report_file", default="", help="name of the NetCDF error report file") parser.add_argument("-t", dest="tests", nargs="+", help="verification tests to use (A,B,C,D,E,F,G,H,I,J,K,L,M,O); specify a space-separated list", default=['C', 'G', 'I', 'J']) parser.add_argument("-u", dest="unequal", action="store_true",
from resources import * def map_dict(val, mdict): try: return mdict[val] except: return val grid_choices = [40, 20, 10] # set up the option parser parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter) parser.description = "Generating scripts to run Storglaciaren." parser.add_argument("--restart_file", dest="restart_file", help="Input file to restart from", default=None) parser.add_argument("-n", '--n_procs', dest="n", type=int, help='''number of cores/processors. default=4.''', default=4) parser.add_argument("-w", '--wall_time', dest="walltime", help='''walltime. default: 100:00:00.''', default="100:00:00")
def arg_parser(prog=None): from argparse import ArgumentParser, Action, ArgumentError class DictAction(Action): # pylint: disable=R0903 def __init__(self, option_strings, dest, nargs=None, **kwargs): super(DictAction, self).__init__(option_strings, dest, **kwargs) def __call__(self, parser, namespace, value, option_string=None): if not re.match(r"\s*\w+\s*=\s*\d+", value): raise ArgumentError(self, "should be like nloc=20") k, val = value.split("=", 2) getattr(namespace, self.dest)[k.strip()] = int(val.strip()) parser = ArgumentParser(prog=prog) parser.add_argument('paths', nargs='*', default=['.'], help='list of the filename/paths.') parser.add_argument('--version', action='version', version=VERSION) parser.add_argument("-l", "--languages", help='''List the programming languages you want to analyze. if left empty, it'll search for all languages it knows. `lizard -l cpp -l java`searches for C++ and Java code. The available languages are: ''' + ', '.join(x.language_names[0] for x in languages()), action="append", dest="languages", default=[]) parser.add_argument("-V", "--verbose", help="Output in verbose mode (long function name)", action="store_true", dest="verbose", default=False) parser.add_argument("-C", "--CCN", help='''Threshold for cyclomatic complexity number warning. The default value is %d. Functions with CCN bigger than it will generate warning ''' % DEFAULT_CCN_THRESHOLD, type=int, dest="CCN", default=DEFAULT_CCN_THRESHOLD) parser.add_argument("-L", "--length", help='''Threshold for maximum function length warning. The default value is %d. Functions length bigger than it will generate warning ''' % DEFAULT_MAX_FUNC_LENGTH, type=int, dest="length", default=DEFAULT_MAX_FUNC_LENGTH) parser.add_argument("-a", "--arguments", help="Limit for number of parameters", type=int, dest="arguments", default=100) parser.add_argument("-w", "--warnings_only", help='''Show warnings only, using clang/gcc's warning format for printing warnings. http://clang.llvm.org/docs/UsersManual.html#cmdoption-fdiagnostics-format ''', action="store_const", const=print_clang_style_warning, dest="printer") parser.add_argument("-i", "--ignore_warnings", help='''If the number of warnings is equal or less than the number, the tool will exit normally, otherwise it will generate error. Useful in makefile for legacy code.''', type=int, dest="number", default=0) parser.add_argument("-x", "--exclude", help='''Exclude files that match this pattern. * matches everything, ? matches any single character, "./folder/*" exclude everything in the folder recursively. Multiple patterns can be specified. Don't forget to add "" around the pattern.''', action="append", dest="exclude", default=[]) parser.add_argument("-t", "--working_threads", help='''number of working threads. The default value is 1. Using a bigger number can fully utilize the CPU and often faster.''', type=int, dest="working_threads", default=1) parser.add_argument("-X", "--xml", help='''Generate XML in cppncss style instead of the tabular output. Useful to generate report in Jenkins server''', action="store_const", const=print_xml, dest="printer") parser.add_argument("-H", "--html", help='''Output HTML report''', action="store_const", const=html_output, dest="printer") parser.add_argument("-m", "--modified", help="Calculate modified cyclomatic complexity number", action="append_const", const="modified", dest="extensions", default=[]) _extension_arg(parser) parser.add_argument("-s", "--sort", help='''Sort the warning with field. The field can be nloc, cyclomatic_complexity, token_count, p#arameter_count, etc. Or an customized field.''', action="append", dest="sorting", default=[]) parser.add_argument("-T", "--Threshold", help='''Set the limit for a field. The field can be nloc, cyclomatic_complexity, token_count, parameter_count, etc. Or an customized file. Lizard will report warning if a function exceed the limit''', action=DictAction, dest="thresholds", default={}) parser.add_argument("-W", "--whitelist", help='''The path and file name to the whitelist file. It's './whitelizard.txt' by default. Find more information in README.''', type=str, dest="whitelist", default=DEFAULT_WHITELIST) parser.usage = '''lizard [options] [PATH or FILE] [PATH] ...''' parser.description = __doc__ return parser
def add_arguments(self, parser: ArgumentParser) -> None: parser.add_argument('filepath', help="Path to credentials.json") parser.formatter_class = RawTextHelpFormatter parser.description = f'''Use the init command to initialise the token and to set up your gmail account for hassle-free mail deliveries.
def build_parser(): """Build the argument parser.""" # Map of top-level commands and their setup functions/description # New top-level commands should be added to this dictionary commands = StreamAlertCLICommandRepository.command_parsers() description_template = """ StreamAlert v{} Configure, test, build, and deploy StreamAlert Available Commands: {} For additional help with any command above, try: {} [command] --help """ parser = ArgumentParser(formatter_class=RawDescriptionHelpFormatter, prog=__file__) parser.add_argument('-v', '--version', action='version', version=version) parser.add_argument( '-d', '--debug', help= 'enable debugging logger output for all of the StreamAlert loggers', action='store_true') parser.add_argument( '-c', '--config-dir', default=DEFAULT_CONFIG_PATH, help='Path to directory containing configuration files', type=DirectoryType()) parser.add_argument( '-t', '--terraform-file', dest='terraform_files', help=('Path to one or more additional Terraform configuration ' 'files to include in this deployment'), action=UniqueSortedFileListAppendAction, type=FileType('r'), default=[]) parser.add_argument( '-b', '--build-directory', help= ('Path to directory to use for building StreamAlert and its infrastructure. ' 'If no path is provided, a temporary directory will be used.'), type=str) # Dynamically generate subparsers, and create a 'commands' block for the prog description command_block = [] subparsers = parser.add_subparsers(dest='command', required=True) command_col_size = max([len(command) for command in commands]) + 10 for command in sorted(commands): setup_subparser_func, description = commands[command] subparser = generate_subparser(subparsers, command, description=description) # If there are additional arguments to set for this command, call its setup function if setup_subparser_func: setup_subparser_func(subparser) command_block.append('\t{command: <{pad}}{description}'.format( command=command, pad=command_col_size, description=description)) # Update the description on the top level parser parser.description = description_template.format(version, '\n'.join(command_block), __file__) parser.epilog = 'Issues? Please report here: https://github.com/airbnb/streamalert/issues' return parser
def __repr__(self): return "ObservationsDataset" # ############################################################################## # MAIN # ############################################################################## if __name__ == "__main__": __spec__ = None # Set up the option parser parser = ArgumentParser() parser.description = "Analyze flux gates. Used for 'Complex Greenland Outlet Glacier Flow Captured'." parser.add_argument("FILE", nargs="*") parser.add_argument("--aspect_ratio", dest="aspect_ratio", type=float, help='''Plot aspect ratio"''', default=0.8) parser.add_argument( "--colormap", dest="colormap", nargs=1, help="""Name of matplotlib colormap""", default="tab20c" ) parser.add_argument( "--label_params", dest="label_params", help='''comma-separated list of parameters that appear in the legend, e.g. "sia_enhancement_factor"''', default="exp", ) parser.add_argument( "--normalize", dest="normalize",
#!/usr/bin/env python3 # Copyright (C) 2017 Andy Aschwanden import numpy as np import time from netCDF4 import Dataset as NC from argparse import ArgumentParser # Set up the option parser parser = ArgumentParser() parser.description = "Create climate forcing for a warming climate" parser.add_argument("FILE", nargs='*') parser.add_argument("-T_max", dest="T_max", type=float, help="Maximum temperature", default=1) parser.add_argument("-t_max", dest="t_max", type=float, help="lower time bound for maximum temperature", default=100) parser.add_argument("-amplitude", dest="amplitude", type=float, help="Amplitde of seasonal cycle.", default=12) options = parser.parse_args() args = options.FILE start = 0
cdo.seltimestep("2/1000", input="-setmissval,1.e20 {}".format(a_file), output=o_file, options="-f nc4 -z zip_3 -O -L") adjust_timeline(o_file, start_date=start_date, interval=time_interval, interval_type="mid", bounds=True) else: print("how did I get here") # Set up the option parser parser = ArgumentParser() parser.description = "Script to make ISMIP6-conforming time series." parser.add_argument("INDIR", nargs=1) parser.add_argument("--model", dest="model", type=str, help="""Model ID""", default="1") parser.add_argument("-o", dest="base_dir", type=str, help="""Basedirectory for output""", default=".") parser.add_argument("--resource_dir", dest="resource_dir", type=str, help="""Directory with ISMIP6 resources""",
import subprocess32 as sub except: import subprocess as sub from argparse import ArgumentParser import sys sys.path.append('../resources/') from resources import * grid_choices = [ 18000, 9000, 6000, 4500, 3600, 3000, 2400, 1800, 1500, 1200, 900, 600, 450, 300, 150 ] # set up the option parser parser = ArgumentParser() parser.description = "Generating scripts for model initialization." parser.add_argument("FILE", nargs=1, help="Input file to restart from", default=None) parser.add_argument("-n", '--n_procs', dest="n", type=int, help='''number of cores/processors. default=140.''', default=140) parser.add_argument("-w", '--wall_time', dest="walltime", help='''walltime. default: 100:00:00.''', default="100:00:00")
#!/usr/bin/env python # Copyright (C) 2016, 2017 Andy Aschwanden import numpy as np import pylab as plt from scipy.interpolate import griddata from netCDF4 import Dataset as NC from argparse import ArgumentParser # set up the option parser parser = ArgumentParser() parser.description = "Generating synthetic outlet glacier." parser.add_argument("FILE", nargs="*") parser.add_argument("-g", "--grid", dest="grid_spacing", type=int, help="horizontal grid resolution", default=1000) parser.add_argument( "-s", "--side_walls", dest="has_sidewalls", action="store_true", help="horizontal grid resolution", default=False ) parser.add_argument( "-f", "--format", dest="fileformat", type=str.upper, choices=["NETCDF4", "NETCDF4_CLASSIC", "NETCDF3_CLASSIC", "NETCDF3_64BIT"], help="file format out output file", default="netcdf3_64bit", ) options = parser.parse_args() args = options.FILE fileformat = options.fileformat.upper()
if lon_bounds.flat[i] < 0: lon_bounds.flat[i] += 360.0 lat_min = np.min(lat) lat_max = np.max(lat) for i in xrange(lat_bounds.size): if lat_bounds.flat[i] < lat_min: lat_bounds.flat[i] = -90.0 if lat_bounds.flat[i] > lat_max: lat_bounds.flat[i] = 90.0 return lon_bounds, lat_bounds if __name__ == "__main__": parser = ArgumentParser() parser.description = "Converts an ASCII file produced by a GIA model to a NetCDF file that can be used with CDO" parser.add_argument("INPUT", nargs=1) parser.add_argument("OUTPUT", nargs=1) parser.add_argument("--n_lat", default=256, dest="n_lat") parser.add_argument("--n_lon", default=512, dest="n_lon") options = parser.parse_args() lon, lat, data = read_data(options.INPUT[0], options.n_lon, options.n_lat) lon_bounds, lat_bounds = compute_bounds(lon, lat, options.n_lon, options.n_lat) write_data(options.OUTPUT[0], options.n_lon, lon, lon_bounds, options.n_lat, lat, lat_bounds, data)
#!/usr/bin/env python import numpy as np from pyproj import Proj from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter from netCDF4 import Dataset as CDF # set up the argument parser parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter) parser.description = "Create CDO-compliant grid description" parser.add_argument("FILE", nargs="*") parser.add_argument("-g", "--grid_spacing", dest="grid_spacing", type=float, help="use X m grid spacing", default=5000) parser.add_argument( "-f", "--format", dest="fileformat", type=str.upper, choices=["NETCDF4", "NETCDF4_CLASSIC", "NETCDF3_CLASSIC", "NETCDF3_64BIT"], help="file format out output file", default="netcdf3_64bit", ) options = parser.parse_args() args = options.FILE grid_spacing = options.grid_spacing # convert fileformat = options.fileformat.upper() if len(args) == 0: nc_outfile = "grn" + str(grid_spacing) + "m.nc" elif len(args) == 1:
# Importe from argparse import ArgumentParser from googlesearch import search # Run on commandline: python search.py -q meonet if __name__ == '__main__': parser = ArgumentParser() parser.description = "Suchanfrage bei Google" parser.add_argument("-q", "--query", dest="query", default="meonet") args = parser.parse_args() query = args.query for j in search(query, tld="ch", num=10, stop=10, pause=2, lang='de'): print(j)
def main(): parser = ArgumentParser(formatter_class=RawTextHelpFormatter) parser.description = '''\nScript to simplify the configuration of vSAN Stretched Cluster with a VMware Cloud Foundation on VxRail Environment:\n\n''' parser.add_argument( '--workflow', choices=['prepare-stretch', 'stretch-vsan', 'expand-stretch-cluster'], required=True, help= '''Provide prepare-stretch, stretch-vsan or expand-stretch-cluster option \nprepare-stretch: Perform vsan prepare stretch operation workflow, should be called with following options --sc-domain --sc-cluster Later with this option, script will prompt for following inputs SSO username and SSO password \nstretch-vsan: Creates json payload for stretch vsan and executes workflow, should be called with following options -—sc-domain --sc-cluster --sc-hosts --witness-host-fqdn --witness-vsan-ip --witness-vsan-cidr Later with this option, script will prompt for following inputs SSO username and SSO password ip-address and password for hosts provided with --sc-hosts option vSAN gateway ip and vSAN CIDR for preferred site and non-preferred site non-preferred site overlay vlan id (Check help for supported params to be used for your environment and also refer Admin Guide for instructions) \nexpand-stretch-cluster: Creates json payload for expand workflow, this operation is used for expansion of existing stretched cluster. This operation must be run with --sc-domain --sc-cluster --sc-hosts --witness-host-fqdn --witness-vsan-ip --witness-vsan-cidr Later with this option, script will prompt for following inputs SSO username and SSO password ip-address, password and fault domain for hosts provided with --sc-hosts option vSAN gateway ip and vSAN CIDR for preferred site and non-preferred site (Check help for supported params to be used for your environment and also refer Admin Guide for instructions)\n\n''') parser.add_argument('--sc-domain', help='Use this domain name for vsan stretch\n\n') parser.add_argument( '--sc-cluster', help='Use this cluster name for vsan stretch workflow\n\n') parser.add_argument( '--sc-hosts', help= 'Use these hosts for vsan stretch workflow (values: should be qualified ' '\ndomain names) Sample: esx1.vsphere.local,esx-2.vsphere.local\n\n') parser.add_argument( '--witness-host-fqdn', help='Witness Host fully qualified domain name or ip address\n\n') parser.add_argument('--witness-vsan-ip', help='Witness Host vsan ip address\n\n') parser.add_argument('--witness-vsan-cidr', help='Witness Host vsan cidr') args = parser.parse_args() if args.workflow == 'prepare-stretch' and args.sc_domain and args.sc_cluster: sso_username, sso_password = sso_inputs() domain_id, cluster_id = get_domain_and_cluster_id( args.sc_domain, args.sc_cluster, sso_username, sso_password) prepare_stretch(cluster_id, sso_username, sso_password) elif args.workflow == 'stretch-vsan' and args.sc_domain and args.sc_cluster and args.sc_hosts and args.witness_host_fqdn \ and args.witness_vsan_ip and args.witness_vsan_cidr: sso_username, sso_password, hosts_list, vsan_spec = get_inputs( args.sc_hosts, args.workflow) overlay_vlan_id = input( '\033[95m Please enter non-preferred site overlay vlan id : \033[00m' ) if not overlay_vlan_id: print( '\033[91m Please provide non-preferred site overlay vlan id. Input field cannot be empty \033[00m' ) print() domain_id, cluster_id = get_domain_and_cluster_id( args.sc_domain, args.sc_cluster, sso_username, sso_password) stretch_vsan_cluster(sso_username, sso_password, domain_id, cluster_id, hosts_list, vsan_spec, args.witness_host_fqdn, args.witness_vsan_ip, args.witness_vsan_cidr, overlay_vlan_id) elif args.workflow == 'expand-stretch-cluster' and args.sc_domain and args.sc_cluster and args.sc_hosts and args.witness_host_fqdn \ and args.witness_vsan_ip and args.witness_vsan_cidr: sso_username, sso_password, hosts_list, vsan_spec = get_inputs( args.sc_hosts, args.workflow) print() domain_id, cluster_id = get_domain_and_cluster_id( args.sc_domain, args.sc_cluster, sso_username, sso_password) expand_stretch_cluster(sso_username, sso_password, domain_id, cluster_id, hosts_list, vsan_spec, args.witness_host_fqdn, args.witness_vsan_ip, args.witness_vsan_cidr) else: print( '\033[91m Please provide required arguments for workflow execution. Use -h option for more details' )
import subprocess as sub from glob import glob import numpy as np import gdal from nco import Nco nco = Nco() from nco import custom as c import logging import logging.handlers from argparse import ArgumentParser from netCDF4 import Dataset as NC # set up the option parser parser = ArgumentParser() parser.description = "Postprocessing files." parser.add_argument("INDIR", nargs=1, help="main directory", default=None) options = parser.parse_args() idir = options.INDIR[0] # create logger logger = logging.getLogger('postprocess') logger.setLevel(logging.DEBUG) # create file handler which logs even debug messages fh = logging.handlers.RotatingFileHandler('prepare_velocity_observations.log') fh.setLevel(logging.DEBUG) # create console handler with a higher log level ch = logging.StreamHandler()
deglac_time.long_name = 'year of deglaciation' nx = len(x) ny = len(y) for n in range(ny): for m in range(nx): try: idx = np.where(thk[:, n, m] < thickness_threshold)[0][0] deglac_time[n, m] = time[idx] / secpera except: pass nc.close() # set up the option parser parser = ArgumentParser() parser.description = "Postprocessing files." parser.add_argument("INDIR", nargs=1, help="main directory", default=None) options = parser.parse_args() idir = options.INDIR[0] # create logger logger = logging.getLogger('postprocess') logger.setLevel(logging.DEBUG) # create file handler which logs even debug messages fh = logging.handlers.RotatingFileHandler('prepare_velocity_observations.log') fh.setLevel(logging.DEBUG) # create console handler with a higher log level ch = logging.StreamHandler() ch.setLevel(logging.INFO)
################################################################################ #_______________________________________________________________________________ def _main_(args): tracks = DataLoadUtils.getTrackWithAnalysis() with open(METADATA_FILE, 'r') as f: metadata = json.loads(f.read()) doPlot = functools.partial( plotComparison, tracks=tracks, metadata=metadata) doPlot(name='width', label='Width') doPlot(name='length', label='Length') doPlot(name='stride', label='Stride Length') doPlot(name='pace', label='Pace Length') #_______________________________________________________________________________ if __name__ == '__main__': from argparse import ArgumentParser from textwrap import dedent parser = ArgumentParser() parser.description = dedent(""" ValidationPaper does...""") _main_(parser.parse_args())
import numpy as np import pandas as pa import pylab as plt import ogr try: from pypismtools import unit_converter, smooth except: from pypismtools.pypismtools import unit_converter, smooth basin_list = ['CW', 'NE', 'NO', 'NW', 'SE', 'SW'] rcp_list = ['26', '45', '85'] # Set up the option parser parser = ArgumentParser() parser.description = "A script for PISM output files to time series plots using pylab/matplotlib." parser.add_argument("FILE", nargs='*') parser.add_argument("--bounds", dest="bounds", nargs=2, type=float, help="lower and upper bound for ordinate, eg. -1 1", default=None) parser.add_argument("--time_bounds", dest="time_bounds", nargs=2, type=float, help="lower and upper bound for abscissa, eg. 1990 2000", default=[2008, 3008]) parser.add_argument("-b", "--basin",
#!/usr/bin/env python # Copyright (C) 2015 Andy Aschwanden import itertools from collections import OrderedDict import os from argparse import ArgumentParser from resources import * # set up the option parser parser = ArgumentParser() parser.description = "Generating scripts for parameter study." parser.add_argument("regridfile", nargs=1) parser.add_argument( "-n", "--n_procs", dest="n", type=int, help="""number of cores/processors. default=64.""", default=64 ) parser.add_argument("-w", "--wall_time", dest="walltime", help="""walltime. default: 12:00:00.""", default="12:00:00") parser.add_argument( "-q", "--queue", dest="queue", choices=["standard_4", "standard_16", "standard", "gpu", "gpu_long", "long", "normal"], help="""queue. default=standard_4.""", default="standard_4", ) parser.add_argument( "--calving", dest="calving", choices=["float_kill", "ocean_kill", "eigen_calving", "thickness_calving", "mixed_calving"], help="claving", default="eigen_calving",
#!/usr/bin/env python # Copyright (C) 2015 Andy Aschwanden import numpy as np from netCDF4 import Dataset as NC from argparse import ArgumentParser # Set up the option parser parser = ArgumentParser() parser.description = "Create delta mass flux fractions from GRIP record." parser.add_argument("FILE", nargs="*") parser.add_argument("-b", dest="backpressure_max", type=float, help="Maximum backpressure fraction", default=0.3) parser.add_argument("-n", dest="n", type=float, help="power-law exponent", default=2) options = parser.parse_args() args = options.FILE n = options.n backpressure_max = options.backpressure_max infile = args[0] nc = NC(infile, "a")
#!/usr/bin/env python # Copyright (C) 2015 Andy Aschwanden import itertools from collections import OrderedDict import os from argparse import ArgumentParser grid_choices = [9000, 4500, 3600, 1800, 1500, 1200, 900, 600] # set up the option parser parser = ArgumentParser() parser.description = "Generating scripts for model initialization." parser.add_argument("-n", '--n_procs', dest="n", type=int, help='''number of cores/processors. default=64.''', default=64) parser.add_argument("-w", '--wall_time', dest="walltime", help='''walltime. default: 12:00:00.''', default="12:00:00") parser.add_argument("-q", '--queue', dest="queue", choices=['standard_4', 'standard_16', 'standard', 'gpu', 'gpu_long', 'long', 'normal'], help='''queue. default=standard_4.''', default='standard_4') parser.add_argument("--climate", dest="climate", choices=['const', 'paleo'], help="Climate", default='paleo') parser.add_argument("--calving", dest="calving", choices=['float_kill', 'ocean_kill', 'eigen_calving'], help="claving", default='ocean_kill') parser.add_argument("-d", "--domain", dest="domain", choices=['greenland'], help="sets the modeling domain", default='greenland') parser.add_argument("-f", "--o_format", dest="oformat", choices=['netcdf3', 'netcdf4_parallel', 'pnetcdf'], help="output format", default='netcdf4_parallel')
and B.salary_max<={} and year(B.end_time)<=year(current_date()) and year(B.end_time)>=2000 """.format(SALARY_MIN_MEAN, SALARY_MIN_STD, SALARY_MAX_MEAN, SALARY_MAX_STD, SALARY_MIN, SALARY_MAX) print(s_sql) df_salary = spark.sql(s_sql) df_salary.repartition(100).write.mode('overwrite').parquet(OUTPUT_PATH) if __name__ == '__main__': # # 为了计算中减少方差,对所有薪资先计算log,再计算标准分布 # # parser = ArgumentParser(usage=__doc__) parser.description = "简历薪资信息预估职么力计算【数据来自resume_works】" parser.add_argument('-i', '--input_path', action='store', dest='input_path', default=INPUT_PATH, help='resume_works信息文件路径,json格式') parser.add_argument('-o', '--output_path', action='store', dest='output_path', default=OUTPUT_PATH, help='resume_works职么力计算后的文件保存路径, parquet格式') parser.add_argument('-a', '--salary_min_mean', action='store', dest='salary_min_mean', default=SALARY_MIN_MEAN, help='resume_works中由salary_min计算得到的薪资均值') parser.add_argument('-b', '--salary_min_std', action='store', dest='salary_min_std', default=SALARY_MIN_STD, help='resume_works中由salary_min计算得到的薪资标准差') parser.add_argument('-c', '--salary_max_mean', action='store', dest='salary_max_mean', default=SALARY_MAX_MEAN, help='resume_works中由salary_max计算得到的薪资均值') parser.add_argument('-d', '--salary_max_std', action='store', dest='salary_max_std', default=SALARY_MAX_STD, help='resume_works中由salary_max计算得到的薪资标准差')
dimensions = var_in.dimensions dtype = var_in.dtype var_out = out_file.createVariable(var_name, dtype, dimensions=dimensions, fill_value=fill_value) copy_attributes(var_in, var_out) return var_out if __name__ == "__main__": # Set up the option parser description = """A script to extract data along (possibly multiple) profile using piece-wise constant or bilinear interpolation. The profile must be given as a ESRI shape file.""" parser = ArgumentParser() parser.description = description parser.add_argument("INPUTFILE", nargs=1, help="input NetCDF file name") parser.add_argument("OUTPUTFILE", nargs=1, help="output NetCDF file name", default="out.nc") parser.add_argument("-n", "--n_levels", dest="n_levels", help="no. of levels", default=25) parser.add_argument( "-a", "--age_iso", dest="age_iso", help="list of increasing iso age levels", default="9000,11700,29000,57000,115000", ) parser.add_argument( "-v", "--variable", dest="variables", help="comma-separated list with variables", default="age" )
"average_bedrock_temperature" ], 'K', "temperature errors") self.plot('dz', ["maximum_basal_melt_rate"], 'O', "basal melt rate errors") # test V: plot only the u component if test_name == 'V': self.plot('dx', ["relative_velocity"], test_name, "relative velocity errors") self.plot('dx', ["maximum_u", "average_u"], test_name, "velocity errors") from argparse import ArgumentParser parser = ArgumentParser() parser.description = """Plot script for PISM verification results.""" parser.add_argument( "filename", help= "The NetCDF error report file name, usually produces by running vfnow.py") parser.add_argument("-t", nargs="+", dest="tests_to_plot", default=None, help="Test results to plot (space-delimited list)") parser.add_argument("--save_figures", dest="save_figures", action="store_true", help="Save figures to .png files") parser.add_argument("--file_format",
"maximum_bedrock_temperature", "average_bedrock_temperature"], 'K', "temperature errors") self.plot('dz', ["maximum_basal_melt_rate"], 'O', "basal melt rate errors") # test V: plot only the u component if test_name == 'V': self.plot('dx', ["relative_velocity"], test_name, "relative velocity errors") self.plot('dx', ["maximum_u", "average_u"], test_name, "velocity errors") from argparse import ArgumentParser parser = ArgumentParser() parser.description = """Plot script for PISM verification results.""" parser.add_argument("filename", help="The NetCDF error report file name, usually produces by running vfnow.py") parser.add_argument("-t", nargs="+", dest="tests_to_plot", default=None, help="Test results to plot (space-delimited list)") parser.add_argument("--save_figures", dest="save_figures", action="store_true", help="Save figures to .png files") parser.add_argument("--file_format", dest="file_format", default="png", help="File format for --save_figures (png, pdf, jpg, ...)") options = parser.parse_args() input_file = NC(options.filename, 'r') available_tests = unique(array(list(map(chr, input_file.variables['test'][:])))) tests_to_plot = options.tests_to_plot
sys.path.append(join(script_directory, "../resources")) from resources import * def map_dict(val, mdict): try: return mdict[val] except: return val grid_choices = [18000, 9000, 6000, 4500, 3600, 3000, 2400, 1800, 1500, 1200, 1000, 900, 600, 450, 300, 150] # set up the option parser parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter) parser.description = "Generating scripts for warming experiments." parser.add_argument("FILE", nargs=1, help="Input file to restart from", default=None) parser.add_argument( "-n", "--n_procs", dest="n", type=int, help="""number of cores/processors. default=140.""", default=140 ) parser.add_argument( "-w", "--wall_time", dest="walltime", help="""walltime. default: 100:00:00.""", default="100:00:00" ) parser.add_argument( "-q", "--queue", dest="queue", choices=list_queues(), help="""queue. default=long.""", default="long" ) parser.add_argument( "-d", "--domain", dest="domain", choices=["gris", "gris_ext", "jib", "jakobshavn", "nw", "ismip6"],
return realpath(dirname(filename)) script_directory = current_script_directory() sys.path.append(join(script_directory, "../resources")) from resources import * def map_dict(val, mdict): try: return mdict[val] except: return val # set up the option parser parser = ArgumentParser() parser.description = "Generating scripts for prognostic simulations." parser.add_argument("-n", '--n_procs', dest="n", type=int, help='''number of cores/processors. default=2.''', default=2) parser.add_argument("-w", '--wall_time', dest="walltime", help='''walltime. default: 12:00:00.''', default="12:00:00") parser.add_argument("-q", '--queue', dest="queue", choices=list_queues(), help='''queue. default=t1standard.''', default='normal') parser.add_argument("--climate", dest="climate", choices=['elev', 'paleo', 'calib', 'present'], help="Climate", default='paleo') parser.add_argument("-d", "--domain", dest="domain", choices=['olympics', 'olympics_mtns'], help="sets the modeling domain", default='olympics') parser.add_argument("--exstep", dest="exstep", type=float, help="Spatial time series writing interval", default=100) parser.add_argument("-f", "--o_format", dest="oformat",
# -n 8 jakobshavn_flightlines.txt tmp_flightlines_500m.nc # for the Jakobshavn basin, assuming the projection is EPSG:3413 import numpy as np import pylab as plt from argparse import ArgumentParser from pyproj import Proj import pyresample as pr try: from netCDF3 import Dataset as CDF except: from netCDF4 import Dataset as CDF # Set up the option parser parser = ArgumentParser() parser.description = '''A script to preprocess ice thickness data.''' parser.add_argument("FILE", nargs='*') parser.add_argument("--bounds", dest="bounds", nargs=4, type=float, help="xmin xmax ymin ymax", default=[-230000.0, 80000.0, -2350000.0, -2200000.0]) parser.add_argument("-g","--grid_spacing", dest="grid_spacing", type=float, help='''target grid spacing in meters. Default=500m''', default=500) parser.add_argument("-m","--missing_value", dest="miss_val", type=float, help='''Missing value. Default=-9999.''', default=-9999.) parser.add_argument("-n","--no_procs", dest="nprocs", type=int, help='''No. of cores used for resamping.''', default=4) parser.add_argument("-c","--constraints", dest="constraints", help='''ASCII file (lon, lat, thk) with additional constraints''', default=None) options = parser.parse_args() args = options.FILE
usurf_new = 1.75 * np.pi * np.ones((Mx, My)) z = np.linspace(0, 2 * np.pi, Mz) var_old = np.zeros((Mx, My, Mz)) for k in range(0, Mx): for l in range(0, My): var_old[k, l, :] = np.sin(z) return z, var_old, usurf_old, usurf_new if __name__ == '__main__': # Set up the argument parser parser = ArgumentParser() parser.description = '''A to remap/rescale 3D fields (e.g. enthalpy) from one ice sheet body to another, given their ice thicknesses. Both files need to have same (Mx,My) dimensions''' parser.add_argument("FILE", nargs='*') parser.add_argument("--test", dest="test", action='store_true', help="test with some fake date", default=False) parser.add_argument("-c", "--copy_thickness", dest="copy_thickness", action='store_true', help="copy ice thickness to new file", default=False) parser.add_argument("-v", "--variable", dest="varname", help='''Variable used for remapping, default = "enthalpy".''', default='enthalpy') options = parser.parse_args() args = options.FILE copy_thickness = options.copy_thickness test = options.test interp_var_name = options.varname thk_var_name = 'thk'
import sys import numpy as np from argparse import ArgumentParser from pyproj import Proj # try different netCDF modules try: from netCDF4 import Dataset as CDF except: print("netCDF4 is not installed!") sys.exit(1) # Set up the option parser parser = ArgumentParser() parser.description = '''Script makes netCDF file ready for Climate Data Operators (CDO). Either a global attribute "projection", a mapping variable, or a command-line proj4 string or a EPSG code must be given.''' parser.add_argument("FILE", nargs=1) parser.add_argument("--no_bounds", dest="bounds", action="store_false", help="do not add lat/lon bounds.", default=True) parser.add_argument("--srs", dest="srs", help=''' a valid proj4 string describing describing the projection ''', default=None) options = parser.parse_args() args = options.FILE srs = options.srs bounds = options.bounds if len(args) == 1: nc_outfile = args[0] else:
from dateutil.parser import parse from datetime import datetime import time import numpy as np try: import netCDF4 as netCDF except: print("netCDF4 is not installed!") sys.exit(1) NC = netCDF.Dataset from netcdftime import utime # Set up the option parser parser = ArgumentParser() parser.description = '''Script creates a time file with time and time bounds that can be used to determine to force PISM via command line option -time_file''' parser.add_argument("FILE", nargs='*') parser.add_argument("-p", "--periodicity", dest="periodicity", help='''periodicity, e.g. monthly, daily, etc. Default=monthly''', default="monthly") parser.add_argument("-a", "--start_date", dest="start_date", help='''Start date in ISO format. Default=1989-1-1''', default='1989-1-1') parser.add_argument("-e", "--end_date", dest="end_date", help='''End date in ISO format. Default=2012-1-1''', default='2012-1-1') parser.add_argument("-i", "--interval_type", dest="interval_type", choices=['start', 'mid', 'end'], help='''Defines whether the time values t_k are the end points of the time bounds tb_k or the mid points 1/2*(tb_k -tb_(k-1)). Default="mid".''',
#!/usr/bin/env python import numpy as np import netCDF4 as NC import pylab as plt from argparse import ArgumentParser parser = ArgumentParser() parser.description = "" parser.add_argument("FILE", nargs=1) parser.add_argument("-o", dest="output", default="dem.geo") parser.add_argument("-m", dest="min_size", type=float, default=1.0) parser.add_argument("-M", dest="max_size", type=float, default=10.0) options = parser.parse_args() nc = NC.Dataset(options.FILE[0]) usurf = np.squeeze(nc.variables['usurf'][:]) thk = np.squeeze(nc.variables['thk'][:]) # convert to km: x = nc.variables['x'][:] / 1000.0 y = nc.variables['y'][:] / 1000.0 width = x.max() - x.min() height = y.max() - y.min() x_min = x.min() y_min = y.min() output = open(options.output, mode="w")
def arg_parser(prog=None): from argparse import ArgumentParser, Action, ArgumentError class DictAction(Action): # pylint: disable=R0903 def __init__(self, option_strings, dest, nargs=None, **kwargs): super(DictAction, self).__init__(option_strings, dest, **kwargs) def __call__(self, parser, namespace, value, option_string=None): if not re.match(r"\s*\w+\s*=\s*\d+", value): raise ArgumentError(self, "should be like nloc=20") k, val = value.split("=", 2) getattr(namespace, self.dest)[k.strip()] = int(val.strip()) parser = ArgumentParser(prog=prog) parser.add_argument('paths', nargs='*', default=['.'], help='list of the filename/paths.') parser.add_argument('--version', action='version', version=version) parser.add_argument("-l", "--languages", help='''List the programming languages you want to analyze. if left empty, it'll search for all languages it knows. `lizard -l cpp -l java`searches for C++ and Java code. The available languages are: ''' + ', '.join(x.language_names[0] for x in languages()), action="append", dest="languages", default=[]) parser.add_argument("-V", "--verbose", help="Output in verbose mode (long function name)", action="store_true", dest="verbose", default=False) parser.add_argument("-C", "--CCN", help='''Threshold for cyclomatic complexity number warning. The default value is %d. Functions with CCN bigger than it will generate warning ''' % DEFAULT_CCN_THRESHOLD, type=int, dest="CCN", default=DEFAULT_CCN_THRESHOLD) parser.add_argument("-f", "--input_file", help='''get a list of filenames from the given file ''', type=str, dest="input_file") parser.add_argument("-o", "--output_file", help='''Output file. The output format is inferred from the file extension (e.g. .html), unless it is explicitly specified (e.g. using --xml). ''', type=str, dest="output_file") parser.add_argument("-L", "--length", help='''Threshold for maximum function length warning. The default value is %d. Functions length bigger than it will generate warning ''' % DEFAULT_MAX_FUNC_LENGTH, type=int, dest="length", default=DEFAULT_MAX_FUNC_LENGTH) parser.add_argument("-a", "--arguments", help="Limit for number of parameters", type=int, dest="arguments", default=100) parser.add_argument("-w", "--warnings_only", help='''Show warnings only, using clang/gcc's warning format for printing warnings. http://clang.llvm.org/docs/UsersManual.html#cmdoption-fdiagnostics-format ''', action="store_const", const=print_clang_style_warning, dest="printer") parser.add_argument("--warning-msvs", help='''Show warnings only, using Visual Studio's warning format for printing warnings. https://msdn.microsoft.com/en-us/library/yxkt8b26.aspx ''', action="store_const", const=print_msvs_style_warning, dest="printer") parser.add_argument("-i", "--ignore_warnings", help='''If the number of warnings is equal or less than the number, the tool will exit normally; otherwise, it will generate error. If the number is negative, the tool exits normally regardless of the number of warnings. Useful in makefile for legacy code.''', type=int, dest="number", default=0) parser.add_argument("-x", "--exclude", help='''Exclude files that match the pattern. * matches everything, ? matches any single character, "./folder/*" exclude everything in the folder recursively. Multiple patterns can be specified. Don't forget to add "" around the pattern.''', action="append", dest="exclude", default=[]) parser.add_argument("-t", "--working_threads", help='''number of working threads. The default value is 1. Using a bigger number can fully utilize the CPU and often faster.''', type=int, dest="working_threads", default=1) parser.add_argument("-X", "--xml", help='''Generate XML in cppncss style instead of the tabular output. Useful to generate report in Jenkins server''', action="store_const", const=print_xml, dest="printer") parser.add_argument("--csv", help='''Generate CSV output as a transform of the default output''', action="store_const", const=print_csv, dest="printer") parser.add_argument("-H", "--html", help='''Output HTML report''', action="store_const", const=html_output, dest="printer") parser.add_argument("-m", "--modified", help='''Calculate modified cyclomatic complexity number , which count a switch/case with multiple cases as one CCN.''', action="append_const", const="modified", dest="extensions", default=[]) _extension_arg(parser) parser.add_argument("-s", "--sort", help='''Sort the warning with field. The field can be nloc, cyclomatic_complexity, token_count, p#arameter_count, etc. Or an customized field.''', action="append", dest="sorting", default=[]) parser.add_argument("-T", "--Threshold", help='''Set the limit for a field. The field can be nloc, cyclomatic_complexity, token_count, parameter_count, etc. Or an customized file. Lizard will report warning if a function exceed the limit''', action=DictAction, dest="thresholds", default={}) parser.add_argument("-W", "--whitelist", help='''The path and file name to the whitelist file. It's './whitelizard.txt' by default. Find more information in README.''', type=str, dest="whitelist", default=DEFAULT_WHITELIST) parser.usage = '''lizard [options] [PATH or FILE] [PATH] ...''' parser.description = __doc__ return parser
#!/usr/bin/env python # Copyright (C) 2016-17 Andy Aschwanden from argparse import ArgumentParser import numpy as np from netCDF4 import Dataset as NC # set up the option parser parser = ArgumentParser() parser.description = "Pasting 3d fields from subset domain into large domain." parser.add_argument("FILE", nargs=2, help="Small and large domain files with 3d fields", default=None) options = parser.parse_args() file_sm = options.FILE[0] file_lg = options.FILE[1] print(("Pasting regrid fields from {} to {}".format(file_sm, file_lg))) nc_sm = NC(file_sm, "r") nc_lg = NC(file_lg, "a") x_sm = nc_sm.variables["x"][:] y_sm = nc_sm.variables["y"][:] x_lg = nc_lg.variables["x"][:] y_lg = nc_lg.variables["y"][:]
def create_command_line_parser(prog=None): from argparse import ArgumentParser parser = ArgumentParser(prog=prog) parser.add_argument('paths', nargs='*', default=['.'], help='list of the filename/paths.') parser.add_argument('--version', action='version', version=VERSION) parser.add_argument("-V", "--verbose", help="Output in verbose mode (long function name)", action="store_true", dest="verbose", default=False) parser.add_argument("-C", "--CCN", help='''Threshold for cyclomatic complexity number warning. The default value is %d. Functions with CCN bigger than it will generate warning ''' % DEFAULT_CCN_THRESHOLD, type=int, dest="CCN", default=DEFAULT_CCN_THRESHOLD) parser.add_argument("-L", "--length", help='''Threshold for maximum function length warning. The default value is %d. Functions length bigger than it will generate warning ''' % DEFAULT_MAX_FUNC_LENGTH, type=int, dest="length", default=DEFAULT_MAX_FUNC_LENGTH) parser.add_argument("-a", "--arguments", help="Limit for number of parameters", type=int, dest="arguments", default=100) parser.add_argument("-w", "--warnings_only", help='''Show warnings only, using clang/gcc's warning format for printing warnings. http://clang.llvm.org/docs/UsersManual.html#cmdoption-fdiagnostics-format ''', action="store_true", dest="warnings_only", default=False) parser.add_argument("-i", "--ignore_warnings", help='''If the number of warnings is equal or less than the number, the tool will exit normally, otherwise it will generate error. Useful in makefile for legacy code.''', type=int, dest="number", default=0) parser.add_argument("-x", "--exclude", help='''Exclude files that match this pattern. * matches everything, ? matches any single character, "./folder/*" exclude everything in the folder recursively. Multiple patterns can be specified. Don't forget to add "" around the pattern.''', action="append", dest="exclude", default=[]) parser.add_argument("-X", "--xml", help='''Generate XML in cppncss style instead of the tabular output. Useful to generate report in Jenkins server''', action="store_true", dest="xml", default=None) parser.add_argument("-t", "--working_threads", help='''number of working threads. The default value is 1. Using a bigger number can fully utilize the CPU and often faster.''', type=int, dest="working_threads", default=1) parser.add_argument("-m", "--modified", help="Calculate modified cyclomatic complexity number", action="store_true", dest="switchCasesAsOneCondition", default=False) parser.add_argument("-E", "--extension", help='''User the extensions. The available extensions are: -Ecpre: it will ignore code in the #else branch. -Ewordcount: count word frequencies and generate tag cloud. -Eoutside: include the global code as one function. ''', action="append", dest="extensions", default=[]) parser.add_argument("-s", "--sort", help='''Sort the warning with field. The field can be nloc, cyclomatic_complexity, token_count, parameter_count, etc. Or an customized file.''', action="append", dest="sorting", default=[]) parser.add_argument("-W", "--whitelist", help='''The path and file name to the whitelist file. It's './whitelizard.txt' by default.''', type=str, dest="whitelist", default=DEFAULT_WHITELIST) parser.usage = '''lizard [options] [PATH or FILE] [PATH] ...''' parser.description = __doc__ return parser
def make_parser(parser: argparse.ArgumentParser): parser.description = ( "Build a pyodide package.\n\n" "Note: this is a private endpoint that should not be used " "outside of the Pyodide Makefile." ) parser.add_argument( "package", type=str, nargs=1, help="Path to meta.yaml package description" ) parser.add_argument( "--cflags", type=str, nargs="?", default=common.get_make_flag("SIDE_MODULE_CFLAGS"), help="Extra compiling flags", ) parser.add_argument( "--cxxflags", type=str, nargs="?", default=common.get_make_flag("SIDE_MODULE_CXXFLAGS"), help="Extra C++ specific compiling flags", ) parser.add_argument( "--ldflags", type=str, nargs="?", default=common.get_make_flag("SIDE_MODULE_LDFLAGS"), help="Extra linking flags", ) parser.add_argument( "--target-install-dir", type=str, nargs="?", default=common.get_make_flag("TARGETINSTALLDIR"), help="The path to the target Python installation", ) parser.add_argument( "--host-install-dir", type=str, nargs="?", default=common.get_make_flag("HOSTINSTALLDIR"), help=( "Directory for installing built host packages. Defaults to setup.py " "default. Set to 'skip' to skip installation. Installation is " "needed if you want to build other packages that depend on this one." ), ) parser.add_argument( "--force-rebuild", action="store_true", help=( "Force rebuild of package regardless of whether it appears to have been updated" ), ) parser.add_argument( "--continue", type=str, nargs="?", dest="continue_from", default="None", const="script", help=( dedent( """ Continue a build from the middle. For debugging. Implies "--force-rebuild". Possible arguments: 'script' : Don't prepare source, start with running script. `--continue` with no argument has the same effect. 'capture' : Start with capture step 'replay' : Start with replay step 'replay:15' : Replay the capture step starting with the 15th compile command (any integer works) """ ).strip() ), ) return parser
#!/usr/bin/env python import numpy as np from pyproj import Proj from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter from netCDF4 import Dataset as CDF # set up the argument parser parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter) parser.description = "Create CDO-compliant grid description" parser.add_argument("FILE", nargs="*") parser.add_argument("-g", "--grid_spacing", dest="grid_spacing", type=float, help="use X m grid spacing", default=1800) parser.add_argument( "-f", "--format", dest="fileformat", type=str.upper, choices=["NETCDF4", "NETCDF4_CLASSIC", "NETCDF3_CLASSIC", "NETCDF3_64BIT"], help="file format out output file", default="netcdf3_64bit", ) options = parser.parse_args() args = options.FILE grid_spacing = options.grid_spacing # convert fileformat = options.fileformat.upper() if len(args) == 0: nc_outfile = "grn" + str(grid_spacing) + "m.nc" elif len(args) == 1:
from dateutil import rrule from dateutil.parser import parse import time import numpy as np try: import netCDF4 as netCDF except: print "netCDF4 is not installed!" sys.exit(1) NC = netCDF.Dataset from netcdftime import utime, datetime # Set up the option parser parser = ArgumentParser() parser.description = '''Script adjusts the time file with time and time bounds that can be used to determine to force PISM via command line option -time_file or adjust the time axis for postprocessing.''' parser.add_argument("FILE", nargs='*') parser.add_argument( "-p", "--periodicity", dest="periodicity", help='''periodicity, e.g. monthly, daily, etc. Default=monthly''', default="monthly") parser.add_argument("-a", "--start_date", dest="start_date", help='''Start date in ISO format. Default=1989-1-1''', default='1989-1-1') parser.add_argument("-c",