Uncomment the following line to install geemap if needed.
# !pip install geemap
import geemap
import ee
ee.Initialize()
import numpy as np
band1 = np.array([[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11]])
band2 = np.array([[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]])
band3 = np.array([[3, 3, 3, 3], [2, 2, 2, 2], [1, 1, 1, 1]])
data = np.dstack([band1, band2, band3])
# Test bad input
img = geemap.numpy_to_ee(1)
# Test with only one band:
img = geemap.numpy_to_ee(
band1, crs='EPSG:4326', transform=[14.5, 0, -125, 0, -8, 49], band_names='a'
)
# Test with multiple bands:
img_multi = geemap.numpy_to_ee(
data,
crs='EPSG:4326',
transform=[14.5, 0, -125, 0, -8, 49],
band_names=['a', 'b', 'c'],
)
# Add images to a map
Map = geemap.Map()
Map.addLayer(img, {'min': 0, 'max': 11})
Map.addLayer(img_multi, {'min': 0, 'max': 11, 'bands': ['a', 'b', 'c']})
Map