Wednesday, 6 December 2017

time series - Getting weekly mean composite in Google Earth Engine?


I am currently working on a time-series in Google Earth Engine. Iam still quite inexperienced, especially when it comes to functions. I want to extract the mean values of Sentinel1-images for each week in a period of 7 month and aggregate them into a new Image Collection I can then further process.


So far I tried to do it for a single month:


 var testsubset = ee.FeatureCollection("users/xyz/test_subset");

//set start-dates

var images = {
'2018-02-01': getWeeklySentinelComposite('2018-02-01'),
'2018-02-08': getWeeklySentinelComposite('2018-02-08'),

'2018-02-15': getWeeklySentinelComposite('2018-02-15'),
'2018-02-22': getWeeklySentinelComposite('2018-02-22'),
'2018-03-01': getWeeklySentinelComposite('2018-03-01')
};

//function to get a weekly composite

function getWeeklySentinelComposite(date) {
var date = ee.Date(date);
// Only include the VV polarization, for consistent compositing.

var polarization = 'VV';
var sentinel1 = ee.ImageCollection('COPERNICUS/S1_GRD')
.filterBounds(testsubset)
.filterDate(date, date.advance(1, 'week'))
.filter(ee.Filter.listContains('transmitterReceiverPolarisation', polarization))
.filter(ee.Filter.eq('instrumentMode', 'IW'))
.select(polarization)
.mean();
return sentinel1;
}


I currently run into two main issues: I'am not sure how to return the images I picked and how to turn them into a new ImageCollection. Second: I get


"Invalid argument specified for ee.Date(): [object Object]"


and don't really know why (I used a similar function for another script and it worked fine)


Just to clarify, this is what I want to do with the Image Collection in the end:


//Map.addLayer(testsubset, {color:'green'}, 'Testshape', true , 0.5);

var tempTimeSeries = ui.Chart.image.series({
imageCollection: sentinel1_IC,
region: testsubset,

reducer: ee.Reducer.mean(),
scale: 200,
xProperty: 'system:time_start'
});

tempTimeSeries.setChartType('ScatterChart');
tempTimeSeries.setOptions({
title: 'VV-over-time',
vAxis: {
title: 'sigma VV'

},
lineWidth: 1,
pointSize: 4,
series: {
0: {color: 'blue'},
1: {color: 'red'},
2: {color: 'green'}
}
});


print(tempTimeSeries);

Answer



You are almost there. The fact you cannot get an imagecollection from your function now, is that you make a clientside dictionary with dates as key. Instead, first make a server side list of dates seperated a week apart:


//set a list of start dates
var startDate = '2018-02-01';
var endDate = '2018-12-31';
var weekDifference = ee.Date(startDate).advance(1, 'week').millis().subtract(ee.Date(startDate).millis());
var listMap = ee.List.sequence(ee.Date(startDate).millis(), ee.Date(endDate).millis(), weekDifference);

Once you have this, you can map over the list and return an image for every start date of a week with your function. Note that you will have to set something like a date property to every image to work with them later on. You can transform this list of image to an image collection using ee.ImageCollection.fromImages():



var sentinel1_IC = ee.ImageCollection.fromImages(listMap.map(function(dateMillis){
var date = ee.Date(dateMillis);
return getWeeklySentinelComposite(date);
}));

You can then continue with your analysis. Link script


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...