Metadata-Version: 2.5
Name: herbievtx
Version: 0.1.0a1
Summary: Herbie weather data with HEC-Vortex via JPype
Author-email: Jeff Gregory <jeffrey.s.gregory@icloud.com>
License-Expression: MIT
Keywords: gfs,grib,hrrr,hydrology,shg
Classifier: Development Status :: 3 - Alpha
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.13
Requires-Dist: herbie-data>=2026.10.0
Requires-Dist: jpype1>=1.7.1
Requires-Dist: platformdirs>=4.14.8
Requires-Dist: requests>=2.34.2
Requires-Dist: tqdm>=4.70.1
Description-Content-Type: text/markdown

# herbievtx

Download NOAA model data with [Herbie](https://github.com/blaylockbk/Herbie) and process it into HEC-DSS files with [HEC-Vortex](https://github.com/HydrologicEngineeringCenter/Vortex), scripted from Python through [JPype](https://jpype.readthedocs.io/).

> **Status: alpha (0.1.0).** The API and CLI may change without notice.

## What it does

- Uses Herbie to fetch GRIB2 data (GFS, HRRR, etc.), including subsetting by variable.
- Starts a JVM with Vortex on the classpath via JPype, so you can call Vortex classes (`DataReader`, `BatchImporter`, ...) directly from Python.
- Provides a `herbievtx setup` command that downloads and unpacks a pinned Vortex release for your OS.

## Requirements

- Python 3.13 or newer
- A Java runtime that JPype can find (for example, `JAVA_HOME` set)
- Network access, for Herbie downloads and the one-time Vortex download
- Windows, Linux or macOS. Vortex is downloaded as a `.zip`, `.tar.gz` or `.dmg` respectively.

## Installation

```bash
pip install herbievtx
# or
uv add herbievtx
```

## Quick start

### 1. Install Vortex

```bash
herbievtx setup
```

This downloads Vortex 1.1.1 from the HEC GitHub releases and unpacks it into a per-user data directory.

| Command                       | Purpose                                                |
| ----------------------------- | ------------------------------------------------------ |
| `herbievtx setup`             | Download and install Vortex                            |
| `herbievtx setup --dest PATH` | Install to a custom location (overrides `VORTEX_HOME`) |
| `herbievtx setup --force`     | Re-download even if already present                    |
| `herbievtx setup --quiet`     | Hide the progress bar                                  |
| `herbievtx where`             | Print the resolved Vortex location                     |
| `herbievtx where --dest PATH` | Show the path for an override                          |

The Vortex location is resolved in this order:

1. The `--dest` argument
2. The `VORTEX_HOME` environment variable
3. The per-user data directory (`platformdirs.user_data_dir("herbievtx")/vortex/<version>`)

### 2. Download data and write DSS

```python
from pathlib import Path

from jpype import JString

from herbievtx.jvm import ensure_jvm

ensure_jvm()  # starts the JVM with Vortex on the classpath (default max heap 2g)

from java.util import ArrayList
from mil.army.usace.hec.vortex.io import BatchImporter
from herbie.core import Herbie

# Download a subset of GFS (precipitation rate only)
H = Herbie(date="2026-11-24", model="gfs", product="pgrb2.0p50", fxx=3)
grib = Path(H.download(search=":PRATE:surface:.*ave fcst:"))

# Process into HEC-DSS with Vortex
importer = (
    BatchImporter.builder()
    .inFiles(ArrayList([JString(grib.as_posix())]))
    .variables(ArrayList([JString("Precipitation_rate_surface_3_Hour_Average")]))
    .destination("vortex.dss")
    .geoOptions({
        "targetCellSize": "2000",
        "targetEpsg": "5070",
        "resamplingMethod": "Bilinear",
        "minX": "-81.6251", "minY": "6.8749",
        "maxX": "-77.8749", "maxY": "10.6251",
    })
    .writeOptions({
        "partA": "SHG",
        "partB": "Panama",
        "partC": "PRECIPITATION",
        "partF": "GFS 0p50",
        "dataType": "PER-CUM",
        "units": "MM",
    })
    .build()
)
importer.process()
```

A fuller example is in [`scripts/processGfs.py`](scripts/processGfs.py).

Notes:

- Call `ensure_jvm()` before importing any `java.*` or `mil.army.usace.hec.vortex.*` modules.
- A JVM can only be started once per Python process.
- To list the variables available in a file, use `DataReader.getVariables(path)`.

## Troubleshooting

- **"Vortex not found at ..."**: run `herbievtx setup` or set `VORTEX_HOME`.
- **"No Vortex jars found under ..."**: the install is incomplete. Run `herbievtx setup --force`.
- **JVM or DLL errors on Windows**: confirm that a Java runtime is installed and that the Vortex `app`, `gdal` and `netcdf` folders exist under the install.

## Development

```bash
git clone [https://github.com/jeffsuperglide/herbievtx](https://github.com/jeffsuperglide/herbievtx)
cd herbievtx
uv sync
uv run pytest              # tests marked `integration` need network and Vortex
uv run pytest -m "not integration"
uv run ruff check .
```

## Acknowledgments

- [HEC-Vortex](https://github.com/HydrologicEngineeringCenter/Vortex), US Army Corps of Engineers Hydrologic Engineering Center
- [Herbie](https://github.com/blaylockbk/Herbie), by Brian Blaylock
- [JPype](https://github.com/jpype-project/jpype)

This project is not affiliated with or endorsed by USACE, HEC or NOAA.

## License

Released under the [MIT License](LICENSE).
