How to plot a solar image in Python

In this tutorial, we will learn how to plot a solar image using Python.
We can plot the solar image using a sunpy package. by using this package we can analyze the solar data.
Firstly, we need to install the sunpy package using the command line pip install sunpy.

The Sunpy package is a free and open-source solar data analysis for Python.
The following are the most important sub-packages of sunpy.

  1. sunpy.net.
  2. sunpy.map.
  3. sunpy.coordinates.

Code to plot a solar image

#code 1.
This is the Python code to plot solar image

import astropy.units as s
import matplotlib.pyplot as plot

import sunpy.map
from sunpy.data.sample import AIA_171_IMAGE
smap = sunpy.map.Map(AIA_171_IMAGE)
figure = plot.figure(frameon=False)
axes = plot.Axes(figure, [0., 0., 1., 1.])
axes.set_axis_off()
figure.add_axes(axes)

im = smap.plot(axes=axes, annotate=False, clip_interval=(1, 99.99)*s.percent
plot.show()

This code will give an image without any axes.
We get the following image……

sphx_glr_plot_frameless_image_001

You can save the image using plt.savefig().

#code 2:

We will see another code to plot the solar image using Python.

import astropy.units as s
from astropy.coordinates import SkyCoord

import sunpy.map
import sunpy.data.sample
import matplotlib.pyplot as plt

swap_map = sunpy.map.Map(sunpy.data.sample.SWAP_LEVEL1_IMAGE)

top_right = SkyCoord(0 * u.arcsec, -200 * u.arcsec, frame=swap_map.coordinate_frame)
bottom_left = SkyCoord(-900 * u.arcsec, -900 * u.arcsec, frame=swap_map.coordinate_frame)
swap_submap = swap_map.submap(bottom_left, top_right)

fig = plt.figure()
ax = fig.add_subplot(111, projection=swap_submap)
swap_submap.plot()
swap_submap.draw_limb()
swap_submap.draw_grid()
plt.show()

Here, we will get the following image.

sphx_glr_submaps_and_cropping_001

Finally, sunpy also provides physical models of solar behavior, such as rotations and color maps for particular data sources.

Leave a Reply

Your email address will not be published. Required fields are marked *