Skip to content

Commit

Permalink
Merge branch 'main' into Feature/ras_1d
Browse files Browse the repository at this point in the history
  • Loading branch information
slawler committed Jun 15, 2024
2 parents 61a1a7c + 025cf0e commit a9d14da
Show file tree
Hide file tree
Showing 24 changed files with 436 additions and 107 deletions.
14 changes: 12 additions & 2 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
os: ["ubuntu-latest"]

runs-on: ${{ matrix.os }}
environment: ci-env

steps:
- uses: actions/checkout@v4
Expand All @@ -45,6 +46,15 @@ jobs:
ruff check
ruff format --check
- name: Test with pytest
- name: Run tests with coverage
run: |
pytest
pytest --cov=src --cov-report term-missing
- name: Run coverage
run: |
coverage xml
- name: Upload coverage reports to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
27 changes: 27 additions & 0 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# .readthedocs.yaml
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the OS, Python version and other tools you might need
build:
os: ubuntu-22.04
tools:
python: mambaforge-latest

# Build documentation in the "docs/" directory with Sphinx
sphinx:
configuration: docs/source/conf.py

# Optionally build your docs in additional formats such as PDF and ePub
# formats:
# - pdf
# - epub

# Optional but recommended, declare the Python requirements required
# to build your documentation
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
conda:
environment: docs/environment.yml
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
[![CI](https://github.com/fema-ffrd/rashdf/actions/workflows/continuous-integration.yml/badge.svg?branch=main)](https://github.com/fema-ffrd/rashdf/actions/workflows/continuous-integration.yml)
[![Release](https://github.com/fema-ffrd/rashdf/actions/workflows/release.yml/badge.svg)](https://github.com/fema-ffrd/rashdf/actions/workflows/release.yml)
[![PyPI version](https://badge.fury.io/py/rashdf.svg)](https://badge.fury.io/py/rashdf)
[![codecov](https://codecov.io/gh/fema-ffrd/rashdf/graph/badge.svg?token=CTIIONEHV1)](https://codecov.io/gh/fema-ffrd/rashdf)
[![Documentation Status](https://readthedocs.org/projects/rashdf/badge/?version=latest)](https://rashdf.readthedocs.io/en/latest/?badge=latest)

Read data from [HEC-RAS](https://www.hec.usace.army.mil/software/hec-ras/) [HDF](https://github.com/HDFGroup/hdf5) files.

*Pronunciation: `raz·aitch·dee·eff`*

## Documentation
[rashdf on ReadTheDocs](http://rashdf.readthedocs.io/)

## Install
```bash
$ pip install rashdf
Expand Down Expand Up @@ -97,9 +102,6 @@ Example: write structures GeoJSON to `stdout`:
$ rashdf structures Potomac.p01.hdf
```

## Documentation
Coming soon.

## Developer Setup
Create a virtual environment in the project directory:
```
Expand Down
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
BUILDDIR = build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
9 changes: 9 additions & 0 deletions docs/environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: rashdf-docs
channels:
- conda-forge
- defaults
dependencies:
- python=3.9
- pip
- pip:
- -e ../[docs]
35 changes: 35 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=source
set BUILDDIR=build

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
)

if "%1" == "" goto help

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
18 changes: 18 additions & 0 deletions docs/source/RasGeomHdf.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
RasGeomHdf
==========
.. currentmodule:: rashdf
.. autoclass:: RasGeomHdf
:show-inheritance:
:members: projection,
mesh_area_names,
mesh_areas,
mesh_cell_polygons,
mesh_cell_points,
mesh_cell_faces,
bc_lines,
breaklines,
refinement_regions,
structures,
get_geom_attrs,
get_geom_structures_attrs,
get_geom_2d_flow_area_attrs
7 changes: 7 additions & 0 deletions docs/source/RasHdf.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
RasHdf
======
.. currentmodule:: rashdf
.. autoclass:: RasHdf
:show-inheritance:
:special-members: __init__,
open_uri
11 changes: 11 additions & 0 deletions docs/source/RasPlanHdf.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
RasPlanHdf
==========
.. currentmodule:: rashdf
.. autoclass:: RasPlanHdf
:show-inheritance:
:members: get_plan_info_attrs,
get_plan_param_attrs,
get_meteorology_precip_attrs,
get_results_unsteady_attrs,
get_results_unsteady_summary_attrs,
get_results_volume_accounting_attrs
Empty file added docs/source/_static/.gitkeep
Empty file.
Empty file added docs/source/_templates/.gitkeep
Empty file.
39 changes: 39 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

import sys

sys.path.insert(0, "src")

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = "rashdf"
copyright = "2024, fema-ffrd"
author = "fema-ffrd"
release = "0.2.1"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx_rtd_theme",
"numpydoc",
]

numpydoc_show_class_members = False

templates_path = ["_templates"]
exclude_patterns = []


# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

# html_theme = "alabaster"
html_theme = "sphinx_rtd_theme"
html_static_path = ["_static"]
102 changes: 102 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
.. rashdf documentation master file, created by
sphinx-quickstart on Mon Jun 3 15:55:12 2024.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
rashdf Documentation
====================
:code:`rashdf` is a library for reading data from `HEC-RAS <https://www.hec.usace.army.mil/software/hec-ras/>`_
HDF5 files. It is a wrapper around the :code:`h5py` library, and provides an interface with
convenience functions for reading key HEC-RAS geometry data, output data,
and metadata.

Installation
============
With :code:`pip`::

pip install rashdf


Quickstart
==========
Reading geometry from a HEC-RAS geometry HDF file::

>>> from rashdf import RasGeomHdf
>>> with RasGeomHdf('Muncie.g05.hdf') as geom_hdf:
... projection = geom_hdf.projection()
... mesh_area_names = geom_hdf.mesh_area_names()
... mesh_areas = geom_hdf.mesh_areas()
... mesh_cell_points = geom_hdf.mesh_cell_points()
>>> projection
<Projected CRS: EPSG:2965>
Name: NAD83 / Indiana East (ftUS)
Axis Info [cartesian]:
- E[east]: Easting (US survey foot)
- N[north]: Northing (US survey foot)
Area of Use:
- undefined
Coordinate Operation:
- name: unnamed
- method: Transverse Mercator
Datum: North American Datum 1983
- Ellipsoid: GRS 1980
- Prime Meridian: Greenwich
>>> mesh_area_names
['2D Interior Area', 'Perimeter_NW']
>>> mesh_areas
mesh_name geometry
0 2D Interior Area POLYGON ((409537.180 1802597.310, 409426.140 1...
1 Perimeter_NW POLYGON ((403914.470 1804971.220, 403008.310 1...
>>> mesh_cell_points
mesh_name cell_id geometry
0 2D Interior Area 0 POINT (406000.000 1805000.000)
1 2D Interior Area 1 POINT (406050.000 1805000.000)
2 2D Interior Area 2 POINT (406100.000 1805000.000)
3 2D Interior Area 3 POINT (406150.000 1805000.000)
4 2D Interior Area 4 POINT (406200.000 1805000.000)
... ... ... ...
5785 Perimeter_NW 514 POINT (403731.575 1804124.860)
5786 Perimeter_NW 515 POINT (403650.619 1804121.731)
5787 Perimeter_NW 516 POINT (403585.667 1804141.139)
5788 Perimeter_NW 517 POINT (403534.818 1804186.902)
5789 Perimeter_NW 518 POINT (403632.837 1804235.708)

Reading plan data from a HEC-RAS plan HDF file hosted on AWS S3
(note, this requires installation of the optional :code:`fsspec`
and :code:`s3fs` libraries as well as configuration of S3
credentials)::

>>> from rashdf import RasPlanHdf
>>> with RasPlanHdf.open_uri('s3://bucket/ElkMiddle.p01.hdf') as plan_hdf:
... plan_info = plan_hdf.get_plan_info_attrs()
>>> plan_info
{'Base Output Interval': '1HOUR', 'Computation Time Step Base': '1MIN',
'Flow Filename': 'ElkMiddle.u01', 'Flow Title': 'Jan_1996',
'Geometry Filename': 'ElkMiddle.g01', 'Geometry Title': 'ElkMiddle',
'Plan Filename': 'ElkMiddle.p01', 'Plan Name': 'Jan_1996',
'Plan ShortID': 'Jan_1996', 'Plan Title': 'Jan_1996',
'Project Filename': 'g:\\Jan1996_Kanawha_CloudPrep\\Elk Middle\\ElkMiddle.prj',
'Project Title': 'ElkMiddle',
'Simulation End Time': datetime.datetime(1996, 2, 7, 12, 0),
'Simulation Start Time': datetime.datetime(1996, 1, 14, 12, 0),
'Time Window': [datetime.datetime(1996, 1, 14, 12, 0),
datetime.datetime(1996, 2, 7, 12, 0)]}


API
===
.. toctree::
:maxdepth: 1

RasGeomHdf
RasPlanHdf
RasHdf

:code:`rashdf` provides two primary classes for reading data from
HEC-RAS geometry and plan HDF files: :code:`RasGeomHdf` and :code:`RasPlanHdf`.
Both of these classes inherit from the :code:`RasHdf` base class, which
inherits from the :code:`h5py.File` class.

Note that :code:`RasPlanHdf` inherits from :code:`RasGeomHdf`, so all of the
methods available in :code:`RasGeomHdf` are also available in :code:`RasPlanHdf`.
19 changes: 11 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ classifiers = [
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
version = "0.2.1"
version = "0.2.2"
dependencies = ["h5py", "geopandas", "pyarrow"]

[project.optional-dependencies]
dev = ["pre-commit", "ruff", "pytest"]
dev = ["pre-commit", "ruff", "pytest", "pytest-cov"]
docs = ["sphinx", "numpydoc", "sphinx_rtd_theme"]

[project.urls]
repository = "https://github.com/fema-ffrd/rashdf"
Expand All @@ -28,10 +29,12 @@ rashdf = "cli:main"
pythonpath = "src"
testpaths = "tests"

# TODO: linting for docstrings.
# https://github.com/fema-ffrd/rashdf/issues/15
# [tool.ruff.lint]
# select = ["D"]
[tool.ruff.lint]
select = ["D"]

# [tool.ruff.lint.pydocstyle]
# convention = "numpy"
[tool.ruff.lint.pydocstyle]
convention = "numpy"

[tool.ruff.lint.per-file-ignores]
"tests/**" = ["D"]
"docs/**" = ["D"]
23 changes: 0 additions & 23 deletions requirements.txt

This file was deleted.

Loading

0 comments on commit a9d14da

Please sign in to comment.