I have an imageCollection where I want to create a new property called "DayOfRange" which will contain values similar to "Day of Year" except with day 1 in the middle of the year. Without going too much into details, it has to be this way so that I can make a reduction later based on this property in the metadata.

Below is the code I have tried, but it returns a list of "unknown elements" with the entire "longList" as property:

var chirpsColl = ee.ImageCollection("UCSB-CHG/CHIRPS/DAILY")
var shortList = ee.List.sequence(1,26)
var longList = (ee.List.repeat(shortList,3)).flatten()

var mapped = longList.map(function(i){
  return chirpsColl.set('DayOfRange',longList)

I was thinking perhaps I had to iterate over it? The reduceColumns also looks useful, but I'm not entirely sure how to use that with properties.


When mapping over a list or collection, each part of the mapping will take the current value, something you are not doing in your sample script.

I think your specific goal of adding a relative day to you collection is best done when mapping over the images. You can get the absolute day of the year from each image metadata and get the relative day of the year for your collection from the start day of year:

var startDayOrYear = 3;
var chirpsColl = ee.ImageCollection("UCSB-CHG/CHIRPS/DAILY")

var addedDayRange = chirpsColl.map(function(image){
  // get the actual day of the year of the image
  var DayOfYear = ee.Date(image.get('system:time_start')).getRelative('day', 'year');
  // subtract 2 so the DayOrRange will start at 1
  var DayOfRange = DayOfYear.subtract(startDayOrYear-2);
  return image.set('DayOfRange', DayOfRange);


Link script

  • Thanks a lot for the help! What do you mean with taking the current value? Is it not possible to add the day from the list by matching the positions? This solution works for date ranges that stay within one year, but if the date range extends into the next, the results for the days after the 31st of December return as negative. I probably should have added that issue in my example script... Thanks again! – IskJon Mar 26 at 13:17
  • You can map over that list, but because you have repeated values, you cannot find the corresponding image to value in the list you are mapping over. You will probably have to construct a list of years with a list of dayOfYears and flatten afterwards. In that way you are able to find the corresponding image to the mapped value. – Kuik Mar 26 at 13:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.