That is because the MODIS composite has a single raster that fills the whole planet, so filtering with bound doesn't make any difference. You may want to clip the image. Like this:
var monte = ee.FeatureCollection("ft:1Sm4ObZgrKeCP-VlFa6Jf019-62oDS_AfqvqYw0t6"),
MOD_W = ee.ImageCollection("MODIS/MOD13Q1");
var MOD = MOD_W.filterDate('2002-07-04', '2017-03-30');
var MOD_monte = MOD.map(function(img) {return img.clip(monte)})
Map.addLayer(MOD_monte);
Map.centerObject(monte);
If you want to export it, you have to specify properly the region parameter.
You should definitely try to export the result, which will likely solve the time out problem. Below is a toy example that replicates your two region reduction options and demonstrates exporting the tables as CSV files to your Google Drive account. A few things to note:
There is no need to clip each image by NU009
, the region reducing functions will do this for you based on the provided argument to the geometry
parameter. Additionally, if you are clipping an image by a featureCollection
, be sure to use: clipToCollection()
instead of clip()
.
The two options you are considering produce quite different results. Consider what kind of table output you want. The first calculates the mean of EVI of the aggregate pixels interesting the features of the featureCollection and the second calculates mean EVI per image per feature.
It is worth trying to export the results using the native 30m resolution and all of the features you currently have in the featureCollection and run it with the profiler (Crtl+Alt+Enter) so you can track what functions are using a lot of memory.
The toy example script uses only 5 months of imagery from one path/row and there are about 39 features. These attributes allow it to run quickly in the browser and export in about 1 minute. A larger time series with more features (and/or more complexity) may not process fast enough to print results to the Code Editor console (times out after 5 minutes) and may take much longer to export.
Code Editor script
/**
* @license
* Copyright 2019 Google LLC.
* SPDX-License-Identifier: Apache-2.0
*
* @description
* An example of reducing all the elements of an imageCollection by all
* the elements of a featureCollection and exporting the results to
* Google Drive.
*/
// Import US counties and protected areas featureCollections.
var counties = ee.FeatureCollection('TIGER/2018/Counties');
var protectedAreas = ee.FeatureCollection("WCMC/WDPA/current/polygons");
// Create a featureCollection that is all of the protected areas interesting
// Santa Clara County, CA, USA.
var scCounty = counties.filter(ee.Filter.eq('NAME', 'Santa Clara'));
var polys_filtered = protectedAreas.filterBounds(scCounty);
// Import a Landsat EVI collection and filter it by geographic extent and date
// range.
var l8 = ee.ImageCollection('LANDSAT/LC08/C01/T1_8DAY_EVI')
.filterBounds(polys_filtered)
.filterDate('2018-01-01','2018-06-01');
// Below are two options for summarizing a time series of EVI for the protected
// areas interesting Santa Clara County.
// #############################################################################
// ### REDUCE AGGREGATE REGIONS OPTION ###
// #############################################################################
// Merge the geometries of the 'polys_filtered' featureCollection into a single
// multiPolygon geometry.
var geom = polys_filtered.geometry();
// Define a function that will calculate mean EVI of all pixels within the
// multiPolygon geometry defined by the 'polys_filtered' featureCollection.
var reduceRegion = function(image) {
// This regionReduction returns a dictionary; in this case a single key-value
// pair for the mean summary of EVI.
var meanEVI = image.reduceRegion({
reducer: ee.Reducer.mean(),
geometry: geom,
scale: 30,
bestEffort: true});
// Along with mean EVI for the region (renamed), add some info about the image
// that mean EVI is based on (the image ID and the image date). Define these
// attributes in a dictionary.
var props = {
'meanEVI': meanEVI.get('EVI'),
'imgID': image.id(),
'date': image.date().format('YYYY-MM-dd')};
// Return the information as a feature, so that the result of mapping this
// function over a collection will be another collection that can be cast as
// a featureCollection, which can be exported to Google Drive. Use the 'geom'
// to defined the feature's geometry, and the 'props' dictionary to define the
// properties of the feature.
return ee.Feature(geom, props);
};
// Map the above function over the Landsat EVI imageCollection to calculate mean
// EVI per image for the region expressed by the merged geometries of all the
// features in the 'polys_filtered' featureCollection. Cast the result as a
// featureCollection.
var l8_reduceRegion = ee.FeatureCollection(l8.map(reduceRegion));
// Export the featureCollection (table) as a CSV file to your Google Drive
// account. The resulting table will have as many rows as there are images and
// three columns for the 'props' set above as well as some system properties
// added by default. The table will be written to the Google Drive account
// associated with your Earth Engine account and will be placed in a folder
// called 'reduce_region_test' and named 'l8_reduceRegion' - both provided as
// parameter arguments.
Export.table.toDrive({
collection: l8_reduceRegion,
description: 'l8_reduceRegion',
folder: 'reduce_region_test',
fileFormat: 'CSV'});
// Plot the table as a time series chart. X is the date, Y is mean EVI. There is
// only one series because all of the features' geometries are merged.
print(ui.Chart.feature.byFeature(l8_reduceRegion, 'date', 'meanEVI'));
// #############################################################################
// ### REDUCE BY INDIVIDUAL REGIONS OPTION ###
// #############################################################################
// Define a function to be mapped over the EVI image collection that calculates
// mean EVI per image for all polygons in the 'polys_filtered' featureCollection
// using the 'reduceRegions' method.
var reduceRegions = function(image) {
var meanEVI = image.reduceRegions({
collection: polys_filtered,
reducer: ee.Reducer.mean(),
scale: 30});
// Return the featureCollection with the EVI mean summary per feature, but
// first...
return meanEVI
// ...remove any features that have a null value for any property.
.filter(ee.Filter.notNull(['mean']))
// ...map over the featureCollection to edit properties of each feature.
.map(function(feature) {
// Return the feature, but first...
return feature
// ...select only two properties of interest; there are about 30
// (all of the properties of the original feature plus mean EVI), not all
// are necessary in this case. Also rename the 'mean' property returned
// be default from the above reduceRegions function to 'meanEVI'.
.select(['mean', 'WDPAID'], ['meanEVI', 'WDPAID'])
// ..add an image ID and date property of the image being reduced.
.set({
'imgID': image.id(),
'date': image.date().format('YYYY-MM-dd')
});
});
};
// Apply the above defined function to all images. The result will be a
// collection of featureCollections. Each collection contains all of the
// 'polys_filtered' features with a set of properties that describe the mean
// EVI for each feature along with an image ID from which EVI is based on
// and the date of the image.
var l8_reduceRegions = l8.map(reduceRegions)
// Flatten the collection of featureCollections into a single featureCollection.
.flatten();
// Export the featureCollection (table) as a CSV file to your Google Drive account.
// See the above note on 'Export.table.toDrive' for more information.
Export.table.toDrive({
collection: l8_reduceRegions,
description: 'l8_reduceRegions',
folder: 'reduce_region_test',
fileFormat: 'CSV'
});
// Plot the table as a time series chart. X is the date, Y is mean EVI. There
// are same many series as there are features in the 'polys_filtered' feature
// featureCollection.
print(ui.Chart.feature.groups(l8_reduceRegions, 'date', 'meanEVI', 'WDPAID'));
Best Answer
Here is a code that I found from an answer from google-earth-engine developers group by Gennadii Donchyts: https://code.earthengine.google.com/6270df443326ec0d90a18838bd91c5a5
Essentially, a package has been written in GEE to annotate on ee.Image object, which then can be exported as the video.