The brightest pixel location

How to find and overplot the location of the brightest pixel

from __future__ import print_function, division

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

import astropy.units as u

import sunpy.map
from sunpy.data.sample import AIA_171_IMAGE

We first create the Map using the sample data and import the coordinate functionality.

aia = sunpy.map.Map(AIA_171_IMAGE)

Now we create a new custom aia with our new mask and plot the result using our modified colormap

max_indices = np.unravel_index(aia.data.argmax(), aia.data.shape) * u.pixel
hpc_max = aia.pixel_to_data(max_indices[1], max_indices[0])
r = np.sqrt(hpc_max.Tx ** 2 + hpc_max.Ty ** 2) / aia.rsun_obs
mask = ma.masked_greater_equal(r, 1)
scaled_map = sunpy.map.Map(aia.data, aia.meta, mask=mask.mask)

Let’s now plot the results. We’ll overlay the autogenerated SunPy lon/lat grid as well for comparison.

fig = plt.figure()
ax = plt.subplot(projection=aia)

aia.plot()
ax.plot_coord(hpc_max, color='white', marker='x', markersize=10)

plt.show()
../../_images/sphx_glr_masking_hot_pixels_001.png

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

Generated by Sphinx-Gallery