[GIS] Extracting Soil moisture value using Google Earth Engine

google-earth-engine

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')
                .filterBounds(Zutendaal)
                .filterDate('2018-03-05','2019-03-06');

// 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

Best Answer

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

Related Question