Tuesday 21 August 2018

Extracting position date of max and min value in NDVI time series in Google Earth Engine?



I need to extract the DATE for max and min NDVI values in a MODIS NDVI time series. i think I am able to extract the date for max but I have problems with the minimum.


// turn image collection into an array
var array = NDVI.toArray()

// sort array by the first band, keeping other bands
var axes = { image:0, band:1 }
var sort = array.arraySlice(axes.band, 0, 1); // select bands from index 0 to 1 (NDVI)
var sorted = array.arraySort(sort);

// take the first image only (MAX NDVI)

var length = sorted.arrayLength(axes.image)
var values = sorted.arraySlice(axes.image, length.subtract(1), length);

// convert back to an image
var max = values.arrayProject([axes.band]).arrayFlatten([['ndvi', 'time']])

// get the max band
var ndviMax = max.select(0) // ndvi max
var time = max.select(1) // get day


This is the link to the code https://code.earthengine.google.com/29618e626ddc93d7d6a6d00103518c6e


Any help/suggestion?



Answer



You can get the minimum values similar to how you got the max values, but instead you'll need the first position to use arraySlice.


// for the max value sorted
var valuesMax = sorted.arraySlice(axes.image, length.subtract(1), length);
// for the min value sorted
var valuesMin = sorted.arraySlice(axes.image, 0, 1);

Then you can continue with the script similar as you did with the max values.



Here you can find a link to the full script.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...