2

I'm trying to make an animation of NDVI images from sentinel collection in order to see clearly variance in the field.
The first part of the code works with little error: "Layer name is not a string: null", but I want to use the second part of the code that is much better to work with.

/*  Copyright (c) 2018 Gennadii Donchyts. All rights reserved.
This work is licensed under the terms of the MIT license.  
For a copy, see <https://opensource.org/licenses/MIT>.  */

var img1 = ee.Image('COPERNICUS/S2/20180824T081601_20180824T082948_T36SXA'); 
var img2 = ee.Image('COPERNICUS/S2/20180819T081559_20180819T082121_T36SXA'); 
var img3 = ee.Image('COPERNICUS/S2/20180814T081601_20180814T082955_T36SXA'); 
var img1_ndvi = img1.normalizedDifference(['B8','B4']);
var img2_ndvi = img2.normalizedDifference(['B8','B4']);
var img3_ndvi = img3.normalizedDifference(['B8','B4']);
var IMAGES = [img1_ndvi, img2_ndvi, img3_ndvi];
var animation = require('users/gena/packages:animation')
animation.animate(IMAGES, {label: 'label', maxFrames: 10})

Up to here the code works but that's a long way to do it, I would prefer to do it this way and add also visualization parameters

var visNDVI = {min: 0.3, max: 0.5, palette: 'FFFFFF, CE7E45, DF923D, F1B555'     + 
'FCD163, 99B718, 74A901, 66A000, 529400, 3E8601, 207401, 056201, 004C00' + 
'023B01, 012E01, 011D01, 011301'};

var geometry = ee.Geometry.Polygon(
  [[[-93.33501647520507, 38.46011907110406],[-93.33544562864745,     38.45339786087],
  [-93.33145450163329, 38.4532970379497],[-93.33117555189574,     38.45995104847996]]]);
var aoi =  geometry;
Map.addLayer(aoi, 'geodesic polygon');

var images = ee.ImageCollection("COPERNICUS/S2")
    .filterBounds(aoi)
    .filterDate('2019-01-01','2019-12-31');

var ndvi = images.map(function(image) {
  var result = image.normalizedDifference(['B8','B4']).rename("ndvi");
  return image.addBands(result);
});
imagesNDVI = ee.ImageCollection(ndvi);

var animation = require('users/gena/packages:animation')
animation.animate(imagesNDVI, {label: 'label', maxFrames: 10})
1

There are multiple things going wrong in the second script you provide. I will list them from top to down so you can make this work:

Your defined your palette without brackets (it should be a list) and you did not provide all necessary commas and quotation marks.

var visNDVI = {min: 0, max: 0.8, 
                  palette: ['FFFFFF', 'CE7E45', 'DF923D', 'F1B555',
                            'FCD163', '99B718', '74A901', '66A000', '529400',
                            '3E8601', '207401', '056201', '004C00','023B01', '012E01', '011D01', '011301']};

The second argument in Map.addLayer must be the visualization parameter, while you defined a string. That should be the third. You should leave the second one empty.

Map.addLayer(aoi, {}, 'geodesic polygon');

You should select only the NDVI band to represent the image with a palette.

var imagesNDVI = ee.ImageCollection(ndvi).select('ndvi');

In Gena's package, you can define the visualization as follows:

animation.animate(imagesNDVI, {vis: visNDVI})

link to code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.