Repository: sunpy/sunpy

Issue:
Update Stereo Examples to have better plots
See https://github.com/sunpy/sunpy/pull/5529#pullrequestreview-758873316

We should fix these.


Discussion:

Resolving patch:
diff --git a/examples/units_and_coordinates/AIA_limb_STEREO.py b/examples/units_and_coordinates/AIA_limb_STEREO.py
--- a/examples/units_and_coordinates/AIA_limb_STEREO.py
+++ b/examples/units_and_coordinates/AIA_limb_STEREO.py
@@ -23,11 +23,11 @@
 
 stereo = (a.Source('STEREO_A') &
           a.Instrument("EUVI") &
-          a.Time('2021-01-01', '2021-01-01T00:10:00'))
+          a.Time('2021-01-01 00:06', '2021-01-01 00:07'))
 
 aia = (a.Instrument.aia &
        a.Sample(24 * u.hour) &
-       a.Time('2021-01-01', '2021-01-02'))
+       a.Time('2021-01-01 00:06', '2021-01-02 00:06'))
 
 wave = a.Wavelength(30 * u.nm, 31 * u.nm)
 result = Fido.search(wave, aia | stereo)
@@ -45,6 +45,7 @@
 maps = {m.detector: m.submap(SkyCoord([-1100, 1100], [-1100, 1100],
                                       unit=u.arcsec, frame=m.coordinate_frame))
         for m in sunpy.map.Map(downloaded_files)}
+maps['AIA'].plot_settings['vmin'] = 0  # set the minimum plotted pixel value
 
 ##############################################################################
 # Now, let's plot both maps, and we draw the limb as seen by AIA onto the
@@ -62,22 +63,28 @@
 hidden.remove()
 
 ##############################################################################
-# Let's also plot the helioprojective coordinate grid as seen by SDO on the
-# STEREO image.
+# Let's plot the helioprojective coordinate grid as seen by SDO on the STEREO
+# image in a cropped view.  Note that only those grid lines that intersect the
+# edge of the plot will have corresponding ticks and tick labels.
 
 fig = plt.figure()
 ax = plt.subplot(projection=maps['EUVI'])
 
 maps['EUVI'].plot()
 
-# Move the title so it does not clash with the extra labels.
-tx, ty = ax.title.get_position()
-ax.title.set_position([tx, ty + 0.08])
+# Crop the view
+ax.set_xlim(500, 1300)
+ax.set_ylim(100, 900)
 
-# Change the default grid labels.
+# Shrink the plot slightly and move the title up to make room for new labels.
+ax.set_position([0.1, 0.1, 0.8, 0.7])
+ax.set_title(ax.get_title(), pad=45)
+
+# Change the default grid labels and line properties.
 stereo_x, stereo_y = ax.coords
 stereo_x.set_axislabel("Helioprojective Longitude (STEREO B) [arcsec]")
 stereo_y.set_axislabel("Helioprojective Latitude (STEREO B) [arcsec]")
+ax.coords.grid(color='white', linewidth=1)
 
 # Add a new coordinate overlay in the SDO frame.
 overlay = ax.get_coords_overlay(maps['AIA'].coordinate_frame)
@@ -86,13 +93,17 @@
 # Configure the grid:
 x, y = overlay
 
+# Wrap the longitude at 180 deg rather than the default 360.
+x.set_coord_type('longitude', 180.)
+
+# Set the tick spacing
+x.set_ticks(spacing=250*u.arcsec)
+y.set_ticks(spacing=250*u.arcsec)
+
 # Set the ticks to be on the top and left axes.
 x.set_ticks_position('tr')
 y.set_ticks_position('tr')
 
-# Wrap the longitude at 180 deg rather than the default 360.
-x.set_coord_type('longitude', 180.)
-
 # Change the defaults to arcseconds
 x.set_major_formatter('s.s')
 y.set_major_formatter('s.s')
diff --git a/examples/units_and_coordinates/SDO_to_STEREO_Coordinate_Conversion.py b/examples/units_and_coordinates/SDO_to_STEREO_Coordinate_Conversion.py
--- a/examples/units_and_coordinates/SDO_to_STEREO_Coordinate_Conversion.py
+++ b/examples/units_and_coordinates/SDO_to_STEREO_Coordinate_Conversion.py
@@ -6,6 +6,8 @@
 How to convert a point of a source on an AIA image
 to a position on a STEREO image.
 """
+# sphinx_gallery_thumbnail_number = 5
+
 import matplotlib.pyplot as plt
 
 import astropy.units as u
@@ -15,6 +17,7 @@
 import sunpy.map
 from sunpy.net import Fido
 from sunpy.net import attrs as a
+from sunpy.sun import constants
 
 ###############################################################################
 # The first step is to download some data. We download an image from STEREO-A
@@ -22,12 +25,13 @@
 
 stereo = (a.Source('STEREO_A') &
           a.Instrument("EUVI") &
-          a.Time('2021-01-01', '2021-01-01T00:10:00'))
+          a.Time('2021-01-01 00:06', '2021-01-01 00:07'))
 aia = (a.Instrument.aia &
        a.Sample(24 * u.hour) &
-       a.Time('2021-01-01', '2021-01-02'))
+       a.Time('2021-01-01 00:06', '2021-01-02 00:06'))
 wave = a.Wavelength(30 * u.nm, 31 * u.nm)
 res = Fido.search(wave, aia | stereo)
+print(res)
 
 ###############################################################################
 # Download the files.
@@ -42,6 +46,17 @@
                                       [-1100, 1100]*u.arcsec,
                                       frame=m.coordinate_frame))
         for m in sunpy.map.Map(files)}
+maps['AIA'].plot_settings['vmin'] = 0  # set the minimum plotted pixel value
+
+
+###############################################################################
+# We will be transforming coordinates where the formation height of 304 A
+# emission makes a difference, so we set the reference solar radius to 4 Mm
+# above the solar surface (see `Alissandrakis 2019
+# <https://doi.org/10.1007/s11207-019-1552-1>`__).
+
+for m in maps.values():
+    m.meta['rsun_ref'] = (constants.radius + 4*u.Mm).to_value('m')
 
 ###############################################################################
 # Plot both maps.
@@ -64,69 +79,66 @@
 ###############################################################################
 # Plot a rectangle around the region we want to crop.
 
-m = maps['AIA']
 fig = plt.figure()
-ax = fig.add_subplot(111, projection=m)
-m.plot(axes=ax)
-m.draw_quadrangle(aia_bottom_left, top_right=aia_top_right)
-
+ax = fig.add_subplot(111, projection=maps['AIA'])
+maps['AIA'].plot(axes=ax)
+maps['AIA'].draw_quadrangle(aia_bottom_left, top_right=aia_top_right)
 
 ###############################################################################
-# Create a submap of this area.
+# Create a submap of this area and draw an X at a specific feature of interest.
 
 subaia = maps['AIA'].submap(aia_bottom_left, top_right=aia_top_right)
 fig = plt.figure()
+ax = fig.add_subplot(projection=subaia)
 subaia.plot()
 
-###############################################################################
-# We now want to crop out this same area on the STEREO EUVI image. First, we
-# create a `~astropy.coordinates.SkyCoord` object with the four corners of the box. When we create
-# this object, we use `sunpy.map.GenericMap.coordinate_frame` so that the location parameters of
-# SDO are correctly set.
-
-corners = ([aia_bottom_left.Tx, aia_bottom_left.Ty],
-           [aia_top_right.Tx, aia_bottom_left.Ty],
-           [aia_bottom_left.Tx, aia_top_right.Ty],
-           [aia_top_right.Tx, aia_top_right.Ty])
-
-hpc_aia = SkyCoord(corners, frame=maps['AIA'].coordinate_frame)
-print(hpc_aia)
+feature_aia = SkyCoord(-706 * u.arcsec,
+                       -181 * u.arcsec,
+                       frame=maps['AIA'].coordinate_frame)
+ax.plot_coord(feature_aia, 'bx', fillstyle='none', markersize=20)
 
 ###############################################################################
-# We can now transform to from the AIA frame to the EUVI frame.
-# This transformation first transforms to Heliographic Stonyhurst coordinates
-# and then into the EUVI frame.
+# We can transform the coordinate of the feature to see its representation as
+# seen by STEREO EUVI.  The original coordinate did not contain a distance from
+# the observer, so it is converted to a 3D coordinate assuming that it has a
+# radius from Sun center equal to the reference solar radius of the coordinate
+# frame, which we set earlier to be the formation height of 304 A emission.
 
-hpc_B = hpc_aia.transform_to(maps['EUVI'].coordinate_frame)
-print(hpc_B)
+print(feature_aia.transform_to(maps['EUVI'].coordinate_frame))
 
 ###############################################################################
-# Now we can plot this box on both the AIA and EUVI images:
+# Now we can plot this box on both the AIA and EUVI images.  Note that using
+# :meth:`~sunpy.map.GenericMap.draw_quadrangle` means that the plotted
+# rectangle will be automatically warped appropriately to account for the
+# different coordinate frames.
 
 fig = plt.figure(figsize=(10, 4))
-for i, (m, coord) in enumerate(zip([maps['EUVI'], maps['AIA']],
-                                   [hpc_B, hpc_aia])):
-    ax = fig.add_subplot(1, 2, i+1, projection=m)
-    m.plot(axes=ax)
 
-    # coord[3] is the top-right corner coord[0] is the bottom-left corner.
-    m.draw_quadrangle(coord[0], top_right=coord[3],
-                      transform=ax.get_transform('world'))
+ax1 = fig.add_subplot(1, 2, 1, projection=maps['AIA'])
+maps['AIA'].plot(axes=ax1)
+maps['AIA'].draw_quadrangle(aia_bottom_left, top_right=aia_top_right, axes=ax1)
 
-###############################################################################
-# We can now zoom in on the region in the EUVI image:
-
-subeuvi = maps['EUVI'].submap(hpc_B[0], top_right=hpc_B[3])
-fig = plt.figure()
-plt.subplot(projection=subeuvi)
-subeuvi.plot()
+ax2 = fig.add_subplot(1, 2, 2, projection=maps['EUVI'])
+maps['EUVI'].plot(axes=ax2)
+maps['AIA'].draw_quadrangle(aia_bottom_left, top_right=aia_top_right, axes=ax2)
 
 ###############################################################################
-# Putting them together:
+# We can now zoom in on the region in the EUVI image, and we also draw an X
+# at the feature marked earlier.  We do not need to explicitly transform the
+# feature coordinate to the matching coordinate frame; that is performed
+# automatically by :meth:`~astropy.visualization.wcsaxes.WCSAxes.plot_coord`.
 
 fig = plt.figure(figsize=(15, 5))
-for i, m in enumerate((subeuvi, subaia)):
-    ax = fig.add_subplot(1, 2, i+1, projection=m)
-    m.plot(axes=ax)
+
+ax1 = fig.add_subplot(1, 2, 1, projection=subaia)
+subaia.plot(axes=ax1)
+ax1.plot_coord(feature_aia, 'bx', fillstyle='none', markersize=20)
+
+subeuvi = maps['EUVI'].submap(aia_bottom_left, top_right=aia_top_right)
+
+ax2 = fig.add_subplot(1, 2, 2, projection=subeuvi)
+subeuvi.plot(axes=ax2)
+maps['AIA'].draw_quadrangle(aia_bottom_left, top_right=aia_top_right, axes=ax2)
+ax2.plot_coord(feature_aia, 'bx', fillstyle='none', markersize=20)
 
 plt.show()


Test patch: