peterkuma / ccplot

Command-line application for visualizing data from CloudSat and CALIPSO satellites
http://ccplot.org
Other
35 stars 7 forks source link

colormap problems #7

Closed hmjbarbosa closed 3 years ago

hmjbarbosa commented 3 years ago

Hi,

I'm new to ccplot, which I just installed. Apparently the installation worked ok, but when I try to run the example from the webpage, I get a bunch of errors related to the colormaps and the plot doesn't look good.

I'm running on a macOS Sierra using Anaconda. I've created an environment where I installed the necessary python packages. These are the versions: python (3.6.12), numpy (1.19.5), matplotlib (3.3.3), basemap (1.2.2), cython (0.29.22), hdf4 (4.2.13), and hdfeos2 (2.20).

This is the command, and I've downloaded the HDF from the ccplot webpage: $ ccplot -o calipso532.png -c calipso-backscatter.cmap -a 30 -x 4:16:20..4:21:50 -y 0..30000 calipso532 CAL_LID_L1-ValStage1-V3-01.2007-06-12T03-42-18ZN.hdf

And this is the output

/Users/hbarbosa/miniconda2/envs/geo/bin/ccplot:2243: MatplotlibDeprecationWarning: You are modifying the state of a globally registered colormap. In future versions, you will not be able to modify a registered colormap in-place. To remove this warning, you can make a copy of the colormap first. cmap = copy.copy(mpl.cm.get_cmap("Greys"))
  colormap.set_bad("k", 0.0)
Traceback (most recent call last):
  File "/Users/hbarbosa/miniconda2/envs/geo/bin/ccplot", line 2333, in <module>
    main(sys.argv)
  File "/Users/hbarbosa/miniconda2/envs/geo/bin/ccplot", line 2247, in main
    (colormap, norm, ticks) = loadcolormap(opts.cmapfname, "colormap")
  File "/Users/hbarbosa/miniconda2/envs/geo/bin/ccplot", line 1043, in loadcolormap
    norm = mpl.colors.BoundaryNorm(bounds, colormap.N)
  File "/Users/hbarbosa/miniconda2/envs/geo/lib/python3.6/site-packages/matplotlib/colors.py", line 1486, in __init__
    raise ValueError(f"There are {self._N} color bins including "
ValueError: There are 33 color bins including extensions, but ncolors = 31; ncolors must equal or exceed the number of bins

The first problem is related to a recent change in matplotlib reported here. It can be fixed by doing this:

    # Determine colormap, norm and ticks.
    #delete colormap = mpl.cm.Greys 
    import copy #included
    colormap = copy.copy(mpl.cm.Greys) #included
    colormap.set_bad("k", 0.0)

The second issue happens because of the different number of bins versus number of colors. The issue happens with all colormaps, here:

    if len(bounds) == 0:
        norm = None
    else:
        norm = mpl.colors.BoundaryNorm(bounds, colormap.N)
    if len(ticks) == 0: ticks = None
    return (colormap, norm, ticks)

The problem seems to be that ccplot register the LOW and HIGH colors using set_under() and set_over(), which doesn't add to the total number of available colors (i.e. colormap.N is 31). Hence the number of bins (as defined in the colormap text file) is 33, which is more than the number of colors. ccplot exits without creating the PNG file.

It does work if I manually edit the colormap text file and copy the LOW and HIGH values from the UNDER_OVER_BAD_COLORS section into the COLORS sections (at begin and end respectively). However, I get a new warning that says: /Users/hbarbosa/miniconda2/envs/geo/bin/ccplot:1641: MatplotlibDeprecationWarning: The 'norm' parameter to Colorbar has no effect because it is overridden by the mappable; it is deprecated since 3.3 and will be removed two minor releases later.

Which comes from here:

    # Colorbar.
    cbaxes = fit_colorbar(fig, axes, space=opts.cbspacing, padding=opts.padding)
    cb = fig.colorbar(im, ax=axes, cax=cbaxes, orientation="vertical",
                      extend="both", ticks=ticks, norm=norm,
                      format=SciFormatter())

I don't know how to fix this last one, but it seems harmless.

I hope this is helpful and that a real fix could be provided by the developers in the next release. ccplot is a fantastic tool!

bejucoo commented 3 years ago

Same here. I had to downgrade matplotlib to 3.2 to make ccplot work.

peterkuma commented 3 years ago

@hmjbarbosa Thank you for reporting the issue and investigating the cause. It is fixed by 8211802, 353d4f3 and a1cf806.

peterkuma commented 3 years ago

These issues should now be fixed in ccplot 1.5.5 (not available for Windows yet).

onyxcollc commented 3 years ago

any hint on when it's available? @peterkuma

peterkuma commented 3 years ago

It is available already, but as an installation on the Windows Subsystem for Linux (WSL), described on the Getting Started page. It is probably less ideal than the native installation available before 1.5.2, but it is much easier to maintain. If there is enough demand, I can try to compile ccplot natively on Windows again, which is something have done previously for 32-bit Python 2.4 (now obsolete).

peterkuma commented 3 years ago

Just an update here on the Windows distribution of ccplot - it is now once again available to run natively on Windows with Anaconda Python 3.8. See section "Windows (native)" at https://ccplot.org/download/.