Skip to content
YangLabHKUSTPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

🌊 WaveFlow

Probabilistic ocean-wave and water-level prediction on unstructured meshes

DOI Weights Code licence Weights licence Python PyTorch

WaveFlow is a conditional flow-matching model that predicts ensembles of significant wave height, peak period, mean direction and water level directly on unstructured coastal and global meshes. It conditions on atmospheric fields — ERA5 reanalysis for hindcasts, or an IFS ensemble when a forecast is being emulated — and generates calibrated ensembles at every mesh node.

This repository ships two trained checkpoints and the code needed to sample from them: a small waveflow CLI, the sampling model, and the exact release configs. It also ships the Hong Kong coastline product and the EurOtop mapping that turn an ensemble into a coastal overtopping index (Fig. 6b of the paper), runnable without a GPU from the released case product.

Paper · WaveFlow enables high-resolution prediction of ocean waves and water levels for coastal hazard warning

Contents: Quick start · Models · Install · Sample · Real-time forecast · Plot · Overtopping · Documentation · Citing

WaveFlow overview: atmospheric forcing, conditional flow matching and the patch-token architecture

Figure 1 | WaveFlow generates wave and water-level ensembles directly on unstructured meshes. a, Inputs and outputs: global 10 m winds and mean sea-level pressure condition Hs, period, mean direction and water level on two independent unstructured meshes, a global one and a higher-resolution Hong Kong one. b, Ensemble generation by conditional flow matching: each member is integrated from independent Gaussian noise along the linear path x_t = (1-t) x_0 + t x_1 to a sample of Pr(wave | atmosphere). c, The network architecture: mesh nodes are clustered into patches and embedded as wave tokens, so attention costs O(P^2) + O(N) instead of O(N^2); atmospheric tokens enter the regional model by cross-attention and the global model by pre-interpolation and concatenation.

Quick start

git clone https://github.com/YangLabHKUST/WaveFlow.git && cd WaveFlow
conda env create -f environment.yml && conda activate waveflow

python -m waveflow setup --weights      # 4.1 GB, SHA256 verified
python -m waveflow env                  # packages, CUDA, local weights

# 10 members on the Hong Kong mesh, ERA5 forcing from WeatherBench2
python -m waveflow sample --model hk --timestamps 20211013T00 --members 10

Each member lands in <out>/samples/sample_<timestamp>_ens<NNN>.npz with the array under sample, shape (n_nodes, 4), columns hs, tp, dm, elev in physical units.

Released models

Checkpoint Domain Variables Nodes Params Epoch Config
waveflow-hk-4var-ep50.pt Hong Kong waters Hs, Tp, Dm, water level 7,788 45.69 M 50 configs/release/hk_4var.yaml
waveflow-global-4var-ep200.pt global ocean Hs, Tp, Dm, water level 651,652 966.04 M 200 configs/release/global_4var.yaml
File Size SHA256
waveflow-hk-4var-ep50.pt 183.1 MB 63bd1a4041b777016c9878bf51e2e4fa8c7ba553fa6adeb8375e12077d393239
waveflow-global-4var-ep200.pt 3,883.3 MB cbcf0858743b5774102711f505dc4bd6e5a879fc3e098ec8247dc0bb23234b5a

All checkpoints are EMA-only: the EMA weights are baked into model_state_dict and the non-EMA buffers are preserved. Load them with training.use_ema=false and sampling.use_ema_for_sampling=false — the waveflow CLI does this for you. The state dict also carries the mesh buffers (patch_centroids, local_coords_template, mask_template, cluster_labels), so a checkpoint is self-describing once setup has restored data/.

Sampling needs no optimizer state: the Hong Kong model peaks at ≈ 6 GB, the global model at ≈ 11 GB with batch_size=2. The ≈ 80 GB figure sometimes quoted for the global mesh is the training budget.

Install

conda env create -f environment.yml
conda activate waveflow
python -m waveflow env                 # packages, CUDA, local weights
python -m waveflow setup --weights     # 183.1 MB + 3,883.3 MB + assets

setup downloads from Hugging Face, verifies the SHA256 checksums listed in waveflow/downloads.yaml, and extracts the mesh assets (coordinates, patch clusters, normalization statistics, ocean boundary) into data/.

pip users can install from requirements-pip.txt instead: the PyTorch CUDA index is declared inside the file, and eccodes (only needed by waveflow forecast) requires the system library first — conda install -c conda-forge eccodes or apt-get install libeccodes-dev.

Sample

# 10 members on the Hong Kong mesh at one timestamp, ERA5 forcing
python -m waveflow sample --model hk --timestamps 20211013T00 --members 10

# 10 members on the global mesh
python -m waveflow sample --model global --timestamps 20220924T00 --members 10 --steps 50

The atmospheric forcing comes from WeatherBench2 on demand (public, anonymous access); --era5-dir points the loader at your own NetCDF frames instead. --ens-members emulates a forecast by forcing each member with a different member of an archived IFS ensemble. See docs/INFERENCE.md for the flags, the forcing options and the output layout.

10-member ensemble on the Hong Kong mesh

Hong Kong, 10 members — python -m waveflow sample --model hk --timestamps 20211013T00 --members 10 (or --plot on the same command): one member, the ensemble mean and the ensemble spread of Hs on the 7,788-node Hong Kong mesh, cropped to the mesh's exact bounding box, written to runs/hk_20211013T00/samples/ and drawn to runs/hk_20211013T00/figures/hs_20211013T00.png.

10-member ensemble on the global mesh

Global, 10 members — python -m waveflow sample --model global --timestamps 20220924T00 --members 10 --steps 50: the same three panels on the global mesh (Robinson projection), interpolated from the 651,652 nodes onto a 0.25° grid for display; one file per member and timestamp.

Real-time forecast

python -m waveflow forecast --init latest --leads 24,48,72 --members 10
python -m waveflow forecast --model global --leads 24,48 --members 10
python -m waveflow forecast --init 20261127T18 --leads 24-120:24 --plot

The forcing comes from the IFS ensemble forecast on ECMWF open data (stream enfo, 0.25°, four cycles a day, steps 0–144 h every 3 h), not from reanalysis: this is the operational mode. The command picks the newest published cycle, fetches the three surface fields for the requested members, averages them, and runs the checkpoint at every lead. Each lead writes <out>/lead_<L>h/samples/*.npz.

GRIB decoding needs eccodes (conda install -c conda-forge eccodes, or pip install --target .deps eccodes); everything else is already in environment.yml. See docs/INFERENCE.md for the cycle timing and the lead semantics.

Plot

python -m waveflow plot --run runs/hk_20211013T00          # newest run if omitted
python -m waveflow plot --run runs/hk_20211013T00 --var tp --out tp.png
python -m waveflow sample --model hk --timestamps 20211013T00 --plot

Each figure shows one member, the ensemble mean and the ensemble spread on the model mesh, with Natural Earth coastlines; --var picks hs, tp, dm or elev. Figures land in <run>/figures/.

Overtopping (Hong Kong coast)

python -m waveflow overtopping --demo --plot          # paper's Fig. 6b, no GPU
python -m waveflow overtopping --run runs/hk_20250924T03 --plot

overtopping maps an ensemble of Hs, Tp, Dm and water level onto the 7,239 Hong Kong coastline segments and returns the overtopping index P(q > 1 L/s/m) for the 1,215 engineered defences (663 vertical seawalls, 552 sloping revetments), with q from the EurOtop (2018) mean-discharge formulae. Crest freeboards come from the LandsD DTM/SpotHeight survey, the toe depth from the hindcast, and the tide enters through the model water level. The command writes overtopping_index.csv (per-segment index, median and p90 discharge), the full arrays as npz, and a Fig. 6b-style hazard map; see docs/OVERTOPPING.md for the formulae, the data provenance and the limitations.

Fig. 6b reproduction: Hong Kong overtopping hazard map for Typhoon Ragasa

Reproduction of the manuscript's Fig. 6b — python -m waveflow overtopping --demo --plot on the Ragasa 2025 ensemble: overtopping index per coastline segment at the territorial peak (2025-09-24 03 UTC), the 100-member ensemble-mean Hs on the 7,788-node mesh, the HKO flooding reports and tide gauges, and three street-scale insets. The same code path recomputes the index from raw samples and reproduces the analysis product to float32 precision. The panel uses the manuscript's LandsD orthophoto basemap, shipped downsampled with acknowledgement to the Government of the Hong Kong SAR (DATA.GOV.HK); Natural Earth is the fallback if the asset is absent.

Documentation

File Content
docs/INFERENCE.md sample/forecast flags, forcing, output format, plots
docs/OVERTOPPING.md Hong Kong overtopping index: EurOtop formulae, assets, outputs, limitations
docs/DATA.md what assets.tar.gz contains, forcing sources, normalization statistics
docs/THIRD_PARTY.md data attribution

Citing

See CITATION.cff. The weights carry their own DOI (10.5281/zenodo.24106732); the concept DOI always resolves to the latest version.


Code: MIT · Weights and derived assets: CC BY 4.0 · Built with PyTorch and cartopy.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages