I am a beginner in learning about GEE. I am now calculating sediment using Sentinel 2a satellite images in GEE, but I encountered an issue as follows:
NDSSI Mosaic: Layer error: ImageCollection.mosaic: Error in map(ID=null): Date: Parameter 'value' is required.
Below is the code I have:
// Display catchment boundary
Map.addLayer(boundary, {}, 'Boundary');
// Import the global surface water layer
var gsw = ee.Image("JRC/GSW1_3/GlobalSurfaceWater");
// Select the 'max_extent' band
var water = gsw.select('max_extent').clip(boundary);
// Keep the water areas only (1)
var masked = water.updateMask(water);
// finally masking out 0 values and retain only water areas (1)
var masked = water.selfMask();
Map.addLayer(masked, {}, 'Water');
//////
var masks2a = function (image) {
var qa = image.select('QA60');
var cloudBitMask = 1 << 10;
var cirrusBitMask = 1 << 11;
var mask = qa.bitwiseAnd(cloudBitMask).eq(0)
.and(qa.bitwiseAnd(cirrusBitMask).eq(0));
return image.updateMask(mask).divide(10000);
};
// Function to calculate NDSSI and add time as a band.
var addVariables = function(image) {
// Get the timestamp and convert it to a date.
var timestamp = ee.Number(image.get('system:time_start'));
var date = ee.Date(timestamp);
var yearStart = ee.Date.fromYMD(date.get('year'), 1, 1);
var fractionalYear = date.difference(yearStart, 'day').divide(365);
// Calculate NDSSI.
var ndssi = image.normalizedDifference(['B2', 'B8']).rename('NDSSI');
// Add NDSSI and fractional year as bands.
return image.addBands(ndssi)
.addBands(ee.Image(fractionalYear).rename('fractional_year').toFloat());
};
var filtermasks2a = ee.ImageCollection('COPERNICUS/S2')
.filterBounds(boundary)
.filterDate('2020-01-01', '2023-10-30')
// Pre-filter to get less cloudy granules.
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20))
.map(masks2a)
.map(addVariables)
// Display RGB parameters
var rgb = filtermasks2a.select('B4', 'B3','B2');
// Plot a time series of NDSSI at a single location.
Map.centerObject(boundary, 15);
// Load and define a continuous palette
var palettes = require('users/gena/packages:palettes');
// Choose and define NDSSI display palette
var palette = palettes.colorbrewer.RdBu[10];
var viz = {min: -1, max: 1, palette: palette};
// Display the NDSSI map
Map.addLayer(filtermasks2a.select('NDSSI'), viz, 'NDSSI Mosaic');
Is there a solution?