I'm writing a script to extract the soil moisture content of a specific polygon. The polygon covers multiple pixels, I need a weighted average of the values corresponding to those pixels. When I execute the script, the output is 'null'. I'm relatively new to Google earth engine, and haven't been able to figure out what I've done wrong.

// which dataset + where + when
var image = ee.ImageCollection('NASA_USDA/HSL/SMAP_soil_moisture')

// select bands -> ssm = surface soil moisture (mm)
var soilmoisture = image.select('ssm');

// Take average
var meanDict = image.reduce(ee.Reducer.mean());

// Get the mean from the dictionary and print it.
var mean = meanDict.get('ssm');
print('Gemiddelde bodemvochtgehalte (mm)', mean);

Could someone help me?

Here's the link: https://code.earthengine.google.com/c37820b890bec18142baa2b475dd7dd2

  • Are you trying to get the mean value for each time step or the mean over the whole series? Mar 19, 2019 at 18:38
  • Welcome to GIS SE! We're a little different from other sites. We're a Q&A site, not a discussion forum. For questions that involve code we ask that you show us where you are stuck with your own code by including a code snippet in your question. There is an edit button beneath your question which will enable you to do that and a {} button that enables you to format any highlighted code nicely. Please check out our short tour for more about how the site works. Thanks.
    – PolyGeo
    Mar 19, 2019 at 20:25
  • Please make your asset public or add a simple drawn similar version of it if it contains private information.
    – Kuik
    Mar 19, 2019 at 22:43

1 Answer 1


To get pixel information from an image, you will have to use image.reduceRegion(s). That will return a dictionary or feature collection providing you with the pixel information of the bands of the input image. There can only be one image as input.

If you want the mean soil moisture over the whole study period defined in filterDate(), you probably best make a mean composite image of your image collection (which you confusingly call 'image') and apply reduceRegion on that image:

// Get the mean from the dictionary and print it.
var meanDict = soilmoisture.mean().reduceRegion(ee.Reducer.mean(), Zutendaal, scale);
print('Gemiddelde bodemvochtgehalte studie gebied voor het hele jaar (mm)', meanDict);

It's probably more interesting to get the mean soil moisture of each image in your study period/time. Therefore, you will have to map over the image collection and return every output dictionary as property to the image:

// Take average
var imageCollection = imageCollection.map(function(image){
  return ee.Image(image.setMulti(image.reduceRegion(ee.Reducer.mean(), Zutendaal, scale)));

You can then print a list of soil moistures. Also, I added a chart of the soil moisture inside the study area over the study period:

// Get the mean from the dictionary and print it.
var means = imageCollection.aggregate_array('ssm');
print('Gemiddelde bodemvochtgehalte voor elke afbeelding (mm)', means);
// put in a chart
print(ui.Chart.image.seriesByRegion(imageCollection, Zutendaal, ee.Reducer.mean(), 'ssm', scale));

Think about the scale you will need to use using reduce regions, as your images are on 0.25 arc degrees.

Link script

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.