I want to generate a raster for each year, where the pixel value refers to the number of days per year where there is some snow on the ground. In this example I want to create this raster for Germany and the year range is [2015,2017], which means I will get 2 images. I use NDSI for this. The code I wrote is below; but I feel like the number of days is underestimated. At some areas where I expect to have > 90 days of snow, I have about 60. I would then like to get the average number of days across Germany, i.e. for each year, take the number of days with snow from each pixel and average it.
Any solution?
var startDate = ee.Date.fromYMD(2020, 1, 1)
var endDate = ee.Date.fromYMD(2021, 1, 1) // Exclusive
var dataset = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017');
var aoi = dataset.filter(ee.Filter.eq('country_na', 'Germany'));
var collection = ee.ImageCollection('MODIS/006/MOD10A1')
.filterBounds(aoi)
print(aoi)
var numberOfYears = endDate.difference(startDate, 'years').floor()
print(numberOfYears)
var daysSnowCollection = ee.ImageCollection(
ee.List.sequence(0, numberOfYears.subtract(1))
.map(daysSnow)
)
print(daysSnowCollection)
Map.addLayer(daysSnowCollection.first(), {min: 0, max: 100, palette: 'red,yellow,blue,white'}, 'First image')
//var output = daysSnowCollection.reduce(ee.Reducer.mean())
//print(output)
function daysSnow(yearOffset) {
var date = startDate.advance(yearOffset, 'years')
return collection
.select('NDSI_Snow_Cover')
.filterDate(date, date.advance(1, 'years'))
.map(function (image) {
var snow = image.gte(30)
return image.updateMask(snow)
})
.count()
.unmask(0)
.clip(aoi)
.set('date', date.format('yyyy-MM-dd'))
}