# Moving Averages and Seasonality Filters

What would be a way to compute moving averages of a time series in GEE? Consider we imported an image collection X and filtered by start and finish dates.

``````var Y =ee.ImageCollection(X.filterDate(start,finish));
``````

I want to be able to compute moving averages of the time series

There are issues with this example (clouds), but it illustrates how to do what you want using joins, map and reduce:

``````var l5toa = ee.ImageCollection("LANDSAT/LT5_L1T_TOA");
var geometry = ee.Geometry.Point([-120.69580078125, 37.49229399862877]);

var collection = l5toa.filterBounds(geometry);

var join = ee.Join.saveAll({
matchesKey: 'images'
});

var timeField = 'system:time_start';

var diffFilter = ee.Filter.maxDifference({
difference: 1000 * 60 * 60 * 24 * 17,
leftField: timeField,
rightField: timeField
});

var threeNeighborJoin = join.apply({
primary: collection,
secondary: collection,
condition: diffFilter
});

var smoothed = ee.ImageCollection(threeNeighborJoin.map(function(image) {
var collection = ee.ImageCollection.fromImages(image.get('images'));
• `difference` is 17 days in milliseconds. `threeNeighborJoin` is a `FeatureCollection` in which each image stores a reference (`images`) to whatever images pass the filter (i.e. is within 17 days). The mean is computed by `collection.mean()`. For a 5 day filter, use 34 days in the filter. You can discover all that by printing intermediate results. Feb 5, 2020 at 21:48