0

I am trying to stack a 3 band image (2 NDVI bands and 1 MDPI band). There is some error when I am trying to visualise the MDPI band (which is appearing as masked in the Inspector) and hence the stacked image is also not appearing. Where am I going wrong?

var sent2_1=ee.ImageCollection("COPERNICUS/S2")
           .filterBounds(roi)
           .filterDate('2019-11-15','2019-11-17')
           .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 40))
           .mean();

var sent2_2=ee.ImageCollection("COPERNICUS/S2")
           .filterBounds(roi)
           .filterDate('2019-01-10','2019-01-19')
           .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 40))
           .mean();

Map.addLayer(roi); 
print(sent2_2,'sent2');       
Map.addLayer(sent2_2,{min:0,max:3000,bands:['B8','B4','B3']},'sent2');
//Map.centerObject(roi,13);
           
var sent1=ee.ImageCollection('COPERNICUS/S1_GRD')
          .filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VV'))
          .filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VH'))
          .filter(ee.Filter.eq('instrumentMode', 'IW'))
          .filterDate('2020-03-09','2020-03-10')
          .filterBounds(roi)
          .mean();
 
print(sent1,'sent1');       
Map.addLayer(sent1,{min: [-25, -20, -25], max: [0, 10, 0]},'SAR');

var ndvi=function(image){
  var ndvi_2_2=image.normalizedDifference(['B8', 'B4']).rename('NDVI');
  return image.addBands(ndvi_2_2);
};

var ndvi_1 = ndvi(sent2_1);
print(ndvi_1,'ndvi_1');

var ndvi_2 = ndvi(sent2_2);
print(ndvi_2,'ndvi_2');



var im2 = ndvi_1.select('NDVI');
var im1 = ndvi_2.select('NDVI');

var mpdi_fun=function(image){
  var mpdi=image.normalizedDifference(['VV', 'VH']).rename('MPDI');
  return image.addBands(mpdi);
};

var mpdi = mpdi_fun(sent1);
print(mpdi,'mpdi');

var mpdi_1=mpdi.select('MDPI')
print(mpdi_1,'mpdi_only')
Map.addLayer(mpdi_1,{min:-1, max:1},'MPDI')

var stack=im1.addBands(im2).addBands(mpdi.select('MPDI'));
Map.addLayer(stack,{max:1,min:-1},'stack');
print(stack,'stack');

enter image description here

1 Answer 1

0

I think there is a typo in your .select() part:

var mpdi_1=mpdi.select('MPDI') // note how I changed from MPDI to MDPI 

It should be exactly the same as how you wrote it in the .rename() of your mpdi_fun

2
  • Thanks for pointing out another mistake, but my doubt is still not cleared.
    – susanee_28
    Commented Nov 24, 2020 at 7:52
  • Then you should ask a new question with the updated script (and perhaps provide the geometry etc.). This will definitely increases your chances of somebody helping you out
    – Jobbo90
    Commented Nov 26, 2020 at 10:05

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.