I am new to Google Earth Engine (and do not have a programming background for that matter) and am trying to export a csv to google drive, containing information from a raster brick. The raster brick is derived from a time-series image collection, after mosaicking by day and iterating an NDMI calculation for each image in the collection of mosaicked images.
The script appears to run without any errors, but when running the export task I get the error message:
Error: Collection.iterate: Error in map(ID=0): String: Parameter 'input' is required. (Error code: 3)
I'm guessing it refers to either the mosaicking or the ndmi iterate function, but so far I have not been able to find a solution. Can anyone point me to the direction of what exactly is causing this error and how to resolve it?
This is the script I am using:
//----------------------------------------------------------------
//Input variables
//---------------------------------------------------------------
var aoi = 'thestudyareaasset' //Study area
var export_folder='theexportfolder' //Export folder
var input_Startstr=ee.String('1990-01-01'); //start date
var input_Finishstr=ee.String('2023-01-01'); //end date
var ndmi_ind=['TRUE'] //Index
// Add study area boundary to mapp
var studyarea=ee.FeatureCollection(ee.String(aoi));
Map.addLayer(studyarea, {}, 'USRB extent', false);
Map.centerObject(studyarea, 8);
// -------------------------------------------------------------
// Load landsat images
//--------------------------------------------------------------
// Dictionary with the Landsat missions and their bands
var sensorBands={
'L9':['SR_B2','SR_B3','SR_B4','SR_B5','SR_B6','SR_B7','QA_PIXEL'],
'L8':['SR_B2','SR_B3','SR_B4','SR_B5','SR_B6','SR_B7','QA_PIXEL'],
//'L7':['SR_B1','SR_B2','SR_B3','SR_B4','SR_B5','SR_B7','QA_PIXEL'],
'L5':['SR_B1','SR_B2','SR_B3','SR_B4','SR_B5','SR_B7','QA_PIXEL']
} ;
var bandNames=['Blue','Green', 'Red', 'nir','swir','swir2','QA_PIXEL'];
// Image selection criteria
var start = ee.Date(input_Startstr);
var finish = ee.Date(input_Finishstr);
var meta_cloudcover = 70;
// Get image collection
var studyareaCol= ee.ImageCollection('LANDSAT/LT05/C02/T1_L2')
.select(sensorBands['L5'], bandNamesLandsat)
//.merge(ee.ImageCollection('LANDSAT/LE07/C02/T1_L2')
//.select(sensorBands['L7'], bandNamesLandsat))
.merge(ee.ImageCollection('LANDSAT/LC08/C02/T1_L2')
.select(sensorBands['L8'], bandNamesLandsat))
.merge(ee.ImageCollection('LANDSAT/LC09/C02/T1_L2')
.select(sensorBands['L9'], bandNamesLandsat))
.sort("system:time_start")
.filterDate(start,finish)
.filterBounds(studyarea)
.filter(ee.Filter.lt('CLOUD_COVER', meta_cloudcover))
print(studyareaCol)
//-----------------------------------------------------------------------
// Cloud masking and scale factors
//----------------------------------------------------------------------
// Cloud masking function
function cloudShadowMask(image) {
// Select the correct bits
// (bit 3 is cloud, bit 4 is cloud shadow)
var cloudShadowBitMask = (1 << 4);
var cloudsBitMask = (1 << 3);
// Select the pixel QA band that the data is stored in
var qa = image.select('QA_PIXEL');
// Set both bit flags equal to zero, indicating clear conditions
var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0)
.and(qa.bitwiseAnd(cloudsBitMask).eq(0));
return ee.Image(image).updateMask(mask);
}
// Scaling factors function
function applyScaleFactors(image) {
var opticalBands=image.select(bandNamesLandsat).multiply(0.0000275).add(-0.2);
var qaBand=image.select('QA_PIXEL')
return image.addBands(opticalBands, null, true)
.addBands(qaBand, null, true)
}
// apply functions
var studyareaCol_preprocessed=studyareaCol.map(cloudShadowMask)
.map(applyScaleFactors)
//-----------------------------------------------------------------------
//Mosaick images by day
//-----------------------------------------------------------------------
// Create list with dates
var days=finish.difference(start,'day');
var Dates=ee.List.sequence(0,days.subtract(1)).map(function(Day){
return start.advance(Day, 'day')});
//Mosaicking function
var day_mosaicking = function day_mosaicking(date, newlist) {
//cast
date=ee.Date(date);
newlist=ee.List(newlist);
//Filter collection between date and next day
var filtered=studyareaCol_preprocessed.filterDate(date,date.advance(1,'day'));
var first=filtered.first();
//Mosaic
var image=ee.Image(filtered.mosaic());
image=image.set("system:time_start",date.millis());
image=image.set('SATELLITE', first.get('SATELLITE'));
//Add mosaic to list only if collection has images
return ee.List(ee.Algorithms.If(filtered.size(),newlist.add(image),newlist))
}
//Iterate through dates to create collection of mosaicked images
var studyareaCol_mosaic=ee.ImageCollection(ee.List(Dates.iterate(day_mosaicking,
ee.List([]))))
//--------------------------------------------------------------------
//Calculate NDMI
//--------------------------------------------------------------------
//function to merge all single bands
var mergeBands=function mergeBands(image,previous) {
return ee.Image(previous).addBands(image)
};
//Calculate NDMI
if(ndmi_ind=='TRUE'){
var input_index="NDMI"
var index_bands=['nir','swir']
var NDMI=studyareaCol_mosaic
.map(function(image){
return image.normalizedDifference(index_bands)
.rename(ee.String(input_index+' ')
.cat(image.get('SATELLITE'))
.cat(' ')
.cat(ee.Date(image.get('system:time_start')).format('YYYYMMdd')))
})
.iterate(mergeBands,ee.Image([]));
var NDMI=ee.Image(NDMI).multiply(ee.Image(10000))
.round()
.toFloat()
.clip(studyarea);
//---------------------------------------------------------
// Export image collection time series
//---------------------------------------------------------
// Extracting band layer names for dates to table
var asList=NDMI.bandNames().map(function(layer) {
return ee.Feature(null,{Date: ee.String(layer)});
});
var feature_date=ee.FeatureCollection(asList)
// //Export table
Export.table.toDrive({
collection: feature_date,
description: '22Aug_Landsat_'+input_index+'_'+input_Startstr.getInfo()+
'_'+input_Finishstr.getInfo(),
folder: export_folder
})
I doublechecked the types of input the functions are using and all the variables created, to find perhaps a mismatch in type of variable vs type of input the function requires or any other inconsistencies. But as this is all new for me, I am probably missing/not recognizing something and kind of stuck in trying to resolve whatever is causing this error.