1

I don't understand JavaScript. Following the instructions, I made a beautiful animation with following code:

var geometry = ee.Geometry.Polygon(
        [[[21.171108568177974, 52.71072901884085],
          [21.171108568177974, 43.97825621993774],
          [40.66085466192797, 43.97825621993774],
          [40.66085466192797, 52.71072901884085]]], null, false);

// Fetch a MODIS NDVI collection and select NDVI.
var col = ee.ImageCollection('MODIS/006/MOD13A2').select('NDVI');

// Define a mask to clip the NDVI data by.
var mask = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017')
  .filter(ee.Filter.eq('country_na', 'Ukraine'));

// Define the regional bounds of animation frames.
var region = ee.Geometry.Polygon(
  [[[21.171108568177974,43.97825621993774],
    [40.66085466192797,43.97825621993774],
    [40.66085466192797,52.71072901884085],
     [21.171108568177974,52.71072901884085],
    [21.171108568177974,43.97825621993774]]],
  null, false
);

// Add day-of-year (DOY) property to each image.
col = col.map(function(img) {
  var doy = ee.Date(img.get('system:time_start')).getRelative('day', 'year');
  return img.set('doy', doy);
});

// Get a collection of distinct images by 'doy'.
var distinctDOY = col.filterDate('2013-01-01', '2021-04-01');

// Define a filter that identifies which images from the complete
// collection match the DOY from the distinct DOY collection.
var filter = ee.Filter.equals({leftField: 'doy', rightField: 'doy'});

// Define a join.
var join = ee.Join.saveAll('doy_matches');

// Apply the join and convert the resulting FeatureCollection to an
// ImageCollection.
var joinCol = ee.ImageCollection(join.apply(distinctDOY, col, filter));

// Apply median reduction among matching DOY collections.
var comp = joinCol.map(function(img) {
  var doyCol = ee.ImageCollection.fromImages(
    img.get('doy_matches')
  );
  return doyCol.reduce(ee.Reducer.median());
});

// Define RGB visualization parameters.
var visParams = {
  min: 0.0,
  max: 9000.0,
  palette: [
    'FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718', '74A901',
    '66A000', '529400', '3E8601', '207401', '056201', '004C00', '023B01',
    '012E01', '011D01', '011301'
  ],
};

// Create RGB visualization images for use as animation frames.
var rgbVis = comp.map(function(img) {
  return img.visualize(visParams).clip(mask);
});

Export.video.toDrive({
  collection: rgbVis,
  description: 'sfVideoExample',
  dimensions: 720,
  framesPerSecond: 12,
  region: region
});

But I need animation once a year 2013-2021, not every 16 days. If possible, then the average for the year. If not, then March, or April.

Please tell me what to do with it.

2

Your above code produces 190 images every 16 days so, it works well with 12 frames per second. However, for an animation once a year between 2013-2021, a lower value for this parameter is required because there are only 9 years in obtained image collection (years). In following code, I used only 1 frame per second and it works well. As said before, yearly collection used for animation is named years.

var geometry = ee.Geometry.Polygon(
        [[[21.171108568177974, 52.71072901884085],
          [21.171108568177974, 43.97825621993774],
          [40.66085466192797, 43.97825621993774],
          [40.66085466192797, 52.71072901884085]]], null, false);

// Fetch a MODIS NDVI collection and select NDVI.
var col = ee.ImageCollection('MODIS/006/MOD13A2').select('NDVI');

print(col);

var start = 2013;

//make a list of years and filter the modisNDVI  
var years = ee.List.sequence(2013, 2021, 1).map(function(year){
  var start = ee.Number(year);
  var end = start.add(ee.Number(1));
  var ndviMeanYear = col.filter(ee.Filter.calendarRange(start, end, 'year')).mean();
  return ndviMeanYear.set('year', start);
});

years = ee.ImageCollection(years);

print(years);

// Define a mask to clip the NDVI data by.
var mask = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017')
  .filter(ee.Filter.eq('country_na', 'Ukraine'));

// Define the regional bounds of animation frames.
var region = ee.Geometry.Polygon(
  [[[21.171108568177974,43.97825621993774],
    [40.66085466192797,43.97825621993774],
    [40.66085466192797,52.71072901884085],
     [21.171108568177974,52.71072901884085],
    [21.171108568177974,43.97825621993774]]],
  null, false
);

// Define RGB visualization parameters.
var visParams = {
  min: 0.0,
  max: 9000.0,
  palette: [
    'FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718', '74A901',
    '66A000', '529400', '3E8601', '207401', '056201', '004C00', '023B01',
    '012E01', '011D01', '011301'
  ],
};

// Create RGB visualization images for use as animation frames.
var rgbVis = years.map(function(img) {
  return img.visualize(visParams).clip(mask);
});

Export.video.toDrive({
  collection: rgbVis,
  description: 'sfVideoExample',
  dimensions: 720,
  framesPerSecond: 1,
  region: region
});
1
  • This is exactly what I was looking for. Thank you so much for your help. Perhaps it will be useful to someone. In order not to waste 4 months, slightly changed the provided code var start = 2012-4-1; //make a list of years and filter the modisNDVI var years = ee.List.sequence(2012-4-1, 2021-4-1, 1).map(function(year){ var start = ee.Number(year); var end = start.add(ee.Number(1)); var ndviMeanYear = col.filter(ee.Filter.calendarRange(start, end, 'year')).mean(); return ndviMeanYear.set('year', start); }); – nemos Apr 26 at 20:56

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.