I am trying to save 6 years daily MODIS data in a single image with multi bands.I specifically want the dates as band names.I have been tring to run this script but the page crashes or becomes unresponsive. I want the export a single multi-band image with names such as this: 2021_01_01_LST_Day_1km..
This is my script.
// use a geometry to select the study area
var geom = ee.FeatureCollection('users/payeldastidar/STATE_BUFF_WGS')
var output_name = 'LST_2002_2006'
var crs = 'EPSG:4326'
//print(geom)
// filter image collection to time period of interest
var startDate = '2002-01-01'
var stopDate = '2006-01-01'
// resulting image collection - same set of images as in the python GEE atmospheric correction code
var LST_MOD = ee.ImageCollection('MODIS/061/MOD11A1')
.filterBounds(geom)
.filterDate(startDate,stopDate)
//.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 1))
.sort('system:time_start');
var LST_Assam = LST_MOD.select('LST_Day_1km')
// convert image collection to multi-band image
var LST_Assam_band = ee.ImageCollection(LST_Assam).iterate(function(img, all){
return ee.Image(all).addBands(img)}, ee.Image().select())
LST_Assam_band = ee.Image(LST_Assam_band).multiply(0.02).float()
print(LST_Assam_band,'LST_Assam_band')
// get band names for each collection
var LST_Assam_band_names = ee.Image(LST_Assam_band).bandNames() // s1 or s2_vi1 or pl_vi1
print(LST_Assam_band_names, 'LST_Assam_band_names')
// get a list of image dates
var date_list = ee.ImageCollection(LST_Assam).toList(LST_Assam_band_names.length())
var date_list2 = date_list.map(function(img) {
return ee.Image(img).get('system:index')
//return ee.Image(img).date()
})
print(date_list, 'date_list')
print(date_list2, 'date_list2')
var bnames = ee.List([])
for (var i = 0; i < date_list2.length().getInfo(); i++) {
for (var j = 0; j < LST_Assam.length().getInfo(); j++) {
var bname = ee.String(LST_Assam.get(j)).cat(ee.String(date_list2.get(i)))
var bnames = ee.List(bnames).add(bname)
}
}
var LST_Assam_export = ee.Image(LST_Assam_band).rename(date_list2)
print(LST_Assam_export, 'LST_Assam_export')
// Export image to drive
Export.image.toDrive({
image: LST_Assam_t,
description: output_name,
scale: 1000,
maxPixels: 1e13,
crs: crs,
region: geom
});