Solar Flare Forecasting Code Based on Deep Bayesian Neural Networks and the Concept of Machine Learning Operations
Jiameng Lv ; Peng Jia ; Yiwei Shi ; Song Yu ; Feng Chen ; Yang Guo ; Tie Liu ; Kaifan Ji ; Zhenyu Jin ; Jiaben Lin ; Qi Hao ; Yang Wang ; Shupei Chen
FlareCast is an end-to-end, operational solar flare forecasting system based on deep Bayesian neural networks (BNNs) and machine learning operations (MLOps). It predicts the probability distribution of the maximum X-ray flux over the next 12, 24, and 48 hours using sequences of radial-component vector magnetograms from SDO/HMI. The system has been running continuously since January 1, 2024, and provides real-time forecasts via a public web interface.
This code repository contains the core implementation of the deep learning models, data preprocessing pipelines, model monitoring logic, and visualization tools described in the companion paper: Lv et al. (2026), “FlareCast: A Solar Flare Forecasting System Utilizing Deep Bayesian Neural Networks and the Concept of Machine Learning Operations”, The Astrophysical Journal Supplement Series (in press).
(a) Types and Formats of Uploaded Files
The repository contains the following Python scripts and modules (all in .py format):
Model Architecture & Training Code
Train_model/model/model.py: Defines the hybrid CNN-LSTM-Bayesian Neural Network (BNN) for flare forecasting.
Train_model/model/main.py: Main script to train the model from scratch.
Train_model/model/main_finetuning.py: Script to fine-tune a pre-trained model on new data.
Train_model/model/main_test.py: Evaluates model performance on test data and computes metrics (e.g., precision, recall, MAPE).
Train_model/model/analy_cam.py: Generates Grad-CAM attention maps to visualize which regions of solar magnetograms influence predictions.
Data Preparation
Train_model/datasetMake.py: Processes raw SHARP (Space-weather HMI Active Region Patches) FITS files into structured time-series feature arrays for training.
Real-Time Forecasting & Web Service
Files in Real_Time_Sun_Flares_Predict/: Include scripts to fetch near-real-time (NRT) SHARP data, run predictions, monitor model drift, and serve results via a lightweight Flask web API.
(b) Required Tools and Dependencies
Python 3.9+
Core Libraries:
torch ≥ 2.0 (for BNN with MC Dropout)
sunpy ≥ 5.0 (for GOES flare catalog access)
astropy, fitsio (for FITS I/O)
scikit-learn, numpy, pandas
matplotlib, seaborn, plotly (for visualization)
flask (for optional local web demo)
(c) Purpose and Use Cases of the Code
This codebase implements FlareCast, a machine learning system for probabilistic solar flare forecasting. It allows users to: Train or fine-tune custom BNN models using historical SHARP data (2010–2015 used in the study). Run real-time predictions by automatically downloading and processing NRT SHARP data. Interpret model decisions using attention maps overlaid on line-of-sight magnetograms and polarity inversion lines (PILs).
Target users include space weather forecasters, solar physicists, and ML researchers working on uncertainty-aware time-series prediction.
(d)  Relationship Between Files and the Published Article
Paper Section	Corresponding Code Module
§3. Data Management	Train_model/datasetMake.py
§4.1.1 Feature Extraction Model	Train_model/model/model.py
§4.1.2. Solar Flare Forecasting Model (BNN)	Train_model/model/model.py
§4.2. Grad-CAM Visualization	Train_model/model/analy_cam.py
§4.3. Performance Evaluation	Train_model/model/main_test.py
§5. MLOps & Model Update	Train_model/model/main_finetuning.py+
real-time monitoring scripts
§6. Results Visualization	real-time monitoring scripts
The trained model weights and final dataset used in the paper are archived at the National Astronomical Data Center (NADC) and linked in the Data Availability section of the manuscript.
View real-time forecasts at: https://nadc.china-vo.org/flarecast
Files
.. SolarFlares_Code.rar
34.14 MB
..
Paper Information
Paper Title:
FlareCast: A Solar Flare Forecasting System Utilizing Deep Bayesian Neural Networks and the Concept of Machine Learning Operations
Publication:
The Astrophysical Journal Supplement Series (ApJS)
Identifiers
CSTR:
11379.11.101661
DOI:
10.12149/101661
VO Identifier:
ivo://China-VO/paperdata/101661
Publication Date:
2026-02-06
Usage Statistics
Total Downloads
42
Citations
Jiameng Lv et al. 2026. Solar Flare Forecasting Code Based on Deep Bayesian Neural Networks and the Concept of Machine Learning Operations. Version 1.0. https://doi.org/10.12149/101661
@misc{10.12149/101661,
doi = {10.12149/101661},
url = {https://doi.org/10.12149/101661},
author = {Jiameng Lv},
title = { Solar Flare Forecasting Code Based on Deep Bayesian Neural Networks and the Concept of Machine Learning Operations},
version = {1.0},
publisher = {Nataional Astronomical Data Center of China},
year= {2026}
}
Versions
Version 1.0 (current)
2026-02-06
Main
This DOI represents all versions, and will always resolve to the latest one.
2026-02-06