Skip to main content

SAFE: Stratified Assessments of Forecasts over Earth

arXiv PyPI - Version GitHub Static Badge Website

Installation

pip install safe-earth

To build from source instead:

# get repo
git clone git@github.com:N-Masi/safe.git

# create dev environment
conda create -n safe.env
conda activate safe.env
pip install --file requirements.txt
conda install --channel conda-forge pygmt plotly typing_extensions

Basic Usage

There are 3 basic steps to any SAFE pipeline:

  1. Measure loss: any function that operates between each predicted $\hat{y}$ and the ground truth $y$. There is a loss calculated for every prediction by a given model at every permutation of gridpoint, timestamp, lead time, variable, and vertical level.

    Example: the latitude-weighted squared difference of $\hat{y}$ and $y$.

  2. Measure stratified error: any function that reduces across gridpoints to calculate a metric for each strata.

    Example: RMSE.

  3. Measure fairness: any function that operates on a set of stratified errors. Calculates a fairness metric for each permutation of model and attribute (e.g., the fairness of GraphCast in prediction by territory).

    Example: greatest absolute difference in RMSEs.

It is most useful to look at the errors and fairness. Errors allow you to see how well a particular model works in a specific strata, which can be useful to decision makers determining which model is most accurate for their country or region. Fairness metrics provide a summary statistic for the overall amount of bias in a model.

For now, loss functions should create dataframes with columns for the output of the function. The name of that column is passed into the error function. Calls to src/safe_earth/metrics/fairness.measure_fairness take in the fairness functions as objects and run them all internally. The first major version of the package will bring this paradigm to the errors as well by taking in loss functions as parameters.

Demos

An example of using SAFE to collect metrics on 6 AIWP models across the territory, subregion, income, and landcover attributes is availabe in demos/iclr_workflow.py. It generates error and fairness data by assessing the models on 2020 ERA5 data.

To see the type of analysis that can be performed with this data, you can reproduce the figures and tables from the paper by running demos/iclr_figs.py and demos/iclr_tables.py, respectively.

An interactive notebook utilizing SAFE to investigate territorial disparities is available in demos/interactive_demo.ipynb.

Data Notes

To unify the coordinate system across all integrated data sources, latitude ranges [-90, 90] with index 0 at -90, and longitude [-180, 180) but with index 0 at 0 and a wraparound from 180 to -180 in the middle. This is because metadata sourced from pygeoboundaries_geolab follows this coordinate system, and it is easiest to bring tabular data into conformance.

Testing

Run pytest in the terminal of the repo directory while in a python environment that has pytest installed.

Citation

If you use SAFE in your work, please cite us!

@article{masi2025safe,
  title={SAFE: A Novel Approach to AI Weather Evaluation through Stratified Assessments of Forecasts over Earth},
  author={Masi, Nick and Balestriero, Randall},
  journal={arXiv preprint arXiv:2510.26099},
  year={2025}
}

Release files for safe-earth 0.1.12

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for safe-earth 0.1.12
File Size Uploaded
safe_earth-0.1.12.tar.gz 26.6 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for safe-earth 0.1.12
File Interpreter ABI Platform
safe_earth-0.1.12-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 53.3 MB

Release files / safe_earth-0.1.12.tar.gz

Download URL safe_earth-0.1.12.tar.gz
Size 26.6 MB
Tags Source
SHA-256 checksum
How to use checksums
086d211801db7ad54ffa44782ad1e1aabbd11ce5604e0cecb92a72abf79612ee
BLAKE2b-256 checksum
How to use checksums
d814ca81a0e688e7c9d709511ca5b073e3395081aebeb1b1fa6db942fcb5328f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.10

Release files / safe_earth-0.1.12-py2.py3-none-any.whl

Download URL safe_earth-0.1.12-py2.py3-none-any.whl
Size 26.7 MB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
6f2003b7943671a60b177c89f94a69f74a3d7bc7a81d69fd9e11cb8748154302
BLAKE2b-256 checksum
How to use checksums
b70b36d555d224a9196a343dfe7a31f7a1e152427aae49fde963264d870247e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.10

Release history Release notifications | RSS feed

This release

0.1.12 This release

2 release files

0.1.11

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.19

2 release files

0.0.16

2 release files

0.0.15

2 release files

0.0.14

2 release files

0.0.13

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page