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

  • Supports a wide range of evaluation metrics, including:

    • Mean Absolute Error (MAE)
    • Root Mean Square Error (RMSE)
    • Anomaly Correlation Coefficient (ACC)
    • Fractions Skill Score (FSS)
    • Equitable Threat Score (ETS)
    • Probability of Detection (POD)
    • False Alarm Ratio (FAR)
    • Critical Success Index (CSI)
    • Brier Skill Score (BSS)
    • Heidke Skill Score (HSS)
    • Peirce Skill Score (PSS)
    • Gilbert Skill Score (GS)
    • Symmetric Extreme Dependency Score (SEDS)
    • Frequency Bias (FB)
    • Gilbert Skill Score (GSS)
    • Hanssen-Kuipers Discriminant (H-KD)
    • Odds Ratio Skill Score (ORSS)
    • Extreme Dependency Score (EDS)
    • Symmetric Extremal Dependence Index (SEDI)
    • Ranked Probability Skill Score (RPSS)
    • Total Squared Error (TSE)
    • Explained Variance Score (EVS)
    • Normalized Mean Squared Error (NMSE)
    • Fractional Variance (FV)
    • Pearson Correlation Coefficient (PCC)
    • Standard Deviation Ratio (SDR)
    • Variance Inflation Factor (VIF)
    • Median Absolute Deviation (MAD)
    • Interquartile Range (IQR)
    • Coefficient of Determination (R^2)
    • Normalized Absolute Error (NAE)
    • Relative Mean Bias (RMB)
    • Mean Absolute Percentage Error (MAPE)
    • Weighted Mean Absolute Error (WMAE)
    • Absolute Skill Score (ASS)
    • Relative Skill Score (RSS)
    • Quadratic Skill Score (QSS)
    • Normalized Root Mean Squared Error (NRMSE)
    • Logarithmic Mean Bias Error (LMBE)
    • Scaled Mean Squared Error (SMSE)
    • Mean Bias Deviation (MBD)
    • Geometric Mean Bias (GMB)
    • Symmetric Brier Score (SBS)
    • Adjusted Explained Variance (AEV)
    • Cosine Similarity
    • F1 Score
    • Matthews Correlation Coefficient (MCC)
    • Balanced Accuracy (BA)
    • Negative Predictive Value (NPV)
    • Jaccard Similarity Coefficient
    • Gain
    • Lift
    • Mean Kullback-Leibler Divergence (MKLDIV)
    • Jensen-Shannon Divergence (JSDIV)
    • Hellinger Distance
    • Wasserstein Distance
    • Total Variation Distance
    • Chi-Square Distance
    • Intersection
    • Bhattacharyya Distance
    • Harmonic Mean
    • Geometric Mean
    • Lehmer Mean
    • Chernoff Distance
    • Rényi Divergence
    • Tsallis Divergence
  • Flexible computation of metrics along specified dimensions or over the entire dataset.

  • Support for threshold-based metrics with customizable threshold values.

  • Integration with xarray and NumPy for efficient computation and data handling.

  • Compatibility with both time series and spatial data, supporting 2D, 3D, and 4D datasets.

  • Detailed Examples to guide users in utilizing the package effectively.

Installation

You can install NWPeval using pip:

pip install nwpeval

Usage

Here are a few examples of how to use the package

Example 1: Computing basic metrics

import xarray as xr
from nwpeval import NWP_Stats

# 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}")

Example 2: Computing metrics with thresholds

import xarray as xr
from nwpeval import NWP_Stats

# 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)

# Define thresholds for specific metrics
thresholds = {
    'FSS': 0.6,
    'FSS_neighborhood': 5,
    'ETS': 0.7,
    'POD': 0.5
}

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

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

Example 3: Computing metrics along specific dimensions

import xarray as xr
from nwpeval import NWP_Stats

# 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 metrics along specific dimensions
metrics = ['MAE', 'RMSE', 'ACC']
dimensions = ['lat', 'lon']
results = nwp_stats.compute_metrics(metrics, dim=dimensions)

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

Example 4: Computing probabilistic metrics with custom thresholds

import xarray as xr
from nwpeval import NWP_Stats

# 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)

# Define custom thresholds for probabilistic metrics
thresholds = {
    'SEDS': 0.6,
    'SEDI': 0.7,
    'RPSS': 0.8
}

# Compute probabilistic metrics with custom thresholds
metrics = ['SEDS', 'SEDI', 'RPSS']
results = nwp_stats.compute_metrics(metrics, thresholds=thresholds)

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

Example 5: Computing weighted metrics

import xarray as xr
from nwpeval import NWP_Stats

# 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)

# Define weights for weighted metrics
weights = xr.DataArray(...)

# Compute weighted metrics
metrics = ['WMAE']
thresholds = {'WMAE_weights': weights}
results = nwp_stats.compute_metrics(metrics, thresholds=thresholds)

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

Example 6: Computing distribution comparison metrics

import xarray as xr
from nwpeval import NWP_Stats

# 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 distribution comparison metrics
metrics = ['MKLDIV', 'JSDIV', 'Hellinger', 'Wasserstein']
results = nwp_stats.compute_metrics(metrics)

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

Example 7: Computing reference-based metrics

import xarray as xr
from nwpeval import NWP_Stats

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

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

# Define thresholds for reference-based metrics
thresholds = {
    'ASS_reference_error': reference_data,
    'RSS_reference_skill': 0.6,
    'QSS_reference_forecast': reference_data
}

# Compute reference-based metrics
metrics = ['ASS', 'RSS', 'QSS']
results = nwp_stats.compute_metrics(metrics, thresholds=thresholds)

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

Example 8: Computing metrics with custom parameters

import xarray as xr
from nwpeval import NWP_Stats

# 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)

# Define custom parameters for metrics
thresholds = {
    'LehmerMean_p': 3,
    'Chernoff_alpha': 0.7,
    'Renyi_alpha': 0.8,
    'Tsallis_alpha': 0.9
}

# Compute metrics with custom parameters
metrics = ['LehmerMean', 'Chernoff', 'Renyi', 'Tsallis']
results = nwp_stats.compute_metrics(metrics, thresholds=thresholds)

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

These examples demonstrate the versatility of the package in handling different requirements and scenarios. They showcase the computation of probabilistic metrics with custom thresholds, weighted metrics, distribution comparison metrics, reference-based metrics, and metrics with custom parameters.

By providing a wide range of metrics and the flexibility to customize their computation, the package enables users to perform comprehensive evaluations of NWP models based on their specific needs and requirements.

Help

The help() function provides a convenient way to explore the available methods in the NWP_Stats class and view their descriptions and usage instructions.

Example usage:

from nwpeval import NWP_Stats

# Display help for a specific method
help(NWP_Stats.compute_fss)

# Display help for all available methods
help(NWP_Stats)

For more detailed usage instructions and Documentation and examples, please refer to the Examples directory.

NEXT UPDATE

Instability (Thunderstorm) indices,

  • Total Totals Index (TT)
  • Delta-T Index (DTI)
  • K Index (KI)
  • Lifted Index (LI)
  • Showalter Index (SI)
  • Deep Convective Index (DCI)
  • Severe Weather Threat Index (SWEAT)
  • Convective Available Potential Energy (CAPE) and More !!!

Contributing

Contributions to NWPeval are welcome! If you encounter any issues, have suggestions for improvements, or would like to contribute new features, please open an issue or submit a pull request on the GitHub repository.

License

NWPeval is licensed under the MIT License.

Acknowledgments

I would like to express my gratitude to the developers and contributors of the libraries and tools used in building NWPeval, including NumPy, xarray, and SciPy.

Contact

For any questions, feedback, or inquiries, please contact the maintainer:

I hope you find NWPeval useful in evaluating and analyzing 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.5.0b2.tar.gz (14.6 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.5.0b2-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file nwpeval-1.5.0b2.tar.gz.

File metadata

  • Download URL: nwpeval-1.5.0b2.tar.gz
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.19

File hashes

Hashes for nwpeval-1.5.0b2.tar.gz
Algorithm Hash digest
SHA256 cb28048e9b26279849d54fb8495beca20bf2f81dba25cb86ea6a62489a6f77d1
MD5 deba0eda8bbab5dca5e14408c5fa51d9
BLAKE2b-256 e96fb7c8ff94efda40969081b20d77b542439eada6d6377b73cbbe1ff7448b1c

See more details on using hashes here.

File details

Details for the file nwpeval-1.5.0b2-py3-none-any.whl.

File metadata

  • Download URL: nwpeval-1.5.0b2-py3-none-any.whl
  • Upload date:
  • Size: 12.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.19

File hashes

Hashes for nwpeval-1.5.0b2-py3-none-any.whl
Algorithm Hash digest
SHA256 a312f68e21e2ec665d9bf7e60990803610854a7d65f1fd9c1ce14368e620ff0e
MD5 5f75422ea48afaadda350d225b6c5f0c
BLAKE2b-256 39ec3c0cb3bc26d79cbe96e585aaa94cae95c4157805a6e8cf3e43f5daf07b1e

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