1

I have code that suppose to calculte NDVI and then to cound the number of pixels in the raster that are higher than 0.3 There is part of the code where there is function that suppose to select the band NDVI and then calculte number of pixels. for some reason now, I have gotten the following error:

Image.select: Pattern 'NDVI_mean' did not match any bands.

I have checked many times and this is the name of the band so I don't know why it says it doesn't match. Also, when I check the images in the band they do have this name: enter image description here

this is the fucntion:

var listOfImages =(byYear.toList(byYear.size()));
print(listOfImages, 'list of images');

var stats = listOfImages.map(function(img){
  var image = ee.Image(img).select('NDVI_mean');

  var c03 = image.gt(0.3).selfMask().reduceRegion({
    reducer: ee.Reducer.count(),
    geometry: geometry,
    crs: 'EPSG:4326',
    //maxPixels:1310361348,
    scale: 30,
  }).values().get(0);

  var c05 = image.gt(0.5).selfMask().reduceRegion({
    reducer: ee.Reducer.count(),
    geometry: geometry,
    crs: 'EPSG:4326',
    //maxPixels:1310361348,
    scale: 30,
  }).values().get(0);

    var c07 = image.gt(0.7).selfMask().reduceRegion({
    reducer: ee.Reducer.count(),
    geometry: geometry,
    crs: 'EPSG:4326',
    //maxPixels:1310361348,
    scale: 30,
  }).values().get(0);

  return image.set('c03', c03).set('c05', c05).set('c07', c07);
});

print(stats);

This is the full code, it's a bit long , I have gone over all of it but couldn't find the problem with the band name: https://code.earthengine.google.com/a6726d65d9cddb10aa23f7683464a386

the polygon was the city abidjan

My end goal is to be able to calculte the number of pixels in each image that are higher than 0.3

1 Answer 1

1

You script already contains the answer;

when you print(listOfImages, 'list of images'); the images sometimes don't have a result (e.g. there is no band inside the image).

When you use var image = ee.Image(img).select('NDVI_mean'); there is no ouput and your script stops. Your filter removes to many images for your script to work. So you could either change the filter values:

var filter = ndviWithCount.filter(ee.Filter.rangeContains(
          'count',max_number.multiply(0.3),max_number));  

Or you could remove the years without observations somehow.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.