TL;DR
SWXAI is a new open-source Python library that unifies explainable AI (XAI) workflows for the diverse data types used in space weather forecasting, including solar images, multivariate time series, and tabular event logs. By providing a consistent interface across different machine learning backends like PyTorch and scikit-learn, it reduces the coding effort for generating explanations by up to 90%, making scientific ML models in heliophysics more transparent and reproducible.
What Problem Does This Paper Address?
Predicting space weather—phenomena like solar flares and coronal mass ejections—is critical for protecting satellite operations and power grids. Researchers increasingly use machine learning (ML) to process heterogeneous data: 2D magnetograms (images), temporal magnetic field readings (time series), and structured event catalogs (tabular data).
However, the tools used to explain why these models make certain predictions are fragmented. A researcher might use Captum for image models, SHAP for tabular data, and custom scripts for time series. This lack of a unified framework creates significant engineering overhead, makes it difficult to compare results across different data modalities, and hinders the reproducibility of scientific findings.
Methods
The authors introduce SWXAI, a framework designed to bridge these gaps through a modular architecture:
- Unified API: A single
SpaceWeatherExplainerobject handles requests regardless of the data type or model backend. - Multimodal Support: It integrates popular XAI methods for three main data types:
- Image: Gradient-based methods like Grad-CAM, Integrated Gradients, and Saliency.
- Time-Series: Both gradient-based and model-agnostic occlusion methods, plus specialized feature extractors (e.g., MiniRocket, TSFresh).
- Tabular: Standard local and global explainers like SHAP, LIME, and Ceteris Paribus profiles.
- Backend Agnosticism: The library acts as a wrapper for PyTorch, scikit-learn, and the
aeontime-series toolkit, normalizing inputs and outputs so researchers can swap models without rewriting their entire pipeline. - Standardized Persistence: Every explanation is returned as a consistent dataclass containing raw attribution values, metadata, and generated figures, facilitating long-term storage and comparison.
Datasets
The library comes bundled with three representative heliophysics datasets to demonstrate its capabilities:
- HMI Active-Region Patches: 2,000 line-of-sight magnetogram patches for image-based flare prediction.
- SWAN-SF Subset: 300 multivariate time-series windows of magnetic field parameters.
- Geomagnetic Storms: 132 event-level records from the NASA CDAW catalog, spanning 1996–2025.
Key Insights and Ideas
- Reducing "Glue Code": The primary value of SWXAI isn't a new algorithm, but the "plumbing" that connects disparate tools. By handling validation and adapters internally, it allows scientists to focus on physics rather than software engineering.
- Domain-Specific Visualizations: Unlike general-purpose XAI libraries, SWXAI includes visualization templates tailored for heliophysics, such as temporal importance scores that highlight exactly when a solar region became "flaring-active."
- Reproducibility by Design: By forcing a standard output schema (the
Explanationobject), the library ensures that an explanation generated today can be easily reloaded and compared to a new model's output months later.
Key Results
- Efficiency: In benchmarks, SWXAI reduced the number of user-authored code statements required to generate an explanation by 83% to 91% compared to direct backend implementations.
- Performance: The abstraction layer introduces negligible overhead, with runtime differences remaining below two milliseconds in all tested workflows.
- Fidelity: Attributions generated by SWXAI match direct backend implementations exactly, ensuring that the simplified interface does not sacrifice numerical accuracy.
For example, Figure 4 illustrates how the library can pinpoint specific time intervals and magnetic features (like TOTUSJH) that drive a flare prediction model.
Limitations and Future Work
The authors acknowledge that the current release prioritizes system integration and common modalities over cutting-edge algorithms. Future iterations aim to include:
- Advanced XAI Methods: Incorporating uncertainty-aware and physics-guided counterfactual explanations.
- Broader Architectures: Supporting newer multimodal transformer architectures.
- Expert Validation: Working with heliophysics domain experts to validate whether the "important" regions identified by the AI align with known physical processes.
Summary updated