0

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?

https://code.earthengine.google.com/?scriptPath=users%2Flaraemsinghoff%2FStart%3ANDRS

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

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

Screenshot of NDRS calculation (Huo, L.; Persson, H. J.; Lindberg, E: (2021): Early detection of forest stress from European spruce bark beetle attack, and a new vegetation index: Normalized distance red & SWIR (NDRS). In: Remote Sensing of Environment 255 (2021) 112240) (

CODE:

Map.centerObject (geometry)

//Cloudfiltering
var s2 = Images
.filterMetadata('CLOUDY_PIXEL_PERCENTAGE', 'less_than', 10)
.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);
  var mask = (veg.neq (1))
  .or (soil.neq (1));
return image.updateMask (mask);}
var s2 = s2.map(fieldpixel)

//Mask Clouds
function masks2clouds(image) {
  var qa = image.select ('QA60');
  
  var cloudBitMask = 1 << 10;
  var cirrusBitMask= 1 << 10;
  
  var mask = qa.bitwiseAnd(cloudBitMask).eq(0)
    .and(qa.bitwiseAnd(cirrusBitMask).eq(0));
  
   return image.updateMask (mask); }
   

   
   //DRS
   var addDRS = function(image) {
       var DRS = image.expression('sqrt (((RED)*(RED)) + ((SWIR)*(SWIR)))',
       {'SWIR': image.select ('B11').divide(10000),
       'RED': image.select ('B4').divide(10000).rename('DRS'),
  });
       return image.addBands(DRS);
       
     };
     
  var s2 = s2.map (addDRS);
print (s2)
     
  var DRS = s2.select(['DRS']);
   var DRSmed = DRS.median();
   var pal = ['black', 'red', 'orange', 'yellow', 'lightgreen', 'green'];
  
   Map.addLayer(
     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'];
  
   Map.addLayer(
     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'];
  
   Map.addLayer(
     NDRSmed.clip(geometry),
     {min: 0, max:1, palette: pal},
     'NDRS')


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

1 Answer 1

2

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'))
3
  • 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" ?
    – L.J.E.
    Commented Jan 22, 2022 at 16:55
  • Yes, return statement is probably missing.
    – Padmanabha
    Commented Jan 23, 2022 at 18:05
  • @L.J.E. kindly accept the answer if it solved your problem.
    – Padmanabha
    Commented Jul 28, 2023 at 6:53

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.