Code Monkey home page Code Monkey logo

dem2basin's Introduction

DEM to basin preprocessing

This preprocessing library takes source 1-meter digital elevation model (DEM) data and splits, crops, buffers, and reprojects it to individual hydrologic basins (identified by their unique identifier, the "HUC12" ID).

This preprocessing script also produces ancillary data products corresponding to each new HUC12 DEM raster to describe their sub-basins (ie "catchments"), their streams (ie "flowlines"), and the roughness of each streambed.

Taken together, these are the major inputs needed to run GeoFlood, which creates short-term flood projections.

Alpha-release Python library

The underlying Python library is available on PyPi and can be installed by:

pip install dem2basin

Main Python script

The recommended way to run dem2basin.py:

python3 dem2basin.py \
    --shapefile study_area_polygon.shp \
    --huc12 WBD-HUC12s.shp \
    --nhd NHD_catchments_and_flowlines.gdb/ \
    --raster TNRIS-LIDAR-Datasets/ \
    --availability TNRIS-LIDAR-Dataset_availability.shp \
    --directory HUC12-DEM_outputs/ \
    --restart dem2basin-study_area.pickle

Required source data inputs

There are 5 required inputs.

Optional parameters

  • --directory Outputs directory: a directory to store outputs, which will each be sorted by HUC12
  • --restart Restart file: a Python Pickle file from which you can restart the preprocessing if it's interrupted
  • --overwrite Overwrite flag: optional flag to overwrite all files found in output directory
  • --overwrite_rasters Overwrite rasters flag: optional flag to overwrite just the raster outputs
  • --overwrite_flowlines Overwrite flowlines flag: optional flag to overwrite just the flowline outputs
  • --overwrite_catchments Overwrite catchments flag: optional flag to overwrite just the catchment outputs
  • --overwrite_roughnesses Overwrite roughness table flag: optional flag to overwrite the roughness table
  • --log Log file: a file to store runtime log

Description of outputs

There are 4 outputs per HUC12.

  • Cropped & buffered DEM:
    • buffered 500m
    • cropped to each HUC12 intersecting the study area
    • at least 1m resolution
    • mosaicked with preference for lowest resolution tiles
    • reprojected to the study area's projections
  • corresponding NHD MR flowlines:
    • subset of NHD MR flowlines
    • each flowline's median point along the line lies within the HUC12
    • reprojected to the study area's projections
  • corresponding NHD MR catchments:
    • subset of NHD MR catchments
    • correspond with the NHD MR flowlines above
    • reprojected to the study area's projections
  • Manning's n roughness table:
    • organized by flowline using their ComIDs
    • vary by stream order

Here is an example of these outputs, originally visualized by Prof David Maidment. Example outputs

Already preprocessed DEMs

Already preprocessed DEMs are now available for the vast majority of Texas's HUC12s if you are a TACC user. You can request a TACC account here.

Notes about preprocessed DEMs

  • The DEMs are not provided for any HUC12s that have any gap in 1m resolution data.
  • All of the DEMS are reprojected to WGS 84 / UTM 14N, even if the HUC12 is outside of UTM 14.

Where to find them

The DEMs are located on Stampede2 at /scratch/projects/tnris/dhl-flood-modelling/TX-HUC12-DEM_outputs.

If you run into trouble

Please submit a ticket if you have trouble accessing this data. You may also contact me directly at @dhardestylewis or [email protected]

Available preprocessed HUC12s

These HUC12 DEMs are available right now on Stampede2. Available HUC12 DEMs

Confirmed successfully preprocessed HUC12s

These HUC12 DEMs have been successfully preprocessed in the past, and will soon be available once again on Stampede2. If you need any of these right now, please contact me. Confirmed HUC12 DEMs

Preprocessing workflow

If you would like an understanding of the preprocessing workflow, I provide a simplified but representative example in this Jupyter notebook. This Jupyter notebook was presented at the inaugural TACC Institute on Planet Texas 2050 Cyberecosystem Tools in August, 2020. Please contact me if you would like a recording.

dem2basin's People

Contributors

dhardestylewis avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

dem2basin's Issues

Draft Jupyter notebooks to demonstrate basic use-cases of library

Basic use-cases include:

  • GeoFlood workflow preparation
  • Non-HUC-oriented workflow preparation
  • HEC-RAS preparation excluding road network / bridge segment aspects
  • 10m
  • 3m
  • 1m
  • Backfill 1m with 3m or 10m
  • QA/QC existing DEMs for common issues including nodata gaps, missing source data, and wrong/bad projections
  • Determine accuracy of resulting products

Significantly revise get_bounding_boxes_by_project to center around project-level GDF objects

Significantly revise get_bounding_boxes_by_project to center around project-level GDF objects

As soon as possible, revise the following code to operate on project_coverage GeoDataFrames, with a lambda function to find the files.

Also, dynamically compile a list of separate GeoDataFrames for each project, each row within these GDFs would represent each different DEM tile within that project's GDF, use geopandas.GeoDataFrame.to_crs to reproject these all to the same CRS, before concatenating them to a single master coverage file, which is the final output

    dem_tilenames = []
    filetypes = ('.img', '.dem', '.tif', '.jp2')
    for filetype in filetypes:
#        print(filetype)
        for project in projects:
#            print(project)
            for root, dirs, filenames in os.walk(str(project)):
#                print(root,dirs,filenames)
                for filename in filenames:
#                    print(filename)
                    if filename.endswith(filetype):
#                        print(True)
                        dem_tilenames.append(os.path.join(root,filename))

#    print(dem_tilenames)

    dem_tile_bounds = []
    for dem_tilename in dem_tilenames:
        dem_tile_bounds.append((
            dem_tilename,
            rasterio.open(dem_tilename).bounds
        ))

#    print(dem_tile_bounds)

    dem_tiles = gpd.GeoDataFrame(
        dem_tile_bounds,
        columns = ['lidar_file','bounds']
    )

#    print(dem_tiles)

Include following information in TNRIS Lidar metadata database

  • File name of DEM as found on Stampede2
  • Actual file type of each DEM (.dem,.img,.tif)
  • CRS
  • Geographic CRS
  • EPSG
  • Bounding box
  • Accuracy calculations for reprojections from source CRS to NAD83(2011) / UTM zone 14N & NAD83(2011) Texas Centric Albers Equal Area
  • Polygonizing the rasters
  • File size

Support for point-cloud to DEMs

Consider adding support for point-cloud to DEMs, but:

  • record timings
  • compare against DEM reprojection and mosaicking technique
  • estimate large-scale node-hours usages

Update Lidar index

Run regular scrape of latest Lidar data using tools developed in tnris-lidardata-update

Include timing function

Include timing wrapper function:

def timethis(f):
    start_time = time.time()
    ret = f
    end_time = time.time()
    elapsed_time = end_time - start_time
    return((ret,elapsed_time))

Missing catchments

Catch catchments not assigned to any HUC12 by algorithm. An example of such missing catchments is present in this screenshot


Screen Shot 2021-01-19 at 6 42 00 PM

Consider the following back-ends for performance

Consider the following back-ends for performance:

In time-expensive functions (see pycallgraph.png), consider replacing Shapely-dependent objects with GDAL/OGR objects
This would also mean using either:

  • NetCDF, or
  • PostgreSQL

for I/O

Break up code to speed up each individual import

Break up code to speed up each individual import

Adopt the following organization:

  • General GeoPandas extensions
  • Pandas extensions
  • Function wrappers
  • Misc extensions of other Python libraries
  • Hydro vector processing functions
  • Hydro raster processing functions

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.