0

I've wrote this code but it makes error about min and max image?

var modis = ee.ImageCollection("MODIS/006/MOD13Q1")
.filterBounds(geometry)
.filterDate("2000-01-01","2001-01-01")
.select("NDVI");

print(modis);

var mod13 = modis.map(function(img){
  return img.multiply(0.0001)
  .copyProperties(img,['system:time_start','system:time_end']);
});

print(mod13);

var vci = mod13.map(function(img){
 var id = img.id();
 var min =  img.reduceRegion(ee.Reducer.min(),geometry,250);
 var max = img.reduceRegion(ee.Reducer.max(),geometry,250);
 return img.expression(
   "(NDVI-min)/(max-min)",{
     "NDVI" : img,
     "max" : max,
     "min" : min
   }).copyProperties(img,['system:time_start','system:time_end']);
});
1
  • it's error message: ImageCollection (Error) Error in map(ID=2000_03_05): Image.subtract, argument 'image2': Invalid type. Expected: Image<unknown bands>. Actual: Dictionary<Float>. Commented Nov 11, 2018 at 7:40

1 Answer 1

1

img.reduceRegion returns a dictionary with the result of the reduction in each band, so you have to get the result for the band that you are interested in, which I understand is NDVI.

var modis = ee.ImageCollection("MODIS/006/MOD13Q1")
//.filterBounds(geometry) // no need to filter by bounds in MODIS
.filterDate("2000-01-01","2001-01-01")
.select("NDVI");

print(modis);

var mod13 = modis.map(function(img){
  return img.multiply(0.0001)
  .copyProperties(img,['system:time_start','system:time_end']);
});

print(mod13);

var vci = mod13.map(function(img){
 var id = img.id();
 var min =  img.reduceRegion(ee.Reducer.min(), geometry,250).get('NDVI');
 var max = img.reduceRegion(ee.Reducer.max(), geometry,250).get('NDVI');
 return img.expression(
   "(NDVI-min)/(max-min)",{
     "NDVI" : img,
     "max" : ee.Number(max),
     "min" : ee.Number(min)
   }).copyProperties(img,['system:time_start','system:time_end']);
});
print(vci)
3
  • thanks a lot. your code is true but .copyproperties() must replaced by .rename(id). Commented Nov 12, 2018 at 10:39
  • why is that? If you do that you'll loose the timestamp of the image, and rename the NDVI band with the ID of the image.. That is not what you have asked. I just answer your question Commented Nov 12, 2018 at 11:03
  • because when I was save its result with export.image it returned error, after that I replaced .id instead of .copyproperties(), then it resolved. Commented Nov 13, 2018 at 7:23

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.