Reputation: 355
I am exploring Google Earth Engine and trying some band operation. I have calculated NDVI using two methods,
But I have checked both returns different results, why is so? Is not it the same operation that runs in the normalized difference function.
Here is my code.
#Import earth engine
import ee
# Trigger the authentication flow.
ee.Authenticate()
# Initialize the library.
ee.Initialize()
# Load two 5 year Landsat 7 composite
landsat2008 = ee.Image('LANDSAT/LE7_TOA_5YEAR/2008_2012')
# Compute NDVI using normalizedDifference
ndvi2008_m1 = landsat2008.normalizedDifference(["B4", 'B3'])
##NDVI using method2
diff=landsat2008.select('B4').subtract(landsat2008.select('B3'))
added=landsat2008.select('B4').add(landsat2008.select('B3'))
ndvi2008_m2 = diff.divide(added)
ndvi2008_m2==ndvi2008_m1
ndviParams = {'palette': ["#d73027", "#f46d43", "#fdae61", "#fee08b", "#d9ef8b", '#a6d96a', '#66bd63', '#1a9850']}
# Import the Folium library.
import folium
# Define a method for displaying Earth Engine image tiles to folium map.
def add_ee_layer(self, ee_image_object, vis_params, name):
map_id_dict = ee.Image(ee_image_object).getMapId(vis_params)
folium.raster_layers.TileLayer(
tiles = map_id_dict['tile_fetcher'].url_format,
attr = 'Map Data © <a href="https://earthengine.google.com/">Google Earth Engine</a>',
name = name,
overlay = True,
control = True
).add_to(self)
# Add EE drawing method to folium.
folium.Map.add_ee_layer = add_ee_layer
# Create a folium map object.
my_map = folium.Map(location=[9, 39], zoom_start = 2)
# Add the layer to the map object.
my_map.add_ee_layer(ndvi2008_m1, ndviParams, 'ndvi2008_m1')
my_map.add_ee_layer(ndvi2008_m2, ndviParams, 'ndvi2008_m2')
# Add a layer control panel to the map.
my_map.add_child(folium.LayerControl())
# Display the map.
display(my_map)
Upvotes: 1
Views: 185
Reputation: 11
Casting the image to float solve this (in Javascript). Anyway, the difference is very (very) small.
Upvotes: 1