コード例 #1
0
def argparser_init():

    parser = argparse.ArgumentParser(
        formatter_class=script_utils.RawTextArgumentDefaultsHelpFormatter,
        description=' '.join(
            ["Generate a scene mask raster file for a single scene DEM."]))

    # Positional arguments

    parser.add_argument(ARGSTR_SRCDEM,
                        type=script_utils.ARGTYPE_PATH(
                            argstr=ARGSTR_SRCDEM,
                            existcheck_fn=os.path.isfile,
                            existcheck_reqval=True),
                        help=' '.join([
                            "Path to source scene DEM file to be masked.",
                        ]))
    parser.add_argument(ARGSTR_RES,
                        type=float,
                        help="Resolution of target DEMs in meters.")

    # Optional arguments

    parser.add_argument(
        ARGSTR_MASK_VER,
        type=str,
        choices=ARGCHO_MASK_VER,
        default=ARGCHO_MASK_VER_BITMASK,
        help=' '.join([
            "Filtering scheme to use when generating mask raster images,",
            "to classify bad data in scene DEMs.",
            "\n'{}': Two-component (edge, data density) filter to create".
            format(ARGCHO_MASK_VER_MASKV1),
            "separate edgemask and datamask files for each scene.",
            "\n'{}': Three-component (edge, water, cloud) filter to create".
            format(ARGCHO_MASK_VER_MASKV2),
            "classical 'flat' binary masks for 2m DEMs.",
            "\n'{}': Same filter as '{}', but distinguish between".format(
                ARGCHO_MASK_VER_BITMASK, ARGCHO_MASK_VER_MASKV2),
            "the different filter components by creating a bitmask.",
            "\n'{}': Filter designed specifically for 8m Antarctic DEMs.".
            format(ARGCHO_MASK_VER_REMA2A),
            "\n'{}': General-purpose filter for 8m DEMs.".format(
                ARGCHO_MASK_VER_MASK8M), "\n"
        ]))

    parser.add_argument(ARGSTR_NOENTROPY,
                        action='store_true',
                        help=' '.join([
                            "Use filter without entropy protection.",
                            "Can only be used when {}={}.".format(
                                ARGSTR_MASK_VER, ARGCHO_MASK_VER_MASKV1)
                        ]))

    parser.add_argument(
        ARGSTR_USE_PIL_IMRESIZE,
        action='store_true',
        help=' '.join([
            "Use PIL imresize method over usual fast OpenCV resize method for final resize from ",
            "8m processing resolution back to native scene raster resolution when generating ",
            "output bitmask raster. This is to avoid an OpenCV error with unknown cause that ",
            "can occur when using OpenCV resize on some 50cm scenes at Blue Waters."
        ]))

    parser.add_argument(ARGSTR_DRYRUN,
                        action='store_true',
                        help="Print actions without executing.")

    parser.add_argument(
        ARGSTR_SKIP_ORTHO2_ERROR,
        action='store_true',
        help=' '.join([
            "If at least one scene in a cross-track strip is missing the second ortho component raster,",
            "do not throw an error but instead build the strip as if it were in-track with only one ortho."
        ]))

    return parser
コード例 #2
0
def argparser_init():

    parser = argparse.ArgumentParser(
        formatter_class=script_utils.RawTextArgumentDefaultsHelpFormatter,
        description=' '.join(["Reproject SETSM scene/strip DEM result files."
                              ]))

    # Positional arguments

    parser.add_argument(
        ARGSTR_SRC,
        type=script_utils.ARGTYPE_PATH(argstr=ARGSTR_SRC,
                                       existcheck_fn=os.path.exists,
                                       existcheck_reqval=True),
        help=' '.join([
            "Path to source SETSM scene/strip *{} file or directory containing these files."
            .format(SETSM_META_SUFFIX),
        ]))

    # Optional arguments

    parser.add_argument(
        ARGSTR_DSTDIR,
        type=script_utils.ARGTYPE_PATH(argstr=ARGSTR_DSTDIR,
                                       existcheck_fn=os.path.isfile,
                                       existcheck_reqval=False),
        help=' '.join([
            "Path to destination directory for reprojected SETSM data.",
        ]))

    parser.add_argument(ARGSTR_TARGET_EPSG,
                        type=int,
                        default=None,
                        help=' '.join([
                            "Target EPSG code of reprojected data.",
                        ]))

    parser.add_argument(ARGSTR_TARGET_RESOLUTION,
                        type=int,
                        default=None,
                        help=' '.join([
                            "Target resolution of reprojected data in meters.",
                        ]))

    parser.add_argument(
        ARGSTR_OVERWRITE,
        action='store_true',
        help="Overwrite existing data in destination directory.")

    parser.add_argument(
        ARGSTR_ADD_RES_SUFFIX,
        action='store_true',
        help=' '.join([
            "Add '_<res>m' suffix to filenames of reprojected rasters.",
            "where <res> is the supplied {} argument in meters.".format(
                ARGSTR_TARGET_RESOLUTION),
        ]))

    parser.add_argument(
        ARGSTR_CORRECT_META_FP_VERTS,
        action='store_true',
        default=False,
        help=' '.join([
            "When reprojecting strip DEM data, recalculate correct strip footprint vertices",
            "from reprojected strip *dem.tif raster and write those into reprojected *meta.txt file."
        ]))

    parser.add_argument(
        ARGSTR_STRIPS_NO_BROWSE,
        action='store_true',
        default=False,
        help=' '.join([
            "When reprojecting 2-meter strip DEMs, do not build 10-meter hillshade raster."
        ]))

    parser.add_argument(
        ARGSTR_STRIPS_BUILD_AUX,
        action='store_true',
        default=False,
        help=' '.join([
            "When reprojecting 2-meter strip DEMs, build the same set of auxiliary rasters that would",
            "normally be built at the end of the scenes2strips routine (useful for mosaicking)."
        ]))

    parser.add_argument(ARGSTR_SCHEDULER,
                        type=str,
                        choices=script_utils.SCHED_SUPPORTED,
                        default=None,
                        help="Submit tasks to job scheduler.")
    parser.add_argument(
        ARGSTR_JOBSCRIPT,
        type=script_utils.ARGTYPE_PATH(argstr=ARGSTR_JOBSCRIPT,
                                       existcheck_fn=os.path.isfile,
                                       existcheck_reqval=True),
        default=None,
        help=' '.join([
            "Script to run in job submission to scheduler.",
            "(default scripts are found in {})".format(JOBSCRIPT_DIR)
        ]))
    parser.add_argument(ARGSTR_TASKS_PER_JOB,
                        type=int,
                        choices=None,
                        default=None,
                        help=' '.join([
                            "Number of tasks to bundle into a single job.",
                            "(requires {} option)".format(ARGSTR_SCHEDULER)
                        ]))
    parser.add_argument(
        ARGSTR_SCRATCH,
        type=script_utils.ARGTYPE_PATH(argstr=ARGSTR_SCRATCH,
                                       existcheck_fn=os.path.isfile,
                                       existcheck_reqval=False),
        default=ARGDEF_SCRATCH,
        help="Scratch directory to build task bundle text files.")
    parser.add_argument(
        ARGSTR_LOGDIR,
        type=script_utils.ARGTYPE_PATH(argstr=ARGSTR_LOGDIR,
                                       existcheck_fn=os.path.isfile,
                                       existcheck_reqval=False),
        default=None,
        help=' '.join([
            "Directory to which standard output/error log files will be written for batch job runs.",
            "\nIf not provided, default scheduler (or jobscript #CONDOPT_) options will be used.",
            "\n**Note:** Due to implementation difficulties, this directory will also become the",
            "working directory for the job process. Since relative path inputs are always changed",
            "to absolute paths in this script, this should not be an issue."
        ]))
    parser.add_argument(
        ARGSTR_EMAIL,
        type=script_utils.ARGTYPE_BOOL_PLUS(parse_fn=str),
        nargs='?',
        help="Send email to user upon end or abort of the LAST SUBMITTED task."
    )

    parser.add_argument(ARGSTR_DRYRUN,
                        action='store_true',
                        help="Print actions without executing.")

    return parser
コード例 #3
0
def argparser_init():

    parser = argparse.ArgumentParser(
        formatter_class=script_utils.RawTextArgumentDefaultsHelpFormatter,
        description=' '.join([
            "Selectively apply filter components from the SETSM DEM scene/strip",
            "*{} component raster to mask out corresponding locations".format(
                ARGDEF_MASK_SUFFIX),
            "in another component raster(s), then save the resulting image(s)."
        ]))

    # Positional arguments

    parser.add_argument(
        ARGSTR_SRC,
        type=script_utils.ARGTYPE_PATH(argstr=ARGSTR_SRC,
                                       existcheck_fn=os.path.exists,
                                       existcheck_reqval=True),
        help=' '.join([
            "Path to source DEM directory or raster file.",
            "Accepts a task bundle text file listing paths to *{} files.".
            format(ARGDEF_MASK_SUFFIX)
        ]))

    # Optional arguments

    parser.add_argument(
        ARGSTR_DSTDIR,
        type=script_utils.ARGTYPE_PATH(argstr=ARGSTR_DSTDIR,
                                       existcheck_fn=os.path.isfile,
                                       existcheck_reqval=False),
        help=' '.join([
            "Path to destination directory for output masked raster(s)",
            "(default is alongside source raster file(s))."
        ]))
    parser.add_argument(
        ARGSTR_MASK_SUFFIX,
        type=str,
        default=ARGDEF_MASK_SUFFIX,
        help=' '.join([
            "Filename suffix to search for applicable masking rasters.",
            "Currently only the bitmask mask version is supported."
        ]))
    parser.add_argument(
        ARGSTR_MASK_VALUE,
        type=str,
        default=None,
        help=' '.join([
            "The 'masking value' to set masked pixels in the output raster."
            "This value can be overridden on a per-raster-suffix basis using the {} option."
            .format(ARGSTR_SRC_SUFFIX),
            "\nIf not provided, the NoData value of the source raster will be taken as the masking value.",
            "If the source raster does not have a set NoData value, the raster will not be masked."
        ]))
    parser.add_argument(
        ARGSTR_SRC_SUFFIX,
        type=str,
        default=ARGDEF_SRC_SUFFIX,
        help=' '.join([
            "Mask raster images with a file suffix(es) matching this string.",
            "An optional numeric string may be provided following the suffix string,",
            "delimited with an equal sign (=), to specify the 'masking value' to set",
            "masked pixels in the output raster.",
            "\nIf the numeric string component is not provided, the NoData value",
            "of the source raster will be taken as the masking value. If the source raster",
            "does not have a set NoData value, masking of that raster will be skipped.",
            "\nSpecify multiple source file suffixes (with or without added masking value)",
            "by delimiting string with the pipe character (/), noting that you must then",
            "wrap the whole argument string with quotes like 'dem.tif=0/ortho.tif=0'."
            "\n"
        ]))
    parser.add_argument(
        ARGSTR_DST_SUFFIX,
        type=str,
        default=None,
        help=' '.join([
            "Suffix appended to filename of output masked rasters."
            "\nWorks like 'src-raster-fname.tif' -> 'src-raster-fname_[DST_SUFFIX].tif'.",
            "\nIf not provided, the default output suffix is 'filtXXX', where [XXX] is the",
            "bit-code corresponding to the filter components ([cloud, water, edge], respectively)",
            "applied in the masking for this run with the (-c, -w, -e) mask filter options.",
            "\nIf the --filter-off option is instead provided, by default all output filenames",
            "will be the same as input filenames.",
            "\nIf none of the (-c, -w, -e, --filter-off) filter options are provided, all filter",
            "components are applied and the default output suffix is simply 'filt'."
            "\n"
        ]))
    parser.add_argument(
        ARGSTR_DST_NODATA,
        type=str,
        choices=ARGCHO_DST_NODATA,
        default=ARGCHO_DST_NODATA_SAME,
        help=' '.join([
            "Scheme for handling NoData pixel translations from source to output raster datasets.",
            "\nIf '{}', do not change NoData value or alter values of existing NoData pixels."
            .format(ARGCHO_DST_NODATA_SAME),
            "\nIf '{}' and source raster does not already have a NoData value,"
            .format(ARGCHO_DST_NODATA_ADD),
            "set NoData value to masking value, else function identically to '{}'."
            .format(ARGCHO_DST_NODATA_SAME),
            "\nIf '{}', set NoData value to masking value".format(
                ARGCHO_DST_NODATA_SWITCH),
            "but do not alter values of existing NoData pixels.",
            "\nIf '{}', set NoData value to masking value and change the value of"
            .format(ARGCHO_DST_NODATA_CONVERT),
            "existing NoData pixels to match the masking value.",
            "\nIf '{}', unset NoData value.".format(ARGCHO_DST_NODATA_UNSET),
            "\n"
        ]))

    parser.add_argument(
        ARGSTR_EDGE,
        '-e',
        action='store_true',
        help=' '.join([
            "Selectively apply edge filter. Not really necessary when masking strip DEMs,",
            "as it is already applied in the mosaicking step of scenes2strips."
        ]))
    parser.add_argument(ARGSTR_WATER,
                        '-w',
                        action='store_true',
                        help="Selectively apply water filter.")
    parser.add_argument(ARGSTR_CLOUD,
                        '-c',
                        action='store_true',
                        help="Selectively apply cloud filter.")
    parser.add_argument(
        ARGSTR_FILTER_OFF,
        action='store_true',
        help=
        "Turn off default (edge & water & cloud) so no filters are applied.")

    parser.add_argument(ARGSTR_OVERWRITE,
                        action='store_true',
                        help="Overwrite existing output rasters.")

    parser.add_argument(ARGSTR_SCHEDULER,
                        type=str,
                        choices=script_utils.SCHED_SUPPORTED,
                        default=None,
                        help="Submit tasks to job scheduler.")
    parser.add_argument(
        ARGSTR_JOBSCRIPT,
        type=script_utils.ARGTYPE_PATH(argstr=ARGSTR_JOBSCRIPT,
                                       existcheck_fn=os.path.isfile,
                                       existcheck_reqval=True),
        default=None,
        help=' '.join([
            "Script to run in job submission to scheduler.",
            "(default scripts are found in {})".format(JOBSCRIPT_DIR)
        ]))
    parser.add_argument(ARGSTR_TASKS_PER_JOB,
                        type=int,
                        choices=None,
                        default=None,
                        help=' '.join([
                            "Number of tasks to bundle into a single job.",
                            "(requires {} option)".format(ARGSTR_SCHEDULER)
                        ]))
    parser.add_argument(
        ARGSTR_SCRATCH,
        type=script_utils.ARGTYPE_PATH(argstr=ARGSTR_SCRATCH,
                                       existcheck_fn=os.path.isfile,
                                       existcheck_reqval=False),
        default=ARGDEF_SCRATCH,
        help="Scratch directory to build task bundle text files.")
    parser.add_argument(
        ARGSTR_LOGDIR,
        type=script_utils.ARGTYPE_PATH(argstr=ARGSTR_LOGDIR,
                                       existcheck_fn=os.path.isfile,
                                       existcheck_reqval=False),
        default=None,
        help=' '.join([
            "Directory to which standard output/error log files will be written for batch job runs.",
            "\nIf not provided, default scheduler (or jobscript #CONDOPT_) options will be used.",
            "\n**Note:** Due to implementation difficulties, this directory will also become the",
            "working directory for the job process. Since relative path inputs are always changed",
            "to absolute paths in this script, this should not be an issue."
        ]))
    parser.add_argument(
        ARGSTR_EMAIL,
        type=script_utils.ARGTYPE_BOOL_PLUS(parse_fn=str),
        nargs='?',
        help="Send email to user upon end or abort of the LAST SUBMITTED task."
    )

    parser.add_argument(ARGSTR_DRYRUN,
                        action='store_true',
                        help="Print actions without executing.")

    return parser