0

I was trying to count the number of pixels that are inside my ROI and differs quite a lot one image from the other.

For MODIS image I get a total of 265533 pixels (500x500) spatial resolution and for PERSIANN-CDR I get 75 in total (27000*27000). The total area for both are completely different. Does anyone know why?

var image1 = ee.Image('MODIS/006/MOD16A2/2001_11_17').select('ET');

var c = image1.reduceRegion({
  reducer: ee.Reducer.count(),
  geometry: geometry
  });

print(c);

var image2 = ee.Image('NOAA/PERSIANN-CDR/20011101').select('precipitation');

var c2 = image2.reduceRegion({
  reducer: ee.Reducer.count(),
  geometry: geometry
  });

print(c2);
2

I think this is because you are not specifying the scale argument. You need to use it to force EE to do it at the scale you want, look at this very sikilar thread: https://groups.google.com/d/msg/google-earth-engine-developers/vI6grpVRLCs/rTNFyTImCAAJ

If you indicate the scale, you get a quite similar rsult for the area:

var image1 = ee.Image('MODIS/006/MOD16A2/2001_11_17').select('ET');
var image2 = ee.Image('NOAA/PERSIANN-CDR/20011101').select('precipitation');

var geometry = /* color: #d63000 */ee.Geometry.Polygon(
    [[[-105.325, 37.679], [-105.356, 37.333], [-104.331, 37.4028],  [-104.328, 37.694]]]);

var c = image1.reduceRegion({
  reducer: ee.Reducer.count(),
  geometry: geometry,
  scale: 500
  });

var c2 = image2.reduceRegion({
  reducer: ee.Reducer.count(),
  geometry: geometry,
  scale: 27000
  });

print(c);
print(c2);
print(ee.Number(c.get("ET")).multiply(500).multiply(500));
print(ee.Number(c2.get("precipitation")).multiply(25000).multiply(25000));

For this random polygon, this gives:

  • MODIS: 2699000000
  • NOAA : 2500000000

Note: this might be a rough estimate however, as pixel area is not necessarily constant, depending on the projection used! One way to tweak this would be to use ee.Image.PixelArea(), or just `area(), see:

var im_area_1 = ee.Image.pixelArea().reproject(image1.projection())

var sum_area_1 = im_area_1.reduceRegion({
  reducer: ee.Reducer.sum(),
  geometry: geometry
  });

print(sum_area_1.get("area"), "sum_area_1")
print(geometry.area(), "true ")

Both numbers are very close, at 3153188563, but very different from the counts based on the first method!

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.