Ejemplo n.º 1
0
def parse_args(args):
    """Parse the command line arguments

    Parameters
    ----------
    args : list
        list of arguments from sys.argv

    Returns
    -------
    Namespace
        populated Namespace object from the parsed command line options

    """
    parser = argparse.ArgumentParser('Generate a Raster From a Shapefile')
    """
    Required Arguments
    """

    parser.add_argument("--input_path",
                        "-i",
                        dest="input_path",
                        required=True,
                        type=lambda x: is_valid_path(parser, x),
                        help="the input path to the shapefile file set")

    parser.add_argument("--shapefile",
                        "-s",
                        dest="shapefile",
                        required=True,
                        help="the name of the shapefile file set")

    parser.add_argument("--ref_file",
                        "-r",
                        dest="ref_file",
                        required=True,
                        type=lambda x: is_valid_file(parser, x),
                        help="the reference tif to reproject to")
    """
    Optional Arguments
    """

    parser.add_argument("--out_dir",
                        "-o",
                        dest="out_dir",
                        required=False,
                        default='.',
                        help="the directory to write outputs to",
                        type=lambda x: is_valid_path(parser, x))

    parser.add_argument("--out_file",
                        "-n",
                        dest="out_file",
                        required=False,
                        default=None,
                        help="the filename to give the output",
                        type=str)

    parser.add_argument(
        "--padding",
        "-p",
        dest="padding",
        nargs=4,
        metavar=('Top', 'Right', 'Bottom', 'Left'),
        required=False,
        default=(0, 0, 0, 0),
        type=int,
        help="integer padding value for bounding box on x-sides")

    parser.add_argument("--attribute_ids",
                        "-a",
                        dest="attribute_ids",
                        required=False,
                        default=[1],
                        nargs='+',
                        help="list of attribute ID's to clip",
                        type=lambda x: is_positive_integer(parser, x))

    parser.add_argument(
        "--attribute_name",
        "-e",
        dest="attribute_name",
        required=False,
        default="OBJECTID",
        help="name of the attribute field to query for attribute ids",
        type=str)

    return parser.parse_args(args)
Ejemplo n.º 2
0
def parse_args(args) -> argparse.Namespace:
    """Parse the command line arguments

    Parameters
    ----------
    args : list
        list of arguments from sys.argv

    Returns
    -------
    Namespace
        populated Namespace object from the parsed command line options
    """
    parser = argparse.ArgumentParser(
        'Clip a list of identically gridded files and extract the data within the mask'
    )

    exclusive_group = parser.add_mutually_exclusive_group(required=True)

    exclusive_group.add_argument(
        "--maskfile",
        "-m",
        dest="mask_file",
        required=False,
        type=lambda x: is_valid_file(parser, x),
        help="gridded full_dim_mask file to full extent of files to be clipped"
    )

    exclusive_group.add_argument(
        "--bboxfile",
        "-b",
        dest="bbox_file",
        required=False,
        type=lambda x: is_valid_file(parser, x),
        help=
        "a tab separated text file indicating x1,y1,nx,ny of the files to be clipped"
    )

    exclusive_group.add_argument("--inline-bbox",
                                 "-l",
                                 dest="bbox_def",
                                 nargs=4,
                                 metavar=('X1', 'Y1', 'NX', 'NY'),
                                 required=False,
                                 type=int,
                                 help="bbox defined by x1 y1 nx ny")

    exclusive_group2 = parser.add_mutually_exclusive_group(required=True)

    exclusive_group2.add_argument(
        "--datafiles",
        "-d",
        dest="data_files",
        required=False,
        nargs='+',
        type=lambda x: is_valid_file(parser, x),
        help="the list of gridded data files (.pfb or .tif) to clip from")

    exclusive_group2.add_argument(
        "--glob",
        "-g",
        dest="glob_pattern",
        required=False,
        type=str,
        help="a filter string for filtering files to clip")

    parser.add_argument("--input_path",
                        "-i",
                        dest="input_path",
                        required=False,
                        default='.',
                        type=lambda x: is_valid_path(parser, x),
                        help="the folder to look for input files")

    parser.add_argument("--ref_file",
                        "-r",
                        dest="ref_file",
                        required=False,
                        type=lambda x: is_valid_file(parser, x),
                        help="the reference tif, if writing TIF outputs")

    parser.add_argument("--out_dir",
                        "-o",
                        dest="out_dir",
                        required=False,
                        default='.',
                        help="the directory to write outputs to",
                        type=lambda x: is_valid_path(parser, x))

    parser.add_argument("--pfb_outs",
                        "-p",
                        dest="write_pfbs",
                        required=False,
                        action='store_true',
                        default=True,
                        help="write pfb output files")

    parser.add_argument("--tif_outs",
                        "-t",
                        dest="write_tifs",
                        required=False,
                        action='store_true',
                        help="write tif output files")

    return parser.parse_args(args)
Ejemplo n.º 3
0
def parse_args(args):
    """Parse the command line arguments

    Parameters
    ----------
    args : list
        list of arguments from sys.argv

    Returns
    -------
    Namespace
        populated Namespace object from the parsed command line options

    """
    parser = argparse.ArgumentParser('Subset a ParFlow CONUS domain')
    """
    Required Arguments
    """
    exclusive_group = parser.add_mutually_exclusive_group(required=True)

    parser.add_argument("--input_path",
                        "-i",
                        dest="input_path",
                        required=True,
                        type=lambda x: is_valid_path(parser, x),
                        help="the input path to the shapefile file set")

    exclusive_group.add_argument("--shapefile",
                                 "-s",
                                 dest="shapefile",
                                 required=False,
                                 default=None,
                                 help="the name of the shapefile file set")

    exclusive_group.add_argument(
        "--watershed",
        "-w",
        dest="hucs",
        required=False,
        nargs="+",
        default=None,
        help="one or more HUC 12 values that identify a contiguous watershed")

    parser.add_argument("--conus_files",
                        "-f",
                        dest="conus_files",
                        required=True,
                        help="local path to the CONUS inputs to subset",
                        type=lambda x: is_valid_path(parser, x))
    """
    Optional Arguments
    """
    parser.add_argument(
        "--manifest",
        "-m",
        dest="manifest_file",
        required=False,
        default=conus_manifest,
        type=lambda x: is_valid_file(parser, x),
        help="the manifest of CONUS filenames to build the domain from")

    parser.add_argument("--version",
                        "-v",
                        dest="conus_version",
                        required=False,
                        default=1,
                        choices=[1, 2],
                        type=lambda x: is_positive_integer(parser, x),
                        help="the version of CONUS to subset from")

    parser.add_argument("--out_dir",
                        "-o",
                        dest="out_dir",
                        required=False,
                        default='.',
                        help="the directory to write outputs to",
                        type=lambda x: is_valid_path(parser, x))

    parser.add_argument("--out_name",
                        "-n",
                        dest="out_name",
                        required=False,
                        default=None,
                        help="the name to give the outputs")

    parser.add_argument("--clip_clm",
                        "-c",
                        dest="clip_clm",
                        required=False,
                        action='store_true',
                        help="also clip inputs for CLM")

    parser.add_argument("--run_script",
                        "-r",
                        dest="run_script",
                        required=False,
                        action='store_true',
                        help="generate the run script for this subset")

    parser.add_argument(
        "--padding",
        "-p",
        dest="padding",
        nargs=4,
        metavar=('Top', 'Right', 'Bottom', 'Left'),
        required=False,
        default=(0, 0, 0, 0),
        type=int,
        help="integer padding value for bounding box on x-sides")

    parser.add_argument("--attribute_ids",
                        "-a",
                        dest="attribute_ids",
                        required=False,
                        default=[1],
                        nargs='+',
                        help="list of attribute ID's to clip",
                        type=lambda x: is_positive_integer(parser, x))

    parser.add_argument(
        "--attribute_name",
        "-e",
        dest="attribute_name",
        required=False,
        default="OBJECTID",
        help="name of the attribute field to query for attribute ids",
        type=str)

    parser.add_argument("--tif_outs",
                        "-t",
                        dest="write_tifs",
                        required=False,
                        action='store_true',
                        help="write tif output files")

    return parser.parse_args(args)