1

I received this collection of ordered multiband images and would like to convert them to a single collection, adding a timestamp (system:time_end and system:time_start):

https://code.earthengine.google.com/fdc4aa75742a5b68f3d67813e1086da9

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
  • 1
    It is not fully clear what you want, an imge collection with 1 image per year (and 365 bands for each yearly image) or 1 image collection with 3650 images? I assume it is the last? Check out this answer to give you a first idea: https://gis.stackexchange.com/questions/300738/making-stack-from-many-images-in-google-earth-engine – Jobbo90 Jun 18 '21 at 06:20

1 Answers1

1

I'm sure there is a more elegant way to transfer your bands to an image collection but this is my take on it. Be aware that transferring the Day of Year to an date object like you requested didn't work yet. Instead I added seperate properties for day, month and year to the separate images.

var bandToCollection = function(collection){
// get band names
var bands =  collection.bandNames()
var dayCounter = ee.List.sequence(1, bands.size())

// build new collection with 1 image per band var newCollection = dayCounter.map(function(b){

var img = ee.Image(collection.select(ee.String(bands.get(ee.Number(b).subtract(1)))))

var id = img.propertyNames() var prop = ee.String(img.get('system:id')) // get ID var year = ee.Number(ee.String(prop.split('/').get(2)).split('-').get(4)) // extract the year value

var dateTest = ee.Date.parse('D',ee.Number.parse(ee.Number(b).format('%03d'))) // also yse the day counter to set the Day Of Year

// something goes wrong with converting the number to a date, so left this out // at the moment var finalDate = ee.Date.fromYMD(ee.Number.parse(year), dateTest.get('month'), dateTest.get('day')).millis()

// return img.set('system:time_end', year) return(img.set('year', year).set('doy', b).set('month', dateTest.get('month')).set('day', dateTest.get('day'))) })

return newCollection }

full working example: https://code.earthengine.google.com/57c22e93c861c9a02c2eb62d620ed897

Jobbo90
  • 2,073
  • 1
  • 8
  • 16