0

I am doing some GDD data analysis for a project and am having trouble coming up with a way to effectively analyze a specific time of the season over multiple years.

What I am trying to do is find what areas accumulate GDD and what areas don't during a critical period of fruit production over a period of multiple years.

I have the code below (which does the calculations for GDD), but i am stuck on how to run that calculation for each filter date that I have set (04-15-xx, 05-15-xx) and then either sum or average the image outputs.

This works for an individual year (by replacing ".map(ClipToCol)" with the filterDate function, but i want to average or sum multiple years.

Ideas?

// This function clips images to the ROI feature collection
var clipToCol = function(image){
  return image.clip(geometry);
};

var dataset = ee.ImageCollection('MODIS/006/MYD11A1')
                               .map(clipToCol);

var landSurfaceTemperature = dataset.select(['LST_Day_1km', 'LST_Night_1km']);

// According to: https://gis.stackexchange.com/questions/307548/getting-temperature-data-of-given-point-using-modis-lst-data
// map over the image collection and use server side functions
var tempToFahr = landSurfaceTemperature.map(function(image){
  var props = image.toDictionary(image.propertyNames());
  var Fahr = (image.multiply(0.02).subtract(273.15)).multiply(1.8).add(32);
  // Mask where one of Night or day temperature has no data
  var FahrMasks = Fahr.updateMask(Fahr.select('LST_Day_1km')).updateMask(Fahr.select('LST_Night_1km'));
  // we assume that the night temperature is the min temp, and the day temperature is the max temperature
  var meanFahr = FahrMasks.reduce('mean').rename('meanTemp');
  // Calculate the GGD and make all the negative values 0 (see: https://en.wikipedia.org/wiki/Growing_degree-day)
  var GDD = meanFahr.subtract(52.5).rename('GDD');
  var GDDnonNeg = GDD.where(GDD.lt(0), 0).rename('GDDnonNeg');
  return ee.Image(Fahr.addBands([meanFahr, GDD, GDDnonNeg]).setMulti(props));
});

// calculate the sum of GGD values
var summed = tempToFahr.select('GDDnonNeg').sum().rename('summedGDD');

var landSurfaceTemperatureVis = {
  min: 0,
  max: 100,
  bands: ['LST_Day_1km'],
  palette: [
    '040274', '040281', '0502a3', '0502b8', '0502ce', '0502e6',
    '0602ff', '235cb1', '307ef3', '269db1', '30c8e2', '32d3ef',
    '3be285', '3ff38f', '86e26f', '3ae237', 'b5e22e', 'd6e21f',
    'fff705', 'ffd611', 'ffb613', 'ff8b13', 'ff6e08', 'ff500d',
    'ff0000', 'de0101', 'c21301', 'a71001', '911003'
  ],
};
PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Joey Roses
  • 71
  • 1
  • 8

1 Answers1

2

If I understand you well, you want to repeat the same operation, over different time periods? Let's say you want to do this per year, I would do it along this way:

  1. Add a year property in your initial ImageCollection
  2. Extract a dictionnary of the years in the ImageCollection
  3. Now, map this dictionnary over your function of interest:
    • filter ImageCollection for that year
    • do your operation
    • eventually, rename bands, adding year info
  4. Result of (3) is a list of images. Turn it into an ImageColleciton, or multi-band image

Using your code (not reproduced), here is how I woudl do that:

// 1. add years in each image
var tempToFahr_Y  = tempToFahr.map(function(f) {
  var date = ee.Date(f.get("system:time_start"))
  var year=  date.format("Y")
  return f.set({date: date, year: year})
})


// 2. get years in data
var years_list = tempToFahr_Y.reduceColumns(ee.Reducer.frequencyHistogram(), ["year"]).get("histogram")
var years_dic = ee.Dictionary(years_list).keys()

// 3. now map over the years dic
var tempToFahr_Y_sum = years_dic.map(function(x) { 
  var res= tempToFahr_Y.filter(ee.Filter.eq("year", x))
                  .select('GDDnonNeg').sum();
  var res_name = ee.Image(res).rename(ee.String("summedGDD_").cat(ee.String(x)))
  return res_name
})

// 4. into one imageCollection
var tempToFahr_Y_sum1 = ee.ImageCollection.fromImages(tempToFahr_Y_sum)
print(tempToFahr_Y_sum1)
Matifou
  • 2,011
  • 1
  • 21
  • 43
  • Thank you for the response!

    I am looking to filter a very specific period of months over a period of multiple years.

    So what that looks like as a date format would be:

    2013: 04-15-13, 06-15-13 2014: 04-15-14, 06-15-14 2015: 04-15-15, 06-15-15

    I want to do the GDD calculation for each of those date ranges, then the next step is summing or averaging those output images into a single image that I can then overlay in google earth.

    The reasoning being i want to find what temperature does in specific areas during a specific time of year over multiple years.

    – Joey Roses Apr 19 '19 at 13:50
  • So this code seems to be doing mainly what you want, except for the specific date filtering, which you can add as one more step!? – Matifou Apr 19 '19 at 15:40