Skip to main content

A package for computing metrics for NWP model evaluation

Project description

NWPeval

NWPeval is a Python package designed to facilitate the evaluation and analysis of numerical weather prediction (NWP) models. It provides a comprehensive set of metrics and tools to assess the performance of NWP models by comparing their output with observed weather data.

Features

  • 65 evaluation metrics including:

    • Continuous: MAE, RMSE, R², NRMSE, PCC, and more
    • Categorical: POD, FAR, CSI, ETS, HSS, and more
    • Probabilistic: BSS, RPSS
    • Distributional: KL Divergence, Hellinger, Wasserstein, and more
  • Flexible computation along specified dimensions

  • Support for threshold-based metrics

  • Integration with xarray and NumPy

  • Compatible with 2D, 3D, and 4D datasets

Installation

pip install nwpeval

Usage

New API (Recommended)

The new modular API provides standalone functions for each metric:

import xarray as xr
from nwpeval import rmse, mae, acc, pod, fss

# Load observed and modeled data as xarray DataArrays
obs_data = xr.DataArray(...)
model_data = xr.DataArray(...)

# Compute metrics directly
rmse_value = rmse(obs_data, model_data)
mae_value = mae(obs_data, model_data)
acc_value = acc(obs_data, model_data)

print(f"RMSE: {rmse_value}")
print(f"MAE: {mae_value}")
print(f"ACC: {acc_value}")

Example: Threshold-based metrics

from nwpeval import pod, far, ets, csi

# Compute categorical metrics with threshold
threshold = 0.5
pod_value = pod(obs_data, model_data, threshold=threshold)
far_value = far(obs_data, model_data, threshold=threshold)
ets_value = ets(obs_data, model_data, threshold=threshold)

print(f"POD: {pod_value}")
print(f"FAR: {far_value}")
print(f"ETS: {ets_value}")

Example: Metrics along specific dimensions

from nwpeval import rmse, mae

# Compute metrics along latitude/longitude (get time series)
rmse_timeseries = rmse(obs_data, model_data, dim=['lat', 'lon'])

# Compute metrics along time (get spatial map)
mae_spatial = mae(obs_data, model_data, dim='time')

Example: Fractions Skill Score (FSS)

from nwpeval import fss

# Compute FSS with threshold and neighborhood size
fss_value = fss(
    obs_data, 
    model_data, 
    threshold=0.5, 
    neighborhood_size=5,
    spatial_dims=['lat', 'lon']
)

Example: Distribution comparison metrics

from nwpeval import mkldiv, jsdiv, hellinger, wasserstein

kl = mkldiv(obs_data, model_data)
js = jsdiv(obs_data, model_data)
hell = hellinger(obs_data, model_data)
wass = wasserstein(obs_data, model_data)

Example: Metrics with parameters

from nwpeval import lehmer_mean, chernoff, renyi, tsallis

# Metrics that require additional parameters
lehmer = lehmer_mean(obs_data, model_data, p=3)
chern = chernoff(obs_data, model_data, alpha=0.7)
ren = renyi(obs_data, model_data, alpha=0.8)
tsal = tsallis(obs_data, model_data, alpha=0.9)

Legacy API (Deprecated)

Warning: The NWP_Stats class is deprecated and will be removed in a future version. Please migrate to the new standalone functions.

import xarray as xr
from nwpeval import NWP_Stats  # Shows DeprecationWarning

# Load observed and modeled data as xarray DataArrays
obs_data = xr.DataArray(...)
model_data = xr.DataArray(...)

# Create an instance of NWP_Stats
nwp_stats = NWP_Stats(obs_data, model_data)

# Compute basic metrics
metrics = ['MAE', 'RMSE', 'ACC']
results = nwp_stats.compute_metrics(metrics)

# Print the results
for metric, value in results.items():
    print(f"{metric}: {value}")

Legacy: Computing metrics with thresholds

from nwpeval import NWP_Stats

nwp_stats = NWP_Stats(obs_data, model_data)

thresholds = {
    'FSS': 0.6,
    'FSS_neighborhood': 5,
    'ETS': 0.7,
    'POD': 0.5
}

metrics = ['FSS', 'ETS', 'POD']
results = nwp_stats.compute_metrics(metrics, thresholds=thresholds)

Legacy: Computing metrics along dimensions

from nwpeval import NWP_Stats

nwp_stats = NWP_Stats(obs_data, model_data)

metrics = ['MAE', 'RMSE', 'ACC']
dimensions = ['lat', 'lon']
results = nwp_stats.compute_metrics(metrics, dim=dimensions)

Available Metrics

Category Metrics
Continuous MAE, RMSE, ACC, R², NRMSE, PCC, MBD, TSE, EVS, NMSE, FV, SDR, VIF, MAD, IQR, NAE, RMB, MAPE, WMAE, ASS, RSS, QSS, LMBE, SMSE, GMB, SBS, AEV, Cosine Similarity
Categorical ETS, POD, FAR, CSI, HSS, PSS, GSS, FB, HKD, ORSS, SEDS, EDS, SEDI, F1, MCC, BA, NPV, Jaccard, Gain, Lift
Spatial FSS
Probabilistic BSS, RPSS
Distributional MKLDIV, JSDIV, Hellinger, Wasserstein, TV, Chi-Square, Intersection, Bhattacharyya, Chernoff, Rényi, Tsallis
Mean Harmonic Mean, Geometric Mean, Lehmer Mean

Help

# Get help on a specific function
from nwpeval import rmse
help(rmse)

# List all available metrics
import nwpeval
print(dir(nwpeval))

For more detailed usage instructions, see Documentation and examples.

NEXT UPDATE

Instability (Thunderstorm) indices:

  • Total Totals Index (TT)
  • K Index (KI)
  • Lifted Index (LI)
  • CAPE, SWEAT, and more!

Contributing

Contributions are welcome! Please open an issue or submit a pull request on the GitHub repository.

License

NWPeval is licensed under the MIT License.

Acknowledgments

Thanks to the developers of NumPy, xarray, and SciPy.

Contact

I hope you find NWPeval useful in evaluating your numerical weather prediction models!

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

nwpeval-1.6.0.tar.gz (27.9 kB view details)

Uploaded Source

Built Distribution

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

nwpeval-1.6.0-py3-none-any.whl (46.0 kB view details)

Uploaded Python 3

File details

Details for the file nwpeval-1.6.0.tar.gz.

File metadata

  • Download URL: nwpeval-1.6.0.tar.gz
  • Upload date:
  • Size: 27.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for nwpeval-1.6.0.tar.gz
Algorithm Hash digest
SHA256 3d065f34cc2223aad5d25269f533a7403f5d89da8fa392c84adf1b0992437477
MD5 d58d9a188bb8f84349ebb2b4be7fc5f7
BLAKE2b-256 02f986e42b15d552f2fc4de5dca157680899659472fe7d92d8fdd6448196b10b

See more details on using hashes here.

File details

Details for the file nwpeval-1.6.0-py3-none-any.whl.

File metadata

  • Download URL: nwpeval-1.6.0-py3-none-any.whl
  • Upload date:
  • Size: 46.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for nwpeval-1.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c0af906f74f9cb8c5df216244dbaa73a2b5252e9f582bbd066586db62298adb5
MD5 53dbbb48b3e0c95ea4cacfdd44ef2e09
BLAKE2b-256 895f9894c75ed25408e53ba7f58855194fa5a53923c7fe2bf630aeaade3e3527

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