0

I am trying to generate a raster where each pixel will show a trend of days exceeding a particular threshold of maximum temperature in GEE. I have calculated the number of days exceeding the threshold of maximum temperature for each year. I have written the code below but I think I am wrong somewhere.

var threshold = 313.15; // Threshold temperature in Kelvin

// Filter the data for the month of April and for the years 2011-2020
var temperatureApril = ee.ImageCollection('ECMWF/ERA5/DAILY')
  .select('maximum_2m_air_temperature')
  .filter(ee.Filter.calendarRange(4, 4, 'month'))
  .filter(ee.Filter.calendarRange(2011, 2020, 'year'))
  .map(function(image) {
    var mask = image.select('maximum_2m_air_temperature').gte(threshold);
    return image.select('maximum_2m_air_temperature').gte(threshold)
        .updateMask(mask)
        .clip(table);
  });

// Print the filtered collection
print('Filtered temperature for April and above threshold:', temperatureApril);
// Function to calculate the sum of days exceeding the threshold for each year
var calculateSumForYear = function(year) {
  var filteredByYear = temperatureApril.filter(ee.Filter.calendarRange(year, year, 'year'));
  var sumForYear = filteredByYear.count();
  return sumForYear.set('year', year);
};

// Calculate the sum of days exceeding the threshold for each year
var years = ee.List.sequence(2011, 2020);
var sumPerYear = ee.ImageCollection.fromImages(years.map(calculateSumForYear));

// Print the sum of days exceeding the threshold for each year
print('Count of days exceeding the threshold for each year:', sumPerYear);

I would then like to do a trend for days exceeding the threshold over the years (2011-2020) by using the Mankendall method.

1 Answer 1

0

If you are trying to generate a raster where each pixel will show a trend of days exceeding a particular threshold of maximum temperature in GEE, your approach by using that mask is not entirely correct. Remember that gte method return 1 when the condition is met and zero when it is not so, the count it is automatically done by using sum method for complete Image collection where threshold is reached (only 1 and 0). Following script was used for producing a raster where each pixel shows a trend of days exceeding 313.15 ºK. Complete code can be obtained here.

var threshold = 313.15; // Threshold temperature in Kelvin

// Filter the data for the month of April and for the years 2011-2020
var temperatureApril = ee.ImageCollection('ECMWF/ERA5/DAILY')
  .select('maximum_2m_air_temperature')
  .filter(ee.Filter.calendarRange(4, 4, 'month'))
  .filter(ee.Filter.calendarRange(2011, 2020, 'year'))
  .map(function(image) {
    return image.select('maximum_2m_air_temperature')
        .clip(table);
  });

var colThreshold = temperatureApril.map(function (image){
  
  var thresholdImage = image.gte(threshold);
  
  return thresholdImage;

});

Map.centerObject(table, 7);

print(colThreshold);

var count = ee.ImageCollection(colThreshold).sum();

Map.addLayer(count, imageVisParam, 'count');

After running it for an arbitrary area in India, I got following result. Red pixel in below picture (bottom of it) points out that there are 163 days (maximum possible 300 days) exceeding the threshold of 313.15 ºK. Areas with fewer days over the threshold are expressed with bluer colors.

enter image description here

1
  • Thank you for ypur help @xunilk. The code you have suggested gives only the sum of the pixels> threshold for 10 years total (300 days). I wanted to do the sum of the pixels greater than the threshold for each year for the month of april. So, for april I would get 10 layers or bands where each layer would be a sum of the pixels>threshold. And, then I need to calculate the trend using man kendall method. Commented Oct 8, 2023 at 9:37

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.