1

I want to get a band mean across images from NDMI data but I don't find the correct pattern or the right script to print it in the console. How can I do this?

My script here:

// CALCULO DE INDICES DE HUMEDAD DE DIFERENCIA NORMALIZADA EN EARTH ENGINE


// Coleccion Sentinel 2 nivel 2
var ColeccionSentinel = ee.ImageCollection("COPERNICUS/S2_SR")
  .filterDate ('2022-06-01' ,'2022-06-30') //Definir fecha
  .filterBounds (geometry) //Definir geometria
  .filterMetadata ('CLOUDY_PIXEL_PERCENTAGE', 'Less_Than', 20);
var Moisture = ee.Image(ColeccionSentinel.mean());

  
// NDMI (Normalized Difference Moisture Index)
var NDMI = Moisture.expression ('float ((NIR - SWIR) / (NIR + SWIR))',{
    'NIR': Moisture.select ('B8'),  
    'SWIR': Moisture.select ('B11')});

 
// Simbologia comun para los indices
var Simbologia = {max: 1.0,
    min: -0.5,
    'palette': ['1A3678', '2955BC', '5699FF','8DBAE9', 'ACD1FF', 'CAEBFF', 'E5F9FF',
    'FDFFB4', 'FFE6A2', 'FFC969', 'FFA12D', 'FF7C1F', 'CA531A', 'FF0000', 'AB0000']};

Map.centerObject (geometry, 15); //Ajustar zoom

// Representacion de indice
Map.addLayer (NDMI, Simbologia, 'NDMI',1);
1
  • Try with max: 0.27, min: -0.2.
    – xunilk
    Commented Jul 11, 2022 at 13:53

1 Answer 1

0

Here is a simple extended version of your code.

// Coleccion Sentinel 2 nivel 2
var ColeccionSentinel = ee.ImageCollection("COPERNICUS/S2_SR")
.filterDate ('2022-06-01' ,'2022-06-30') //Definir fecha
.filterBounds (geometry) //Definir geometria
.filterMetadata ('CLOUDY_PIXEL_PERCENTAGE', 'Less_Than', 20);
var Moisture = ee.Image(ColeccionSentinel.mean());


// NDMI (Normalized Difference Moisture Index)
var NDMI = Moisture.expression ('float ((NIR - SWIR) / (NIR + SWIR))',{
'NIR': Moisture.select ('B8'),  
'SWIR': Moisture.select ('B11')});


// Simbologia comun para los indices
var Simbologia = {max: 1.0,
min: -0.5,
'palette': ['1A3678', '2955BC', '5699FF','8DBAE9', 'ACD1FF', 'CAEBFF', 
'E5F9FF','FDFFB4', 'FFE6A2', 'FFC969', 'FFA12D', 'FF7C1F', 'CA531A', 
'FF0000', 'AB0000']};

Map.centerObject (geometry, 15); //Ajustar zoom

// Representacion de indice
Map.addLayer (NDMI, Simbologia, 'NDMI',1);

var bandmeans= function(img){return img.reduceRegion({
reducer: ee.Reducer.mean(),
geometry: geometry,
crs:'EPSG:4326',
scale:30
})};

var means=bandmeans(NDMI);
print(means);

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.