Repository: sunpy/sunpy

Issue:
Remove some coordinate frames from transformation graph in docs?
Thanks to yours truly, it's now possible to create a custom coordinate transformation graph for documentation as of astropy 3.1: https://github.com/astropy/astropy/pull/7135

It might be nice to remove some of the non-solar physics coordinate systems in the current graph to make it more readable? Current graph is here: http://docs.sunpy.org/en/stable/code_ref/coordinates.html#module-sunpy.coordinates.transformations


Discussion:
Sounds reasonable. We could have the full graph on a separate page and link to it maybe? Bonus points for adding a `other astropy coordinate frames` bubble with a link to the graph!!

Resolving patch:
diff --git a/sunpy/coordinates/__init__.py b/sunpy/coordinates/__init__.py
--- a/sunpy/coordinates/__init__.py
+++ b/sunpy/coordinates/__init__.py
@@ -1,3 +1,22 @@
+"""
+This subpackage contains:
+
+* A robust framework for working with coordinate systems
+* Functions to obtain the locations of solar-system bodies
+* Functions to calculate Sun-specific coordinate information
+  (`sunpy.coordinates.sun`)
+
+The diagram below shows all of Sun-based and Earth-based coordinate systems
+available through `sunpy.coordinates`, as well as the transformations between
+them.  Each frame is labeled with the name of its class and its alias (useful
+for converting other coordinates to them using attribute-style access).
+
+The frames colored in cyan are implemented in `astropy.coordinates`, and there
+are other astronomical frames that can be transformed to that are not shown
+below.  See the documentation for `astropy.coordinates` for more information.
+
+"""
+
 from .frames import *
 from .offset_frame import *
 from . import transformations
@@ -5,3 +24,5 @@
 from . import sun
 
 from .wcs_utils import *
+
+__doc__ += transformations._make_sunpy_graph()
diff --git a/sunpy/coordinates/transformations.py b/sunpy/coordinates/transformations.py
--- a/sunpy/coordinates/transformations.py
+++ b/sunpy/coordinates/transformations.py
@@ -13,10 +13,12 @@
   `~astropy.coordinates.SkyCoord` instances.
 
 """
+from copy import deepcopy
+
 import numpy as np
 
 import astropy.units as u
-from astropy.coordinates import HCRS, ConvertError, BaseCoordinateFrame, get_body_barycentric
+from astropy.coordinates import ICRS, HCRS, ConvertError, BaseCoordinateFrame, get_body_barycentric
 from astropy.coordinates.baseframe import frame_transform_graph
 from astropy.coordinates.representation import (CartesianRepresentation, SphericalRepresentation,
                                                 UnitSphericalRepresentation)
@@ -387,4 +389,113 @@ def hcc_to_hcc(hcccoord, hccframe):
 
     return hcccoord
 
-__doc__ += make_transform_graph_docs()
+
+def _make_sunpy_graph():
+    """
+    Culls down the full transformation graph for SunPy purposes and returns the string version
+    """
+    # Frames to keep in the transformation graph
+    keep_list = ['icrs', 'hcrs', 'heliocentrictrueecliptic', 'heliocentricmeanecliptic',
+                 'heliographic_stonyhurst', 'heliographic_carrington',
+                 'heliocentric', 'helioprojective',
+                 'gcrs', 'precessedgeocentric', 'geocentrictrueecliptic', 'geocentricmeanecliptic',
+                 'cirs', 'altaz', 'itrs']
+
+    global frame_transform_graph
+    backup_graph = deepcopy(frame_transform_graph)
+
+    small_graph = deepcopy(frame_transform_graph)
+    cull_list = [name for name in small_graph.get_names() if name not in keep_list]
+    cull_frames = [small_graph.lookup_name(name) for name in cull_list]
+
+    for frame in cull_frames:
+        # Remove the part of the graph where the unwanted frame is the source frame
+        if frame in small_graph._graph:
+            del small_graph._graph[frame]
+
+        # Remove all instances of the unwanted frame as the destination frame
+        for entry in small_graph._graph:
+            if frame in small_graph._graph[entry]:
+                del (small_graph._graph[entry])[frame]
+
+    # Clean up the node list
+    for name in cull_list:
+        small_graph._cached_names.pop(name)
+
+    _add_astropy_node(small_graph)
+
+    # Overwrite the main transform graph
+    frame_transform_graph = small_graph
+
+    docstr = make_transform_graph_docs()
+
+    # Restore the main transform graph
+    frame_transform_graph = backup_graph
+
+    # Make adjustments to the graph
+    docstr = _tweak_graph(docstr)
+
+    return docstr
+
+
+def _add_astropy_node(graph):
+    """
+    Add an 'Astropy' node that links to an ICRS node in the graph
+    """
+    class Astropy(BaseCoordinateFrame):
+        name = "REPLACE"
+
+    @graph.transform(FunctionTransform, Astropy, ICRS)
+    def fake_transform1():
+        pass
+
+    @graph.transform(FunctionTransform, ICRS, Astropy)
+    def fake_transform2():
+        pass
+
+
+def _tweak_graph(docstr):
+    # Remove Astropy's diagram description
+    output = docstr[docstr.find('.. Wrap the graph'):]
+
+    # Change the Astropy node
+    output = output.replace('Astropy [shape=oval label="Astropy\\n`REPLACE`"]',
+                            'Astropy [shape=box3d style=filled fillcolor=lightcyan '
+                            'label="Other frames\\nin Astropy"]')
+
+    # Change the Astropy<->ICRS links to black
+    output = output.replace('ICRS -> Astropy[  color = "#783001" ]',
+                            'ICRS -> Astropy[  color = "#000000" ]')
+    output = output.replace('Astropy -> ICRS[  color = "#783001" ]',
+                            'Astropy -> ICRS[  color = "#000000" ]')
+
+    # Set the nodes to be filled and cyan by default
+    output = output.replace('AstropyCoordinateTransformGraph {',
+                            'AstropyCoordinateTransformGraph {\n'
+                            '        node [style=filled fillcolor=lightcyan]')
+
+    # Set the nodes for SunPy frames to be white
+    sunpy_frames = ['HeliographicStonyhurst', 'HeliographicCarrington',
+                    'Heliocentric', 'Helioprojective']
+    for frame in sunpy_frames:
+        output = output.replace(frame + ' [', frame + ' [fillcolor=white ')
+
+    output = output.replace('<ul>\n\n',
+                            '<ul>\n\n' +
+                            _add_legend_row('SunPy frames', 'white') +
+                            _add_legend_row('Astropy frames', 'lightcyan'))
+
+    return output
+
+
+def _add_legend_row(label, color):
+    row = '        <li style="list-style: none;">\n'\
+          '            <p style="font-size: 12px;line-height: 24px;font-weight: normal;'\
+          'color: #848484;padding: 0;margin: 0;">\n'\
+          '                <b>' + label + ':</b>\n'\
+          '                    <span class="dot" style="height: 20px;width: 40px;'\
+          'background-color: ' + color + ';border-radius: 50%;border: 1px solid black;'\
+          'display: inline-block;"></span>\n'\
+          '            </p>\n'\
+          '        </li>\n\n\n'
+    return row


Test patch: