Exemple #1
0
def main():
    parser = argparse.ArgumentParser(description='GNAT',
                                     # epilog="This is an epilog"
                                     )
    parser.add_argument('huc', help='HUC identifier', type=str)
    parser.add_argument('output_folder', help='Output folder', type=str)
    parser.add_argument('--verbose',
                        help='(optional) a little extra logging ',
                        action='store_true',
                        default=False)

    args = dotenv.parse_args_env(parser)

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

    try:
        gnat(args.hu, args.output_folder)

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

    sys.exit(0)
Exemple #2
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('folder',
                        help='Top level folder where BRAT data are stored',
                        type=str)
    parser.add_argument('database', help='Path to SQLite database', type=str)
    parser.add_argument(
        '--reach_id_field',
        help='(Optional) field that uniquely identifies each reach',
        default='ReachID',
        type=str)
    parser.add_argument(
        '--reach_geom_buffer',
        help='(Optional) reach geometry buffer distance (meters)',
        default=100,
        type=float)
    parser.add_argument(
        '--conflict_buffer',
        help='(Optional) Conflict attribute buffer distance (meters).',
        default=30,
        type=float)
    parser.add_argument(
        '--distance_cell_size',
        help='(Optional) Conflict attribute rasterization cell size (meters).',
        default=5,
        type=float)

    args = dotenv.parse_args_env(
        parser,
        os.path.join(os.path.dirname(__file__), '..', '..', '.env.validation'))

    validate_all(args.folder, args.database, args.reach_id_field,
                 args.reach_geom_buffer, args.conflict_buffer,
                 args.distance_cell_size)
def main():
    """ Combined FIS
    """
    parser = argparse.ArgumentParser()
    parser.add_argument('database',
                        help='BRAT SQLite database',
                        type=argparse.FileType('r'))
    parser.add_argument('maxdrainage',
                        help='Maximum drainage area',
                        type=float)
    parser.add_argument('--verbose',
                        help='(optional) verbose logging mode',
                        action='store_true',
                        default=False)
    args = dotenv.parse_args_env(parser)

    # Initiate the log file
    logg = Logger("Combined FIS")
    logfile = os.path.join(os.path.dirname(args.network.name),
                           "combined_fis.log")
    logg.setup(logPath=logfile, verbose=args.verbose)

    try:
        combined_fis(args.database.name, 'existing', 'EX', args.maxdrainage)
        # combined_fis(args.network.name, 'historic', 'HPE', args.maxdrainage)

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

    sys.exit(0)
Exemple #4
0
def main():

    parser = argparse.ArgumentParser()
    parser.add_argument('lst_xml_folder',
                        help='Top level data folder containing LST data',
                        type=str)
    parser.add_argument('--verbose',
                        help='(optional) a little extra logging ',
                        action='store_true',
                        default=False)

    args = dotenv.parse_args_env(
        parser, os.path.join(os.path.dirname(__file__), '.env'))

    # Initiate the log file
    log = Logger('Land Surface Temperature XML Generator')
    log.setup(logPath=os.path.join(os.path.dirname(args.lst_xml_folder),
                                   'lst_xml.log'),
              verbose=args.verbose)

    try:
        process_lst(args.lst_xml_folder)
        log.info('Process completed successfully')
    except Exception as e:
        log.error(e)
        traceback.print_exc(file=sys.stdout)
        sys.exit(1)

    sys.exit(0)
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('network',
                        help='Output network ShapeFile path',
                        type=argparse.FileType('r'))
    parser.add_argument('flowaccum',
                        help='Flow accumulation raster',
                        type=argparse.FileType('r'))
    parser.add_argument('buffer',
                        help='Distance to buffer reach midpoint',
                        type=float)
    parser.add_argument('--verbose',
                        help='(optional) verbose logging mode',
                        action='store_true',
                        default=False)
    args = dotenv.parse_args_env(parser)

    # Initiate the log file
    logg = Logger("Reach Flow Accum")
    logfile = os.path.join(os.path.dirname(args.network.name),
                           "reach_flowaccum.log")
    logg.setup(logPath=logfile, verbose=args.verbose)

    try:
        reach_drainage_area(args.network.name, args.flowaccum.name,
                            args.buffer)

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

    sys.exit(0)
Exemple #6
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('shapefile', help='Path to full Idaho ShapeFile', type=str)
    parser.add_argument('database', help='Output SQLite database (must exist already)', type=str)
    args = dotenv.parse_args_env(parser)

    load_idaho(args.shapefile, args.database)
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('folder',
                        help='Top level folder where BRAT data are stored',
                        type=str)
    parser.add_argument('database', help='Path to SQLite database', type=str)
    parser.add_argument('--buffer',
                        help='Buffer distance for sampling DEM raster',
                        default=30,
                        type=float)
    parser.add_argument('--cell_size',
                        help='Cell size for rasterization',
                        default=5,
                        type=float)
    parser.add_argument('--reach_id_field',
                        help='(Optional) Reach ID field',
                        default='ReachID',
                        type=str)

    args = dotenv.parse_args_env(
        parser,
        os.path.join(os.path.dirname(__file__), '..', '..', '.env.validation'))

    conflict_attributes_validation(args.folder, args.database,
                                   args.reach_id_field, args.buffer,
                                   args.cell_size)
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('dem', help='DEM raster', type=str)
    parser.add_argument('flowaccum', help='Flow accumulation raster', type=str)
    parser.add_argument('drainagearea', help='Drainage Area output raster', type=str)
    parser.add_argument('--cleanup', help='Deletes temporary files', action='store_true', default=False)
    parser.add_argument('--verbose', help='(optional) verbose logging mode', action='store_true', default=False)
    parser.add_argument('--dinfinity', help='(optional) Use the Dinifinity algorthim. D8 used if omitted', action='store_true', default=False)
    parser.add_argument('--pitfill', help='(optional) Fill DEM pits before flow direction', action='store_true', default=False)
    args = dotenv.parse_args_env(parser)

    # Initiate the log file
    log = Logger("Flow Accum")
    log.setup(logPath=os.path.join(os.path.dirname(args.flowaccum), "flow_accum.log"))

    if os.path.isfile(args.flowaccum):
        log.info('Deleting existing output raster {}'.format(args.flowaccum))
        driver = gdal.GetDriverByName('GTiff')
        gdal.Driver.Delete(driver, args.flowaccum)

    try:
        flow_accumulation(args.dem, args.flowaccum, args.cleanup, args.dinfinity, args.pitfill)
        flow_accum_to_drainage_area(args.flowaccum, args.drainagearea)

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

    sys.exit(0)
Exemple #9
0
def main():

    parser = argparse.ArgumentParser(
        description='RVD XML Augmenter',
        # epilog="This is an epilog"
    )
    parser.add_argument('out_project_xml', help='Input XML file', type=str)
    parser.add_argument('in_xmls', help='Comma-separated list of XMLs in decreasing priority', type=str)
    parser.add_argument('--verbose', help='(optional) a little extra logging ', action='store_true', default=False)

    args = dotenv.parse_args_env(parser)

    # Initiate the log file
    log = Logger('XML Augmenter')
    log.setup(verbose=args.verbose)
    log.title('XML Augmenter: {}'.format(args.out_project_xml))

    try:
        out_prj = RSProject(None, args.out_project_xml)
        out_prj.rs_meta_augment(
            args.in_xmls.split(','),
            lyrs_in_out
        )

        out_prj.XMLBuilder.write()
        report_path = out_prj.XMLBuilder.find('.//HTMLFile[@id="RVD_REPORT"]/Path').text
        report = RVDReport(os.path.join(out_prj.project_dir, report_path), out_prj)
        report.write()

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

    sys.exit(0)
Exemple #10
0
def main():
    """ Main hydrology routine
    """

    parser = argparse.ArgumentParser()
    parser.add_argument('database', help='BRAT SQLite database', type=str)
    parser.add_argument('prefix', help='Q2 or Low prefix', type=str)
    parser.add_argument('huc', help='HUC identification code', type=str)
    parser.add_argument('--verbose',
                        help='(optional) verbose logging mode',
                        action='store_true',
                        default=False)
    args = dotenv.parse_args_env(parser)

    # Initiate the log file
    logg = Logger("Hydrology")
    logfile = os.path.join(os.path.dirname(args.database), "hydrology.log")
    logg.setup(logPath=logfile, verbose=args.verbose)

    try:
        hydrology(args.database, args.prefix, args.huc)

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

    sys.exit(0)
def main():

    parser = argparse.ArgumentParser()
    parser.add_argument('vpuids',
                        help='Comma separated list of VPUs to process',
                        type=str)
    parser.add_argument(
        'data_folder',
        help='Top level data folder containing riverscapes context projects',
        type=str)
    #parser.add_argument('user_name', help='Postgres user name', type=str)
    #parser.add_argument('password', help='Postgres password', type=str)
    args = dotenv.parse_args_env(
        parser, os.path.join(os.path.dirname(__file__), '.env'))

    # Initiate the log file
    log = Logger('Load NHD')
    log.setup(logPath=os.path.join(args.data_folder, 'load_nhd.log'),
              verbose=True)

    try:
        load_nhd(args.vpuids,
                 args.data_folder)  # , args.user_name, args.password)
        log.info('Process completed successfully')
    except Exception as ex:
        log.error(ex)
Exemple #12
0
def main():
    """ Vegetation Suitability
    """
    parser = argparse.ArgumentParser()
    parser.add_argument('database',
                        help='BRAT database path',
                        type=argparse.FileType('r'))
    parser.add_argument('buffer', help='buffer distance (metres)', type=float)
    parser.add_argument('epoch', help='Existing or Historic', type=str)
    parser.add_argument('--verbose',
                        help='(optional) verbose logging mode',
                        action='store_true',
                        default=False)
    args = dotenv.parse_args_env(parser)

    # Initiate the log file
    logg = Logger('Veg Summary')
    logfile = os.path.join(os.path.dirname(args.database.name),
                           'vegetation_summary.log')
    logg.setup(logPath=logfile, verbose=args.verbose)

    try:
        vegetation_suitability(args.database.name, args.raster.name,
                               args.buffer, args.table)

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

    sys.exit(0)
def main():
    """ Main BRAT Run
    """
    parser = argparse.ArgumentParser(
        description='Run brat against a pre-existing sqlite db:',
        # epilog="This is an epilog"
    )
    parser.add_argument('project',
                        help='Riverscapes project folder or project xml file',
                        type=str,
                        default=None)
    parser.add_argument(
        '--csv_dir',
        help='(optional) directory where we can find updated lookup tables',
        action='store_true',
        default=False)
    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)

    if os.path.isfile(args.project):
        logpath = os.path.dirname(args.project)
    elif os.path.isdir(args.project):
        logpath = args.project
    else:
        raise Exception(
            'You must supply a valid path to a riverscapes project')

    log = Logger('BRAT Run')
    log.setup(logPath=os.path.join(logpath, "brat_run.log"),
              verbose=args.verbose)
    log.title('BRAT Run Tool')

    try:
        if args.debug is True:
            from rscommons.debug import ThreadRun
            memfile = os.path.join(logpath, 'brat_run_memusage.log')
            retcode, max_obj = ThreadRun(brat_run, memfile, args.project,
                                         args.csv_dir)
            log.debug('Return code: {}, [Max process usage] {}'.format(
                retcode, max_obj))
        else:
            brat_run(args.project, args.csv_dir)

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

    sys.exit(0)
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('access', help='Input Access database path', type=argparse.FileType('r'))
    parser.add_argument('sqlite', help='Output SQLite database path', type=str)

    args = dotenv.parse_args_env(parser)

    convert(args.access.name, args.sqlite)
Exemple #15
0
def main():

    parser = argparse.ArgumentParser()
    parser.add_argument('csv', help='CSV of 4 digit HUC IDs', type=argparse.FileType('r'))

    args = dotenv.parse_args_env(parser)

    download_nhd(args.csv.name)
Exemple #16
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('watersheds', help='National watershed boundary file geodatabase', type=str)
    parser.add_argument('database', help='Path to SQLite database', type=argparse.FileType('r'))

    args = dotenv.parse_args_env(parser)

    huc_precipitation(args.watersheds, args.database.name)
Exemple #17
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)
def main():

    parser = argparse.ArgumentParser()
    parser.add_argument('csv',
                        help='CSV file identifying four digit HUCs',
                        type=argparse.FileType('r'))
    args = dotenv.parse_args_env(parser)

    sum_lengths(args.csv.name)
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('folder', help='Top level folder where BRAT data are stored', type=str)
    parser.add_argument('database', help='Path to SQLite database', type=str)
    parser.add_argument('buffer', help='Buffer distance for sampling DEM raster', type=float)

    args = dotenv.parse_args_env(parser, os.path.join(os.path.dirname(__file__), '..', '..', '.env.validation'))

    reach_geometry_validation(args.folder, args.database, args.buffer)
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('usu_csv',
                        help='USU hydrology parameter CSV',
                        type=str)
    parser.add_argument('database', help='BRAT database', type=str)

    args = dotenv.parse_args_env(
        parser,
        os.path.join(os.path.dirname(__file__), '..', '..', '.env.validation'))

    hydrology_param_validation(args.usu_csv, args.database)
Exemple #21
0
def main():

    parser = argparse.ArgumentParser()
    parser.add_argument('reach_network',
                        help='Reach Network FeatureClass',
                        type=str)
    parser.add_argument('watershed_id',
                        help='8 digit watershed HUC code',
                        type=str)
    args = dotenv.parse_args_env(parser)

    watershed_parameters(args.reach_network, args.watershed_id)
def main():

    parser = argparse.ArgumentParser()
    parser.add_argument('shapefile',
                        help='Shapefile with inter-mountain west HUC 12s',
                        type=argparse.FileType('r'))

    args = dotenv.parse_args_env(parser)

    identify_huc(args.shapefile.name)

    sys.exit(0)
Exemple #23
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('folder',
                        help='Top level folder where BRAT data are stored',
                        type=str)
    parser.add_argument('database', help='Path to SQLite database', type=str)

    args = dotenv.parse_args_env(
        parser,
        os.path.join(os.path.dirname(__file__), '..', '..', '.env.validation'))

    vegetation_fis_validation(args.folder, args.database)
Exemple #24
0
def main():

    parser = argparse.ArgumentParser()
    parser.add_argument('database', help='Path to SQLite database', type=str)
    parser.add_argument('output', help='Path to output JSON file', type=str)
    args = dotenv.parse_args_env(parser)

    result = huc_summary_stats(args.database)

    with open(args.output, 'w') as jf:
        json.dump(result, jf)

    print('Process complete. Output written to', args.output)
Exemple #25
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('boundary', help='HUC boundary polygon shapefile', type=argparse.FileType('r'))
    parser.add_argument('ownership', help='National ownership polygon shapefile', type=argparse.FileType('r'))
    parser.add_argument('output', help='Output ownership ShapeFile path', type=str)
    parser.add_argument('--epsg', help='Output spatial reference EPSG', default=4326, type=int)
    parser.add_argument('--buffer', help='Buffer distance in meters', default=10000, type=int)

    args = dotenv.parse_args_env(parser)

    if os.path.isfile(args.output):
        print('Deleting existing output', args.output)
        delete_shapefile(args.output)

    clip_ownership(args.boundary.name, args.ownership.name, args.output, args.epsg, args.buffer)
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('wbdhu12', help='WBD HUC 12 ShapeFile path', type=argparse.FileType('r'))
    parser.add_argument('database', help='Output SQLite database path', type=str)

    args = dotenv.parse_args_env(parser)

    try:
        build_watershed_topology(args.wbdhu12.name, args.database)

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

    sys.exit(0)
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('host', help='BRAT parameter DB host', type=str)
    parser.add_argument('port', help='BRAT parameter DB port', type=str)
    parser.add_argument('database', help='BRAT parameter database', type=str)
    parser.add_argument('user_name', help='BRAT parameter DB user name', type=str)
    parser.add_argument('password', help='BRAT parameter DB password', type=str)
    parser.add_argument('--csv_dir', help='directory where the csv lives', type=str)
    args = dotenv.parse_args_env(parser)

    try:
        update_brat_parameters(args.host, args.port, args.database, args.user_name, args.password, args.csv_dir)
        print('Processing completed successfully. Review changes using git.')
    except Exception as ex:
        print('Errors occurred:', str(ex))
Exemple #28
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('folder',
                        help='Top level folder where BRAT data are stored',
                        type=str)
    parser.add_argument('database', help='Path to SQLite database', type=str)
    parser.add_argument('--id_field',
                        help='(Optional) Reach ID field',
                        default='ReachID',
                        type=str)

    args = dotenv.parse_args_env(
        parser,
        os.path.join(os.path.dirname(__file__), '..', '..', '.env.validation'))

    stream_power_validation(args.folder, args.database, args.id_field)
def main():

    parser = argparse.ArgumentParser()
    parser.add_argument('hucs',
                        help='National geodatabase of eight digit HUCs',
                        type=str)
    parser.add_argument('database',
                        help='BRAT database',
                        type=argparse.FileType('r'))
    parser.add_argument(
        'ecoregions',
        help='Ecoregion Shapefile (not intersected with US states)',
        type=argparse.FileType('r'))
    args = dotenv.parse_args_env(parser)

    assign_hucs_to_ecoregions(args.hucs, args.database.name,
                              args.ecoregions.name)
Exemple #30
0
def main():
    parser = argparse.ArgumentParser(description='Import point observation ShapeFile into PostGIS'    )
    parser.add_argument('shapefile', help='Point observation ShapeFile path', type=str, default=None)
    parser.add_argument('host', help='Postgres password', type=str)
    parser.add_argument('port', help='Postgres password', type=str)
    parser.add_argument('db', help='Postgres password', type=str)
    parser.add_argument('user_name', help='Postgres user name', type=str)
    parser.add_argument('password', help='Postgres password', type=str)
    parser.add_argument('--verbose', help='(optional) a little extra logging ', action='store_true', default=False)
    args = dotenv.parse_args_env(parser)


    log = Logger('Import')
    log.setup(logPath=os.path.join(os.path.join(os.path.dirname(args.shapefile)), "shapefile_import.log"), verbose=args.verbose)
    log.title('Point Observation ImportTool')

    import_shapefile(args.shapefile, args.host, args.port, args.user_name, args.password, args.db)