I am writing a script to extract the time series of soil moisture values from the SMAP soil moisture data using a point shapefile in the Google Earth engine.
However in the results I get only 12 elements while I am looking for values from 2006-01-01 to 2016-12-31.
Can someone tell me where the problem is with my code and in addition to that I want to extract the soil moisture information with the date (months and years) and export it in CSV format to drive?
Below code, I am working
var point = ee.Geometry.Point([-8.620027,31.363085]);
// Create a chart for SoilMoi100_200cm_inst trend in point 1.
var dataset = ee.ImageCollection('NASA/GLDAS/V021/NOAH/G025/T3H')
.filterBounds(point)
.filterDate('2006-01-01', '2016-12-31')
.select('SoilMoi100_200cm_inst');
var months = ee.List.sequence(1, 12);
var start_year = 2006;
var start_date = '2006-01-01';
var end_year = 2016;
var end_date = '2016-12-31';
// map over the months
var byMonthYear = ee.ImageCollection.fromImages(
months.map(function (m) {
// cast to an ee.Number()
m = ee.Number(m);
// get the start and end date by adding the amount of months to the start_date
var start = ee.Date(start_date).advance(m.subtract(1), 'month'); // Starting date
var end = ee.Date(end_date).advance(m, 'month'); // Ending date
// make a mean composite per month
var d = dataset.filterDate(start, end).mean()
.set('month', start.format('MM')).set('year', start.format('YYYY'))
.set('system:time_start', start.millis()).set('system:time_end', end.millis());
// get the point information (reducer.first is sufficient, as you already made a mean composite per month)
var pointMean = d.reduceRegion(ee.Reducer.first(), point, dataset.first().projection().nominalScale());
// set the dictionary as property and cast to an ee.Image, as setMulti returns an ee.Element.
return ee.Image(d.setMulti(pointMean));
}));
// print the collection, point information
print('ImageCollection mean composites',byMonthYear);
print('mean point values', byMonthYear.aggregate_array('SoilMoi100_200cm_inst'));
Best Answer
To get the mean values per year and month you could use a nested loop for years and months and return a feature containing information on the date and mean soil moisture. See an example here: https://code.earthengine.google.com/2fc42a761782e5f49927bdae1b5387dc