Plotting a difference image¶
How to compute and plot a difference image.
The example uses
sunpy.map.MapSequence to compute a difference image and then plot it.
This basic method works for base difference or running difference. Just change whether
you’re subtracting the previous image or the first image in a sequence.
import matplotlib.colors as colors import matplotlib.pyplot as plt import astropy.units as u import sunpy.data.sample import sunpy.map
First load a couple of images taken from the sample dataset. These are two cutouts taken during a flare.
Now we’ll do a standard plot of the second image just to see it.
<matplotlib.image.AxesImage object at 0x7f22750389d0>
And now we can do take the actual difference.
diff = maps.data - maps.data
But we have to decide what to do with the metadata. For example, what time does this difference image correspond to? The time of the first or second image? The mean time? You’ll have to decide what makes most sense for your application. Here we’ll just use the metadata from the second image. Then we can store the difference and header back in a Map.
meta = maps.meta diff_map = sunpy.map.Map(diff, meta)
Finally, we’ll plot it. We’ll apply a colormap and re-normalize the intensity so that it shows up well.
Total running time of the script: ( 0 minutes 0.964 seconds)