# Google Earth Engine calculation of new Index NDRS

I want to calclulate this index in GEE. I managed to calculate the DRS, but I do not understand how to calculate the NDRS. Can you help?

Equations: DRS = sqrt ((RED)²+(SWIR)²)

And: NDRS = (DRS-DRSmin)/(DRSmay-DRSmin)

CODE:

``````Map.centerObject (geometry)

//Cloudfiltering
var s2 = Images
.filterDate ('2018-02-01', '2018-10-01')
.filterBounds (geometry);

//Pixel
function fieldpixel (image){
var scl = image.select ('SCL');
var veg = scl.eq (4);
var soil = scl.eq (5);
.or (soil.neq (1));
var s2 = s2.map(fieldpixel)

var qa = image.select ('QA60');

var cloudBitMask = 1 << 10;

//DRS
var DRS = image.expression('sqrt (((RED)*(RED)) + ((SWIR)*(SWIR)))',
{'SWIR': image.select ('B11').divide(10000),
'RED': image.select ('B4').divide(10000).rename('DRS'),
});

};

print (s2)

var DRS = s2.select(['DRS']);
var DRSmed = DRS.median();
var pal = ['black', 'red', 'orange', 'yellow', 'lightgreen', 'green'];

DRSmed.clip(geometry),
{min: 0, max:1, palette: pal},
'DRS')

// NDRS
// = ((DRS- DRSmin)/(DRSmax-DRSmin))
``````

EDIT:

So. I experimented with the code for VCI. It worked and an image appeared. Is this the right way?

``````var DRS = s2.select(['DRS']);
var DRSmed = DRS.median();
var DRSmin = DRS.min()
var DRSmax = DRS.max()
var pal = ['black', 'red', 'orange', 'yellow', 'lightgreen', 'green'];

DRSmed.clip(geometry),
{min: 0, max:1, palette: pal},
'DRS')

var getNDRS = function(image){
var NDRS = image.subtract(DRSmin).divide(DRSmax.subtract(DRSmin))

// return image.addBands(vci) // both output togther
return image.addBands(NDRS) // only the vci
}

var s2 = s2.map (getNDRS);
print (s2)

var NDRS = s2.select(['DRS_1']);
var NDRSmed = NDRS.median();

var pal = ['black', 'red', 'orange', 'yellow', 'lightgreen', 'green'];

NDRSmed.clip(geometry),
{min: 0, max:1, palette: pal},
'NDRS')

``````
• Please share the geometry as "Anyone Can Read". It is creating error Commented Jan 19, 2022 at 16:20
• I hope now it will work Commented Jan 19, 2022 at 16:24
• Unfortunately, it's still not working. Commented Jan 19, 2022 at 16:25
• I do not know why that is why I add the code here Commented Jan 19, 2022 at 16:32
• The error it's showing up is similar to this: stackoverflow.com/questions/51036103/… Commented Jan 19, 2022 at 16:34

You can try out this using the `unitScale()` function

``````      var minmaxs2= function(image){image.reduceRegion({
reducer: ee.Reducer.minMax(),
geometry: geometry,
scale:10,
maxPixels: 10e9
})
};
var news2 = s2.map(minmaxs2)
var ndrs = news2.select('DRS')
.unitScale(news2.get('DRS_min'),news2.get('DRS_max'))
``````
• Thanks for this. I think it will be work. But I tried to add it, and a error occured: "User-defined methods must return a value". Maybe there is a lacks a "return" ? Commented Jan 22, 2022 at 16:55
• Yes, return statement is probably missing. Commented Jan 23, 2022 at 18:05
• @L.J.E. kindly accept the answer if it solved your problem. Commented Jul 28, 2023 at 6:53