I am trying to resample a Sentinel 2A ImageCollection in Google Earth Engine using the bicubic method. However, the resulted map is weird. I am using the folloiwng code. I apprecite if somebody help me to fix this issue:
In the following code, I define an area of interest (aoi) and a fucntion to get Sentinel 2A images for the aoi and a specific date. The function also clip and mosaic the ImageCollectoin. The bicubic method is used to resample the ImageCollection.
/**
* Function to mask clouds using the Sentinel-2 QA band
* @param {ee.Image} image Sentinel-2 image
* @return {ee.Image} cloud masked Sentinel-2 image
*/
function maskS2clouds(image) {
var qa = image.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 image.updateMask(mask).divide(10000);
}
var aoi =
/* color: #98ff00 */
/* displayProperties: [
{
"type": "rectangle"
}
] */
ee.Geometry.Polygon(
[[[-82.14606816037433, 42.900619674967885],
[-82.14606816037433, 42.48476153151389],
[-81.48963505490558, 42.48476153151389],
[-81.48963505490558, 42.900619674967885]]], null, false);
// Show aoi on map
Map.addLayer(aoi, {color: 'yellow'});
// Funcion to clip the sentinel bands
function clipping(im){
return im.clip(aoi)
}
// Function to get Sentinel 2A images for an aoi and specific date
function getSentinel2WithinDateRange(start,end,aoi){
var sentinel2 = ee.ImageCollection('COPERNICUS/S2_SR_HARMONIZED')
.filterBounds(aoi)
.filterDate(start, end)
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20))
.map(maskS2clouds);
return sentinel2.map(clipping).mosaic()
}
var date_start = '2024-05-29'
var date_end = '2024-06-30'
var collections = getSentinel2WithinDateRange(date_start, date_end,aoi)
print('Collection info', collections.getInfo())
var visualization = {
min: 0.0,
max: 0.3,
bands: ['B4', 'B3', 'B2'],
};
Map.centerObject(aoi)
Map.addLayer(collections, visualization, 'RGB');
// Resample the collection using bicubic method
var resampled = collections.resample('bicubic')
print ('resample', resampled.getInfo())
var visualization = {
min: 0.0,
max: 0.3,
bands: ['B4', 'B3', 'B2'],
};
// Display the resampled images
Map.addLayer(resampled,visualization);
I posted the question in https://gis.stackexchange.com/ and got the solution. Please see the following link for the solution: