Esempio n. 1
0
def main():
    parser = argparse.ArgumentParser(
        description='RVD',
        # epilog="This is an epilog"
    )

    parser.add_argument('huc', help='HUC identifier', type=str)
    parser.add_argument('flowlines', help='Segmented flowlines input.', type=str)
    parser.add_argument('existing', help='National existing vegetation raster', type=str)
    parser.add_argument('historic', help='National historic vegetation raster', type=str)
    parser.add_argument('valley_bottom', help='Valley bottom (.shp, .gpkg/layer_name)', type=str)
    parser.add_argument('output_folder', help='Output folder input', type=str)
    parser.add_argument('--reach_codes', help='Comma delimited reach codes (FCode) to retain when filtering features. Omitting this option retains all features.', type=str)
    parser.add_argument('--flow_areas', help='(optional) path to the flow area polygon feature class containing artificial paths', type=str)
    parser.add_argument('--waterbodies', help='(optional) waterbodies input', type=str)
    parser.add_argument('--meta', help='riverscapes project metadata as comma separated key=value pairs', type=str)
    parser.add_argument('--verbose', help='(optional) a little extra logging ', action='store_true', default=False)
    parser.add_argument('--debug', help="(optional) save intermediate outputs for debugging", action='store_true', default=False)

    args = dotenv.parse_args_env(parser)

    reach_codes = args.reach_codes.split(',') if args.reach_codes else None

    meta = parse_metadata(args.meta)

    # Initiate the log file
    log = Logger("RVD")
    log.setup(logPath=os.path.join(args.output_folder, "rvd.log"), verbose=args.verbose)
    log.title('RVD For HUC: {}'.format(args.huc))

    try:
        if args.debug is True:
            from rscommons.debug import ThreadRun
            memfile = os.path.join(args.output_dir, 'rvd_mem.log')
            retcode, max_obj = ThreadRun(rvd, memfile, args.huc,
                                         args.flowlines,
                                         args.existing, args.historic, args.valley_bottom,
                                         args.output_folder,
                                         reach_codes,
                                         args.flow_areas, args.waterbodies,
                                         meta=meta)
            log.debug('Return code: {}, [Max process usage] {}'.format(retcode, max_obj))

        else:
            rvd(args.huc,
                args.flowlines,
                args.existing, args.historic, args.valley_bottom,
                args.output_folder,
                reach_codes,
                args.flow_areas, args.waterbodies,
                meta=meta)

    except Exception as e:
        log.error(e)
        traceback.print_exc(file=sys.stdout)
        sys.exit(1)

    sys.exit(0)
Esempio n. 2
0
def main():

    parser = argparse.ArgumentParser(description='Confinement Tool')

    parser.add_argument('huc', help='HUC identifier', type=str)
    parser.add_argument('flowlines',
                        help="NHD Flowlines (.shp, .gpkg/layer_name)",
                        type=str)
    parser.add_argument(
        'confining_polygon',
        help=
        'valley bottom or other polygon representing confining boundary (.shp, .gpkg/layer_name)',
        type=str)
    parser.add_argument('output_folder', help='Output folder', type=str)
    parser.add_argument(
        'buffer_field',
        help='(optional) float field in flowlines with buffer values',
        default=None)
    parser.add_argument('confinement_type',
                        help='type of confinement',
                        default="Unspecified")
    parser.add_argument(
        '--reach_codes',
        help=
        'Comma delimited reach codes (FCode) to retain when filtering features. Omitting this option retains all features.',
        type=str)
    parser.add_argument(
        '--meta',
        help='riverscapes project metadata as comma separated key=value pairs',
        type=str)
    parser.add_argument('--verbose',
                        help='(optional) a little extra logging ',
                        action='store_true',
                        default=False)
    parser.add_argument(
        '--debug',
        help="(optional) save intermediate outputs for debugging",
        action='store_true',
        default=False)

    args = dotenv.parse_args_env(parser)

    # Initiate the log file
    log = Logger("Confinement")
    log.setup(logPath=os.path.join(args.output_folder, "confinement.log"),
              verbose=args.verbose)
    log.title('Confinement For HUC: {}'.format(args.huc))

    meta = parse_metadata(args.meta)
    reach_codes = args.reach_codes.split(',') if args.reach_codes else None
    try:
        if args.debug is True:
            from rscommons.debug import ThreadRun
            memfile = os.path.join(args.output_folder, 'confinement_mem.log')
            retcode, max_obj = ThreadRun(confinement,
                                         memfile,
                                         args.huc,
                                         args.flowlines,
                                         args.confining_polygon,
                                         args.output_folder,
                                         args.buffer_field,
                                         args.confinement_type,
                                         reach_codes,
                                         min_buffer=10.0,
                                         bankfull_expansion_factor=2.5,
                                         debug=args.debug,
                                         meta=meta)
            log.debug('Return code: {}, [Max process usage] {}'.format(
                retcode, max_obj))

        else:
            confinement(args.huc,
                        args.flowlines,
                        args.confining_polygon,
                        args.output_folder,
                        args.buffer_field,
                        args.confinement_type,
                        reach_codes,
                        min_buffer=10.0,
                        bankfull_expansion_factor=2.5,
                        debug=args.debug,
                        meta=meta)

    except Exception as e:
        log.error(e)
        traceback.print_exc(file=sys.stdout)
        sys.exit(1)

    sys.exit(0)
Esempio n. 3
0
def main():
    """ Main BRAT Build routine
    """

    parser = argparse.ArgumentParser(
        description='Build the inputs for an eventual brat_run:',
        # epilog="This is an epilog"
    )
    parser.add_argument('huc', help='huc input', type=str)

    parser.add_argument('dem', help='dem input', type=str)
    parser.add_argument('slope', help='slope input', type=str)
    parser.add_argument('hillshade', help='hillshade input', type=str)

    parser.add_argument('flowlines', help='flowlines input', type=str)
    parser.add_argument('existing_veg', help='existing_veg input', type=str)
    parser.add_argument('historical_veg', help='historical_veg input', type=str)

    parser.add_argument('valley_bottom', help='Valley bottom shapeFile', type=str)
    parser.add_argument('roads', help='Roads shapeFile', type=str)
    parser.add_argument('rail', help='Railways shapefile', type=str)
    parser.add_argument('canals', help='Canals shapefile', type=str)
    parser.add_argument('ownership', help='Ownership shapefile', type=str)

    parser.add_argument('streamside_buffer', help='streamside_buffer input', type=float)
    parser.add_argument('riparian_buffer', help='riparian_buffer input', type=float)
    parser.add_argument('elevation_buffer', help='elevation_buffer input', type=float)

    parser.add_argument('output_folder', help='output_folder input', type=str)

    parser.add_argument('--reach_codes', help='Comma delimited reach codes (FCode) to retain when filtering features. Omitting this option retains all features.', type=str)
    parser.add_argument('--canal_codes', help='Comma delimited reach codes (FCode) representing canals. Omitting this option retains all features.', type=str)
    parser.add_argument('--peren_codes', help='Comma delimited reach codes (FCode) representing perennial features', type=str)
    parser.add_argument('--flow_areas', help='(optional) path to the flow area polygon feature class containing artificial paths', type=str)
    parser.add_argument('--waterbodies', help='(optional) waterbodies input', type=str)
    parser.add_argument('--max_waterbody', help='(optional) maximum size of small waterbody artificial flows to be retained', type=float)

    parser.add_argument('--meta', help='riverscapes project metadata as comma separated key=value pairs', type=str)
    parser.add_argument('--verbose', help='(optional) a little extra logging ', action='store_true', default=False)
    parser.add_argument('--debug', help='(optional) more output about things like memory usage. There is a performance cost', action='store_true', default=False)

    # Substitute patterns for environment varaibles
    args = dotenv.parse_args_env(parser)

    reach_codes = args.reach_codes.split(',') if args.reach_codes else None
    canal_codes = args.canal_codes.split(',') if args.canal_codes else None
    peren_codes = args.peren_codes.split(',') if args.peren_codes else None

    # Initiate the log file
    log = Logger("BRAT Build")
    log.setup(logPath=os.path.join(args.output_folder, "brat_build.log"), verbose=args.verbose)
    log.title('BRAT Build Tool For HUC: {}'.format(args.huc))

    meta = parse_metadata(args.meta)

    try:
        if args.debug is True:
            from rscommons.debug import ThreadRun
            memfile = os.path.join(args.output_folder, 'brat_build_memusage.log')
            retcode, max_obj = ThreadRun(brat_build, memfile,
                                         args.huc, args.flowlines, args.dem, args.slope, args.hillshade,
                                         args.existing_veg, args.historical_veg, args.output_folder,
                                         args.streamside_buffer, args.riparian_buffer,
                                         reach_codes, canal_codes, peren_codes,
                                         args.flow_areas, args.waterbodies, args.max_waterbody,
                                         args.valley_bottom, args.roads, args.rail, args.canals, args.ownership,
                                         args.elevation_buffer,
                                         meta
                                         )
            log.debug('Return code: {}, [Max process usage] {}'.format(retcode, max_obj))
        else:
            brat_build(
                args.huc, args.flowlines, args.dem, args.slope, args.hillshade,
                args.existing_veg, args.historical_veg, args.output_folder,
                args.streamside_buffer, args.riparian_buffer,
                reach_codes, canal_codes, peren_codes,
                args.flow_areas, args.waterbodies, args.max_waterbody,
                args.valley_bottom, args.roads, args.rail, args.canals, args.ownership,
                args.elevation_buffer,
                meta
            )

    except Exception as ex:
        log.error(ex)
        traceback.print_exc(file=sys.stdout)
        sys.exit(1)

    sys.exit(0)
Esempio n. 4
0
def main():
    parser = argparse.ArgumentParser(description='Riverscapes Context Tool',
                                     # epilog="This is an epilog"
                                     )
    parser.add_argument('huc', help='HUC identifier', type=str)
    parser.add_argument('existing',
                        help='National existing vegetation raster',
                        type=str)
    parser.add_argument('historic',
                        help='National historic vegetation raster',
                        type=str)
    parser.add_argument('ownership',
                        help='National land ownership shapefile',
                        type=str)
    parser.add_argument('fairmarket',
                        help='National fair market value raster',
                        type=str)
    parser.add_argument('ecoregions',
                        help='National EcoRegions shapefile',
                        type=str)
    parser.add_argument('prism',
                        help='Folder containing PRISM rasters in BIL format',
                        type=str)
    parser.add_argument('output', help='Path to the output folder', type=str)
    parser.add_argument(
        'download',
        help=
        'Temporary folder for downloading data. Different HUCs may share this',
        type=str)
    parser.add_argument('--force',
                        help='(optional) download existing files ',
                        action='store_true',
                        default=False)
    parser.add_argument(
        '--parallel',
        help=
        '(optional) for running multiple instances of this at the same time',
        action='store_true',
        default=False)
    parser.add_argument('--temp_folder',
                        help='(optional) cache folder for downloading files ',
                        type=str)
    parser.add_argument(
        '--meta',
        help='riverscapes project metadata as comma separated key=value pairs',
        type=str)
    parser.add_argument('--verbose',
                        help='(optional) a little extra logging ',
                        action='store_true',
                        default=False)
    parser.add_argument(
        '--debug',
        help=
        '(optional) more output about things like memory usage. There is a performance cost',
        action='store_true',
        default=False)

    args = dotenv.parse_args_env(parser)

    # Initiate the log file
    log = Logger("RS Context")
    log.setup(logPath=os.path.join(args.output, "rs_context.log"),
              verbose=args.verbose)
    log.title('Riverscapes Context For HUC: {}'.format(args.huc))

    log.info('HUC: {}'.format(args.huc))
    log.info('EPSG: {}'.format(cfg.OUTPUT_EPSG))
    log.info('Existing veg: {}'.format(args.existing))
    log.info('Historical veg: {}'.format(args.historic))
    log.info('Ownership: {}'.format(args.ownership))
    log.info('Fair Market Value Raster: {}'.format(args.fairmarket))
    log.info('Output folder: {}'.format(args.output))
    log.info('Download folder: {}'.format(args.download))
    log.info('Force download: {}'.format(args.force))

    # This is a general place for unzipping downloaded files and other temporary work.
    # We use GUIDS to make it specific to a particular run of the tool to avoid unzip collisions
    parallel_code = "-" + str(uuid.uuid4()) if args.parallel is True else ""
    scratch_dir = args.temp_folder if args.temp_folder else os.path.join(
        args.download, 'scratch', 'rs_context{}'.format(parallel_code))
    safe_makedirs(scratch_dir)

    meta = parse_metadata(args.meta)

    try:

        if args.debug is True:
            from rscommons.debug import ThreadRun
            memfile = os.path.join(args.output, 'rs_context_memusage.log')
            retcode, max_obj = ThreadRun(
                rs_context, memfile, args.huc, args.existing, args.historic,
                args.ownership, args.fairmarket, args.ecoregions, args.prism,
                args.output, args.download, scratch_dir, args.parallel,
                args.force, meta)
            log.debug('Return code: {}, [Max process usage] {}'.format(
                retcode, max_obj))
        else:
            rs_context(args.huc, args.existing, args.historic, args.ownership,
                       args.fairmarket, args.ecoregions, args.prism,
                       args.output, args.download, scratch_dir, args.parallel,
                       args.force, meta)

    except Exception as e:
        log.error(e)
        traceback.print_exc(file=sys.stdout)
        # Cleaning up the scratch folder is essential
        safe_remove_dir(scratch_dir)
        sys.exit(1)

    # Cleaning up the scratch folder is essential
    safe_remove_dir(scratch_dir)
    sys.exit(0)
Esempio n. 5
0
def main():

    parser = argparse.ArgumentParser(description='Riverscapes VBET Tool',
                                     # epilog="This is an epilog"
                                     )
    parser.add_argument('huc', help='NHD flow line ShapeFile path', type=str)
    parser.add_argument('flowlines',
                        help='NHD flow line ShapeFile path',
                        type=str)
    parser.add_argument('flowareas',
                        help='NHD flow areas ShapeFile path',
                        type=str)
    parser.add_argument('slope', help='Slope raster path', type=str)
    parser.add_argument('dem', help='DEM raster path', type=str)
    parser.add_argument('hillshade', help='Hillshade raster path', type=str)
    parser.add_argument(
        'output_dir',
        help='Folder where output VBET project will be created',
        type=str)
    parser.add_argument(
        '--reach_codes',
        help=
        'Comma delimited reach codes (FCode) to retain when filtering features. Omitting this option retains all features.',
        type=str)
    parser.add_argument('--max_slope',
                        help='Maximum slope to be considered',
                        type=float,
                        default=12)
    parser.add_argument('--max_hand',
                        help='Maximum HAND to be considered',
                        type=float,
                        default=50)
    parser.add_argument('--min_hole_area',
                        help='Minimum hole retained in valley bottom (sq m)',
                        type=float,
                        default=50000)
    parser.add_argument(
        '--meta',
        help='riverscapes project metadata as comma separated key=value pairs',
        type=str)
    parser.add_argument('--verbose',
                        help='(optional) a little extra logging ',
                        action='store_true',
                        default=False)
    parser.add_argument(
        '--debug',
        help=
        'Add debug tools for tracing things like memory usage at a performance cost.',
        action='store_true',
        default=False)

    args = dotenv.parse_args_env(parser)

    # make sure the output folder exists
    safe_makedirs(args.output_dir)

    # Initiate the log file
    log = Logger('VBET')
    log.setup(logPath=os.path.join(args.output_dir, 'vbet.log'),
              verbose=args.verbose)
    log.title('Riverscapes VBET For HUC: {}'.format(args.huc))

    meta = parse_metadata(args.meta)

    json_transform = json.dumps({
        "Slope": 1,
        "HAND": 2,
        "Channel": 3,
        "Flow Areas": 4
    })
    reach_codes = args.reach_codes.split(',') if args.reach_codes else None

    try:
        if args.debug is True:
            from rscommons.debug import ThreadRun
            memfile = os.path.join(args.output_dir, 'vbet_mem.log')
            retcode, max_obj = ThreadRun(vbet, memfile, args.huc,
                                         args.flowlines, args.flowareas,
                                         args.slope, json_transform, args.dem,
                                         args.hillshade, args.max_hand,
                                         args.min_hole_area, args.output_dir,
                                         reach_codes, meta)
            log.debug('Return code: {}, [Max process usage] {}'.format(
                retcode, max_obj))

        else:
            vbet(args.huc, args.flowlines, args.flowareas, args.slope,
                 json_transform, args.dem, args.hillshade, args.max_hand,
                 args.min_hole_area, args.output_dir, reach_codes, meta)

    except Exception as e:
        log.error(e)
        traceback.print_exc(file=sys.stdout)
        sys.exit(1)

    sys.exit(0)