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:
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:
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:
Think about the scale you will need to use using reduce regions, as your images are on 0.25 arc degrees.
Link script