I want to classify water pixels with Sentinel-1 in Google Earth Engine, and I'm using this code I found here: https://mbonnema.github.io/GoogleEarthEngine/07-SAR-Water-Classification/
However, in my case, I observed that the image collection that I print, and the dates on my interactive map, are not the same. Why does this happen?
For example, in my collection the first two images are on 2 and 9-11-2017, and in the graph the date of 3-11-2017, also appears.
var vuursteentocht = ee.Geometry.Polygon([[[5.532513953154625,52.52616495848131],
[5.502301550810875,52.45759977830388], [5.581952429717125,52.44588284288133],
[5.617657996123375,52.51613770643291] , [5.532513953154625,52.52616495848131]]]);
Map.addLayer(vuursteentocht, {}, 'ROI')
Map.centerObject(vuursteentocht, 8)
var collectionVV_desc = ee.ImageCollection('COPERNICUS/S1_GRD')
.filter(ee.Filter.eq('instrumentMode', 'IW'))
.filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VV'))
.filter(ee.Filter.eq('orbitProperties_pass', 'DESCENDING'))
.filterBounds(vuursteentocht)
.filterDate("2017-10-30", "2018-02-21")
print(collectionVV_desc);
var classifyWater = function(image) {
var vv = image.select('VV')
var water = vv.lt(-12).rename('Water') //keep water pixels below that threshold
water = water.updateMask(water)
return image.addBands(water) //Return image with added classified water band
}
//Map classification across sentinel-1 collection and print to console to inspect
collectionVV_desc = collectionVV_desc.map(classifyWater)
print(collectionVV_desc)
//Make time series of water pixels within region
var ClassChart = ui.Chart.image.series({ //
imageCollection: collectionVV_desc.select('Water'),
region: vuursteentocht,
reducer: ee.Reducer.sum(), //sum of water pixels
scale: 10,
})
.setOptions({
title: 'Water Pixels',
hAxis: {'title': 'Date'},
vAxis: {'title': 'Number of Water Pixels'},
lineWidth: 2
})
//Set the postion of the chart and add it to the map
ClassChart.style().set({
position: 'bottom-right',
width: '500px',
height: '300px'
});
Map.add(ClassChart)
// Create a label on the map.
var label = ui.Label('Click a point on the chart to show the image for that date.');
Map.add(label);
//Create callback function that adds image to the map corresponding with clicked data point on //chart
ClassChart.onClick(function(xValue, yValue, seriesName) {
if (!xValue) return; // Selection was cleared.
// Show the image for the clicked date.
var equalDate = ee.Filter.equals('system:time_start', xValue);
//Find image coresponding with clicked data and clip water classification to roi
var classification =
ee.Image(collectionVV_desc.filter(equalDate).first()).clip(vuursteentocht).select('Water');
var SARimage = ee.Image(collectionVV_desc.filter(equalDate).first());
//Make map layer based on SAR image, reset the map layers, and add this new layer
var S1Layer = ui.Map.Layer(SARimage, {
bands: ['VV'],
max: 0,
min: -20
});
Map.layers().reset([S1Layer]);
var visParams = {
min: 0,
max: 1,
palette: ['#FFFFFF','#0000FF']
}
//Add water classification on top of SAR image
Map.addLayer(classification,visParams,'Water')
// Show a label with the date on the map.
label.setValue((new Date(xValue)).toUTCString());
});