File: mask_disk.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 (47 lines) | stat: -rw-r--r-- 1,648 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
"""
==========================
Masking out the solar disk
==========================

How to mask out all emission from the solar disk.
"""
import matplotlib.pyplot as plt

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

###############################################################################
# We start with the sample data.

aia = sunpy.map.Map(AIA_171_IMAGE)

###############################################################################
# A utility function gives us access to the helioprojective coordinate of each
# pixels. We can use that to create a new array of all the coordinates
# that are on the solar disk.

hpc_coords = all_coordinates_from_map(aia)

###############################################################################
# Now, we can create a mask from the coordinates by using another utility
# function that gives us a mask that has `True` for those coordinates that are
# on the solar disk. We also make a slight change to the colormap so that
# masked values are shown as black instead of the default white.

mask = coordinate_is_on_solar_disk(hpc_coords)
palette = aia.cmap.copy()
palette.set_bad('black')

###############################################################################
# Finally we create a new map with our new mask.

scaled_map = sunpy.map.Map(aia.data, aia.meta, mask=mask)

###############################################################################
# Let's plot the results using our modified colormap.

plt.figure()
scaled_map.plot(cmap=palette)
scaled_map.draw_limb()
plt.show()