Repository: sunpy/sunpy

Issue:
LASCO C3 Maps from JP2 sources are badly stretched
See attached: probably need to fix the stretching.

![figure_1](https://user-images.githubusercontent.com/983575/44162559-b65abc00-a08e-11e8-8f6d-0ae9ebb026dd.png)



Discussion:
This is where LASCO C3 gets the square root scaling - https://github.com/sunpy/sunpy/commit/55610e9cad745033a19b41c1ecf26e472df9da3b#diff-62c564e29c6769deb57b644d7414de74
we have already fixed this for other map sources like AIA right?
Yes we have.  For AIA sources, the image stretching is replaced by the LinearStretch.  The linear stretching replacement is working.  When you just plot the data using imshow you get a perfectly reasonable looking plot.  I think in this case the colormap should be changed, say to the matplotlib bone color table - see attached.
![figure_1](https://user-images.githubusercontent.com/983575/44205970-2ff1b900-a126-11e8-931d-95ed37073eae.png)
 
frankly that looks much better than the original cm imo
i agree. the standard colortables are not great for LASCO or COR1,2.

On Thu, Aug 16, 2018, 07:32 Stuart Mumford <notifications@github.com> wrote:

> frankly that looks much better than the original cm imo
>
> —
> You are receiving this because you were assigned.
> Reply to this email directly, view it on GitHub
> <https://github.com/sunpy/sunpy/issues/2724#issuecomment-413515126>, or mute
> the thread
> <https://github.com/notifications/unsubscribe-auth/AA8CF90HuqtITnHTPOOKiWmCzcfp6uRwks5uRVhqgaJpZM4V-fga>
> .
>


Resolving patch:
diff --git a/sunpy/cm/cm.py b/sunpy/cm/cm.py
--- a/sunpy/cm/cm.py
+++ b/sunpy/cm/cm.py
@@ -3,9 +3,11 @@
 """
 from __future__ import absolute_import, division, print_function
 
+from copy import deepcopy
+
 import numpy as np
 import matplotlib.pyplot as plt
-import matplotlib.cm as cm
+import matplotlib.cm as mplcm
 
 from sunpy.cm import color_tables as ct
 from sunpy.util import deprecated
@@ -28,8 +30,18 @@
 sohoeit284 = ct.eit_color_table(284)
 sohoeit304 = ct.eit_color_table(304)
 
-soholasco2 = ct.lasco_color_table(2)
-soholasco3 = ct.lasco_color_table(3)
+# The color tables below returns one of the fundamental color tables for SOHO
+# LASCO images. These are not the same as those used in SSWIDL.  This is
+# because the SSWIDL color scaling for LASCO level 0.5 and 1.0 is highly
+# compressed and does not display the data well.
+soholasco2 = deepcopy(mplcm.get_cmap("gist_heat"))
+soholasco2.name = 'SOHO LASCO C2'
+soholasco3 = deepcopy(mplcm.get_cmap("bone"))
+soholasco3.name = 'SOHO LASCO C3'
+
+# These are the SSWIDL color tables.
+sswidlsoholasco2 = ct.sswidl_lasco_color_table(2)
+sswidlsoholasco3 = ct.sswidl_lasco_color_table(3)
 
 stereocor1 = ct.cor_color_table(1)
 stereocor2 = ct.cor_color_table(2)
@@ -71,11 +83,13 @@
           'sohoeit304': sohoeit304,
           'soholasco2': soholasco2,
           'soholasco3': soholasco3,
+          'sswidlsoholasco2': sswidlsoholasco2,
+          'sswidlsoholasco3': sswidlsoholasco3,
           'stereocor1': stereocor1,
           'stereocor2': stereocor2,
           'stereohi1': stereohi1,
           'stereohi2': stereohi2,
-          'rhessi': cm.jet,
+          'rhessi': mplcm.jet,
           'yohkohsxtal': yohkohsxtal,
           'yohkohsxtwh': yohkohsxtwh,
           'hinodexrt': hinodexrt,
@@ -102,7 +116,8 @@
 
 # Register the colormaps with matplotlib so plt.get_cmap('sdoaia171') works
 for name, cmap in cmlist.items():
-    cm.register_cmap(name=name, cmap=cmap)
+    mplcm.register_cmap(name=name, cmap=cmap)
+
 
 @deprecated("0.9", "Use Matplotlib to load the colormaps", alternative='plt.get_cmap')
 def get_cmap(name):
@@ -137,14 +152,14 @@ def get_cmap(name):
         raise ValueError("Colormap {name!s} is not recognized".format(name=name))
 
 
-def show_colormaps(filter=None):
+def show_colormaps(search=None):
     """Displays a plot of the custom color maps supported in SunPy.
 
     Parameters
     ----------
-    filter : str
-        A string to filter the color maps presented (e.g. aia, EIT, 171). Case
-        insensitive.
+    search : str
+        A string to search for in the names of the color maps (e.g. aia, EIT,
+        171). Case insensitive.
 
     Returns
     -------
@@ -154,18 +169,18 @@ def show_colormaps(filter=None):
     --------
     >>> import sunpy.cm as cm
     >>> cm.show_colormaps()
-    >>> cm.show_colormaps(filter='aia')
-    >>> cm.show_colormaps(filter='171')
+    >>> cm.show_colormaps(search='aia')
+    >>> cm.show_colormaps(search='171')
 
     References
     ----------
 
     """
 
-    if filter:
-        maps =  sorted({k:v for (k,v) in cmlist.items() if k.lower().count(filter.lower())})
+    if search is not None:
+        maps = sorted({k: v for (k, v) in cmlist.items() if k.lower().count(search.lower())})
         if len(maps) == 0:
-            raise KeyError('No color maps found for key - ' + filter)
+            raise KeyError('No color maps found for search term "{:s}"'.format(search))
     else:
         maps = sorted(cmlist)
 
diff --git a/sunpy/cm/color_tables.py b/sunpy/cm/color_tables.py
--- a/sunpy/cm/color_tables.py
+++ b/sunpy/cm/color_tables.py
@@ -8,7 +8,7 @@
 import matplotlib.colors as colors
 from sunpy.extern.six.moves import range, zip
 
-__all__ = ['aia_color_table', 'lasco_color_table', 'eit_color_table',
+__all__ = ['aia_color_table', 'sswidl_lasco_color_table', 'eit_color_table',
            'sxt_color_table', 'xrt_color_table', 'trace_color_table',
            'sot_color_table', 'hmi_mag_color_table']
 
@@ -68,6 +68,7 @@ def paden(lst, len_, pad=0):
                  335: (c2, c0, c1)
                  }
 
+
 def aia_color_table(wavelength):
     """Returns one of the fundamental color tables for SDO AIA images.
        Based on aia_lct.pro part of SDO/AIA on SSWIDL written by
@@ -277,6 +278,7 @@ def eit_color_table(wavelength):
 
     return colors.LinearSegmentedColormap('SOHO EIT {:s}'.format(str(wavelength)), cdict)
 
+
 lasco_c2_r = np.concatenate((np.array(
       [   0.,    1.,    2.,    5.,    8.,   11.,   14.,   17.,   20.,
          23.,   26.,   28.,   31.,   34.,   37.,   42.,   44.,   47.,
@@ -329,8 +331,12 @@ def eit_color_table(wavelength):
         244.,  248.,  250.]), 255 * np.ones(181)))
 
 
-def lasco_color_table(number):
-    """Returns one of the fundamental color tables for SOHO LASCO images."""
+def sswidl_lasco_color_table(number):
+    """Returns one of the SSWIDL-defined color tables for SOHO LASCO images.
+    This function is included to allow users to access the SSWIDL-defined
+    LASCO color tables provided by SunPy. It is recommended to use the function
+    'lasco_color_table' to obtain color tables for use with LASCO data
+    and Helioviewer JP2 images."""
     # SOHO LASCO Color tables
     # LASCO C2 white light IDL Name
     # LASCO C3 white light IDL Name
@@ -341,8 +347,7 @@ def lasco_color_table(number):
         }[number]
     except KeyError:
         raise ValueError(
-            "Invalid LASCO number. Valid values are "
-            "2, 3."
+            "Invalid LASCO number. Valid values are 2, 3."
         )
 
     # Now create the color dictionary in the correct format
@@ -1005,6 +1010,7 @@ def cor_color_table(number):
        117, 117, 117, 118, 118, 118, 119, 119, 119, 119, 120, 120, 120,
        121, 121, 121, 121, 122, 122, 122, 123, 123])
 
+
 def trace_color_table(measurement):
     """Returns one of the standard color tables for TRACE JP2 files."""
     # TRACE color tables
@@ -1031,6 +1037,7 @@ def trace_color_table(measurement):
     # Return the color table
     return colors.LinearSegmentedColormap('TRACE {:s}'.format(measurement), cdict)
 
+
 def sot_color_table(measurement):
     """Returns one of the standard color tables for SOT files (following osdc convention).
     The relations between observation and color have been defined in hinode.py"""
@@ -1047,6 +1054,7 @@ def sot_color_table(measurement):
     cdict = create_cdict(r, g, b)
     return colors.LinearSegmentedColormap('Hinode SOT {:s}'.format(measurement), cdict)
 
+
 def iris_sji_color_table(measurement, aialike=False):
     """Return the standard color table for IRIS SJI files"""
     # base vectors for IRIS SJI color tables
@@ -1172,6 +1180,7 @@ def iris_sji_color_table(measurement, aialike=False):
        188, 186, 182, 179, 175, 172, 168, 165, 161, 158, 154, 149, 147,
        142, 140, 135, 133, 121, 109,  96,  84,  73])
 
+
 def hmi_mag_color_table():
     """
     Returns an alternate HMI Magnetogram color table; from Stanford
@@ -1352,6 +1361,7 @@ def stereo_hi_color_table(camera):
     else:
         raise ValueError("Valid HI cameras are 1 and 2")
 
+
 def create_cdict(r, g, b):
     """Create the color tuples in the correct format."""
     i = np.linspace(0, 1, r0.size)


Test patch: