Skip to main content

A Python framework for AI-powered hazard prediction and risk assessment

Project description

PyHazards

PyPI - Version Build Status License PyPI - Downloads Issues Pull Requests Stars GitHub forks

Introduction

PyHazards is a Python framework for AI-powered hazard prediction and risk assessment. It provides a hazard-first API for loading data, building models, running end-to-end experiments, and extending with your own modules.

Core Components

  • Datasets: Unified interfaces for tabular, temporal, raster, and graph-style hazard data through DataBundle.
  • Models: Built-in hazard models plus reusable backbones/heads via a registry-driven model API.
  • Engine: Trainer for fit/evaluate/predict workflows with mixed precision and distributed options.
  • Metrics and Utilities: Classification/regression/segmentation metrics, hardware helpers, and reproducibility tools.

Install

pip install pyhazards

Optional CUDA setup:

export PYHAZARDS_DEVICE=cuda:0

Load Data

Example using the implemented ERA5 flood subset loader:

from pyhazards.data.load_hydrograph_data import load_hydrograph_data

data = load_hydrograph_data(
    era5_path="pyhazards/data/era5_subset",
    max_nodes=50,
)
print(data.feature_spec)
print(data.label_spec)
print(list(data.splits.keys()))  # ["train"]

Load Model

Example using wildfire_aspp:

from pyhazards.models import build_model

model = build_model(
    name="wildfire_aspp",
    task="segmentation",
    in_channels=12,
)
print(type(model).__name__)

Full Test

Short end-to-end example using real ERA5 data and an implemented flood model:

import torch
from pyhazards.data.load_hydrograph_data import load_hydrograph_data
from pyhazards.datasets import graph_collate
from pyhazards.engine import Trainer
from pyhazards.models import build_model

data = load_hydrograph_data("pyhazards/data/era5_subset", max_nodes=50)

model = build_model(
    name="hydrographnet",
    task="regression",
    node_in_dim=2,
    edge_in_dim=3,
    out_dim=1,
)

trainer = Trainer(model=model, mixed_precision=False)
optimizer = torch.optim.Adam(model.parameters(), lr=1e-3)
loss_fn = torch.nn.MSELoss()

trainer.fit(
    data,
    optimizer=optimizer,
    loss_fn=loss_fn,
    max_epochs=1,
    batch_size=1,
    collate_fn=graph_collate,
)

metrics = trainer.evaluate(
    data,
    split="train",
    batch_size=1,
    collate_fn=graph_collate,
)
print(metrics)

Custom Module

To upload and use your own data/model modules:

  1. Upload your raw data files to your project path and write a dataset loader that returns a DataBundle.
  2. Register your model with register_model and a builder function that returns an nn.Module.
  3. Build with build_model(...) and train/evaluate through Trainer.

Implementation details:

Star History

Star History Chart

How to Cite

If you use PyHazards in your research, please cite:

@software{pyhazards2025,
  title={PyHazards: A Python Framework for AI-Powered Hazard Prediction},
  author={Cheng, Xueqi},
  year={2025},
  url={https://github.com/LabRAI/PyHazards}
}

Documentation

Full documentation is available at: https://labrai.github.io/PyHazards

License

MIT License

Contact

For questions or contributions, please contact xc25@fsu.edu.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyhazards-1.0.3.tar.gz (60.1 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyhazards-1.0.3-py3-none-any.whl (60.1 MB view details)

Uploaded Python 3

File details

Details for the file pyhazards-1.0.3.tar.gz.

File metadata

  • Download URL: pyhazards-1.0.3.tar.gz
  • Upload date:
  • Size: 60.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.7

File hashes

Hashes for pyhazards-1.0.3.tar.gz
Algorithm Hash digest
SHA256 c55166271ba743304030cad617fceac29a649e23ea5c8f9e7197c5a02fb43870
MD5 fa19ab353b79650972a42835c15da569
BLAKE2b-256 89843254f57d4d754cc58a9e2b535421b44db17095b7a083d608a4f6582a034c

See more details on using hashes here.

File details

Details for the file pyhazards-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: pyhazards-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 60.1 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.7

File hashes

Hashes for pyhazards-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 1e138892cfc711fb981b856b5411f5f439c71baf104b14bc9ed6bbaf1165c9fc
MD5 eec77c4d9e59e4dd2817ba30440dcfb1
BLAKE2b-256 7a021abddf2ba318bfa7637653e5cec79f532eba081879b86a2377a92310bd38

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page