Google Earth Engine Explorer – Add Sentinel-2 Image by Specific ID

google-earth-engine-explorerndvisentinel-2

I'm new at Google Earth Engine and Javascript.

I am using the graphical user interface of Google Earth Engine (Explorer) to obtain NDVI using sentinel 2. My study site is somewhere in Peru with an id:

S2A_MSIL1C_20180110T150701_N0206_R039_T18KYG_20180110T162736.SAFE

However, the format required is:

COPERNICUS/S2/20151128T002653_20151128T102149_T56MNN

and so I attempted to truncate my id using this code:

var image = ee.Image('COPERNICUS/S2/20180110T150701_20180110T162736_T18KYG');

But I get in response: Image.load:

Image asset 'COPERNICUS/S2/20180110T150701_20180110T162736_T18KYG' not found.

My complete code is:

//  image

var image = ee.Image('COPERNICUS/S2/20180110T150701_20180110T162736_T18KYG');


// Visualization parameters 

var visParams = {bands: ['B8', 'B4', 'B3'], max: 3048, gamma: 1};
var visParams_ndvi = {min: -0.2, max: 0.8, palette: 'FFFFFF, CE7E45, DF923D, F1B555, FCD163, 99B718, 74A901, 66A000, 529400,' +
    '3E8601, 207401, 056201, 004C00, 023B01, 012E01, 011D01, 011301'};

// Calculate NDVI

var image_ndvi = image.normalizedDifference(['B8','B4']);


// Map results

Map.centerObject(image,9)
Map.addLayer(image,visParams,'Sentinel-2 False Color Infrared')
Map.addLayer(image_ndvi,visParams_ndvi,'Sentinel-2 NDVI')

Best Answer

ID is different, is COPERNICUS/S2/20180110T150701_20180110T150702_T18KYG. But, how to get it? Filter with date and tile. Check:

var imageCollection = ee.ImageCollection("COPERNICUS/S2");

var image = ee.Image(imageCollection.filterDate('2018-01-10','2018-01-11').filterMetadata('MGRS_TILE','equals','18KYG').first());

print(image);

Result:

Image COPERNICUS/S2/20180110T150701_20180110T150702_T18KYG (16 bands)

type: Image id: COPERNICUS/S2/20180110T150701_20180110T150702_T18KYG

version: 1515717142204526 bands: List (16 elements) properties: Object

(62 properties)

Link to full code: https://code.earthengine.google.com/fbebf04d399497c5d3456a7f7981011b