Closed serbinsh closed 3 years ago
It should make a map that looks like this
On my computer here are my versions python 3.9
earthengine-api 0.1.273 folium 0.12.1 geemap 0.8.18
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.
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'
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.
add_colorbar()
: https://geemap.org/geemap/#geemap.geemap.Map.add_colorbaradd_colorbar_branca()
: https://geemap.org/geemap/#geemap.geemap.Map.add_colorbar_brancaadd_colorbar()
: https://geemap.org/foliumap/#geemap.foliumap.Map.add_colorbarFor 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
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
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 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
Environment Information
Description
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
or
or in my code (again works on my computer in Jupyter)
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?