fema-ffrd / rashdf

Read data from HEC-RAS HDF files.
MIT License
8 stars 1 forks source link

CLI #30

Closed thwllms closed 6 months ago

thwllms commented 6 months ago

Note: when the library is installed, the rashdf command-line utility is created (just like pip or other Python CLI programs). This isn't really available in the development environment, but you can do this:

(venv-rashdf) $ cd src/
(venv-rashdf) src/ $ python ./cli.py --help

If you want to test creation of the rashdf CLI, you can build the library locally and install it to a new environment.

(venv-rashdf) $ pip install build
(venv-rashdf) $ python -m build
(venv-rashdf) $ deactivate
$ cd ../test
$ python -m venv venv-test-rashdf
$ source ./venv-test-rashdf/bin/activate
(venv-test-rashdf) $ pip install ../rashdf/dist/rashdf-0.2.0-py3-none-any.whl
(venv-test-rashdf) $ rashdf --help

Example usage

Main Help Menu

$ rashdf --help
usage: cli.py [-h] [--fiona-drivers] {mesh_areas,mesh_cell_points,mesh_cell_polygons,mesh_cell_faces,refinement_regions,bc_lines,breaklines,structures} ...

Extract data from HEC-RAS HDF files.

positional arguments:
  {mesh_areas,mesh_cell_points,mesh_cell_polygons,mesh_cell_faces,refinement_regions,bc_lines,breaklines,structures}
                        Sub-command help
    mesh_areas          Export 2D flow area perimeter polygons.
    mesh_cell_points    Export 2D flow mesh cell points.
    mesh_cell_polygons  Export 2D flow mesh cell polygons.
    mesh_cell_faces     Export 2D flow mesh cell faces.
    refinement_regions  Export 2D mesh area refinement regions.
    bc_lines            Export 2D mesh area boundary condition lines.
    breaklines          Export 2D mesh area breaklines.
    structures          Export model structures.

options:
  -h, --help            show this help message and exit
  --fiona-drivers       List the drivers supported by Fiona for writing output files.

Subcommand Help

$ rashdf mesh_areas --help
usage: cli.py mesh_areas [-h] [--to-crs TO_CRS] [--parquet | --feather | --json] [--kwargs KWARGS] hdf_file output_file

Export 2D flow area perimeter polygons.

positional arguments:
  hdf_file         Path to HEC-RAS HDF file.
  output_file      Path to output file.

options:
  -h, --help       show this help message and exit
  --to-crs TO_CRS  Output CRS.
  --parquet        Output as Parquet.
  --feather        Output as Feather.
  --json           Output as GeoJSON.
  --kwargs KWARGS  Keyword arguments as a Python dictionary literal passed to the corresponding GeoPandas output method.

Export to ESRI Shapefile

$ rashdf mesh_cell_points ./models/BigRiver.g01.hdf ./export-data/bigriver-cell-points.shp

Export from S3 HDF to Parquet with CRS Transform

Note: requires installation of optional dependencies fsspec and s3fs, and creating environment variables with S3 credentials.

$ rashdf mesh_cell_polygons s3://my-bucket/Potomac.g04.hdf ./export-data/potomac-cell-polygons.parquet --parquet --to-crs "EPSG:4326"