File: brightness_pixel_location.py

package info (click to toggle)
sunpy 2.0.7-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 17,716 kB
  • sloc: python: 36,852; ansic: 1,776; makefile: 19
file content (34 lines) | stat: -rw-r--r-- 1,134 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
"""
===========================
Finding the brightest pixel
===========================

How to find and overplot the location of the brightest pixel
"""
import matplotlib.pyplot as plt
import numpy as np

import astropy.units as u

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

###############################################################################
# We start with the sample data.
aia = sunpy.map.Map(AIA_171_IMAGE)

###############################################################################
# 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(aia.data == aia.data.max()) * u.pixel
hpc_max = aia.pixel_to_world(pixel_pos[:, 1], pixel_pos[:, 0])

###############################################################################
# Let's now plot the results.
fig = plt.figure()
ax = plt.subplot(projection=aia)
aia.plot()
ax.plot_coord(hpc_max, 'wx', fillstyle='none', markersize=15)
# or you could also use
ax.plot(pixel_pos[:, 1], pixel_pos[:, 0], 'ro', fillstyle='none', markersize=15)
plt.show()