I'm trying to source average NDVI raster images from July of every year from 2008 through 2018 for the USA. I need to export this data to link with PHI offline. Exporting the images for the entire country isn't allowed so I need to break it up into 4 regions. This will result in 44 raster images exported from GEE. I'm having a really hard time automating this process since for loops are not allowed.
Below is an example I'm trying with just two regions and one date. My approach was to try and create a ee.List
composed of two ee.Dictionaries
then map the drawDateRegion
function over that ee.List
. It's not working. I think that some of the issue might be in the fact that I can't seem to reference elements of the dictionaries contained in the flatRegionsAndDates2
list.
I'm willing to try another approach if somebody has a suggestion. Essentially I need to clip and filter an ee.Image
collection over all combinations of regions 1-4 and Julys 2008-2018.
//Getting MODIS Image Collection
var modis = ee.ImageCollection('MODIS/006/MOD13Q1');
//New program to get all regions and years
//Import all 4 US regions as FeatureCollections
//Importing region
var region1 = ee.FeatureCollection("users/fossaal/us_region1_10km_buffer");
var region2 = ee.FeatureCollection("users/fossaal/us_region2_10km_buffer");
//var region3 = ee.FeatureCollection("users/fossaal/us_region3_10km_buffer");
//var region4 = ee.FeatureCollection("users/fossaal/us_region4_10km_buffer");
//Creating date ranges
var startDate = ee.Date('2016-07-01');
var dateRange = ee.DateRange(startDate,startDate.advance(1,'month'));
//Create arrays
var allRegions = [region1,region2]
var allDates = [dateRange]
//Functions for mapping
var arrayOfArrays = function(region){
var regionDatePair = function(date){
return {
region:region,
date:date
}
}
return allDates.map(regionDatePair)
}
var regionsAndDates = allRegions.map(arrayOfArrays)
print(regionsAndDates)
var flatRegionsAndDates = ee.List(regionsAndDates).flatten()
print(flatRegionsAndDates)
//Make elements of list into Dictionaries
var toDict = function(a){
return ee.Dictionary(a)
}
var flatRegionsAndDates2 = flatRegionsAndDates.map(toDict)
print(flatRegionsAndDates2)
//Creating function to clip and filter
var drawDateRegion = function(dateRegionObject){
print(dateRegionObject)
var dataset = modis.filter(ee.Filter.date(dateRegionObject.get('date')));
//Reducing MODIS images to averages for all bands
var redDataset = dataset.mean();
// Clip to to US borders.
var clippedRedDataset = redDataset.clipToCollection(dateRegionObject.get('region'));
// Select only NDVI band
var ndvi = clippedRedDataset.select('NDVI');
return ndvi
}
var output = flatRegionsAndDates2.map(drawDateRegion)