A Python tool for tracking sunspots in solar images and analyzing the Sun's differential rotation. Developed as part of a Bachelor's thesis.
This project processes HMI (Helioseismic and Magnetic Imager) continuum images from the Solar Dynamics Observatory (SDO) to:
- Detect sunspots using adaptive thresholding and connected component analysis
- Track sunspot motion across image sequences using OpenCV's MIL tracker
- Convert coordinates from pixel space to heliographic coordinates (latitude/longitude)
- Calculate differential rotation rates and fit to the standard solar rotation model
- Visualize results with interactive displays and PDF output
Interactive sunspot tracking with real-time bounding box overlay
The Sun does not rotate as a rigid body. Instead, it exhibits differential rotation - the equator rotates faster (~25 days) than the poles (~35 days). This rotation profile follows the empirical law:
where
This tool measures differential rotation by tracking sunspot positions over time and fitting the observed velocities to this model.
- Python 3.8 or higher
- OpenCV with GUI support
git clone https://github.com/quooky/solar_tracking.git
cd solar_tracking
pip install -e .Or install dependencies directly:
pip install -r requirements.txtThe package provides a solar-tracking CLI with three main commands:
solar-tracking downloader --start "2023-11-23 00:00:00" --end "2023-11-25 00:00:00" --sample 1Options:
--start: Start time (YYYY-MM-DD HH:MM:SS)--end: End time (YYYY-MM-DD HH:MM:SS)--instrument: Instrument name (default: hmi)--sample: Sampling interval in hours (default: 1)
solar-tracking run_tracking --trace 1Options:
--trace: Trace series number (corresponds to data/TR_0X folder)--no-interactive: Run without user interaction
Interactive Controls:
Space: Pause/resume trackingS: Skip current spotQ: Save results and quitN: Next spot
solar-tracking view_fits path/to/file.fitsfrom solar_tracking.downloader import download_fits
from solar_tracking.tracking import run_tracking
from solar_tracking.sunspot_detection import find_spots_and_bounding_boxes
from solar_tracking.fitting import perform_fitting
# Download data
files = download_fits("2023-11-23 00:00:00", "2023-11-25 00:00:00")
# Run tracking
run_tracking(trace=1, interactive=True)
# Or use individual components
spots, boxes = find_spots_and_bounding_boxes(image, sun_center, sun_radius)solar_tracking/
├── solar_tracking/ # Main package
│ ├── cli.py # Command line interface
│ ├── downloader.py # FITS file downloading via SunPy
│ ├── tracking.py # Main tracking algorithm
│ ├── sunspot_detection.py # Spot detection with OpenCV
│ ├── image_processing.py # FITS preprocessing
│ ├── rotation_analysis.py # Coordinate transformation
│ ├── fitting.py # Differential rotation fitting
│ └── plotting.py # Result visualization
├── tests/ # Test suite
├── data/ # Solar observation data (not in repo)
├── docs/ # Documentation and thesis
└── setup.py
The tracking requires HMI continuum intensity images (hmi_ic_45s). Data is automatically downloaded from the Virtual Solar Observatory using SunPy.
Sample data structure:
data/
├── TR_01/
│ ├── *.fits # HMI FITS files
│ ├── names.txt # File listing
│ └── data_points.csv # Tracking results
The tool outputs:
- CSV files with tracked positions (pixel and heliographic coordinates)
- PDF plots showing the differential rotation curve with fitted parameters
See example rotation plots (PDF) for sample output.
- SunPy - Solar data analysis
- OpenCV - Computer vision and tracking
- Astropy - FITS handling and coordinates
- NumPy - Numerical computing
- Matplotlib - Visualization
- SciPy - Curve fitting
pytest tests/This project was developed as part of a Bachelor's thesis on solar differential rotation analysis.
This project is licensed under the MIT License - see the LICENSE file for details.
Dominic Foerster
- Solar Dynamics Observatory (SDO) for providing HMI data
- SunPy community for the excellent solar physics library