SunPy | Plotting a Solar Image in Python
Last Updated :
22 Oct, 2017
SunPy is a package for solar data analysis using Python. We will be using this package for analysis of solar data
Installation
On the command line type:
pip install sunpy
Downloading Sample Data
The SunPy package contains a number of data files which are solar data of proton/electron fluxes from various solar observatory and solar labs. They are stored under the module sunpy.data.
To download the sample data simply run the following command:
import sunpy.data
sunpy.data.download_sample_data()
In this small project, we will see a very simple way to plot a sample AIA image.
AIA = Atmospheric Imaging Assembly (AIA), is another instrument board the Solar Dynamics Observatory(SDO) designed to study the solar corona, taking simultaneous full disc images in multiple wavelengths of the corona and transitional region (up to half a solar radius above the solar limb), with 1.5 arc sec resolution and 12 second temporal cadence or better.
First we try to explore.
Maps: Maps are the primary data type in SunPy they are spatially and / or temporally aware data arrays. There are types of maps for a 2D image, a time series of 2D images or 1D spectra or 2D spectrograms. Making a map of your data is the normally the first step in using SunPy to work with your data.
Creating a Map
SunPy supports many different data products from various sources ‘out of the box’ we shall use SDO’s AIA instrument as an example in this tutorial. The general way to create a map from one of the supported data products is with the sunpy.Map() command.
sunpy.Map() takes either a filename, list of filenames data array and header. We can test map with:
import sunpy
aia = sunpy.Map(sunpy.AIA_171_IMAGE)
This returns a map named aia.
Plotting a sample solar data file
Let’s begin by creating a simple plot of an AIA image. To make things easy, SunPy includes several example files. These files have names like sunpy.AIA_171_IMAGE and sunpy.RHESSI_IMAGE.
Python
from sunpy.data.sample import AIA_171_IMAGE
import sunpy.map
# We now create the Map using the sample data.
aiamap = sunpy.map.Map(AIA_171_IMAGE)
# Now we do a quick plot.
aiamap.peek()
Output

If everything has been configured properly you should see an AIA image with a red colormap, a colorbar on the right-hand side and a title and some labels.
Solar data plotting is a crucial aspect in order to detect future solar flares and solar storms. Also it is important to note the variation of the proton and electron flux at various intervals of time.
Similar Reads
Reading an image in OpenCV using Python Prerequisite: Basics of OpenCVIn this article, we'll try to open an image by using OpenCV (Open Source Computer Vision) library.  Following types of files are supported in OpenCV library:Windows bitmaps - *.bmp, *.dibJPEG files - *.jpeg, *.jpgPortable Network Graphics - *.png WebP - *.webp Sun raste
6 min read
Plotting polar curves in Python A point in polar coordinates is represented as (r, θ) where r is the distance from the origin and θ is the angle measured from the origin. Any mathematical function in Cartesian coordinate system can be plotted using the polar coordinates. The matplotlib.pyplot module contains a function polar() whi
3 min read
Image Processing with SciPy and NumPy in Python Image processing is used in areas like computer vision and medical imaging, focusing on enhancing and analyzing digital images. In Python, NumPy treats images as arrays for efficient pixel-level operations, while SciPyâs ndimage module provides tools for filtering and transformations, enabling fast
5 min read
Image Processing with SciPy and NumPy in Python Image processing is used in areas like computer vision and medical imaging, focusing on enhancing and analyzing digital images. In Python, NumPy treats images as arrays for efficient pixel-level operations, while SciPyâs ndimage module provides tools for filtering and transformations, enabling fast
5 min read
Working with Images in Python using Matplotlib Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack. Working with Images in Python using Matplotlib The image module in matplotlib library is
3 min read
Working with Images in Python using Matplotlib Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack. Working with Images in Python using Matplotlib The image module in matplotlib library is
3 min read