0

I am having issues filtering multiple date ranges. For example I want to make a image collection that also includes the same months from 2020, 2021, 2022, 2023 etc. What's the best way to do this?

//1 Mask Clouds
function maskS2clouds(sentColl) {
  var qa = sentColl.select('QA60');

  // Bits 10 and 11 are clouds and cirrus, respectively.
  var cloudBitMask = 1 << 10;
  var cirrusBitMask = 1 << 11;

  // Both flags should be set to zero, indicating clear conditions.
  var mask = qa.bitwiseAnd(cloudBitMask).eq(0)
    .and(qa.bitwiseAnd(cirrusBitMask).eq(0));

  return sentColl.updateMask(mask).divide(10000);
}
//2. Define Sentinel-2 Image Collection
var sentColl = ee.ImageCollection('COPERNICUS/S2_SR_HARMONIZED')
  .filterDate('2019-06-01', '2019-08-31')
  .filterMetadata('CLOUDY_PIXEL_PERCENTAGE', 'less_than', 10)
  .filterBounds(AOI)
  //.select(['B2', 'B3', 'B4', 'B8'])
  .map(maskS2clouds);

print(sentColl);

//4. Compute the median in each band and each pixel and then select RGBI bands. Band names are B2_Median, B3_Median etc.
var imgMed = sentColl.reduce(ee.Reducer.median())
  .select('B2_median', 'B3_median', 'B4_median', 'B8_median');
//5. Output image. Add it to map.
var VisualizeP = {
  bands: ['B2_median', 'B3_median', 'B4_median'],
  min: 0.012,
  max: 0.145,
  gamma: 1.30,
};
//Map.addLayer(imgMed,VisualizeP);
Map.centerObject(AOI, 10);

//Clip image
var NS_Sent_2019 = imgMed.clip(AOI)
Map.addLayer(NS_Sent_2019, VisualizeP);
//6. Export image 
Export.image.toDrive({
  image: imgMed,
  description: 'Y2019',
  scale: 5,
  region: AOI,
  maxPixels: 16792443500
})

1 Answer 1

0

You would typically use an ee.Filter.calendarRange(). One option is to start by quickly filter down the images to the years you're interested in, using a regular filterDate(), then apply the calander range filter.

ee.ImageCollection('COPERNICUS/S2_SR_HARMONIZED')
  .filterDate('2020-06-01', '2023-09-01')
  .filter(ee.Filter.calendarRange(6, 8, 'month'))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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