Finding and masking bright pixels

How to find and overplot the location of the brightest pixel and then mask pixels around that region.

# sphinx_gallery_thumbnail_number = 2

import numpy as np
import as ma
import matplotlib.pyplot as plt

import astropy.units as u

from import AIA_171_IMAGE
from import all_coordinates_from_map

We start with the sample data.

aia =

To find the brightest pixel, we find the maximum in the AIA image data then transform that pixel coordinate to a map coordinate.

pixel_pos = np.argwhere( == * u.pixel
hpc_max = aia.pixel_to_world(pixel_pos[:, 1], pixel_pos[:, 0])

Let’s plot the results.

fig = plt.figure()
ax = plt.subplot(projection=aia)
ax.plot_coord(hpc_max, 'bx', color='white', marker='x', markersize=15)
AIA $171 \; \mathrm{\mathring{A}}$ 2011-06-07 06:33:02

A utility function gives us access to the helioprojective coordinate of each pixels. We create a new array which contains the normalized radial position for each pixel adjusted for the position of the brightest pixel (using hpc_max) and then create a new map.

hpc_coords = all_coordinates_from_map(aia)
r_mask = np.sqrt((hpc_coords.Tx-hpc_max.Tx) ** 2 + (hpc_coords.Ty-hpc_max.Ty) ** 2) / aia.rsun_obs
mask = ma.masked_less_equal(r_mask, 0.1)
scaled_map =, aia.meta, mask=mask.mask)

Let’s plot the results.

fig = plt.figure()
ax = plt.subplot(projection=scaled_map)
AIA $171 \; \mathrm{\mathring{A}}$ 2011-06-07 06:33:02

Total running time of the script: ( 0 minutes 1.463 seconds)

Gallery generated by Sphinx-Gallery