Skip to content

Collection NDVI

While single image operations are direct and can be applied to the imagery for a one to one result. Applying any kind of analysis on a single image means you have to call the image and run the analysis which is quick and easy. To be able to turn this same into a function that you can iterate over an entire collection requires us to convert a single analysis to a function. A function is then mapped or run over an entire collection. To avoid any errors make sure that the collection images are consistent and have same name and number of band and characteristics.

For this setup we look at how we added PlanetScope Surface Reflectance data earlier , and calculated Normalized Difference Vegetation Index (NDVI) over the entire collection which takes an image collection and iteratively passes an image to the function. The resultant structure is also an image collection where we are returning a single band which is the NDVI. Note that we also renamed the band to NDVI since they are not autorenamed. We also decided to choose one point or geometry and see how the NDVI value has changed over time

This tool will not run in your accounts unless access has been given. For this demo Tyson has access to the imagery and as such able to run the analysis. However if you download and upload new imagery or use existing imagery in Google Earth Engine you can modify and use this script

NDVI

You can access the full script here or copy and past the same code into code.earthengine.google.com

var ps = ee.ImageCollection("users/samapriya/planet-impact/neon_ps4b")
var psr = ee.ImageCollection("users/samapriya/planet-impact/neon_ps4b_sr")
var srvis = {"opacity":1,"bands":["b4","b3","b2"],"min":351,"max":4729,"gamma":1}
var psvis = {"opacity":1,"bands":["b4","b3","b2"],"min":1830,"max":16207,"gamma":1}
var geom = /* color: #d63000 */ee.Geometry.Point([-110.98749160242733, 31.830023615698792])
var geometry = /* color: #98ff00 */ee.Geometry.Polygon(
        [[[-111.12258911132812, 31.78187474629157],
          [-110.58700561523438, 31.689605853938378],
          [-110.555419921875, 31.834391869807774],
          [-111.0772705078125, 31.92301962048709]]]),
var ndvivis = {"opacity":1,"bands":["NDVI"],"min":0.03585313260555267,"max":0.7418604493141174,"gamma":1}

//Print some collection info
print('PlanetScope Radiance Images',ps.size())
print('PlanetScope Surface Reflectance Images',psr.size())
print('Sample Image Properties: PS Radiance',ps.first())
print('Sample Image Properties: PS Surface Reflectance',psr.first())

//Center the Map around the first image from collection
Map.centerObject(geom,11)

//Add median value of collection (This is for whole year)
Map.addLayer(ps.median().clip(geometry),psvis,'PlanetScope Radiance 2017 Median')
Map.addLayer(psr.median().clip(geometry),srvis,'PlanetScope Surface Reflectance 2017 Median')

//NDVI calculation
var addNDVI = function(image) {
  var ndvi = image.normalizedDifference(['b4', 'b3']).rename('NDVI');
  return ndvi.set('system:time_start',image.get('system:time_start'));
};

var ndvicoll=psr.map(addNDVI)
print("NDVI Collection",ndvicoll)

//Add the first of the result
Map.addLayer(ee.Image(ndvicoll.max()).clip(geometry),ndvivis,"Max NDVI 2017")


//Time Series Chart
print(ui.Chart.image.series(ndvicoll.select('NDVI'), geom.buffer(50), ee.Reducer.max(), 30))
//Set basemap options
Map.setOptions('SATELLITE')