File: autoalign_aia_hmi.py

package info (click to toggle)
sunpy 4.1.2-1%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 11,972 kB
  • sloc: python: 39,301; ansic: 1,780; makefile: 35
file content (72 lines) | stat: -rw-r--r-- 2,871 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
"""
==============================================
Auto-Aligning AIA and HMI Data During Plotting
==============================================

This example shows how to auto-align two images with different reference frames
during plotting.

Here we use the optional keyword ``autoalign`` when calling Map's
:meth:`~sunpy.map.GenericMap.plot` method.  The reference frames are defined by
the respective World Coordinate System (WCS) information.

See :ref:`sphx_glr_generated_gallery_map_transformations_reprojection_align_aia_hmi.py`
for an alternate approach to image alignment, where one of the maps is modified
prior to plotting, and thus is available for purposes other than plotting.
"""
import matplotlib.pyplot as plt

import astropy.units as u

import sunpy.data.sample
import sunpy.map

######################################################################
# We use the AIA image and HMI image from the sample data.  For the
# HMI map, we use the special HMI color map, which expects the plotted
# range to be -1500 to 1500.

map_aia = sunpy.map.Map(sunpy.data.sample.AIA_171_IMAGE)
map_hmi = sunpy.map.Map(sunpy.data.sample.HMI_LOS_IMAGE)
map_hmi.plot_settings['cmap'] = "hmimag"
map_hmi.plot_settings['norm'] = plt.Normalize(-1500, 1500)

######################################################################
# Plot both images side by side.  Note that the HMI image is oriented
# "upside down" relative to the AIA image.

fig = plt.figure(figsize=(12, 5))
ax1 = fig.add_subplot(121, projection=map_aia)
map_aia.plot(axes=ax1, clip_interval=(1, 99.9)*u.percent)
ax2 = fig.add_subplot(122, projection=map_hmi)
map_hmi.plot(axes=ax2)

######################################################################
# Setting ``autoalign=True`` allows plotting the HMI image onto axes
# defined by the AIA reference frame.  In contrast to the above code
# block, we intentionally set the ``projection`` for the axes to be
# the AIA map # instead of the HMI map.  We also need to manually set
# the plot limits because Matplotlib gets confused by the off-disk
# parts of the image.  Note that the HMI image now has the same
# orientation as the AIA image.

fig = plt.figure(figsize=(12, 5))
ax1 = fig.add_subplot(121, projection=map_aia)
map_aia.plot(axes=ax1, clip_interval=(1, 99.9)*u.percent)
ax2 = fig.add_subplot(122, projection=map_aia)
map_hmi.plot(axes=ax2, autoalign=True, title='HMI image in AIA reference frame')
ax2.axis(ax1.axis())

######################################################################
# We can directly plot them over one another, by setting the
# transparency of the HMI plot.

fig = plt.figure()
ax1 = fig.add_subplot(projection=map_aia)
map_aia.plot(axes=ax1, clip_interval=(1, 99.9)*u.percent)
map_hmi.plot(axes=ax1, autoalign=True, alpha=0.5)
ax1.set_title('HMI overlaid on AIA')

plt.show()

# sphinx_gallery_thumbnail_number = 2