A Python framework for AI-powered hazard prediction and risk assessment
Project description
PyHazards
PyHazards is a Python framework for AI-powered hazard prediction and risk assessment. It provides a modular, hazard-first architecture for building, training, and deploying machine learning models to predict and analyze natural hazards (earthquake, wildfire, flood, hurricane, landslide, etc.).
Features
- Hazard-First Design: Unified dataset interface for tabular, temporal, and raster data
- Simple Models: Ready-to-use MLP/CNN/temporal encoders with task heads (classification, regression, segmentation)
- Trainer API: Fit/evaluate/predict with optional mixed precision and multi-GPU (DDP) support
- Metrics: Built-in classification/regression/segmentation metrics
- Extensible: Registries for datasets, models, transforms, and pipelines
Installation
PyHazards supports both CPU and GPU environments. Make sure you have Python installed (version >= 3.8, <3.13).
Base Installation
Install the core package:
pip install pyhazards
This will install PyHazards with minimal dependencies.
Python 3.8 and PyTorch (CUDA 12.6 example)
If you need a specific PyTorch build (e.g., CUDA 12.6), install PyTorch first, then install PyHazards:
# Example for CUDA 12.6 wheels
pip install torch --index-url https://download.pytorch.org/whl/cu126
pip install pyhazards
Quick Start
Here's a simple example to get started with PyHazards using a toy tabular dataset:
import torch
from pyhazards.datasets import DataBundle, DataSplit, Dataset, FeatureSpec, LabelSpec
from pyhazards.models import build_model
from pyhazards.engine import Trainer
from pyhazards.metrics import ClassificationMetrics
class ToyHazard(Dataset):
def _load(self):
x = torch.randn(500, 16)
y = torch.randint(0, 2, (500,))
splits = {
"train": DataSplit(x[:350], y[:350]),
"val": DataSplit(x[350:425], y[350:425]),
"test": DataSplit(x[425:], y[425:]),
}
return DataBundle(
splits=splits,
feature_spec=FeatureSpec(input_dim=16, description="toy features"),
label_spec=LabelSpec(num_targets=2, task_type="classification"),
)
data = ToyHazard().load()
model = build_model(name="mlp", task="classification", in_dim=16, out_dim=2)
trainer = Trainer(model=model, metrics=[ClassificationMetrics()], mixed_precision=True)
optimizer = torch.optim.Adam(model.parameters(), lr=1e-3)
loss_fn = torch.nn.CrossEntropyLoss()
trainer.fit(data, optimizer=optimizer, loss_fn=loss_fn, max_epochs=5)
results = trainer.evaluate(data, split="test")
print(results)
Using CUDA
To use CUDA for GPU acceleration, set the environment variable:
export PYHAZARDS_DEVICE=cuda:0
Or specify the device in your code:
from pyhazards.utils import set_device
set_device("cuda:0")
Documentation
Full documentation is available at: https://labrai.github.io/PyHazards
Contributing
We welcome contributions! Please see our:
- Implementation Guideline - For implementing new models
- Contributors Guideline - For contributing to the project
Citation
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}
}
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyhazards-1.0.1.tar.gz.
File metadata
- Download URL: pyhazards-1.0.1.tar.gz
- Upload date:
- Size: 18.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7530406c64a5a922221880442840c97effac24c28eb6abfe0f7995e765a062f0
|
|
| MD5 |
8e31bf3b261be918d3fba74f7e68f143
|
|
| BLAKE2b-256 |
6ed378b677856ff3af041a840a1818f06b9fdc9891e61d21ccc56e0178728ff2
|
File details
Details for the file pyhazards-1.0.1-py3-none-any.whl.
File metadata
- Download URL: pyhazards-1.0.1-py3-none-any.whl
- Upload date:
- Size: 22.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cccb49bed4a5647a9f06b267f19af6ca3d38c1a0639f09b4a41728b0f5732c22
|
|
| MD5 |
82f1150b211d0342958eeab1701ffb07
|
|
| BLAKE2b-256 |
8e281bfbae63891da31b63d43c4c0479b67af7c45155efb716099da9e8484be2
|