Make a list of millisecond dates, and then use filter inList
:
var collection = ee.ImageCollection("MODIS/MYD11A1").select('LST_Day_1km');
var reference = collection.filterDate('2016-01-01', '2016-12-31')
var datelist = ee.List(['2005-08-05','2009-09-01','2017-02-08'])
.map(function(date){return ee.Date(date).millis()})
var newcol = collection.filter(ee.Filter.inList("system:time_start", datelist))
print(newcol)
Your Code
These lines don't seem to work out:
var dateFilter = ee.ImageCollection(longRain2016.merge(shortRain2016).merge(longRain2017).merge(shortRain2017).merge(longRain2018));
var s2dateFilter = s2.filter(dateFilter);
You are trying to construct another ee.ImageCollection
passing existing ImageCollection
s to it. According to the API, this won't work.
I also think that it is not necessary to achieve what you want because ee.ImageCollection.merge
returns an ImageCollection
anyway.
This should work:
var allSeasons = longRain2016.merge(shortRain2016).merge(longRain2017).merge(shortRain2017).merge(longRain2018);
Now, since you already should have a merged ImageCollection
of all the seasons in allSeasons
, you don't need the second step. (Actually this wouldn't work because your dateFilter
object is not a Filter
and filter()
only accepts a Filter
.)
You can simply proceed with var count = allSeasons.size();
Alternative way ("The Multiple-Filter-Method")
You could first create the Filter
s and then Filter.or()
-join them together. Next you could apply this joint Filter
to the ImageCollection
:
//Create Filters
var longRain2016Filter = ee.Filter.date('2016-04-01','2016-05-31');
var shortRain2016Filter = ee.Filter.date('2016-11-15','2016-12-31');
var longRain2017Filter = ee.Filter.date('2017-04-01','2016-05-31');
var shortRain2017Filter = ee.Filter.date('2017-10-01','2016-12-31');
var longRain2018Filter = ee.Filter.date('2018-03-01','2018-05-31');
var allSeasonsFilter = ee.Filter.or(longRain2016Filter, shortRain2016Filter, longRain2017Filter, shortRain2017Filter, longRain2018Filter); // Create joint Filter
var allSeasons = s2.filter(allSeasonsFilter); //apply Filter to ImageCollection
Best Answer
You can remove images from an image collection by creating a date filter for the 'bad/missing' data and then remove it using ee.Filter.not(). For example: