2

I want to filter the Sentinel ImageCollection for the rainseasons of my ROI (March to may AND October to December) for all data available (2015-2018). With .filterDate(startdate, enddate) I can only filter one season of one year. With my code I get an Error: Layer 1: Layer error: User memory limit exceeded. Is there another way?

var s2 = ee.ImageCollection('COPERNICUS/S2').filterDate('2016-03-01', '2016-05-31')
.filter(ee.Filter.calendarRange(3,5,'month'))
.filter(ee.Filter.calendarRange(10,12,'month'));

var composite = s2.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20))
              .map(maskS2clouds)
              .median();

function maskS2clouds(image) {
  var qa = image.select('QA60');
  var cloudBitMask = ee.Number(2).pow(10).int();
  var cirrusBitMask = ee.Number(2).pow(11).int();
  var mask = 
  qa.bitwiseAnd(cloudBitMask).eq(0).and(qa.bitwiseAnd(cirrusBitMask).eq(0));
  return image.updateMask(mask).divide(10000);
  }

Map.setCenter(37.5211, 1.3182, 13);
Map.addLayer(composite, {bands: ['B3', 'B2', 'B1'], min: 0, max: 0.3});
  • You use ee.Filter.calendarRange(3,5,'month') and over this result, you apply ee.Filter.calendarRange(10,12,'month'). There is no 10-12 month after applying the first filter. Maybe this could be the root of your issue – aldo_tapia Feb 14 '18 at 11:36
1

As I commented, the problem is with a double filter without and or or and condition. Use:

var s2 = ee.ImageCollection('COPERNICUS/S2').filterDate('2016-03-01', '2016-05-31')
.filter(ee.Filter.or(ee.Filter.calendarRange(3,5,'month'),
ee.Filter.calendarRange(10,12,'month')));

var composite = s2.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20))
              .map(maskS2clouds)
              .median();

function maskS2clouds(image) {
  var qa = image.select('QA60');
  var cloudBitMask = ee.Number(2).pow(10).int();
  var cirrusBitMask = ee.Number(2).pow(11).int();
  var mask = 
  qa.bitwiseAnd(cloudBitMask).eq(0).and(qa.bitwiseAnd(cirrusBitMask).eq(0));
  return image.updateMask(mask).divide(10000);
  }

Map.setCenter(37.5211, 1.3182, 13);
Map.addLayer(composite, {bands: ['B3', 'B2', 'B1'], min: 0, max: 0.3});
  • Thank you so much! It worked with the or condition, but not with the and condition. I dont know why. But it should not make a difference because the or condition is inclusive, right? I also defined the region of interest so it doesn't run out of memory. – loloj0 Feb 14 '18 at 14:18
  • With and you need to agree with both conditions... You can't have an image of two different months. I put and and or as two ways to apply different filters at the same time, each use depends on the desired output. If this answer was helpful, please accept it (tick mark in up-left corner of the answer), this is how this site works – aldo_tapia Feb 14 '18 at 14:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.