Skip to content
Advertisement

Google Earth Engine multiple filters on date

Using Google Earth engine API, I can filter the start and end date of a satellite data. In this code for example, I can retrieve ASTER information between January 1st 2018 to July 15th 2018.

var dataset = ee.ImageCollection('ASTER/AST_L1T_003')
                  .filter(ee.Filter.date('2018-01-01', '2018-08-15'));
var falseColor = dataset.select(['B3N', 'B02', 'B01']);
var falseColorVis = {
  min: 0.0,
  max: 255.0,
};
Map.setCenter(-122.0272, 39.6734, 11);
Map.addLayer(falseColor.median(), falseColorVis, 'False Color');

What I need to do, is to retrieve data between 2010 to 2020 but in summers only. Definitely, when I apply multiple ee.Filter.date filters, it returns nothing since summers of every year, doesn’t have overlaps. Is there any way to have multiple OR filters or somehow exclude the fall and winter from my retrieved data.

Advertisement

Answer

Here is my discoveries. In Google Earth Engine’s javascript api, you can find the following filter:

ee.Filter.dayOfYear(start, end)

And fix the problem as

var dataset = ee.ImageCollection('ASTER/AST_L1T_003')
                  .filter(ee.Filter.date('2018-01-01', '2018-08-15'));
var falseColor = dataset.select(['B3N', 'B02', 'B01']);
var falseColorVis = {
  min: 0.0,
  max: 255.0,
};
Map.setCenter(-122.0272, 39.6734, 11);
Map.addLayer(falseColor.median(), falseColorVis, 'False Color');

But in python api, it was not possible as I guess some functions were not implemented. So, one possible alternative is to use ee.filter.OR() to add a filter of multiple dates like:

    filterSummer = ee.Filter.Or(
        ee.Filter.date('2004-06-01', '2004-10-01'),
        ee.Filter.date('2005-06-01', '2005-10-01'),
        ee.Filter.date('2006-06-01', '2006-10-01'),        
        ee.Filter.date('2007-06-01', '2007-10-01')                
    )

and then apply it on ImageCollection() class:

        dataset = ee.ImageCollection('ASTER/AST_L1T_003') 
            .filterDate(start, end) 
            .filter(filterSummer)
            .filterBounds(roi)
            .filterMetadata('CLOUDCOVER', 'less_than', cloud_filter)
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement