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.2.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.2-py3-none-any.whl (60.1 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyhazards-1.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 533eb5a95898be44ba9c3b33be6d7b8c97e882eb671413372ae5f16b8d13b85b
MD5 ba9d58676721355d12eeaa3392057225
BLAKE2b-256 ea9734c9fe8576783e03c60522a33904534eaf29622a893ab6f5f7b6b9c97c8b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyhazards-1.0.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 959a9f527adaa5a7b8231e807a3029ccf1ea3a2355fd84e856552ae4aaacd09f
MD5 3e9efa0f945e179648620052497c6351
BLAKE2b-256 554603c54e88d3c51e54be1fb6ca8ab0a8104ae814cc42f89242ced2f15b09a9

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