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

Error with add_colorbar and colormaps #450

Closed
davemlz opened this issue Apr 29, 2021 · 2 comments
Closed

Error with add_colorbar and colormaps #450

davemlz opened this issue Apr 29, 2021 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@davemlz
Copy link

davemlz commented Apr 29, 2021

Environment Information

  • geemap version: 0.8.15
  • eemont version: 0.1.9
  • ee version: 0.1.241
  • Python version: 3.8.3
  • Operating System: Win 10

Description

Hi, @giswqs! Thank you very much again for the update in geemap! Here is a sample of the complete chunk of code. When I use the palette from the colormaps module to create a colorbar (locally - ipyleaflet), it doesn't work, however, when it is converted into a list, it works:

What I Did

import ee, eemont, geemap
import geemap.colormaps as cm

Map = geemap.Map()

MOD09GA = (ee.ImageCollection('MODIS/006/MOD09GA')
           .filterDate('2020-01-01','2021-01-01')
           .maskClouds()
           .scale()
           .index(['GNDVI','NBR','NDWI'])
           .median())

vegetationPalette = cm.palettes.ndvi

GNDVIvis = {'min':0,'max':1,'palette':vegetationPalette,'bands':'GNDVI'}

aoi = ee.Geometry.PointFromQuery('Lago Cocibolca, Nicaragua',user_agent = 'eemont-tutorial-012')

Map.addLayer(MOD09GA,GNDVIvis,'GNDVI')
Map.add_colorbar(GNDVIvis['palette'],caption = 'GNDVI')
Map.centerObject(aoi,8)
Map

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-62b343a4aa50> in <module>
     15 
     16 Map.addLayer(MOD09GA,GNDVIvis,'GNDVI')
---> 17 Map.add_colorbar(GNDVIvis['palette'],caption = 'GNDVI')
     18 Map.centerObject(aoi,8)
     19 Map

~\anaconda3\lib\site-packages\geemap\geemap.py in add_colorbar(self, vis_params, cmap, discrete, label, orientation, position, transparent_bg, layer_name, **kwargs)
   2625 
   2626         if not isinstance(vis_params, dict):
-> 2627             raise TypeError("The vis_params must be a dictionary.")
   2628 
   2629         if orientation not in ["horizontal", "vertical"]:

TypeError: The vis_params must be a dictionary.

This works

import ee, eemont, geemap
import geemap.colormaps as cm

Map = geemap.Map()

MOD09GA = (ee.ImageCollection('MODIS/006/MOD09GA')
           .filterDate('2020-01-01','2021-01-01')
           .maskClouds()
           .scale()
           .index(['GNDVI','NBR','NDWI'])
           .median())

vegetationPalette = cm.palettes.ndvi

GNDVIvis = {'min':0,'max':1,'palette':vegetationPalette,'bands':'GNDVI'}

aoi = ee.Geometry.PointFromQuery('Lago Cocibolca, Nicaragua',user_agent = 'eemont-tutorial-012')

Map.addLayer(MOD09GA,GNDVIvis,'GNDVI')
Map.add_colorbar(list(GNDVIvis['palette']),caption = 'GNDVI') # <--- Converted the Box to list
Map.centerObject(aoi,8)
Map
@davemlz davemlz added the bug Something isn't working label Apr 29, 2021
@giswqs giswqs self-assigned this Apr 29, 2021
giswqs added a commit that referenced this issue Apr 29, 2021
@giswqs
Copy link
Member

giswqs commented Apr 29, 2021

@davemlz Thanks for reporting. This bug has been fixed now. Run geemap.update_package() and try your code again without list

@davemlz
Copy link
Author

davemlz commented Apr 29, 2021

It works perfectly! Thank you, @giswqs! I'll close the issue.

@davemlz davemlz closed this as completed Apr 29, 2021
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