File: masked_composite_plot.py

package info (click to toggle)
sunpy 7.0.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,592 kB
  • sloc: python: 41,765; ansic: 1,710; makefile: 39
file content (62 lines) | stat: -rw-r--r-- 2,530 bytes parent folder | download | duplicates (3)
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
"""
================================
Combining off-limb and disk maps
================================

This example combines creating a composite plot with masking out the
solar disk. The purpose is to introduce users to the plotting process
required to overlay multiple maps that have been modified with other
``sunpy`` functions. The resulting plot in this tutorial shows information
on the upper photosphere, quiet corona, and magnetogram contours.
"""
import matplotlib.pyplot as plt

import astropy.units as u

import sunpy.data.sample
from sunpy.map import Map
from sunpy.map.maputils import all_coordinates_from_map, coordinate_is_on_solar_disk

###############################################################################
# Let's import sample data representing the three types of data we want to
# overlay: AIA 1600 (upper photosphere), AIA 171 (quiet corona), and HMI
# data (magnetic fields in the photosphere).

aia_1600 = Map(sunpy.data.sample.AIA_1600_IMAGE)
aia_171 = Map(sunpy.data.sample.AIA_171_IMAGE)
hmi = Map(sunpy.data.sample.HMI_LOS_IMAGE)

###############################################################################
# Next, let's mask out the solar disk of the AIA 171 image since we will be
# overlaying the AIA 1600 photosphere.

hpc_coords = all_coordinates_from_map(aia_171)
mask = coordinate_is_on_solar_disk(hpc_coords)
colormap = aia_171.cmap.copy()
colormap.set_bad('black')

scaled_map = Map(aia_171.data, aia_171.meta, mask=mask)

###############################################################################
# Before we plot the composite image, let's define the contour levels that will
# be applied to the HMI image. Also, grab the AIA 171 colormap to use with
# the AIA 1600 image to better match the images.

levels = [-1000, -500, -250, 250, 500, 1000]*u.G
aia171_cmap = plt.get_cmap('sdoaia171')

###############################################################################
# Now, create the plot by overlaying the maps and contours. Note that
# ``clip_interval`` is being defined to highlight the coronal features of the
# scaled AIA 171 map and the AIA 1600 map is autoaligned to the AIA 171 WCS
# Axes.

fig = plt.figure()
ax = fig.add_subplot(projection=scaled_map)
scaled_map.plot(axes=ax, clip_interval=(1, 99.95)*u.percent,
                cmap=colormap, zorder=0)
aia_1600.plot(axes=ax, cmap=aia171_cmap, autoalign=True, zorder=1)
hmi.draw_contours(axes=ax, levels=levels, zorder=2)
ax.set_title("AIA 171 (off limb) + AIA 1600 (on disk) + HMI (contours)")

plt.show()