-
-
Notifications
You must be signed in to change notification settings - Fork 591
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Difference image example for the gallery (#3627)
* Difference image example for the gallery * Added changelog file * Updates responding to code review * Pass keywords to plot() instead of using plot_settings * Line break to avoid PEP8 >80 character * Moved sphinx gallery thumbnail command to end to avoid narrative interruption * Include channel and imager in comment Co-Authored-By: Will Barnes <[email protected]> * No need to use plt.get_cmap() Co-Authored-By: Will Barnes <[email protected]> * Space between title and byline Co-Authored-By: Nabil Freij <[email protected]> * line break for multi-argument function call Co-Authored-By: Stuart Mumford <[email protected]> * Update 3627.doc.rst Co-authored-by: Will Barnes <[email protected]> Co-authored-by: Nabil Freij <[email protected]> Co-authored-by: Stuart Mumford <[email protected]>
- Loading branch information
1 parent
b4de731
commit 111369c
Showing
2 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
A new example gallery example "Plotting a difference image" has been added, | ||
which can be used for base difference or running difference images. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
""" | ||
=========================== | ||
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.pyplot as plt | ||
import matplotlib.colors as colors | ||
import astropy.units as u | ||
from sunpy.net import Fido, attrs as a | ||
import sunpy.map | ||
|
||
########################################################################### | ||
# First we'll download a couple images and store them in a | ||
# `sunpy.map.MapSequence`. This could be from any channel of any imager. | ||
# Here, we use SDO/AIA 304 Å. | ||
|
||
instrument = a.Instrument('AIA') | ||
wave = a.Wavelength(30 * u.nm, 31 * u.nm) | ||
result = Fido.search(a.Time('2015-06-18T00:00:00', '2015-06-18T00:00:10') | | ||
a.Time('2015-06-18T01:03:30', '2015-06-18T01:03:35'), | ||
instrument, | ||
wave) | ||
downloaded_files = Fido.fetch(result) | ||
maps = sunpy.map.Map(downloaded_files, sequence=True) | ||
|
||
########################################################################### | ||
# Now we'll do a standard plot of the second image just to see it. | ||
|
||
plt.figure() | ||
ax = plt.subplot(projection=maps[1]) | ||
maps[1].plot() | ||
|
||
########################################################################### | ||
# And now we can do take the actual difference. | ||
|
||
diff = maps[1].data - maps[0].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[1].meta | ||
diff_map = sunpy.map.Map(diff, meta) | ||
|
||
########################################################################### | ||
# Finally, we'll plot it. We'll apply a colormap and renormalize the | ||
# intensity so that it shows up well. | ||
|
||
plt.figure() | ||
ax_diff = plt.subplot(projection=diff_map) | ||
diff_map.plot(cmap='Greys_r', | ||
norm=colors.Normalize(vmin=-50, vmax=50)) | ||
plt.show() | ||
|
||
#sphinx_gallery_thumbnail_number = 2 |