This is the code that has an error. I don´t know how to fix it.
I am trying to get the albedo values of a range of time: 2001-2018 and just of 4 months of each year, September to December.
var col = ee.ImageCollection('MODIS/006/MCD43A3')
.filter(ee.Filter.date('2001-01-01', '2018-12-31'))
.filterBounds(geometry).select('Albedo_WSA_shortwave');
// Functions to stack colletion series into image bands
var stackCollection = function(collection) {
var first = ee.Image(collection.first()).select([]);
var appendBands = function(image, previous)
{return ee.Image(previous).addBands(image);};
return ee.Image(collection.iterate(appendBands, first));};
// Function to generate mask for each Scene.
var getSceneMask = function(scene) {
var dateString = ee.Date(scene.get('system:time_start')).format('yyyy-MM-dd');
var mask = scene.select('Albedo_WSA_shortwave').gt(-9999).updateMask(ee.Image(1));
return mask.rename(dateString);};
//Stacked mask for collection
var Maskcol = stackCollection(col.map(getSceneMask));
// Generate a datelist for collection
var datelist = ee.List(Maskcol.bandNames()).map(function(date){return ee.Date(date).format('yyyy-MM-dd')});
// Stack bands and rename by date
var WSA_stacked = stackCollection(col.select('Albedo_WSA_shortwave')).multiply(0.001).rename(datelist).clip(geometry);
Map.addLayer(WSA_stacked.select(20), {min:0.0, max:400, gamma:2});
print(WSA_stacked);
print(datelist);
// Exportar datos //
Export.image.toDrive({
image: WSA_stacked.clip(geometry),
description: 'MODIS_WSA_stacked',
region: geometry,
folder: 'ejemplo',
scale: 500,
crs: 'EPSG:4326'});