0

I have calculated the monthly total rainfall for a region using CHIRPS data and would like to add this data onto a graph. At the moment it works for one single year, when I set "month" as the xProperty. However, when I sum the images by month in this function below, the system:time_start variable is lost, meaning I cannot add images from multiple years to a graph whilst showing the date correctly along the x-axis. I believe I need to copy over the system:time_start variable from the first image of the month to the summed image in this function but I am not sure how to do this.

var lt_precip = ee.ImageCollection.fromImages(
      years.map(function (y) {
        return months.map(function (m) {
          return precipitation.filter(ee.Filter.calendarRange(y, y, 'year'))
                    .filter(ee.Filter.calendarRange(m, m, 'month'))
                    .sum()
                    .set('year', y)
                    .set('month', m)
          });
      }).flatten());
print("lt_precip",lt_precip); 

Please find a full link to the code here: https://code.earthengine.google.com/43c0eebd26ac7a22c33f7a6ef2160ee4.

1 Answer 1

1

You are right about the need to copy the 'system:time_start' from the first image. This is one way to do it:

var lt_precip = ee.ImageCollection.fromImages(
      years.map(function (y) {
        return months.map(function (m) {
          var collection = precipitation.filter(ee.Filter.calendarRange(y, y, 'year'))
                    .filter(ee.Filter.calendarRange(m, m, 'month'));
          return collection
                    .sum()
                    .set('year', y)
                    .set('month', m)
                    .copyProperties(collection.first(),['system:time_start'])
          });
      }).flatten());

https://code.earthengine.google.com/27c369fd5e45b99a405f88189170caa9

1
  • This works perfectly, thank you
    – Simba06
    Commented Sep 7, 2023 at 11:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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