Histograming map data#

How to inspect the histogram of the data of a map.

import matplotlib.pyplot as plt
import numpy as np

import astropy.units as u
from astropy.coordinates import SkyCoord

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

We start with the sample data and create a cutout.

AIA $171 \; \mathrm{\mathring{A}}$ 2011-06-07 06:33:02
<matplotlib.image.AxesImage object at 0x70968f4fd1d0>

The image of a GenericMap is always available in the data attribute. Map also provides shortcuts to the image minimum and maximum values. Let’s create a histogram of the data in this submap.

Let’s plot the histogram as well as some standard values such as mean upper, and lower value and the one-sigma range.

fig, ax = plt.subplots()
# Note that we have to use ``.ravel()`` here to avoid matplotlib interpreting each
# row in the array as a different dataset to histogram.
ax.hist(aia_smap.data.ravel(), bins=bins, label='Histogram', histtype='step')
ax.set_xlabel('Intensity')
ax.axvline(aia_smap.min(), label=f'Data min={aia_smap.min():.2f}', color='black')
ax.axvline(aia_smap.max(), label=f'Data max={aia_smap.max():.2f}', color='black')
ax.axvline(aia_smap.data.mean(),
           label=f'mean={aia_smap.data.mean():.2f}', color='green')
one_sigma = np.array([aia_smap.data.mean() - aia_smap.data.std(),
                      aia_smap.data.mean() + aia_smap.data.std()])
ax.axvspan(one_sigma[0], one_sigma[1], alpha=0.3, color='green',
           label=f'mean +/- std = [{one_sigma[0]:.2f}, {one_sigma[1]:.2f}]')
ax.axvline(one_sigma[0], color='green')
ax.axvline(one_sigma[1], color='red')
ax.set_yscale('log')
ax.legend(loc=9)
map data histogram
<matplotlib.legend.Legend object at 0x7096ac8dd6d0>

Finally let’s overplot the one-sigma contours.

AIA $171 \; \mathrm{\mathring{A}}$ 2011-06-07 06:33:02

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

🏷 Tags: Map, AIA, Coordinates

Gallery generated by Sphinx-Gallery