Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: Unknown color None. when trying to use a coloramp #586

Closed
serbinsh opened this issue Jul 16, 2021 · 7 comments
Closed

ValueError: Unknown color None. when trying to use a coloramp #586

serbinsh opened this issue Jul 16, 2021 · 7 comments
Labels
bug Something isn't working

Comments

@serbinsh
Copy link

Environment Information

  • geemap version: 0.8.18
  • Python version: 3
  • Operating System: google collab

Description

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-8-8010224dd26d> in <module>()
      4 vmax = visPara['max']
      5 
----> 6 Map.add_colorbar(visPara, label="Elevation (m a.s.l)", orientation="vertical", layer_name="Arctic DEM")
      7 # Map.add_colorbar_branca(colors=colors, vmin=vmin, vmax=vmax, caption="m a.s.l")

3 frames
/usr/local/lib/python3.7/dist-packages/branca/colormap.py in _parse_color(x)
     43         cname = _cnames.get(x.lower(), None)
     44         if cname is None:
---> 45             raise ValueError('Unknown color {!r}.'.format(cname))
     46         color_tuple = _parse_hex(cname)
     47     else:

ValueError: Unknown color None.

What I Did

For either my geemap code or even this example (https://colab.research.google.com/github/fsn1995/GIS-at-deep-purple/blob/main/02%20gee%20map%20greenland.ipynb#scrollTo=RJdNLlhQjajw) I cant get the colorbars to display (see error above). On the other hand using the same version of geemap etc on my own computer in a Jupyter notebook running in conda it works. It seems to be some issue when I try to run the exact same code in google collab; or that's a red herring and I am doing something else wrong

Here is the code in that example that fails

greenlandmask = ee.Image('OSU/GIMP/2000_ICE_OCEAN_MASK') \
                   .select('ice_mask').eq(1); #'ice_mask', 'ocean_mask'
arcticDEM = ee.Image('UMN/PGC/ArcticDEM/V3/2m_mosaic')

arcticDEMgreenland = arcticDEM.updateMask(greenlandmask)

palette = cm.get_palette('terrain', n_class=10)

visPara = {'min': 0,  'max': 2500.0, 'palette': ['0d13d8', '60e1ff', 'ffffff']}
visPara
# visPara = {'min': 0,  'max': 2500.0, 'palette': palette}
Map.addLayer(arcticDEMgreenland, visPara, 'Arctic DEM')
Map.setCenter(-41.0, 74.0, 3)

#add colorbar
colors = visPara['palette']
vmin = visPara['min']
vmax = visPara['max']

Map.add_colorbar(visPara, label="Elevation (m a.s.l)", orientation="vertical", layer_name="Arctic DEM")
# Map.add_colorbar_branca(colors=colors, vmin=vmin, vmax=vmax, caption="m a.s.l")

or

greenlandmask = ee.Image('OSU/GIMP/2000_ICE_OCEAN_MASK') \
                   .select('ice_mask').eq(1); #'ice_mask', 'ocean_mask'
arcticDEM = ee.Image('UMN/PGC/ArcticDEM/V3/2m_mosaic')

arcticDEMgreenland = arcticDEM.updateMask(greenlandmask)

palette = cm.get_palette('terrain', n_class=10)

# visPara = {'min': 0,  'max': 2500.0, 'palette': ['0d13d8', '60e1ff', 'ffffff']}
visPara = {'min': 0,  'max': 2500.0, 'palette': palette}
Map.addLayer(arcticDEMgreenland, visPara, 'Arctic DEM terrain')
Map.setCenter(-41.0, 74.0, 3)
Map.add_colorbar(visPara, label="Elevation (m)", discrete=False, orientation="vertical", layer_name="Arctic DEM terrain")

or in my code (again works on my computer in Jupyter)

### Get GEE imagery

# DEM
elev_dataset = ee.Image('USGS/NED')
ned_elevation = elev_dataset.select('elevation')
#colors = cmr.take_cmap_colors('viridis', 5, return_fmt='hex')
#colors = cmr.take_cmap_colors('viridis', None, cmap_range=(0.2, 0.8), return_fmt='hex')
#dem_palette = cmr.take_cmap_colors(mpl.cm.get_cmap('Spectral', 30).reversed(),30, return_fmt='hex')
dem_palette = cm.get_palette('Spectral_r', n_class=30)
demViz = {'min': 0.0, 'max': 2000.0, 'palette': dem_palette, 'opacity': 1}

# LandFire
lf = ee.ImageCollection('LANDFIRE/Vegetation/EVH/v1_4_0');
lf_evh = lf.select('EVH')
#evh_palette = cmr.take_cmap_colors(mpl.cm.get_cmap('Spectral', 30).reversed(),30, return_fmt='hex')
evh_palette = cm.get_palette('Spectral_r', n_class=30)
evhViz = {'min': 0.0, 'max': 30.0, 'palette': evh_palette, 'opacity': 1}

# Global Forest Canopy Height (2005)
gfch = ee.Image('NASA/JPL/global_forest_canopy_height_2005');
forestCanopyHeight = gfch.select('1');
#gfch_palette = cmr.take_cmap_colors(mpl.cm.get_cmap('Spectral', 30).reversed(),30, return_fmt='hex')
gfch_palette = cm.get_palette('Spectral_r', n_class=30)
gfchViz = {'min': 0.0, 'max': 40.0, 'palette': gfch_palette, 'opacity': 1}


### Plot the elevation data

# Prints the elevation of Mount Everest.
xy = ee.Geometry.Point(sitecoords[:2])
site_elev = ned_elevation.sample(xy, 30).first().get('elevation').getInfo()
print('Selected site elevation (m):', site_elev)

# display NED data
# https://geemap.org/notebooks/14_legends/
# https://geemap.org/notebooks/49_colorbar/
# https://colab.research.google.com/github/fsn1995/GIS-at-deep-purple/blob/main/02%20gee%20map%20greenland.ipynb#scrollTo=uwLvDKHDlN0l
#colors = demViz['palette']
#vmin = demViz['min']
#vmax = demViz['max']

srtm = geemap.Map(center=[33.315809,-85.198609], zoom=6)
srtm.addLayer(ned_elevation, demViz, 'Elevation above sea level');
srtm.addLayer(xy, {'color': 'black', 'strokeWidth': 1}, 'Selected Site')
#srtm.add_colorbar_branca(colors=colors, vmin=vmin, vmax=vmax, label="Elevation (m)", 
#                         orientation="vertical", layer_name="SRTM DEM")
srtm.add_colorbar(demViz, label="Elevation (m)", layer_name="SRTM DEM")
states = ee.FeatureCollection('TIGER/2018/States')
statesImage = ee.Image().paint(states, 0, 2)
srtm.addLayer(statesImage, {'palette': 'black'}, 'US States')
srtm.addLayerControl()
srtm

here is the script on GitHub
https://github.com/serbinsh/amf3_seus/blob/main/python/amf3_radar_blockage_demo_gee.ipynb

Any ideas? I was using a different colormap system (cmasher) that also worked for me but not on collab. I switched to the geemap version based on that geemap lib example in the hopes it would fix this "none" issue but it doesn't seem to have fixed it. I wonder if its a geemap versioning issue?

@serbinsh serbinsh added the bug Something isn't working label Jul 16, 2021
@serbinsh
Copy link
Author

It should make a map that looks like this
Screen Shot 2021-07-16 at 12 28 51 PM

@serbinsh
Copy link
Author

On my computer here are my versions
python 3.9

earthengine-api 0.1.273
folium 0.12.1
geemap 0.8.18

@serbinsh
Copy link
Author

https://colab.research.google.com/github/fsn1995/GIS-at-deep-purple/blob/main/02%20gee%20map%20greenland.ipynb

Sorry for the spam, here is a little more info that may help

palette = cm.get_palette('terrain', n_class=10)
palette

['333399',
 '0d7fe5',
 '00be90',
 '55dd77',
 'c6f48e',
 'e3db8a',
 'aa926b',
 '8e6e67',
 'c6b6b3',
 'ffffff']

visPara = {'min': 0,  'max': 2500.0, 'palette': palette}
visPara

{'max': 2500.0,
 'min': 0,
 'palette': ['333399',
  '0d7fe5',
  '00be90',
  '55dd77',
  'c6f48e',
  'e3db8a',
  'aa926b',
  '8e6e67',
  'c6b6b3',
  'ffffff']}
  

but again when trying to use that in add_colorbar

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-16-8771062d12f8> in <module>()
     10 Map.addLayer(arcticDEMgreenland, visPara, 'Arctic DEM terrain')
     11 Map.setCenter(-41.0, 74.0, 3);
---> 12 Map.add_colorbar(visPara, label="Elevation (m)", discrete=False, orientation="vertical", layer_name="Arctic DEM terrain")

3 frames
/usr/local/lib/python3.7/dist-packages/branca/colormap.py in _parse_color(x)
     43         cname = _cnames.get(x.lower(), None)
     44         if cname is None:
---> 45             raise ValueError('Unknown color {!r}.'.format(cname))
     46         color_tuple = _parse_hex(cname)
     47     else:

ValueError: Unknown color None.

@serbinsh
Copy link
Author

I also wondered if it was a mismatch on backend with folium so I tried 49_colorbar.ipynb and Map.add_colorbar_branca

but then I get

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-4-6baa67c548ac> in <module>()
     13 vmax = vis_params['max']
     14 
---> 15 Map.add_colorbar_branca(colors=colors, vmin=vmin, vmax=vmax, layer_name="SRTM DEM")
     16 
     17 # nlcd_2016 = ee.Image('USGS/NLCD/NLCD2016').select('landcover')

AttributeError: 'Map' object has no attribute 'add_colorbar_branca'

@giswqs
Copy link
Member

giswqs commented Jul 17, 2021

When creating colorbars, ipyleaflet can use either matplotlib or branca, while folium can only use branca.
Map.add_colorbar() have different parameters between ipyleaflet and folium. ipyleaflet's Map.add_colorbar_branca() and folium's Map.add_colorbar() use the same function parameters. Check the link below to see function parameters.

For ipyleaflet

import ee
import geemap
import geemap.colormaps as cm

Map = geemap.Map()

greenlandmask = ee.Image('OSU/GIMP/2000_ICE_OCEAN_MASK') \
                   .select('ice_mask').eq(1); #'ice_mask', 'ocean_mask'
arcticDEM = ee.Image('UMN/PGC/ArcticDEM/V3/2m_mosaic')

arcticDEMgreenland = arcticDEM.updateMask(greenlandmask)

palette = cm.get_palette('terrain', n_class=10)

visPara = {'min': 0,  'max': 2500.0, 'palette': ['0d13d8', '60e1ff', 'ffffff']}
visPara
# visPara = {'min': 0,  'max': 2500.0, 'palette': palette}
Map.addLayer(arcticDEMgreenland, visPara, 'Arctic DEM')
Map.setCenter(-41.0, 74.0, 3)

#add colorbar
colors = visPara['palette']
vmin = visPara['min']
vmax = visPara['max']

Map.add_colorbar(visPara, label="Elevation (m a.s.l)", orientation="vertical", layer_name="Arctic DEM")
# Map.add_colorbar_branca(colors=colors, vmin=vmin, vmax=vmax, caption="m a.s.l")
Map

image

For folium

import ee
import geemap.foliumap as geemap
import geemap.colormaps as cm

Map = geemap.Map()
greenlandmask = ee.Image('OSU/GIMP/2000_ICE_OCEAN_MASK') \
                   .select('ice_mask').eq(1); #'ice_mask', 'ocean_mask'
arcticDEM = ee.Image('UMN/PGC/ArcticDEM/V3/2m_mosaic')

arcticDEMgreenland = arcticDEM.updateMask(greenlandmask)

palette = cm.get_palette('terrain', n_class=10)

visPara = {'min': 0,  'max': 2500.0, 'palette': ['0d13d8', '60e1ff', 'ffffff']}
visPara
# visPara = {'min': 0,  'max': 2500.0, 'palette': palette}
Map.addLayer(arcticDEMgreenland, visPara, 'Arctic DEM')
Map.setCenter(-41.0, 74.0, 3)

#add colorbar
colors = visPara['palette']
vmin = visPara['min']
vmax = visPara['max']

Map.add_colorbar(colors=colors, vmin=vmin, vmax=vmax, caption="m a.s.l")
Map

image

giswqs added a commit that referenced this issue Jul 17, 2021
@giswqs
Copy link
Member

giswqs commented Jul 17, 2021

Run geemap.update_package() and restart the kernel. Now the code below should work on both local Jupyter and Google Colab.

import ee
import geemap
import geemap.colormaps as cm

Map = geemap.Map()

greenlandmask = ee.Image('OSU/GIMP/2000_ICE_OCEAN_MASK') \
                   .select('ice_mask').eq(1); #'ice_mask', 'ocean_mask'
arcticDEM = ee.Image('UMN/PGC/ArcticDEM/V3/2m_mosaic')

arcticDEMgreenland = arcticDEM.updateMask(greenlandmask)

palette = cm.get_palette('terrain', n_class=10)

visPara = {'min': 0,  'max': 2500.0, 'palette': ['0d13d8', '60e1ff', 'ffffff']}
visPara
# visPara = {'min': 0,  'max': 2500.0, 'palette': palette}
Map.addLayer(arcticDEMgreenland, visPara, 'Arctic DEM')
Map.setCenter(-41.0, 74.0, 3)

#add colorbar
colors = visPara['palette']
vmin = visPara['min']
vmax = visPara['max']

# Map.add_colorbar(visPara, label="Elevation (m a.s.l)", orientation="vertical", layer_name="Arctic DEM")
Map.add_colorbar_branca(colors=colors, vmin=vmin, vmax=vmax, caption="m a.s.l")
Map

@giswqs giswqs closed this as completed Jul 17, 2021
@serbinsh
Copy link
Author

@giswqs Excellent, thank you!! and thank you for the detailed reply. I definitely think I was getting tripped up on which backend and options I was using. This is really helpful, thank you. I am going to give it a try now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants