TransWikia.com

GEE: How to iterate through a feature collection to calculate annual average indices from MODIS for each feature

Geographic Information Systems Asked by Simba06 on April 30, 2021

I am trying to calculate the average annual vegetation condition index from MODIS data for a set of raions (districts) for spring months (march, april and may). I am wanting to export this data to a table with this annual data for each individual raion. I have created this script which works for all of the raions as a whole, but I need to adapt the code to loop through the raions feature collection and calculate the average VCI for each raion each year in spring and summer months. I believe I need to use the map() function but my GEE/Javascript experience is minimal and am not sure how to integrate this into the code.

//calculate average seasonal NDVI for a set of raions 
//get MODIS NDVI
var collection = ee.ImageCollection('MODIS/006/MOD13A1').select('NDVI');

// reference period for baseline
var reference = ee.ImageCollection(collection.filterDate('2001-01-01', '2020-12-31'))
  .sort('system:time_start');
print("reference",reference);

//filter out images from specific months
//march, april, may (spring)
var spring = reference.filter(ee.Filter.dayOfYear(59,150));

//filter bounds to raions
var spring_soa = spring.filterBounds(raions.geometry());

//calulate min of full series (mam 2001-2020) for each pixel for spring and summer seasons
var spring_min = spring.min();

//calculate max of full series (spr 2001-2020) for each pixel
var spring_max = spring.max();

//mask out agriculture
var spring_min_agrimask = spring_min.multiply(agrimask_ukr);
var spring_max_agrimask = spring_max.multiply(agrimask_ukr);

//calc bottom of VCI equations
var vci_bot_spr = spring_max_agriSoA.subtract(spring_min_agrimask);

//function to iterate through months and calculate average Vegetation condition Index (SPRING) FOR RAIONS
var years = ee.List.sequence(2001, 2020);
print("years",years);

var spring_vci = ee.ImageCollection.fromImages(
      years.map(function (y) {
        return spring.filter(ee.Filter.calendarRange(y, y, 'year'))
                    .select(("NDVI")).mean()
                    .multiply(agrimask_UKR)
                    .subtract(spring_min_agrimask)
                    .divide(vci_bot_spr)
                    .set('year', y);
}));
print("spring_vci",spring_vci);

//get means as table and add to Drive
var spring_vci_means_raions = spring_vci.map(function(image){
  return image.reduceRegions({
    collection:spring_vci, 
    reducer:ee.Reducer.mean(), 
    scale: 30
  });
});
var ukr_spring_table = spring_vci_means_ukr.flatten();
print(ukr_spring_table);
Export.table.toDrive(ukr_spring_table,"ukr_spring_vci");


Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP